blob: dd0133fa972f0e59f7873ec47b37d6373cb3b419 [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 Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, 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
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040038namespace nfd::tests {
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060039
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040040class TablesConfigSectionFixture : public GlobalIoFixture
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060041{
Junxiao Shi9685cc52016-08-29 12:47:05 +000042protected:
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060043 TablesConfigSectionFixture()
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060044 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000045 DummyStrategy::registerAs(strategyP);
46 DummyStrategy::registerAs(strategyP1);
Eric Newberry7249fb42021-04-04 21:09:32 -070047 // strategyP1Marker is NOT registered
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000048 DummyStrategy::registerAs(strategyQ);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060049 }
50
51 void
Junxiao Shi9685cc52016-08-29 12:47:05 +000052 runConfig(const std::string& config, bool isDryRun)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060053 {
Junxiao Shi9685cc52016-08-29 12:47:05 +000054 ConfigFile cf;
55 tablesConfig.setConfigFile(cf);
56 cf.parse(config, isDryRun, "dummy-config");
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060057 }
58
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060059protected:
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040060 FaceTable faceTable;
Eric Newberry7249fb42021-04-04 21:09:32 -070061 Forwarder forwarder{faceTable};
62 Cs& cs{forwarder.getCs()};
63 StrategyChoice& strategyChoice{forwarder.getStrategyChoice()};
64 NetworkRegionTable& networkRegionTable{forwarder.getNetworkRegionTable()};
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060065
Eric Newberry7249fb42021-04-04 21:09:32 -070066 TablesConfigSection tablesConfig{forwarder};
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000067
Eric Newberry7249fb42021-04-04 21:09:32 -070068 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 DiBenedetto3a4f83d2014-06-02 14:58:54 -060073};
74
Junxiao Shi9685cc52016-08-29 12:47:05 +000075BOOST_AUTO_TEST_SUITE(Mgmt)
76BOOST_FIXTURE_TEST_SUITE(TestTablesConfigSection, TablesConfigSectionFixture)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060077
Junxiao Shi9685cc52016-08-29 12:47:05 +000078BOOST_AUTO_TEST_SUITE(CsMaxPackets)
79
80BOOST_AUTO_TEST_CASE(NoSection)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060081{
Junxiao Shi9685cc52016-08-29 12:47:05 +000082 const size_t initialLimit = cs.getLimit();
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060083
Junxiao Shi9685cc52016-08-29 12:47:05 +000084 tablesConfig.ensureConfigured();
85 BOOST_CHECK_NE(cs.getLimit(), initialLimit);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060086}
87
Junxiao Shi9685cc52016-08-29 12:47:05 +000088BOOST_AUTO_TEST_CASE(Default)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060089{
Junxiao Shi9685cc52016-08-29 12:47:05 +000090 const std::string CONFIG = R"CONFIG(
91 tables
92 {
93 }
94 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060095
Junxiao Shi9685cc52016-08-29 12:47:05 +000096 const size_t initialLimit = cs.getLimit();
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060097
98 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +000099 BOOST_CHECK_EQUAL(cs.getLimit(), initialLimit);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600100
101 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000102 BOOST_CHECK_NE(cs.getLimit(), initialLimit);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600103}
104
Junxiao Shi9685cc52016-08-29 12:47:05 +0000105BOOST_AUTO_TEST_CASE(Valid)
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500106{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000107 const std::string CONFIG = R"CONFIG(
108 tables
109 {
110 cs_max_packets 101
111 }
112 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500113
Junxiao Shi9685cc52016-08-29 12:47:05 +0000114 BOOST_REQUIRE_NE(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600115
116 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000117 BOOST_CHECK_NE(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600118
119 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000120 BOOST_CHECK_EQUAL(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600121
Junxiao Shi9685cc52016-08-29 12:47:05 +0000122 tablesConfig.ensureConfigured();
123 BOOST_CHECK_EQUAL(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600124}
125
Junxiao Shi9685cc52016-08-29 12:47:05 +0000126BOOST_AUTO_TEST_CASE(MissingValue)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600127{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000128 const std::string CONFIG = R"CONFIG(
129 tables
130 {
131 cs_max_packets
132 }
133 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600134
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500135 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
136 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600137}
138
Junxiao Shi9685cc52016-08-29 12:47:05 +0000139BOOST_AUTO_TEST_CASE(InvalidValue)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600140{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000141 const std::string CONFIG = R"CONFIG(
142 tables
143 {
144 cs_max_packets invalid
145 }
146 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600147
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500148 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
149 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600150}
151
Junxiao Shi9685cc52016-08-29 12:47:05 +0000152BOOST_AUTO_TEST_SUITE_END() // CsMaxPackets
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500153
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000154BOOST_AUTO_TEST_SUITE(CsPolicy)
155
156BOOST_AUTO_TEST_CASE(Default)
157{
158 const std::string CONFIG = R"CONFIG(
159 tables
160 {
161 }
162 )CONFIG";
163
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700164 runConfig(CONFIG, false);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000165 cs::Policy* currentPolicy = cs.getPolicy();
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700166 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000167}
168
169BOOST_AUTO_TEST_CASE(Known)
170{
171 const std::string CONFIG = R"CONFIG(
172 tables
173 {
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700174 cs_policy priority_fifo
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000175 }
176 )CONFIG";
177
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700178 runConfig(CONFIG, true);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000179 cs::Policy* currentPolicy = cs.getPolicy();
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000180 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy);
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700181
182 runConfig(CONFIG, false);
183 currentPolicy = cs.getPolicy();
184 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000185}
186
187BOOST_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
200BOOST_AUTO_TEST_SUITE_END() // CsPolicy
201
Junxiao Shi9685cc52016-08-29 12:47:05 +0000202class CsUnsolicitedPolicyFixture : public TablesConfigSectionFixture
203{
204protected:
Junxiao Shi9685cc52016-08-29 12:47:05 +0000205 CsUnsolicitedPolicyFixture()
206 {
Davide Pesavento3db98072021-03-09 23:03:27 -0500207 forwarder.setUnsolicitedDataPolicy(make_unique<fw::AdmitNetworkUnsolicitedDataPolicy>());
Junxiao Shi9685cc52016-08-29 12:47:05 +0000208 }
209};
210
211BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture)
212
213BOOST_AUTO_TEST_CASE(NoSection)
214{
215 tablesConfig.ensureConfigured();
216
Davide Pesavento3db98072021-03-09 23:03:27 -0500217 auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
Junxiao Shi9685cc52016-08-29 12:47:05 +0000218 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
219}
220
221BOOST_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 Pesavento3db98072021-03-09 23:03:27 -0500230 auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
Junxiao Shi9685cc52016-08-29 12:47:05 +0000231 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
238BOOST_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 Pesavento3db98072021-03-09 23:03:27 -0500248 auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
Junxiao Shi9685cc52016-08-29 12:47:05 +0000249 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
256BOOST_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
269BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy
270
271BOOST_AUTO_TEST_SUITE(StrategyChoice)
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500272
273BOOST_AUTO_TEST_CASE(Unversioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700274{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000275 const std::string CONFIG = R"CONFIG(
276 tables
277 {
278 strategy_choice
279 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000280 / /tables-config-section-strategy-P
281 /a /tables-config-section-strategy-Q
Junxiao Shi9685cc52016-08-29 12:47:05 +0000282 }
283 }
284 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700285
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500286 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700287 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000288 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Eric Newberry7249fb42021-04-04 21:09:32 -0700289 BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), defaultStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700290
Junxiao Shi9685cc52016-08-29 12:47:05 +0000291 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Eric Newberry7249fb42021-04-04 21:09:32 -0700292 BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), defaultStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700293 }
294
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500295 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700296 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000297 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000298 BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), strategyP.getPrefix(-1));
Eric Newberry7249fb42021-04-04 21:09:32 -0700299 NFD_CHECK_TYPEID_EQUAL(rootStrategy, DummyStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700300
Junxiao Shi9685cc52016-08-29 12:47:05 +0000301 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000302 BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Eric Newberry7249fb42021-04-04 21:09:32 -0700303 NFD_CHECK_TYPEID_EQUAL(aStrategy, DummyStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700304 }
305}
306
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500307BOOST_AUTO_TEST_CASE(Versioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700308{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000309 const std::string CONFIG = R"CONFIG(
310 tables
311 {
312 strategy_choice
313 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000314 /test/latest /tables-config-section-strategy-P
Eric Newberry7249fb42021-04-04 21:09:32 -0700315 /test/old /tables-config-section-strategy-P/v=1
316 /test/marker /tables-config-section-strategy-P/%FD%01
Junxiao Shi9685cc52016-08-29 12:47:05 +0000317 }
318 }
319 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700320
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500321 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700322 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000323 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Eric Newberry7249fb42021-04-04 21:09:32 -0700324 BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), defaultStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700325
Junxiao Shi9685cc52016-08-29 12:47:05 +0000326 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Eric Newberry7249fb42021-04-04 21:09:32 -0700327 BOOST_CHECK_EQUAL(testOldStrategy.getInstanceName(), defaultStrategy);
328
329 fw::Strategy& testMarkerStrategy = strategyChoice.findEffectiveStrategy("/test/marker");
330 BOOST_CHECK_EQUAL(testMarkerStrategy.getInstanceName(), defaultStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700331 }
332
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500333 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700334 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000335 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000336 BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1));
Eric Newberry7249fb42021-04-04 21:09:32 -0700337 NFD_CHECK_TYPEID_EQUAL(testLatestStrategy, DummyStrategy);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700338
Junxiao Shi9685cc52016-08-29 12:47:05 +0000339 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000340 BOOST_CHECK_EQUAL(testOldStrategy.getInstanceName(), strategyP1);
Eric Newberry7249fb42021-04-04 21:09:32 -0700341 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 DiBenedettoc0640f52014-11-03 15:55:43 -0700346 }
347}
348
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500349BOOST_AUTO_TEST_CASE(NonExisting)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700350{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000351 const std::string CONFIG = R"CONFIG(
352 tables
353 {
354 strategy_choice
355 {
356 / /localhost/nfd/strategy/test-doesnotexist
357 }
358 }
359 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700360
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500361 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
362 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700363}
364
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500365BOOST_AUTO_TEST_CASE(MissingPrefix)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700366{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000367 const std::string CONFIG = R"CONFIG(
368 tables
369 {
370 strategy_choice
371 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000372 /tables-config-section-strategy-P
Junxiao Shi9685cc52016-08-29 12:47:05 +0000373 }
374 }
375 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700376
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500377 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
378 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700379}
380
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500381BOOST_AUTO_TEST_CASE(Duplicate)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700382{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000383 const std::string CONFIG = R"CONFIG(
384 tables
385 {
386 strategy_choice
387 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000388 / /tables-config-section-strategy-P
389 /a /tables-config-section-strategy-Q
390 / /tables-config-section-strategy-Q
Junxiao Shi9685cc52016-08-29 12:47:05 +0000391 }
392 }
393 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700394
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500395 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
396 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700397}
398
Junxiao Shi593887c2016-12-24 02:39:29 +0000399BOOST_AUTO_TEST_CASE(UnacceptableParameters)
400{
401 const std::string CONFIG = R"CONFIG(
402 tables
403 {
404 strategy_choice
405 {
Eric Newberry7249fb42021-04-04 21:09:32 -0700406 / /localhost/nfd/strategy/best-route/v=5/param
Junxiao Shi593887c2016-12-24 02:39:29 +0000407 }
408 }
409 )CONFIG";
410
411 BOOST_CHECK_NO_THROW(runConfig(CONFIG, true));
412 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
413}
414
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500415BOOST_AUTO_TEST_SUITE_END() // StrategyChoice
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600416
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500417BOOST_AUTO_TEST_SUITE(NetworkRegion)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600418
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500419BOOST_AUTO_TEST_CASE(Basic)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600420{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000421 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 DiBenedetto9bcc88f2014-07-08 09:52:13 -0600431
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500432 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000433 BOOST_CHECK_EQUAL(networkRegionTable.size(), 0);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600434
Junxiao Shi9685cc52016-08-29 12:47:05 +0000435 BOOST_CHECK(networkRegionTable.find("/test/regionA") == networkRegionTable.end());
436 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") == networkRegionTable.end());
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600437
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500438 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000439 BOOST_CHECK_EQUAL(networkRegionTable.size(), 2);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600440
Junxiao Shi9685cc52016-08-29 12:47:05 +0000441 BOOST_CHECK(networkRegionTable.find("/test/regionA") != networkRegionTable.end());
442 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") != networkRegionTable.end());
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600443}
444
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500445BOOST_AUTO_TEST_CASE(Reload)
446{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000447 const std::string CONFIG1 = R"CONFIG(
448 tables
449 {
450 network_region
451 {
452 /some/region
453 }
454 }
455 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500456
457 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000458 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500459
460 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000461 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500462
Junxiao Shi9685cc52016-08-29 12:47:05 +0000463 const std::string CONFIG2 = R"CONFIG(
464 tables
465 {
466 network_region
467 {
468 /different/region
469 }
470 }
471 )CONFIG";
472
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500473 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000474 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
475 BOOST_CHECK(networkRegionTable.find("/different/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500476
477 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000478 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
479 BOOST_CHECK(networkRegionTable.find("/different/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500480}
481
482BOOST_AUTO_TEST_SUITE_END() // NetworkRegion
483
Junxiao Shi0cc125c2016-08-25 21:50:04 +0000484BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500485BOOST_AUTO_TEST_SUITE_END() // Mgmt
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600486
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400487} // namespace nfd::tests