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: |
| 209 | class DummyUnsolicitedDataPolicy : public fw::AdmitNetworkUnsolicitedDataPolicy |
| 210 | { |
| 211 | }; |
| 212 | |
| 213 | CsUnsolicitedPolicyFixture() |
| 214 | { |
| 215 | forwarder.setUnsolicitedDataPolicy(make_unique<DummyUnsolicitedDataPolicy>()); |
| 216 | } |
| 217 | }; |
| 218 | |
| 219 | BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture) |
| 220 | |
| 221 | BOOST_AUTO_TEST_CASE(NoSection) |
| 222 | { |
| 223 | tablesConfig.ensureConfigured(); |
| 224 | |
| 225 | fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 226 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 227 | } |
| 228 | |
| 229 | BOOST_AUTO_TEST_CASE(Default) |
| 230 | { |
| 231 | const std::string CONFIG = R"CONFIG( |
| 232 | tables |
| 233 | { |
| 234 | } |
| 235 | )CONFIG"; |
| 236 | |
| 237 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
| 238 | fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 239 | NFD_CHECK_TYPEID_NE(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 240 | |
| 241 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 242 | currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 243 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 244 | } |
| 245 | |
| 246 | BOOST_AUTO_TEST_CASE(Known) |
| 247 | { |
| 248 | const std::string CONFIG = R"CONFIG( |
| 249 | tables |
| 250 | { |
| 251 | cs_unsolicited_policy admit-all |
| 252 | } |
| 253 | )CONFIG"; |
| 254 | |
| 255 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
| 256 | fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 257 | NFD_CHECK_TYPEID_NE(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy); |
| 258 | |
| 259 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 260 | currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 261 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy); |
| 262 | } |
| 263 | |
| 264 | BOOST_AUTO_TEST_CASE(Unknown) |
| 265 | { |
| 266 | const std::string CONFIG = R"CONFIG( |
| 267 | tables |
| 268 | { |
| 269 | cs_unsolicited_policy unknown |
| 270 | } |
| 271 | )CONFIG"; |
| 272 | |
| 273 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 274 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
| 275 | } |
| 276 | |
| 277 | BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy |
| 278 | |
| 279 | BOOST_AUTO_TEST_SUITE(StrategyChoice) |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 280 | |
| 281 | BOOST_AUTO_TEST_CASE(Unversioned) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 282 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 283 | const std::string CONFIG = R"CONFIG( |
| 284 | tables |
| 285 | { |
| 286 | strategy_choice |
| 287 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 288 | / /tables-config-section-strategy-P |
| 289 | /a /tables-config-section-strategy-Q |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 293 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 294 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
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& rootStrategy = strategyChoice.findEffectiveStrategy("/"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 297 | BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
| 298 | BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyQ.getPrefix(-1)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 299 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 300 | fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 301 | BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
| 302 | BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyQ.getPrefix(-1)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 305 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 306 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 307 | fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 308 | BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 309 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 310 | fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 311 | BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), strategyQ.getPrefix(-1)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 315 | BOOST_AUTO_TEST_CASE(Versioned) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 316 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 317 | const std::string CONFIG = R"CONFIG( |
| 318 | tables |
| 319 | { |
| 320 | strategy_choice |
| 321 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 322 | /test/latest /tables-config-section-strategy-P |
| 323 | /test/old /tables-config-section-strategy-P/%FD%01 |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 327 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 328 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
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& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 331 | BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
| 332 | BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP1); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 333 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 334 | fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 335 | BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
| 336 | BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP1); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 339 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 340 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 341 | fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 342 | BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 343 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 344 | fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 345 | BOOST_CHECK_EQUAL(testOldStrategy.getInstanceName(), strategyP1); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 349 | BOOST_AUTO_TEST_CASE(NonExisting) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 350 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 351 | const std::string CONFIG = R"CONFIG( |
| 352 | tables |
| 353 | { |
| 354 | strategy_choice |
| 355 | { |
| 356 | / /localhost/nfd/strategy/test-doesnotexist |
| 357 | } |
| 358 | } |
| 359 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 360 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 361 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 362 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 365 | BOOST_AUTO_TEST_CASE(MissingPrefix) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 366 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 367 | const std::string CONFIG = R"CONFIG( |
| 368 | tables |
| 369 | { |
| 370 | strategy_choice |
| 371 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 372 | /tables-config-section-strategy-P |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 376 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 377 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 378 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 381 | BOOST_AUTO_TEST_CASE(Duplicate) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 382 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 383 | const std::string CONFIG = R"CONFIG( |
| 384 | tables |
| 385 | { |
| 386 | strategy_choice |
| 387 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 388 | / /tables-config-section-strategy-P |
| 389 | /a /tables-config-section-strategy-Q |
| 390 | / /tables-config-section-strategy-Q |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 394 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 395 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 396 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Junxiao Shi | 593887c | 2016-12-24 02:39:29 +0000 | [diff] [blame] | 399 | BOOST_AUTO_TEST_CASE(UnacceptableParameters) |
| 400 | { |
| 401 | const std::string CONFIG = R"CONFIG( |
| 402 | tables |
| 403 | { |
| 404 | strategy_choice |
| 405 | { |
Davide Pesavento | 5809158 | 2021-03-05 19:02:48 -0500 | [diff] [blame] | 406 | / /localhost/nfd/strategy/best-route/%FD%05/param |
Junxiao Shi | 593887c | 2016-12-24 02:39:29 +0000 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | )CONFIG"; |
| 410 | |
| 411 | BOOST_CHECK_NO_THROW(runConfig(CONFIG, true)); |
| 412 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
| 413 | } |
| 414 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 415 | BOOST_AUTO_TEST_SUITE_END() // StrategyChoice |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 416 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 417 | BOOST_AUTO_TEST_SUITE(NetworkRegion) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 418 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 419 | BOOST_AUTO_TEST_CASE(Basic) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 420 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 421 | const std::string CONFIG = R"CONFIG( |
| 422 | tables |
| 423 | { |
| 424 | network_region |
| 425 | { |
| 426 | /test/regionA |
| 427 | /test/regionB/component |
| 428 | } |
| 429 | } |
| 430 | )CONFIG"; |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 431 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 432 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 433 | BOOST_CHECK_EQUAL(networkRegionTable.size(), 0); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 434 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 435 | BOOST_CHECK(networkRegionTable.find("/test/regionA") == networkRegionTable.end()); |
| 436 | BOOST_CHECK(networkRegionTable.find("/test/regionB/component") == networkRegionTable.end()); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 437 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 438 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 439 | BOOST_CHECK_EQUAL(networkRegionTable.size(), 2); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 440 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 441 | BOOST_CHECK(networkRegionTable.find("/test/regionA") != networkRegionTable.end()); |
| 442 | BOOST_CHECK(networkRegionTable.find("/test/regionB/component") != networkRegionTable.end()); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 443 | } |
| 444 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 445 | BOOST_AUTO_TEST_CASE(Reload) |
| 446 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 447 | const std::string CONFIG1 = R"CONFIG( |
| 448 | tables |
| 449 | { |
| 450 | network_region |
| 451 | { |
| 452 | /some/region |
| 453 | } |
| 454 | } |
| 455 | )CONFIG"; |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 456 | |
| 457 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 458 | BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end()); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 459 | |
| 460 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 461 | BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end()); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 462 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 463 | const std::string CONFIG2 = R"CONFIG( |
| 464 | tables |
| 465 | { |
| 466 | network_region |
| 467 | { |
| 468 | /different/region |
| 469 | } |
| 470 | } |
| 471 | )CONFIG"; |
| 472 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 473 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true)); |
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 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 478 | BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end()); |
| 479 | BOOST_CHECK(networkRegionTable.find("/different/region") != networkRegionTable.end()); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | BOOST_AUTO_TEST_SUITE_END() // NetworkRegion |
| 483 | |
Junxiao Shi | 0cc125c | 2016-08-25 21:50:04 +0000 | [diff] [blame] | 484 | BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 485 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 486 | |
| 487 | } // namespace tests |
| 488 | } // namespace nfd |