blob: 4f07f78d9dfee255568eaaa45597077c595c271f [file] [log] [blame]
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -07002/*
Davide Pesavento58091582021-03-05 19:02:48 -05003 * Copyright (c) 2014-2021, Regents of the University of California,
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08004 * 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 DiBenedetto3a4f83d2014-06-02 14:58:54 -060010 *
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 Newberry7249fb42021-04-04 21:09:32 -070027
28#include "fw/best-route-strategy.hpp"
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060029#include "fw/forwarder.hpp"
Junxiao Shib4a5acd2016-12-07 19:59:18 +000030#include "table/cs-policy-lru.hpp"
31#include "table/cs-policy-priority-fifo.hpp"
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060032
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060033#include "tests/test-common.hpp"
Junxiao Shi9685cc52016-08-29 12:47:05 +000034#include "tests/check-typeid.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040035#include "tests/daemon/global-io-fixture.hpp"
36#include "tests/daemon/fw/dummy-strategy.hpp"
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060037
38namespace nfd {
39namespace tests {
40
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040041class TablesConfigSectionFixture : public GlobalIoFixture
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060042{
Junxiao Shi9685cc52016-08-29 12:47:05 +000043protected:
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060044 TablesConfigSectionFixture()
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060045 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000046 DummyStrategy::registerAs(strategyP);
47 DummyStrategy::registerAs(strategyP1);
Eric Newberry7249fb42021-04-04 21:09:32 -070048 // strategyP1Marker is NOT registered
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000049 DummyStrategy::registerAs(strategyQ);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060050 }
51
52 void
Junxiao Shi9685cc52016-08-29 12:47:05 +000053 runConfig(const std::string& config, bool isDryRun)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060054 {
Junxiao Shi9685cc52016-08-29 12:47:05 +000055 ConfigFile cf;
56 tablesConfig.setConfigFile(cf);
57 cf.parse(config, isDryRun, "dummy-config");
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060058 }
59
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060060protected:
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040061 FaceTable faceTable;
Eric Newberry7249fb42021-04-04 21:09:32 -070062 Forwarder forwarder{faceTable};
63 Cs& cs{forwarder.getCs()};
64 StrategyChoice& strategyChoice{forwarder.getStrategyChoice()};
65 NetworkRegionTable& networkRegionTable{forwarder.getNetworkRegionTable()};
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060066
Eric Newberry7249fb42021-04-04 21:09:32 -070067 TablesConfigSection tablesConfig{forwarder};
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000068
Eric Newberry7249fb42021-04-04 21:09:32 -070069 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 DiBenedetto3a4f83d2014-06-02 14:58:54 -060074};
75
Junxiao Shi9685cc52016-08-29 12:47:05 +000076BOOST_AUTO_TEST_SUITE(Mgmt)
77BOOST_FIXTURE_TEST_SUITE(TestTablesConfigSection, TablesConfigSectionFixture)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060078
Junxiao Shi9685cc52016-08-29 12:47:05 +000079BOOST_AUTO_TEST_SUITE(CsMaxPackets)
80
81BOOST_AUTO_TEST_CASE(NoSection)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060082{
Junxiao Shi9685cc52016-08-29 12:47:05 +000083 const size_t initialLimit = cs.getLimit();
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060084
Junxiao Shi9685cc52016-08-29 12:47:05 +000085 tablesConfig.ensureConfigured();
86 BOOST_CHECK_NE(cs.getLimit(), initialLimit);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060087}
88
Junxiao Shi9685cc52016-08-29 12:47:05 +000089BOOST_AUTO_TEST_CASE(Default)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060090{
Junxiao Shi9685cc52016-08-29 12:47:05 +000091 const std::string CONFIG = R"CONFIG(
92 tables
93 {
94 }
95 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060096
Junxiao Shi9685cc52016-08-29 12:47:05 +000097 const size_t initialLimit = cs.getLimit();
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060098
99 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000100 BOOST_CHECK_EQUAL(cs.getLimit(), initialLimit);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600101
102 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000103 BOOST_CHECK_NE(cs.getLimit(), initialLimit);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600104}
105
Junxiao Shi9685cc52016-08-29 12:47:05 +0000106BOOST_AUTO_TEST_CASE(Valid)
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500107{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000108 const std::string CONFIG = R"CONFIG(
109 tables
110 {
111 cs_max_packets 101
112 }
113 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500114
Junxiao Shi9685cc52016-08-29 12:47:05 +0000115 BOOST_REQUIRE_NE(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600116
117 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000118 BOOST_CHECK_NE(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600119
120 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000121 BOOST_CHECK_EQUAL(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600122
Junxiao Shi9685cc52016-08-29 12:47:05 +0000123 tablesConfig.ensureConfigured();
124 BOOST_CHECK_EQUAL(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600125}
126
Junxiao Shi9685cc52016-08-29 12:47:05 +0000127BOOST_AUTO_TEST_CASE(MissingValue)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600128{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000129 const std::string CONFIG = R"CONFIG(
130 tables
131 {
132 cs_max_packets
133 }
134 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600135
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500136 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
137 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600138}
139
Junxiao Shi9685cc52016-08-29 12:47:05 +0000140BOOST_AUTO_TEST_CASE(InvalidValue)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600141{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000142 const std::string CONFIG = R"CONFIG(
143 tables
144 {
145 cs_max_packets invalid
146 }
147 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600148
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500149 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
150 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600151}
152
Junxiao Shi9685cc52016-08-29 12:47:05 +0000153BOOST_AUTO_TEST_SUITE_END() // CsMaxPackets
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500154
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000155BOOST_AUTO_TEST_SUITE(CsPolicy)
156
157BOOST_AUTO_TEST_CASE(Default)
158{
159 const std::string CONFIG = R"CONFIG(
160 tables
161 {
162 }
163 )CONFIG";
164
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700165 runConfig(CONFIG, false);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000166 cs::Policy* currentPolicy = cs.getPolicy();
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700167 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000168}
169
170BOOST_AUTO_TEST_CASE(Known)
171{
172 const std::string CONFIG = R"CONFIG(
173 tables
174 {
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700175 cs_policy priority_fifo
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000176 }
177 )CONFIG";
178
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700179 runConfig(CONFIG, true);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000180 cs::Policy* currentPolicy = cs.getPolicy();
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000181 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy);
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700182
183 runConfig(CONFIG, false);
184 currentPolicy = cs.getPolicy();
185 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000186}
187
188BOOST_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
201BOOST_AUTO_TEST_SUITE_END() // CsPolicy
202
Junxiao Shi9685cc52016-08-29 12:47:05 +0000203class CsUnsolicitedPolicyFixture : public TablesConfigSectionFixture
204{
205protected:
Junxiao Shi9685cc52016-08-29 12:47:05 +0000206 CsUnsolicitedPolicyFixture()
207 {
Davide Pesavento3db98072021-03-09 23:03:27 -0500208 forwarder.setUnsolicitedDataPolicy(make_unique<fw::AdmitNetworkUnsolicitedDataPolicy>());
Junxiao Shi9685cc52016-08-29 12:47:05 +0000209 }
210};
211
212BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture)
213
214BOOST_AUTO_TEST_CASE(NoSection)
215{
216 tablesConfig.ensureConfigured();
217
Davide Pesavento3db98072021-03-09 23:03:27 -0500218 auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
Junxiao Shi9685cc52016-08-29 12:47:05 +0000219 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
220}
221
222BOOST_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 Pesavento3db98072021-03-09 23:03:27 -0500231 auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
Junxiao Shi9685cc52016-08-29 12:47:05 +0000232 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
239BOOST_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 Pesavento3db98072021-03-09 23:03:27 -0500249 auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
Junxiao Shi9685cc52016-08-29 12:47:05 +0000250 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
257BOOST_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
270BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy
271
272BOOST_AUTO_TEST_SUITE(StrategyChoice)
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500273
274BOOST_AUTO_TEST_CASE(Unversioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700275{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000276 const std::string CONFIG = R"CONFIG(
277 tables
278 {
279 strategy_choice
280 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000281 / /tables-config-section-strategy-P
282 /a /tables-config-section-strategy-Q
Junxiao Shi9685cc52016-08-29 12:47:05 +0000283 }
284 }
285 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700286
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500287 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700288 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000289 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Eric Newberry7249fb42021-04-04 21:09:32 -0700290 BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), defaultStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700291
Junxiao Shi9685cc52016-08-29 12:47:05 +0000292 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Eric Newberry7249fb42021-04-04 21:09:32 -0700293 BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), defaultStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700294 }
295
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500296 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700297 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000298 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000299 BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), strategyP.getPrefix(-1));
Eric Newberry7249fb42021-04-04 21:09:32 -0700300 NFD_CHECK_TYPEID_EQUAL(rootStrategy, DummyStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700301
Junxiao Shi9685cc52016-08-29 12:47:05 +0000302 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000303 BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Eric Newberry7249fb42021-04-04 21:09:32 -0700304 NFD_CHECK_TYPEID_EQUAL(aStrategy, DummyStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700305 }
306}
307
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500308BOOST_AUTO_TEST_CASE(Versioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700309{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000310 const std::string CONFIG = R"CONFIG(
311 tables
312 {
313 strategy_choice
314 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000315 /test/latest /tables-config-section-strategy-P
Eric Newberry7249fb42021-04-04 21:09:32 -0700316 /test/old /tables-config-section-strategy-P/v=1
317 /test/marker /tables-config-section-strategy-P/%FD%01
Junxiao Shi9685cc52016-08-29 12:47:05 +0000318 }
319 }
320 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700321
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500322 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700323 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000324 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Eric Newberry7249fb42021-04-04 21:09:32 -0700325 BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), defaultStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700326
Junxiao Shi9685cc52016-08-29 12:47:05 +0000327 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Eric Newberry7249fb42021-04-04 21:09:32 -0700328 BOOST_CHECK_EQUAL(testOldStrategy.getInstanceName(), defaultStrategy);
329
330 fw::Strategy& testMarkerStrategy = strategyChoice.findEffectiveStrategy("/test/marker");
331 BOOST_CHECK_EQUAL(testMarkerStrategy.getInstanceName(), defaultStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700332 }
333
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500334 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700335 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000336 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000337 BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1));
Eric Newberry7249fb42021-04-04 21:09:32 -0700338 NFD_CHECK_TYPEID_EQUAL(testLatestStrategy, DummyStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700339
Junxiao Shi9685cc52016-08-29 12:47:05 +0000340 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000341 BOOST_CHECK_EQUAL(testOldStrategy.getInstanceName(), strategyP1);
Eric Newberry7249fb42021-04-04 21:09:32 -0700342 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 DiBenedettoc0640f52014-11-03 15:55:43 -0700347 }
348}
349
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500350BOOST_AUTO_TEST_CASE(NonExisting)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700351{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000352 const std::string CONFIG = R"CONFIG(
353 tables
354 {
355 strategy_choice
356 {
357 / /localhost/nfd/strategy/test-doesnotexist
358 }
359 }
360 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700361
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500362 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
363 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700364}
365
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500366BOOST_AUTO_TEST_CASE(MissingPrefix)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700367{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000368 const std::string CONFIG = R"CONFIG(
369 tables
370 {
371 strategy_choice
372 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000373 /tables-config-section-strategy-P
Junxiao Shi9685cc52016-08-29 12:47:05 +0000374 }
375 }
376 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700377
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500378 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
379 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700380}
381
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500382BOOST_AUTO_TEST_CASE(Duplicate)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700383{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000384 const std::string CONFIG = R"CONFIG(
385 tables
386 {
387 strategy_choice
388 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000389 / /tables-config-section-strategy-P
390 /a /tables-config-section-strategy-Q
391 / /tables-config-section-strategy-Q
Junxiao Shi9685cc52016-08-29 12:47:05 +0000392 }
393 }
394 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700395
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500396 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
397 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700398}
399
Junxiao Shi593887c2016-12-24 02:39:29 +0000400BOOST_AUTO_TEST_CASE(UnacceptableParameters)
401{
402 const std::string CONFIG = R"CONFIG(
403 tables
404 {
405 strategy_choice
406 {
Eric Newberry7249fb42021-04-04 21:09:32 -0700407 / /localhost/nfd/strategy/best-route/v=5/param
Junxiao Shi593887c2016-12-24 02:39:29 +0000408 }
409 }
410 )CONFIG";
411
412 BOOST_CHECK_NO_THROW(runConfig(CONFIG, true));
413 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
414}
415
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500416BOOST_AUTO_TEST_SUITE_END() // StrategyChoice
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600417
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500418BOOST_AUTO_TEST_SUITE(NetworkRegion)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600419
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500420BOOST_AUTO_TEST_CASE(Basic)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600421{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000422 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 DiBenedetto9bcc88f2014-07-08 09:52:13 -0600432
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500433 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000434 BOOST_CHECK_EQUAL(networkRegionTable.size(), 0);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600435
Junxiao Shi9685cc52016-08-29 12:47:05 +0000436 BOOST_CHECK(networkRegionTable.find("/test/regionA") == networkRegionTable.end());
437 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") == networkRegionTable.end());
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600438
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500439 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000440 BOOST_CHECK_EQUAL(networkRegionTable.size(), 2);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600441
Junxiao Shi9685cc52016-08-29 12:47:05 +0000442 BOOST_CHECK(networkRegionTable.find("/test/regionA") != networkRegionTable.end());
443 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") != networkRegionTable.end());
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600444}
445
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500446BOOST_AUTO_TEST_CASE(Reload)
447{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000448 const std::string CONFIG1 = R"CONFIG(
449 tables
450 {
451 network_region
452 {
453 /some/region
454 }
455 }
456 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500457
458 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000459 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500460
461 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000462 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500463
Junxiao Shi9685cc52016-08-29 12:47:05 +0000464 const std::string CONFIG2 = R"CONFIG(
465 tables
466 {
467 network_region
468 {
469 /different/region
470 }
471 }
472 )CONFIG";
473
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500474 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000475 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
476 BOOST_CHECK(networkRegionTable.find("/different/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500477
478 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000479 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
480 BOOST_CHECK(networkRegionTable.find("/different/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500481}
482
483BOOST_AUTO_TEST_SUITE_END() // NetworkRegion
484
Junxiao Shi0cc125c2016-08-25 21:50:04 +0000485BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500486BOOST_AUTO_TEST_SUITE_END() // Mgmt
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600487
488} // namespace tests
489} // namespace nfd