blob: 789d64fa1cc58155ed84c3b0ce999138a673dba2 [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"
27#include "fw/forwarder.hpp"
Junxiao Shib4a5acd2016-12-07 19:59:18 +000028#include "table/cs-policy-lru.hpp"
29#include "table/cs-policy-priority-fifo.hpp"
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060030
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060031#include "tests/test-common.hpp"
Junxiao Shi9685cc52016-08-29 12:47:05 +000032#include "tests/check-typeid.hpp"
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040033#include "tests/daemon/global-io-fixture.hpp"
34#include "tests/daemon/fw/dummy-strategy.hpp"
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060035
36namespace nfd {
37namespace tests {
38
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040039class TablesConfigSectionFixture : public GlobalIoFixture
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060040{
Junxiao Shi9685cc52016-08-29 12:47:05 +000041protected:
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060042 TablesConfigSectionFixture()
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040043 : forwarder(faceTable)
44 , cs(forwarder.getCs())
Junxiao Shi9685cc52016-08-29 12:47:05 +000045 , strategyChoice(forwarder.getStrategyChoice())
46 , networkRegionTable(forwarder.getNetworkRegionTable())
47 , tablesConfig(forwarder)
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000048 , strategyP("/tables-config-section-strategy-P/%FD%02")
49 , strategyP1("/tables-config-section-strategy-P/%FD%01")
50 , strategyQ("/tables-config-section-strategy-Q/%FD%02")
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060051 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000052 DummyStrategy::registerAs(strategyP);
53 DummyStrategy::registerAs(strategyP1);
54 DummyStrategy::registerAs(strategyQ);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060055 }
56
57 void
Junxiao Shi9685cc52016-08-29 12:47:05 +000058 runConfig(const std::string& config, bool isDryRun)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060059 {
Junxiao Shi9685cc52016-08-29 12:47:05 +000060 ConfigFile cf;
61 tablesConfig.setConfigFile(cf);
62 cf.parse(config, isDryRun, "dummy-config");
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060063 }
64
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060065protected:
Davide Pesaventoa4abfb02019-10-06 16:02:56 -040066 FaceTable faceTable;
Junxiao Shi9685cc52016-08-29 12:47:05 +000067 Forwarder forwarder;
68 Cs& cs;
69 StrategyChoice& strategyChoice;
70 NetworkRegionTable& networkRegionTable;
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060071
Junxiao Shi9685cc52016-08-29 12:47:05 +000072 TablesConfigSection tablesConfig;
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000073
74 const Name strategyP;
75 const Name strategyP1;
76 const Name strategyQ;
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060077};
78
Junxiao Shi9685cc52016-08-29 12:47:05 +000079BOOST_AUTO_TEST_SUITE(Mgmt)
80BOOST_FIXTURE_TEST_SUITE(TestTablesConfigSection, TablesConfigSectionFixture)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060081
Junxiao Shi9685cc52016-08-29 12:47:05 +000082BOOST_AUTO_TEST_SUITE(CsMaxPackets)
83
84BOOST_AUTO_TEST_CASE(NoSection)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060085{
Junxiao Shi9685cc52016-08-29 12:47:05 +000086 const size_t initialLimit = cs.getLimit();
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060087
Junxiao Shi9685cc52016-08-29 12:47:05 +000088 tablesConfig.ensureConfigured();
89 BOOST_CHECK_NE(cs.getLimit(), initialLimit);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060090}
91
Junxiao Shi9685cc52016-08-29 12:47:05 +000092BOOST_AUTO_TEST_CASE(Default)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060093{
Junxiao Shi9685cc52016-08-29 12:47:05 +000094 const std::string CONFIG = R"CONFIG(
95 tables
96 {
97 }
98 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060099
Junxiao Shi9685cc52016-08-29 12:47:05 +0000100 const size_t initialLimit = cs.getLimit();
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600101
102 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000103 BOOST_CHECK_EQUAL(cs.getLimit(), initialLimit);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600104
105 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000106 BOOST_CHECK_NE(cs.getLimit(), initialLimit);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600107}
108
Junxiao Shi9685cc52016-08-29 12:47:05 +0000109BOOST_AUTO_TEST_CASE(Valid)
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500110{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000111 const std::string CONFIG = R"CONFIG(
112 tables
113 {
114 cs_max_packets 101
115 }
116 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500117
Junxiao Shi9685cc52016-08-29 12:47:05 +0000118 BOOST_REQUIRE_NE(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600119
120 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000121 BOOST_CHECK_NE(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600122
123 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000124 BOOST_CHECK_EQUAL(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600125
Junxiao Shi9685cc52016-08-29 12:47:05 +0000126 tablesConfig.ensureConfigured();
127 BOOST_CHECK_EQUAL(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600128}
129
Junxiao Shi9685cc52016-08-29 12:47:05 +0000130BOOST_AUTO_TEST_CASE(MissingValue)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600131{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000132 const std::string CONFIG = R"CONFIG(
133 tables
134 {
135 cs_max_packets
136 }
137 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600138
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500139 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
140 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600141}
142
Junxiao Shi9685cc52016-08-29 12:47:05 +0000143BOOST_AUTO_TEST_CASE(InvalidValue)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600144{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000145 const std::string CONFIG = R"CONFIG(
146 tables
147 {
148 cs_max_packets invalid
149 }
150 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600151
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500152 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
153 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600154}
155
Junxiao Shi9685cc52016-08-29 12:47:05 +0000156BOOST_AUTO_TEST_SUITE_END() // CsMaxPackets
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500157
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000158BOOST_AUTO_TEST_SUITE(CsPolicy)
159
160BOOST_AUTO_TEST_CASE(Default)
161{
162 const std::string CONFIG = R"CONFIG(
163 tables
164 {
165 }
166 )CONFIG";
167
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700168 runConfig(CONFIG, false);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000169 cs::Policy* currentPolicy = cs.getPolicy();
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700170 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000171}
172
173BOOST_AUTO_TEST_CASE(Known)
174{
175 const std::string CONFIG = R"CONFIG(
176 tables
177 {
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700178 cs_policy priority_fifo
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000179 }
180 )CONFIG";
181
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700182 runConfig(CONFIG, true);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000183 cs::Policy* currentPolicy = cs.getPolicy();
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000184 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy);
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700185
186 runConfig(CONFIG, false);
187 currentPolicy = cs.getPolicy();
188 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000189}
190
191BOOST_AUTO_TEST_CASE(Unknown)
192{
193 const std::string CONFIG = R"CONFIG(
194 tables
195 {
196 cs_policy unknown
197 }
198 )CONFIG";
199
200 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
201 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
202}
203
204BOOST_AUTO_TEST_SUITE_END() // CsPolicy
205
Junxiao Shi9685cc52016-08-29 12:47:05 +0000206class CsUnsolicitedPolicyFixture : public TablesConfigSectionFixture
207{
208protected:
209 class DummyUnsolicitedDataPolicy : public fw::AdmitNetworkUnsolicitedDataPolicy
210 {
211 };
212
213 CsUnsolicitedPolicyFixture()
214 {
215 forwarder.setUnsolicitedDataPolicy(make_unique<DummyUnsolicitedDataPolicy>());
216 }
217};
218
219BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture)
220
221BOOST_AUTO_TEST_CASE(NoSection)
222{
223 tablesConfig.ensureConfigured();
224
225 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
226 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
227}
228
229BOOST_AUTO_TEST_CASE(Default)
230{
231 const std::string CONFIG = R"CONFIG(
232 tables
233 {
234 }
235 )CONFIG";
236
237 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
238 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
239 NFD_CHECK_TYPEID_NE(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
240
241 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
242 currentPolicy = &forwarder.getUnsolicitedDataPolicy();
243 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
244}
245
246BOOST_AUTO_TEST_CASE(Known)
247{
248 const std::string CONFIG = R"CONFIG(
249 tables
250 {
251 cs_unsolicited_policy admit-all
252 }
253 )CONFIG";
254
255 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
256 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
257 NFD_CHECK_TYPEID_NE(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
258
259 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
260 currentPolicy = &forwarder.getUnsolicitedDataPolicy();
261 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
262}
263
264BOOST_AUTO_TEST_CASE(Unknown)
265{
266 const std::string CONFIG = R"CONFIG(
267 tables
268 {
269 cs_unsolicited_policy unknown
270 }
271 )CONFIG";
272
273 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
274 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
275}
276
277BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy
278
279BOOST_AUTO_TEST_SUITE(StrategyChoice)
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500280
281BOOST_AUTO_TEST_CASE(Unversioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700282{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000283 const std::string CONFIG = R"CONFIG(
284 tables
285 {
286 strategy_choice
287 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000288 / /tables-config-section-strategy-P
289 /a /tables-config-section-strategy-Q
Junxiao Shi9685cc52016-08-29 12:47:05 +0000290 }
291 }
292 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700293
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500294 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700295 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000296 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000297 BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyP.getPrefix(-1));
298 BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700299
Junxiao Shi9685cc52016-08-29 12:47:05 +0000300 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000301 BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyP.getPrefix(-1));
302 BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700303 }
304
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500305 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700306 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000307 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000308 BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), strategyP.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700309
Junxiao Shi9685cc52016-08-29 12:47:05 +0000310 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000311 BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700312 }
313}
314
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500315BOOST_AUTO_TEST_CASE(Versioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700316{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000317 const std::string CONFIG = R"CONFIG(
318 tables
319 {
320 strategy_choice
321 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000322 /test/latest /tables-config-section-strategy-P
323 /test/old /tables-config-section-strategy-P/%FD%01
Junxiao Shi9685cc52016-08-29 12:47:05 +0000324 }
325 }
326 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700327
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500328 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700329 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000330 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000331 BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1));
332 BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP1);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700333
Junxiao Shi9685cc52016-08-29 12:47:05 +0000334 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000335 BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP.getPrefix(-1));
336 BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP1);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700337 }
338
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500339 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700340 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000341 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000342 BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700343
Junxiao Shi9685cc52016-08-29 12:47:05 +0000344 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000345 BOOST_CHECK_EQUAL(testOldStrategy.getInstanceName(), strategyP1);
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 {
Davide Pesavento58091582021-03-05 19:02:48 -0500406 / /localhost/nfd/strategy/best-route/%FD%05/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
487} // namespace tests
488} // namespace nfd