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" |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 27 | |
| 28 | #include "fw/best-route-strategy.hpp" |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 29 | #include "fw/forwarder.hpp" |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 30 | #include "table/cs-policy-lru.hpp" |
| 31 | #include "table/cs-policy-priority-fifo.hpp" |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 32 | |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 33 | #include "tests/test-common.hpp" |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 34 | #include "tests/check-typeid.hpp" |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 35 | #include "tests/daemon/global-io-fixture.hpp" |
| 36 | #include "tests/daemon/fw/dummy-strategy.hpp" |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 37 | |
| 38 | namespace nfd { |
| 39 | namespace tests { |
| 40 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 41 | class TablesConfigSectionFixture : public GlobalIoFixture |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 42 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 43 | protected: |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 44 | TablesConfigSectionFixture() |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 45 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 46 | DummyStrategy::registerAs(strategyP); |
| 47 | DummyStrategy::registerAs(strategyP1); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 48 | // strategyP1Marker is NOT registered |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 49 | DummyStrategy::registerAs(strategyQ); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 53 | runConfig(const std::string& config, bool isDryRun) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 54 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 55 | ConfigFile cf; |
| 56 | tablesConfig.setConfigFile(cf); |
| 57 | cf.parse(config, isDryRun, "dummy-config"); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 58 | } |
| 59 | |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 60 | protected: |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 61 | FaceTable faceTable; |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 62 | Forwarder forwarder{faceTable}; |
| 63 | Cs& cs{forwarder.getCs()}; |
| 64 | StrategyChoice& strategyChoice{forwarder.getStrategyChoice()}; |
| 65 | NetworkRegionTable& networkRegionTable{forwarder.getNetworkRegionTable()}; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 66 | |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 67 | TablesConfigSection tablesConfig{forwarder}; |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 68 | |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 69 | const Name defaultStrategy = fw::BestRouteStrategy::getStrategyName(); |
| 70 | const Name strategyP = Name("/tables-config-section-strategy-P").appendVersion(2); |
| 71 | const Name strategyP1 = "/tables-config-section-strategy-P/v=1"; |
| 72 | const Name strategyP1Marker = "/tables-config-section-strategy-P/%FD%01"; |
| 73 | const Name strategyQ = Name("/tables-config-section-strategy-Q").appendVersion(2); |
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 | |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 165 | runConfig(CONFIG, false); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 166 | cs::Policy* currentPolicy = cs.getPolicy(); |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 167 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | BOOST_AUTO_TEST_CASE(Known) |
| 171 | { |
| 172 | const std::string CONFIG = R"CONFIG( |
| 173 | tables |
| 174 | { |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 175 | cs_policy priority_fifo |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 176 | } |
| 177 | )CONFIG"; |
| 178 | |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 179 | runConfig(CONFIG, true); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 180 | cs::Policy* currentPolicy = cs.getPolicy(); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 181 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy); |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 182 | |
| 183 | runConfig(CONFIG, false); |
| 184 | currentPolicy = cs.getPolicy(); |
| 185 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 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: |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 206 | CsUnsolicitedPolicyFixture() |
| 207 | { |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 208 | forwarder.setUnsolicitedDataPolicy(make_unique<fw::AdmitNetworkUnsolicitedDataPolicy>()); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 209 | } |
| 210 | }; |
| 211 | |
| 212 | BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture) |
| 213 | |
| 214 | BOOST_AUTO_TEST_CASE(NoSection) |
| 215 | { |
| 216 | tablesConfig.ensureConfigured(); |
| 217 | |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 218 | auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 219 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 220 | } |
| 221 | |
| 222 | BOOST_AUTO_TEST_CASE(Default) |
| 223 | { |
| 224 | const std::string CONFIG = R"CONFIG( |
| 225 | tables |
| 226 | { |
| 227 | } |
| 228 | )CONFIG"; |
| 229 | |
| 230 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 231 | auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 232 | NFD_CHECK_TYPEID_NE(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 233 | |
| 234 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 235 | currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 236 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 237 | } |
| 238 | |
| 239 | BOOST_AUTO_TEST_CASE(Known) |
| 240 | { |
| 241 | const std::string CONFIG = R"CONFIG( |
| 242 | tables |
| 243 | { |
| 244 | cs_unsolicited_policy admit-all |
| 245 | } |
| 246 | )CONFIG"; |
| 247 | |
| 248 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 249 | auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 250 | NFD_CHECK_TYPEID_NE(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy); |
| 251 | |
| 252 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 253 | currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 254 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy); |
| 255 | } |
| 256 | |
| 257 | BOOST_AUTO_TEST_CASE(Unknown) |
| 258 | { |
| 259 | const std::string CONFIG = R"CONFIG( |
| 260 | tables |
| 261 | { |
| 262 | cs_unsolicited_policy unknown |
| 263 | } |
| 264 | )CONFIG"; |
| 265 | |
| 266 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 267 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
| 268 | } |
| 269 | |
| 270 | BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy |
| 271 | |
| 272 | BOOST_AUTO_TEST_SUITE(StrategyChoice) |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 273 | |
| 274 | BOOST_AUTO_TEST_CASE(Unversioned) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 275 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 276 | const std::string CONFIG = R"CONFIG( |
| 277 | tables |
| 278 | { |
| 279 | strategy_choice |
| 280 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 281 | / /tables-config-section-strategy-P |
| 282 | /a /tables-config-section-strategy-Q |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 286 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 287 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
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& rootStrategy = strategyChoice.findEffectiveStrategy("/"); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 290 | BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), defaultStrategy); |
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& aStrategy = strategyChoice.findEffectiveStrategy("/a"); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 293 | BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), defaultStrategy); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 296 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 297 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 298 | fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 299 | BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 300 | NFD_CHECK_TYPEID_EQUAL(rootStrategy, DummyStrategy); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 301 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 302 | fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 303 | BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), strategyQ.getPrefix(-1)); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 304 | NFD_CHECK_TYPEID_EQUAL(aStrategy, DummyStrategy); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 308 | BOOST_AUTO_TEST_CASE(Versioned) |
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 | const std::string CONFIG = R"CONFIG( |
| 311 | tables |
| 312 | { |
| 313 | strategy_choice |
| 314 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 315 | /test/latest /tables-config-section-strategy-P |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 316 | /test/old /tables-config-section-strategy-P/v=1 |
| 317 | /test/marker /tables-config-section-strategy-P/%FD%01 |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 321 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 322 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 323 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 324 | fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest"); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 325 | BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), defaultStrategy); |
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& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old"); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 328 | BOOST_CHECK_EQUAL(testOldStrategy.getInstanceName(), defaultStrategy); |
| 329 | |
| 330 | fw::Strategy& testMarkerStrategy = strategyChoice.findEffectiveStrategy("/test/marker"); |
| 331 | BOOST_CHECK_EQUAL(testMarkerStrategy.getInstanceName(), defaultStrategy); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 334 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 335 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 336 | fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 337 | BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 338 | NFD_CHECK_TYPEID_EQUAL(testLatestStrategy, DummyStrategy); |
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); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 342 | NFD_CHECK_TYPEID_EQUAL(testOldStrategy, DummyStrategy); |
| 343 | |
| 344 | fw::Strategy& testMarkerStrategy = strategyChoice.findEffectiveStrategy("/test/marker"); |
| 345 | BOOST_CHECK_EQUAL(testMarkerStrategy.getInstanceName(), strategyP1Marker); |
| 346 | NFD_CHECK_TYPEID_EQUAL(testMarkerStrategy, DummyStrategy); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 350 | BOOST_AUTO_TEST_CASE(NonExisting) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 351 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 352 | const std::string CONFIG = R"CONFIG( |
| 353 | tables |
| 354 | { |
| 355 | strategy_choice |
| 356 | { |
| 357 | / /localhost/nfd/strategy/test-doesnotexist |
| 358 | } |
| 359 | } |
| 360 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 361 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 362 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 363 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 366 | BOOST_AUTO_TEST_CASE(MissingPrefix) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 367 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 368 | const std::string CONFIG = R"CONFIG( |
| 369 | tables |
| 370 | { |
| 371 | strategy_choice |
| 372 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 373 | /tables-config-section-strategy-P |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 377 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 378 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 379 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 382 | BOOST_AUTO_TEST_CASE(Duplicate) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 383 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 384 | const std::string CONFIG = R"CONFIG( |
| 385 | tables |
| 386 | { |
| 387 | strategy_choice |
| 388 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 389 | / /tables-config-section-strategy-P |
| 390 | /a /tables-config-section-strategy-Q |
| 391 | / /tables-config-section-strategy-Q |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 395 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 396 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 397 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Junxiao Shi | 593887c | 2016-12-24 02:39:29 +0000 | [diff] [blame] | 400 | BOOST_AUTO_TEST_CASE(UnacceptableParameters) |
| 401 | { |
| 402 | const std::string CONFIG = R"CONFIG( |
| 403 | tables |
| 404 | { |
| 405 | strategy_choice |
| 406 | { |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 407 | / /localhost/nfd/strategy/best-route/v=5/param |
Junxiao Shi | 593887c | 2016-12-24 02:39:29 +0000 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | )CONFIG"; |
| 411 | |
| 412 | BOOST_CHECK_NO_THROW(runConfig(CONFIG, true)); |
| 413 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
| 414 | } |
| 415 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 416 | BOOST_AUTO_TEST_SUITE_END() // StrategyChoice |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 417 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 418 | BOOST_AUTO_TEST_SUITE(NetworkRegion) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 419 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 420 | BOOST_AUTO_TEST_CASE(Basic) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 421 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 422 | const std::string CONFIG = R"CONFIG( |
| 423 | tables |
| 424 | { |
| 425 | network_region |
| 426 | { |
| 427 | /test/regionA |
| 428 | /test/regionB/component |
| 429 | } |
| 430 | } |
| 431 | )CONFIG"; |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 432 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 433 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 434 | BOOST_CHECK_EQUAL(networkRegionTable.size(), 0); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 435 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 436 | BOOST_CHECK(networkRegionTable.find("/test/regionA") == networkRegionTable.end()); |
| 437 | BOOST_CHECK(networkRegionTable.find("/test/regionB/component") == networkRegionTable.end()); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 438 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 439 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 440 | BOOST_CHECK_EQUAL(networkRegionTable.size(), 2); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 441 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 442 | BOOST_CHECK(networkRegionTable.find("/test/regionA") != networkRegionTable.end()); |
| 443 | BOOST_CHECK(networkRegionTable.find("/test/regionB/component") != networkRegionTable.end()); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 444 | } |
| 445 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 446 | BOOST_AUTO_TEST_CASE(Reload) |
| 447 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 448 | const std::string CONFIG1 = R"CONFIG( |
| 449 | tables |
| 450 | { |
| 451 | network_region |
| 452 | { |
| 453 | /some/region |
| 454 | } |
| 455 | } |
| 456 | )CONFIG"; |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 457 | |
| 458 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 459 | BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end()); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 460 | |
| 461 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 462 | BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end()); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 463 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 464 | const std::string CONFIG2 = R"CONFIG( |
| 465 | tables |
| 466 | { |
| 467 | network_region |
| 468 | { |
| 469 | /different/region |
| 470 | } |
| 471 | } |
| 472 | )CONFIG"; |
| 473 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 474 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true)); |
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 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 479 | BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end()); |
| 480 | BOOST_CHECK(networkRegionTable.find("/different/region") != networkRegionTable.end()); |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | BOOST_AUTO_TEST_SUITE_END() // NetworkRegion |
| 484 | |
Junxiao Shi | 0cc125c | 2016-08-25 21:50:04 +0000 | [diff] [blame] | 485 | BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 486 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 487 | |
| 488 | } // namespace tests |
| 489 | } // namespace nfd |