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 | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, 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 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 38 | namespace nfd::tests { |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 39 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 40 | class TablesConfigSectionFixture : public GlobalIoFixture |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 41 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 42 | protected: |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 43 | TablesConfigSectionFixture() |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 44 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 45 | DummyStrategy::registerAs(strategyP); |
| 46 | DummyStrategy::registerAs(strategyP1); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 47 | // strategyP1Marker is NOT registered |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 48 | DummyStrategy::registerAs(strategyQ); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 52 | runConfig(const std::string& config, bool isDryRun) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 53 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 54 | ConfigFile cf; |
| 55 | tablesConfig.setConfigFile(cf); |
| 56 | cf.parse(config, isDryRun, "dummy-config"); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 57 | } |
| 58 | |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 59 | protected: |
Davide Pesavento | a4abfb0 | 2019-10-06 16:02:56 -0400 | [diff] [blame] | 60 | FaceTable faceTable; |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 61 | Forwarder forwarder{faceTable}; |
| 62 | Cs& cs{forwarder.getCs()}; |
| 63 | StrategyChoice& strategyChoice{forwarder.getStrategyChoice()}; |
| 64 | NetworkRegionTable& networkRegionTable{forwarder.getNetworkRegionTable()}; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 65 | |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 66 | TablesConfigSection tablesConfig{forwarder}; |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 67 | |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 68 | const Name defaultStrategy = fw::BestRouteStrategy::getStrategyName(); |
| 69 | const Name strategyP = Name("/tables-config-section-strategy-P").appendVersion(2); |
| 70 | const Name strategyP1 = "/tables-config-section-strategy-P/v=1"; |
| 71 | const Name strategyP1Marker = "/tables-config-section-strategy-P/%FD%01"; |
| 72 | const Name strategyQ = Name("/tables-config-section-strategy-Q").appendVersion(2); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 73 | }; |
| 74 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 75 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 76 | BOOST_FIXTURE_TEST_SUITE(TestTablesConfigSection, TablesConfigSectionFixture) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 77 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 78 | BOOST_AUTO_TEST_SUITE(CsMaxPackets) |
| 79 | |
| 80 | BOOST_AUTO_TEST_CASE(NoSection) |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 81 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 82 | const size_t initialLimit = cs.getLimit(); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 83 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 84 | tablesConfig.ensureConfigured(); |
| 85 | BOOST_CHECK_NE(cs.getLimit(), initialLimit); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 86 | } |
| 87 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 88 | BOOST_AUTO_TEST_CASE(Default) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 89 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 90 | const std::string CONFIG = R"CONFIG( |
| 91 | tables |
| 92 | { |
| 93 | } |
| 94 | )CONFIG"; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 95 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 96 | const size_t initialLimit = cs.getLimit(); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 97 | |
| 98 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 99 | BOOST_CHECK_EQUAL(cs.getLimit(), initialLimit); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 100 | |
| 101 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 102 | BOOST_CHECK_NE(cs.getLimit(), initialLimit); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 103 | } |
| 104 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 105 | BOOST_AUTO_TEST_CASE(Valid) |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 106 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 107 | const std::string CONFIG = R"CONFIG( |
| 108 | tables |
| 109 | { |
| 110 | cs_max_packets 101 |
| 111 | } |
| 112 | )CONFIG"; |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 113 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 114 | BOOST_REQUIRE_NE(cs.getLimit(), 101); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 115 | |
| 116 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 117 | BOOST_CHECK_NE(cs.getLimit(), 101); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 118 | |
| 119 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 120 | BOOST_CHECK_EQUAL(cs.getLimit(), 101); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 121 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 122 | tablesConfig.ensureConfigured(); |
| 123 | BOOST_CHECK_EQUAL(cs.getLimit(), 101); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 124 | } |
| 125 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 126 | BOOST_AUTO_TEST_CASE(MissingValue) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 127 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 128 | const std::string CONFIG = R"CONFIG( |
| 129 | tables |
| 130 | { |
| 131 | cs_max_packets |
| 132 | } |
| 133 | )CONFIG"; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 134 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 135 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 136 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 137 | } |
| 138 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 139 | BOOST_AUTO_TEST_CASE(InvalidValue) |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 140 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 141 | const std::string CONFIG = R"CONFIG( |
| 142 | tables |
| 143 | { |
| 144 | cs_max_packets invalid |
| 145 | } |
| 146 | )CONFIG"; |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 147 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 148 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 149 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
Steve DiBenedetto | 9bcc88f | 2014-07-08 09:52:13 -0600 | [diff] [blame] | 150 | } |
| 151 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 152 | BOOST_AUTO_TEST_SUITE_END() // CsMaxPackets |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 153 | |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 154 | BOOST_AUTO_TEST_SUITE(CsPolicy) |
| 155 | |
| 156 | BOOST_AUTO_TEST_CASE(Default) |
| 157 | { |
| 158 | const std::string CONFIG = R"CONFIG( |
| 159 | tables |
| 160 | { |
| 161 | } |
| 162 | )CONFIG"; |
| 163 | |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 164 | runConfig(CONFIG, false); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 165 | cs::Policy* currentPolicy = cs.getPolicy(); |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 166 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | BOOST_AUTO_TEST_CASE(Known) |
| 170 | { |
| 171 | const std::string CONFIG = R"CONFIG( |
| 172 | tables |
| 173 | { |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 174 | cs_policy priority_fifo |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 175 | } |
| 176 | )CONFIG"; |
| 177 | |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 178 | runConfig(CONFIG, true); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 179 | cs::Policy* currentPolicy = cs.getPolicy(); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 180 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy); |
Chavoosh Ghasemi | 32e7609 | 2018-09-10 14:51:33 -0700 | [diff] [blame] | 181 | |
| 182 | runConfig(CONFIG, false); |
| 183 | currentPolicy = cs.getPolicy(); |
| 184 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy); |
Junxiao Shi | b4a5acd | 2016-12-07 19:59:18 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | BOOST_AUTO_TEST_CASE(Unknown) |
| 188 | { |
| 189 | const std::string CONFIG = R"CONFIG( |
| 190 | tables |
| 191 | { |
| 192 | cs_policy unknown |
| 193 | } |
| 194 | )CONFIG"; |
| 195 | |
| 196 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 197 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
| 198 | } |
| 199 | |
| 200 | BOOST_AUTO_TEST_SUITE_END() // CsPolicy |
| 201 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 202 | class CsUnsolicitedPolicyFixture : public TablesConfigSectionFixture |
| 203 | { |
| 204 | protected: |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 205 | CsUnsolicitedPolicyFixture() |
| 206 | { |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 207 | forwarder.setUnsolicitedDataPolicy(make_unique<fw::AdmitNetworkUnsolicitedDataPolicy>()); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 208 | } |
| 209 | }; |
| 210 | |
| 211 | BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture) |
| 212 | |
| 213 | BOOST_AUTO_TEST_CASE(NoSection) |
| 214 | { |
| 215 | tablesConfig.ensureConfigured(); |
| 216 | |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 217 | auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 218 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 219 | } |
| 220 | |
| 221 | BOOST_AUTO_TEST_CASE(Default) |
| 222 | { |
| 223 | const std::string CONFIG = R"CONFIG( |
| 224 | tables |
| 225 | { |
| 226 | } |
| 227 | )CONFIG"; |
| 228 | |
| 229 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 230 | auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 231 | NFD_CHECK_TYPEID_NE(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 232 | |
| 233 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 234 | currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 235 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy); |
| 236 | } |
| 237 | |
| 238 | BOOST_AUTO_TEST_CASE(Known) |
| 239 | { |
| 240 | const std::string CONFIG = R"CONFIG( |
| 241 | tables |
| 242 | { |
| 243 | cs_unsolicited_policy admit-all |
| 244 | } |
| 245 | )CONFIG"; |
| 246 | |
| 247 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Davide Pesavento | 3db9807 | 2021-03-09 23:03:27 -0500 | [diff] [blame] | 248 | auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 249 | NFD_CHECK_TYPEID_NE(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy); |
| 250 | |
| 251 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
| 252 | currentPolicy = &forwarder.getUnsolicitedDataPolicy(); |
| 253 | NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy); |
| 254 | } |
| 255 | |
| 256 | BOOST_AUTO_TEST_CASE(Unknown) |
| 257 | { |
| 258 | const std::string CONFIG = R"CONFIG( |
| 259 | tables |
| 260 | { |
| 261 | cs_unsolicited_policy unknown |
| 262 | } |
| 263 | )CONFIG"; |
| 264 | |
| 265 | BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error); |
| 266 | BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error); |
| 267 | } |
| 268 | |
| 269 | BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy |
| 270 | |
| 271 | BOOST_AUTO_TEST_SUITE(StrategyChoice) |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 272 | |
| 273 | BOOST_AUTO_TEST_CASE(Unversioned) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 274 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 275 | const std::string CONFIG = R"CONFIG( |
| 276 | tables |
| 277 | { |
| 278 | strategy_choice |
| 279 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 280 | / /tables-config-section-strategy-P |
| 281 | /a /tables-config-section-strategy-Q |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 285 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 286 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 287 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 288 | fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/"); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 289 | BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), defaultStrategy); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 290 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 291 | fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a"); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 292 | BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), defaultStrategy); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 295 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
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& rootStrategy = strategyChoice.findEffectiveStrategy("/"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 298 | BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 299 | NFD_CHECK_TYPEID_EQUAL(rootStrategy, DummyStrategy); |
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 | fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 302 | BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), strategyQ.getPrefix(-1)); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 303 | NFD_CHECK_TYPEID_EQUAL(aStrategy, DummyStrategy); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 307 | BOOST_AUTO_TEST_CASE(Versioned) |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 308 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 309 | const std::string CONFIG = R"CONFIG( |
| 310 | tables |
| 311 | { |
| 312 | strategy_choice |
| 313 | { |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 314 | /test/latest /tables-config-section-strategy-P |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 315 | /test/old /tables-config-section-strategy-P/v=1 |
| 316 | /test/marker /tables-config-section-strategy-P/%FD%01 |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | )CONFIG"; |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 320 | |
Vince Lehman | 63ab1bb | 2015-09-04 17:06:58 -0500 | [diff] [blame] | 321 | BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true)); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 322 | { |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 323 | fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest"); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 324 | BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), defaultStrategy); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 325 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 326 | fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old"); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 327 | BOOST_CHECK_EQUAL(testOldStrategy.getInstanceName(), defaultStrategy); |
| 328 | |
| 329 | fw::Strategy& testMarkerStrategy = strategyChoice.findEffectiveStrategy("/test/marker"); |
| 330 | BOOST_CHECK_EQUAL(testMarkerStrategy.getInstanceName(), defaultStrategy); |
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_REQUIRE_NO_THROW(runConfig(CONFIG, false)); |
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 | fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 336 | BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1)); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 337 | NFD_CHECK_TYPEID_EQUAL(testLatestStrategy, DummyStrategy); |
Steve DiBenedetto | c0640f5 | 2014-11-03 15:55:43 -0700 | [diff] [blame] | 338 | |
Junxiao Shi | 9685cc5 | 2016-08-29 12:47:05 +0000 | [diff] [blame] | 339 | fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old"); |
Junxiao Shi | 0e4a1f1 | 2016-12-24 02:39:01 +0000 | [diff] [blame] | 340 | BOOST_CHECK_EQUAL(testOldStrategy.getInstanceName(), strategyP1); |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 341 | NFD_CHECK_TYPEID_EQUAL(testOldStrategy, DummyStrategy); |
| 342 | |
| 343 | fw::Strategy& testMarkerStrategy = strategyChoice.findEffectiveStrategy("/test/marker"); |
| 344 | BOOST_CHECK_EQUAL(testMarkerStrategy.getInstanceName(), strategyP1Marker); |
| 345 | NFD_CHECK_TYPEID_EQUAL(testMarkerStrategy, DummyStrategy); |
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 | { |
Eric Newberry | 7249fb4 | 2021-04-04 21:09:32 -0700 | [diff] [blame] | 406 | / /localhost/nfd/strategy/best-route/v=5/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 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 487 | } // namespace nfd::tests |