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