Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 2 | /* |
Davide Pesavento | 5809158 | 2021-03-05 19:02:48 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2021, Regents of the University of California, |
Spyridon Mastorakis | d0381c0 | 2015-02-19 10:29:41 -0800 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "mgmt/tables-config-section.hpp" |
| 27 | #include "fw/forwarder.hpp" |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 28 | #include "table/cs-policy-lru.hpp" |
| 29 | #include "table/cs-policy-priority-fifo.hpp" |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 30 | |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 31 | #include "tests/test-common.hpp" |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 32 | #include "tests/check-typeid.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 33 | #include "tests/daemon/global-io-fixture.hpp" |
| 34 | #include "tests/daemon/fw/dummy-strategy.hpp" |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 35 | |
| 36 | namespace nfd { |
| 37 | namespace tests { |
| 38 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 39 | class TablesConfigSectionFixture : public GlobalIoFixture |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 40 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 41 | protected: |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 42 | TablesConfigSectionFixture() |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 43 | : forwarder(faceTable) |
| 44 | , cs(forwarder.getCs()) |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 45 | , strategyChoice(forwarder.getStrategyChoice()) |
| 46 | , networkRegionTable(forwarder.getNetworkRegionTable()) |
| 47 | , tablesConfig(forwarder) |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 48 | , strategyP("/tables-config-section-strategy-P/%FD%02") |
| 49 | , strategyP1("/tables-config-section-strategy-P/%FD%01") |
| 50 | , strategyQ("/tables-config-section-strategy-Q/%FD%02") |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 51 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 52 | DummyStrategy::registerAs(strategyP); |
| 53 | DummyStrategy::registerAs(strategyP1); |
| 54 | DummyStrategy::registerAs(strategyQ); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 58 | runConfig(const std::string& config, bool isDryRun) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 59 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 60 | ConfigFile cf; |
| 61 | tablesConfig.setConfigFile(cf); |
| 62 | cf.parse(config, isDryRun, "dummy-config"); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 63 | } |
| 64 | |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 65 | protected: |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 66 | FaceTable faceTable; |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 67 | Forwarder forwarder; |
| 68 | Cs& cs; |
| 69 | StrategyChoice& strategyChoice; |
| 70 | NetworkRegionTable& networkRegionTable; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 71 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 72 | TablesConfigSection tablesConfig; |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 73 | |
| 74 | const Name strategyP; |
| 75 | const Name strategyP1; |
| 76 | const Name strategyQ; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 77 | }; |
| 78 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 79 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 80 | BOOST_FIXTURE_TEST_SUITE(TestTablesConfigSection, TablesConfigSectionFixture) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 81 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 82 | BOOST_AUTO_TEST_SUITE(CsMaxPackets) |
| 83 | |
| 84 | BOOST_AUTO_TEST_CASE(NoSection) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 85 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 86 | const size_t initialLimit = cs.getLimit(); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 87 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 88 | tablesConfig.ensureConfigured(); |
| 89 | BOOST_CHECK_NE(cs.getLimit(), initialLimit); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 90 | } |
| 91 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 92 | BOOST_AUTO_TEST_CASE(Default) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 93 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 94 | const std::string CONFIG = R"CONFIG( |
| 95 | tables |
| 96 | { |
| 97 | } |
| 98 | )CONFIG"; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 99 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 100 | const size_t initialLimit = cs.getLimit(); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 101 | |
| 102 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 103 | BOOST_CHECK_EQUAL(cs.getLimit(), initialLimit); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 104 | |
| 105 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 106 | BOOST_CHECK_NE(cs.getLimit(), initialLimit); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 107 | } |
| 108 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 109 | BOOST_AUTO_TEST_CASE(Valid) |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 110 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 111 | const std::string CONFIG = R"CONFIG( |
| 112 | tables |
| 113 | { |
| 114 | cs_max_packets 101 |
| 115 | } |
| 116 | )CONFIG"; |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 117 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 118 | BOOST_REQUIRE_NE(cs.getLimit(), 101); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 119 | |
| 120 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 121 | BOOST_CHECK_NE(cs.getLimit(), 101); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 122 | |
| 123 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 124 | BOOST_CHECK_EQUAL(cs.getLimit(), 101); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 125 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 126 | tablesConfig.ensureConfigured(); |
| 127 | BOOST_CHECK_EQUAL(cs.getLimit(), 101); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 128 | } |
| 129 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 130 | BOOST_AUTO_TEST_CASE(MissingValue) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 131 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 132 | const std::string CONFIG = R"CONFIG( |
| 133 | tables |
| 134 | { |
| 135 | cs_max_packets |
| 136 | } |
| 137 | )CONFIG"; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 138 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 139 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 140 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 141 | } |
| 142 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 143 | BOOST_AUTO_TEST_CASE(InvalidValue) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 144 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 145 | const std::string CONFIG = R"CONFIG( |
| 146 | tables |
| 147 | { |
| 148 | cs_max_packets invalid |
| 149 | } |
| 150 | )CONFIG"; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 151 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 152 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 153 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 154 | } |
| 155 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 156 | BOOST_AUTO_TEST_SUITE_END() // CsMaxPackets |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 157 | |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 158 | BOOST_AUTO_TEST_SUITE(CsPolicy) |
| 159 | |
| 160 | BOOST_AUTO_TEST_CASE(Default) |
| 161 | { |
| 162 | const std::string CONFIG = R"CONFIG( |
| 163 | tables |
| 164 | { |
| 165 | } |
| 166 | )CONFIG"; |
| 167 | |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 168 | runConfig(CONFIG, false); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 169 | cs::Policy* currentPolicy = cs.getPolicy(); |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 170 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | BOOST_AUTO_TEST_CASE(Known) |
| 174 | { |
| 175 | const std::string CONFIG = R"CONFIG( |
| 176 | tables |
| 177 | { |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 178 | cs_policy priority_fifo |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 179 | } |
| 180 | )CONFIG"; |
| 181 | |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 182 | runConfig(CONFIG, true); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 183 | cs::Policy* currentPolicy = cs.getPolicy(); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 184 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy); |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 185 | |
| 186 | runConfig(CONFIG, false); |
| 187 | currentPolicy = cs.getPolicy(); |
| 188 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | BOOST_AUTO_TEST_CASE(Unknown) |
| 192 | { |
| 193 | const std::string CONFIG = R"CONFIG( |
| 194 | tables |
| 195 | { |
| 196 | cs_policy unknown |
| 197 | } |
| 198 | )CONFIG"; |
| 199 | |
| 200 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 201 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
| 202 | } |
| 203 | |
| 204 | BOOST_AUTO_TEST_SUITE_END() // CsPolicy |
| 205 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 206 | class CsUnsolicitedPolicyFixture : public TablesConfigSectionFixture |
| 207 | { |
| 208 | protected: |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 209 | CsUnsolicitedPolicyFixture() |
| 210 | { |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 211 | forwarder.setUnsolicitedDataPolicy(make_unique<fw::AdmitNetworkUnsolicitedDataPolicy>()); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 212 | } |
| 213 | }; |
| 214 | |
| 215 | BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture) |
| 216 | |
| 217 | BOOST_AUTO_TEST_CASE(NoSection) |
| 218 | { |
| 219 | tablesConfig.ensureConfigured(); |
| 220 | |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 221 | auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 222 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 223 | } |
| 224 | |
| 225 | BOOST_AUTO_TEST_CASE(Default) |
| 226 | { |
| 227 | const std::string CONFIG = R"CONFIG( |
| 228 | tables |
| 229 | { |
| 230 | } |
| 231 | )CONFIG"; |
| 232 | |
| 233 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 234 | auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 235 | NFD_CHECK_TYPEID_NE(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 236 | |
| 237 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 238 | currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 239 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 240 | } |
| 241 | |
| 242 | BOOST_AUTO_TEST_CASE(Known) |
| 243 | { |
| 244 | const std::string CONFIG = R"CONFIG( |
| 245 | tables |
| 246 | { |
| 247 | cs_unsolicited_policy admit-all |
| 248 | } |
| 249 | )CONFIG"; |
| 250 | |
| 251 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 252 | auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 253 | NFD_CHECK_TYPEID_NE(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy); |
| 254 | |
| 255 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 256 | currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 257 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy); |
| 258 | } |
| 259 | |
| 260 | BOOST_AUTO_TEST_CASE(Unknown) |
| 261 | { |
| 262 | const std::string CONFIG = R"CONFIG( |
| 263 | tables |
| 264 | { |
| 265 | cs_unsolicited_policy unknown |
| 266 | } |
| 267 | )CONFIG"; |
| 268 | |
| 269 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 270 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
| 271 | } |
| 272 | |
| 273 | BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy |
| 274 | |
| 275 | BOOST_AUTO_TEST_SUITE(StrategyChoice) |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 276 | |
| 277 | BOOST_AUTO_TEST_CASE(Unversioned) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 278 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 279 | const std::string CONFIG = R"CONFIG( |
| 280 | tables |
| 281 | { |
| 282 | strategy_choice |
| 283 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 284 | / /tables-config-section-strategy-P |
| 285 | /a /tables-config-section-strategy-Q |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 289 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 290 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 291 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 292 | fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 293 | BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
| 294 | BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyQ.getPrefix(-1)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 295 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 296 | fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 297 | BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
| 298 | BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyQ.getPrefix(-1)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 301 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 302 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 303 | fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 304 | BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 305 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 306 | fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 307 | BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), strategyQ.getPrefix(-1)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 311 | BOOST_AUTO_TEST_CASE(Versioned) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 312 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 313 | const std::string CONFIG = R"CONFIG( |
| 314 | tables |
| 315 | { |
| 316 | strategy_choice |
| 317 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 318 | /test/latest /tables-config-section-strategy-P |
| 319 | /test/old /tables-config-section-strategy-P/%FD%01 |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 323 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 324 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 325 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 326 | fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 327 | BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
| 328 | BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP1); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 329 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 330 | fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 331 | BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
| 332 | BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP1); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 335 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 336 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 337 | fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 338 | BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 339 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 340 | fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 341 | BOOST_CHECK_EQUAL(testOldStrategy.getInstanceName(), strategyP1); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 345 | BOOST_AUTO_TEST_CASE(NonExisting) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 346 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 347 | const std::string CONFIG = R"CONFIG( |
| 348 | tables |
| 349 | { |
| 350 | strategy_choice |
| 351 | { |
| 352 | / /localhost/nfd/strategy/test-doesnotexist |
| 353 | } |
| 354 | } |
| 355 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 356 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 357 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 358 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 361 | BOOST_AUTO_TEST_CASE(MissingPrefix) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 362 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 363 | const std::string CONFIG = R"CONFIG( |
| 364 | tables |
| 365 | { |
| 366 | strategy_choice |
| 367 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 368 | /tables-config-section-strategy-P |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 372 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 373 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 374 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 377 | BOOST_AUTO_TEST_CASE(Duplicate) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 378 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 379 | const std::string CONFIG = R"CONFIG( |
| 380 | tables |
| 381 | { |
| 382 | strategy_choice |
| 383 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 384 | / /tables-config-section-strategy-P |
| 385 | /a /tables-config-section-strategy-Q |
| 386 | / /tables-config-section-strategy-Q |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 390 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 391 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 392 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Junxiao Shi | 593887c | 2016-12-24 02:39:29 +0000 | [diff] [blame] | 395 | BOOST_AUTO_TEST_CASE(UnacceptableParameters) |
| 396 | { |
| 397 | const std::string CONFIG = R"CONFIG( |
| 398 | tables |
| 399 | { |
| 400 | strategy_choice |
| 401 | { |
Davide Pesavento | 5809158 | 2021-03-05 19:02:48 -0500 | [diff] [blame] | 402 | / /localhost/nfd/strategy/best-route/%FD%05/param |
Junxiao Shi | 593887c | 2016-12-24 02:39:29 +0000 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | )CONFIG"; |
| 406 | |
| 407 | BOOST_CHECK_NO_THROW(runConfig(CONFIG, true)); |
| 408 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
| 409 | } |
| 410 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 411 | BOOST_AUTO_TEST_SUITE_END() // StrategyChoice |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 412 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 413 | BOOST_AUTO_TEST_SUITE(NetworkRegion) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 414 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 415 | BOOST_AUTO_TEST_CASE(Basic) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 416 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 417 | const std::string CONFIG = R"CONFIG( |
| 418 | tables |
| 419 | { |
| 420 | network_region |
| 421 | { |
| 422 | /test/regionA |
| 423 | /test/regionB/component |
| 424 | } |
| 425 | } |
| 426 | )CONFIG"; |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 427 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 428 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 429 | BOOST_CHECK_EQUAL(networkRegionTable.size(), 0); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 430 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 431 | BOOST_CHECK(networkRegionTable.find("/test/regionA") == networkRegionTable.end()); |
| 432 | BOOST_CHECK(networkRegionTable.find("/test/regionB/component") == networkRegionTable.end()); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 433 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 434 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 435 | BOOST_CHECK_EQUAL(networkRegionTable.size(), 2); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 436 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 437 | BOOST_CHECK(networkRegionTable.find("/test/regionA") != networkRegionTable.end()); |
| 438 | BOOST_CHECK(networkRegionTable.find("/test/regionB/component") != networkRegionTable.end()); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 439 | } |
| 440 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 441 | BOOST_AUTO_TEST_CASE(Reload) |
| 442 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 443 | const std::string CONFIG1 = R"CONFIG( |
| 444 | tables |
| 445 | { |
| 446 | network_region |
| 447 | { |
| 448 | /some/region |
| 449 | } |
| 450 | } |
| 451 | )CONFIG"; |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 452 | |
| 453 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 454 | BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end()); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 455 | |
| 456 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 457 | BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end()); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 458 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 459 | const std::string CONFIG2 = R"CONFIG( |
| 460 | tables |
| 461 | { |
| 462 | network_region |
| 463 | { |
| 464 | /different/region |
| 465 | } |
| 466 | } |
| 467 | )CONFIG"; |
| 468 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 469 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 470 | BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end()); |
| 471 | BOOST_CHECK(networkRegionTable.find("/different/region") == networkRegionTable.end()); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 472 | |
| 473 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 474 | BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end()); |
| 475 | BOOST_CHECK(networkRegionTable.find("/different/region") != networkRegionTable.end()); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | BOOST_AUTO_TEST_SUITE_END() // NetworkRegion |
| 479 | |
Junxiao Shi | 0cc125c | 2016-08-25 21:50:04 +0000 | [diff] [blame] | 480 | BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 481 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 482 | |
| 483 | } // namespace tests |
| 484 | } // namespace nfd |