Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, 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" |
Junxiao Shi | a49a1ab | 2016-07-15 18:24:36 +0000 | [diff] [blame] | 33 | #include "../fw/dummy-strategy.hpp" |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 34 | |
| 35 | namespace nfd { |
| 36 | namespace tests { |
| 37 | |
| 38 | class TablesConfigSectionFixture : protected BaseFixture |
| 39 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 40 | protected: |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 41 | TablesConfigSectionFixture() |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 42 | : cs(forwarder.getCs()) |
| 43 | , strategyChoice(forwarder.getStrategyChoice()) |
| 44 | , networkRegionTable(forwarder.getNetworkRegionTable()) |
| 45 | , tablesConfig(forwarder) |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 46 | , strategyP("/tables-config-section-strategy-P/%FD%02") |
| 47 | , strategyP1("/tables-config-section-strategy-P/%FD%01") |
| 48 | , strategyQ("/tables-config-section-strategy-Q/%FD%02") |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 49 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 50 | DummyStrategy::registerAs(strategyP); |
| 51 | DummyStrategy::registerAs(strategyP1); |
| 52 | DummyStrategy::registerAs(strategyQ); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 56 | runConfig(const std::string& config, bool isDryRun) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 57 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 58 | ConfigFile cf; |
| 59 | tablesConfig.setConfigFile(cf); |
| 60 | cf.parse(config, isDryRun, "dummy-config"); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 61 | } |
| 62 | |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 63 | protected: |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 64 | Forwarder forwarder; |
| 65 | Cs& cs; |
| 66 | StrategyChoice& strategyChoice; |
| 67 | NetworkRegionTable& networkRegionTable; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 68 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 69 | TablesConfigSection tablesConfig; |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 70 | |
| 71 | const Name strategyP; |
| 72 | const Name strategyP1; |
| 73 | const Name strategyQ; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 74 | }; |
| 75 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 76 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 77 | BOOST_FIXTURE_TEST_SUITE(TestTablesConfigSection, TablesConfigSectionFixture) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 78 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 79 | BOOST_AUTO_TEST_SUITE(CsMaxPackets) |
| 80 | |
| 81 | BOOST_AUTO_TEST_CASE(NoSection) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 82 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 83 | const size_t initialLimit = cs.getLimit(); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 84 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 85 | tablesConfig.ensureConfigured(); |
| 86 | BOOST_CHECK_NE(cs.getLimit(), initialLimit); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 87 | } |
| 88 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 89 | BOOST_AUTO_TEST_CASE(Default) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 90 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 91 | const std::string CONFIG = R"CONFIG( |
| 92 | tables |
| 93 | { |
| 94 | } |
| 95 | )CONFIG"; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 96 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 97 | const size_t initialLimit = cs.getLimit(); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 98 | |
| 99 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 100 | BOOST_CHECK_EQUAL(cs.getLimit(), initialLimit); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 101 | |
| 102 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 103 | BOOST_CHECK_NE(cs.getLimit(), initialLimit); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 104 | } |
| 105 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 106 | BOOST_AUTO_TEST_CASE(Valid) |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 107 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 108 | const std::string CONFIG = R"CONFIG( |
| 109 | tables |
| 110 | { |
| 111 | cs_max_packets 101 |
| 112 | } |
| 113 | )CONFIG"; |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 114 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 115 | BOOST_REQUIRE_NE(cs.getLimit(), 101); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 116 | |
| 117 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 118 | BOOST_CHECK_NE(cs.getLimit(), 101); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 119 | |
| 120 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 121 | BOOST_CHECK_EQUAL(cs.getLimit(), 101); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 122 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 123 | tablesConfig.ensureConfigured(); |
| 124 | BOOST_CHECK_EQUAL(cs.getLimit(), 101); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 125 | } |
| 126 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 127 | BOOST_AUTO_TEST_CASE(MissingValue) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 128 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 129 | const std::string CONFIG = R"CONFIG( |
| 130 | tables |
| 131 | { |
| 132 | cs_max_packets |
| 133 | } |
| 134 | )CONFIG"; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 135 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 136 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 137 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 138 | } |
| 139 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 140 | BOOST_AUTO_TEST_CASE(InvalidValue) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 141 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 142 | const std::string CONFIG = R"CONFIG( |
| 143 | tables |
| 144 | { |
| 145 | cs_max_packets invalid |
| 146 | } |
| 147 | )CONFIG"; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 148 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 149 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 150 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 151 | } |
| 152 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 153 | BOOST_AUTO_TEST_SUITE_END() // CsMaxPackets |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 154 | |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 155 | BOOST_AUTO_TEST_SUITE(CsPolicy) |
| 156 | |
| 157 | BOOST_AUTO_TEST_CASE(Default) |
| 158 | { |
| 159 | const std::string CONFIG = R"CONFIG( |
| 160 | tables |
| 161 | { |
| 162 | } |
| 163 | )CONFIG"; |
| 164 | |
| 165 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 166 | cs::Policy* currentPolicy = cs.getPolicy(); |
| 167 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy); |
| 168 | } |
| 169 | |
| 170 | BOOST_AUTO_TEST_CASE(Known) |
| 171 | { |
| 172 | const std::string CONFIG = R"CONFIG( |
| 173 | tables |
| 174 | { |
| 175 | cs_policy lru |
| 176 | } |
| 177 | )CONFIG"; |
| 178 | |
| 179 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
| 180 | cs::Policy* currentPolicy = cs.getPolicy(); |
| 181 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy); |
| 182 | |
| 183 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 184 | currentPolicy = cs.getPolicy(); |
| 185 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy); |
| 186 | } |
| 187 | |
| 188 | BOOST_AUTO_TEST_CASE(Unknown) |
| 189 | { |
| 190 | const std::string CONFIG = R"CONFIG( |
| 191 | tables |
| 192 | { |
| 193 | cs_policy unknown |
| 194 | } |
| 195 | )CONFIG"; |
| 196 | |
| 197 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 198 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
| 199 | } |
| 200 | |
| 201 | BOOST_AUTO_TEST_SUITE_END() // CsPolicy |
| 202 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 203 | class CsUnsolicitedPolicyFixture : public TablesConfigSectionFixture |
| 204 | { |
| 205 | protected: |
| 206 | class DummyUnsolicitedDataPolicy : public fw::AdmitNetworkUnsolicitedDataPolicy |
| 207 | { |
| 208 | }; |
| 209 | |
| 210 | CsUnsolicitedPolicyFixture() |
| 211 | { |
| 212 | forwarder.setUnsolicitedDataPolicy(make_unique<DummyUnsolicitedDataPolicy>()); |
| 213 | } |
| 214 | }; |
| 215 | |
| 216 | BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture) |
| 217 | |
| 218 | BOOST_AUTO_TEST_CASE(NoSection) |
| 219 | { |
| 220 | tablesConfig.ensureConfigured(); |
| 221 | |
| 222 | fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 223 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 224 | } |
| 225 | |
| 226 | BOOST_AUTO_TEST_CASE(Default) |
| 227 | { |
| 228 | const std::string CONFIG = R"CONFIG( |
| 229 | tables |
| 230 | { |
| 231 | } |
| 232 | )CONFIG"; |
| 233 | |
| 234 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
| 235 | fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 236 | NFD_CHECK_TYPEID_NE(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 237 | |
| 238 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 239 | currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 240 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 241 | } |
| 242 | |
| 243 | BOOST_AUTO_TEST_CASE(Known) |
| 244 | { |
| 245 | const std::string CONFIG = R"CONFIG( |
| 246 | tables |
| 247 | { |
| 248 | cs_unsolicited_policy admit-all |
| 249 | } |
| 250 | )CONFIG"; |
| 251 | |
| 252 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
| 253 | fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 254 | NFD_CHECK_TYPEID_NE(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy); |
| 255 | |
| 256 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 257 | currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 258 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy); |
| 259 | } |
| 260 | |
| 261 | BOOST_AUTO_TEST_CASE(Unknown) |
| 262 | { |
| 263 | const std::string CONFIG = R"CONFIG( |
| 264 | tables |
| 265 | { |
| 266 | cs_unsolicited_policy unknown |
| 267 | } |
| 268 | )CONFIG"; |
| 269 | |
| 270 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 271 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
| 272 | } |
| 273 | |
| 274 | BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy |
| 275 | |
| 276 | BOOST_AUTO_TEST_SUITE(StrategyChoice) |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 277 | |
| 278 | BOOST_AUTO_TEST_CASE(Unversioned) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 279 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 280 | const std::string CONFIG = R"CONFIG( |
| 281 | tables |
| 282 | { |
| 283 | strategy_choice |
| 284 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 285 | / /tables-config-section-strategy-P |
| 286 | /a /tables-config-section-strategy-Q |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 290 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 291 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 292 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 293 | fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 294 | BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
| 295 | BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyQ.getPrefix(-1)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 296 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 297 | fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 298 | BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
| 299 | BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyQ.getPrefix(-1)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 302 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 303 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 304 | fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 305 | BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
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& aStrategy = strategyChoice.findEffectiveStrategy("/a"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 308 | BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), strategyQ.getPrefix(-1)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 312 | BOOST_AUTO_TEST_CASE(Versioned) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 313 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 314 | const std::string CONFIG = R"CONFIG( |
| 315 | tables |
| 316 | { |
| 317 | strategy_choice |
| 318 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 319 | /test/latest /tables-config-section-strategy-P |
| 320 | /test/old /tables-config-section-strategy-P/%FD%01 |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 324 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 325 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 326 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 327 | fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 328 | BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
| 329 | BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP1); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 330 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 331 | fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 332 | BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
| 333 | BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP1); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 336 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 337 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 338 | fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 339 | BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
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& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 342 | BOOST_CHECK_EQUAL(testOldStrategy.getInstanceName(), strategyP1); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 346 | BOOST_AUTO_TEST_CASE(NonExisting) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 347 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 348 | const std::string CONFIG = R"CONFIG( |
| 349 | tables |
| 350 | { |
| 351 | strategy_choice |
| 352 | { |
| 353 | / /localhost/nfd/strategy/test-doesnotexist |
| 354 | } |
| 355 | } |
| 356 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 357 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 358 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 359 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 362 | BOOST_AUTO_TEST_CASE(MissingPrefix) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 363 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 364 | const std::string CONFIG = R"CONFIG( |
| 365 | tables |
| 366 | { |
| 367 | strategy_choice |
| 368 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 369 | /tables-config-section-strategy-P |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 373 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 374 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 375 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 378 | BOOST_AUTO_TEST_CASE(Duplicate) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 379 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 380 | const std::string CONFIG = R"CONFIG( |
| 381 | tables |
| 382 | { |
| 383 | strategy_choice |
| 384 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 385 | / /tables-config-section-strategy-P |
| 386 | /a /tables-config-section-strategy-Q |
| 387 | / /tables-config-section-strategy-Q |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 391 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 392 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 393 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Junxiao Shi | 593887c | 2016-12-24 02:39:29 +0000 | [diff] [blame^] | 396 | BOOST_AUTO_TEST_CASE(UnacceptableParameters) |
| 397 | { |
| 398 | const std::string CONFIG = R"CONFIG( |
| 399 | tables |
| 400 | { |
| 401 | strategy_choice |
| 402 | { |
| 403 | / /localhost/nfd/strategy/best-route/%FD%01/param |
| 404 | } |
| 405 | } |
| 406 | )CONFIG"; |
| 407 | |
| 408 | BOOST_CHECK_NO_THROW(runConfig(CONFIG, true)); |
| 409 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
| 410 | } |
| 411 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 412 | BOOST_AUTO_TEST_SUITE_END() // StrategyChoice |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 413 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 414 | BOOST_AUTO_TEST_SUITE(NetworkRegion) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 415 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 416 | BOOST_AUTO_TEST_CASE(Basic) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 417 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 418 | const std::string CONFIG = R"CONFIG( |
| 419 | tables |
| 420 | { |
| 421 | network_region |
| 422 | { |
| 423 | /test/regionA |
| 424 | /test/regionB/component |
| 425 | } |
| 426 | } |
| 427 | )CONFIG"; |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 428 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 429 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 430 | BOOST_CHECK_EQUAL(networkRegionTable.size(), 0); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 431 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 432 | BOOST_CHECK(networkRegionTable.find("/test/regionA") == networkRegionTable.end()); |
| 433 | BOOST_CHECK(networkRegionTable.find("/test/regionB/component") == networkRegionTable.end()); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 434 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 435 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 436 | BOOST_CHECK_EQUAL(networkRegionTable.size(), 2); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 437 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 438 | BOOST_CHECK(networkRegionTable.find("/test/regionA") != networkRegionTable.end()); |
| 439 | BOOST_CHECK(networkRegionTable.find("/test/regionB/component") != networkRegionTable.end()); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 440 | } |
| 441 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 442 | BOOST_AUTO_TEST_CASE(Reload) |
| 443 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 444 | const std::string CONFIG1 = R"CONFIG( |
| 445 | tables |
| 446 | { |
| 447 | network_region |
| 448 | { |
| 449 | /some/region |
| 450 | } |
| 451 | } |
| 452 | )CONFIG"; |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 453 | |
| 454 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 455 | BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end()); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 456 | |
| 457 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false)); |
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 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 460 | const std::string CONFIG2 = R"CONFIG( |
| 461 | tables |
| 462 | { |
| 463 | network_region |
| 464 | { |
| 465 | /different/region |
| 466 | } |
| 467 | } |
| 468 | )CONFIG"; |
| 469 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 470 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 471 | BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end()); |
| 472 | BOOST_CHECK(networkRegionTable.find("/different/region") == networkRegionTable.end()); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 473 | |
| 474 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 475 | BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end()); |
| 476 | BOOST_CHECK(networkRegionTable.find("/different/region") != networkRegionTable.end()); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | BOOST_AUTO_TEST_SUITE_END() // NetworkRegion |
| 480 | |
Junxiao Shi | 0cc125c | 2016-08-25 21:50:04 +0000 | [diff] [blame] | 481 | BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 482 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 483 | |
| 484 | } // namespace tests |
| 485 | } // namespace nfd |