blob: df9992f5c33bc73ce63f02d8e13223adfcefc1cf [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)
Eric Newberry358414d2021-03-21 20:56:42 -070048 , strategyP(Name("/tables-config-section-strategy-P").appendVersion(2))
49 , strategyP1(Name("/tables-config-section-strategy-P").appendVersion(1))
50 , strategyQ(Name("/tables-config-section-strategy-Q").appendVersion(2))
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:
Junxiao Shi9685cc52016-08-29 12:47:05 +0000209 CsUnsolicitedPolicyFixture()
210 {
Davide Pesavento3db98072021-03-09 23:03:27 -0500211 forwarder.setUnsolicitedDataPolicy(make_unique<fw::AdmitNetworkUnsolicitedDataPolicy>());
Junxiao Shi9685cc52016-08-29 12:47:05 +0000212 }
213};
214
215BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture)
216
217BOOST_AUTO_TEST_CASE(NoSection)
218{
219 tablesConfig.ensureConfigured();
220
Davide Pesavento3db98072021-03-09 23:03:27 -0500221 auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
Junxiao Shi9685cc52016-08-29 12:47:05 +0000222 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
223}
224
225BOOST_AUTO_TEST_CASE(Default)
226{
227 const std::string CONFIG = R"CONFIG(
228 tables
229 {
230 }
231 )CONFIG";
232
233 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Davide Pesavento3db98072021-03-09 23:03:27 -0500234 auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
Junxiao Shi9685cc52016-08-29 12:47:05 +0000235 NFD_CHECK_TYPEID_NE(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
236
237 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
238 currentPolicy = &forwarder.getUnsolicitedDataPolicy();
239 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
240}
241
242BOOST_AUTO_TEST_CASE(Known)
243{
244 const std::string CONFIG = R"CONFIG(
245 tables
246 {
247 cs_unsolicited_policy admit-all
248 }
249 )CONFIG";
250
251 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Davide Pesavento3db98072021-03-09 23:03:27 -0500252 auto* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
Junxiao Shi9685cc52016-08-29 12:47:05 +0000253 NFD_CHECK_TYPEID_NE(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
254
255 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
256 currentPolicy = &forwarder.getUnsolicitedDataPolicy();
257 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
258}
259
260BOOST_AUTO_TEST_CASE(Unknown)
261{
262 const std::string CONFIG = R"CONFIG(
263 tables
264 {
265 cs_unsolicited_policy unknown
266 }
267 )CONFIG";
268
269 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
270 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
271}
272
273BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy
274
275BOOST_AUTO_TEST_SUITE(StrategyChoice)
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500276
277BOOST_AUTO_TEST_CASE(Unversioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700278{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000279 const std::string CONFIG = R"CONFIG(
280 tables
281 {
282 strategy_choice
283 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000284 / /tables-config-section-strategy-P
285 /a /tables-config-section-strategy-Q
Junxiao Shi9685cc52016-08-29 12:47:05 +0000286 }
287 }
288 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700289
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500290 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700291 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000292 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000293 BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyP.getPrefix(-1));
294 BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700295
Junxiao Shi9685cc52016-08-29 12:47:05 +0000296 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000297 BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyP.getPrefix(-1));
298 BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700299 }
300
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500301 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700302 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000303 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000304 BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), strategyP.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700305
Junxiao Shi9685cc52016-08-29 12:47:05 +0000306 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000307 BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700308 }
309}
310
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500311BOOST_AUTO_TEST_CASE(Versioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700312{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000313 const std::string CONFIG = R"CONFIG(
314 tables
315 {
316 strategy_choice
317 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000318 /test/latest /tables-config-section-strategy-P
319 /test/old /tables-config-section-strategy-P/%FD%01
Junxiao Shi9685cc52016-08-29 12:47:05 +0000320 }
321 }
322 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700323
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500324 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700325 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000326 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000327 BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1));
328 BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP1);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700329
Junxiao Shi9685cc52016-08-29 12:47:05 +0000330 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000331 BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP.getPrefix(-1));
332 BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP1);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700333 }
334
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500335 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700336 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000337 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000338 BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1));
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);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700342 }
343}
344
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500345BOOST_AUTO_TEST_CASE(NonExisting)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700346{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000347 const std::string CONFIG = R"CONFIG(
348 tables
349 {
350 strategy_choice
351 {
352 / /localhost/nfd/strategy/test-doesnotexist
353 }
354 }
355 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700356
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500357 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
358 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700359}
360
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500361BOOST_AUTO_TEST_CASE(MissingPrefix)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700362{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000363 const std::string CONFIG = R"CONFIG(
364 tables
365 {
366 strategy_choice
367 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000368 /tables-config-section-strategy-P
Junxiao Shi9685cc52016-08-29 12:47:05 +0000369 }
370 }
371 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700372
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500373 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
374 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700375}
376
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500377BOOST_AUTO_TEST_CASE(Duplicate)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700378{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000379 const std::string CONFIG = R"CONFIG(
380 tables
381 {
382 strategy_choice
383 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000384 / /tables-config-section-strategy-P
385 /a /tables-config-section-strategy-Q
386 / /tables-config-section-strategy-Q
Junxiao Shi9685cc52016-08-29 12:47:05 +0000387 }
388 }
389 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700390
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500391 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
392 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700393}
394
Junxiao Shi593887c2016-12-24 02:39:29 +0000395BOOST_AUTO_TEST_CASE(UnacceptableParameters)
396{
397 const std::string CONFIG = R"CONFIG(
398 tables
399 {
400 strategy_choice
401 {
Davide Pesavento58091582021-03-05 19:02:48 -0500402 / /localhost/nfd/strategy/best-route/%FD%05/param
Junxiao Shi593887c2016-12-24 02:39:29 +0000403 }
404 }
405 )CONFIG";
406
407 BOOST_CHECK_NO_THROW(runConfig(CONFIG, true));
408 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
409}
410
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500411BOOST_AUTO_TEST_SUITE_END() // StrategyChoice
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600412
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500413BOOST_AUTO_TEST_SUITE(NetworkRegion)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600414
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500415BOOST_AUTO_TEST_CASE(Basic)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600416{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000417 const std::string CONFIG = R"CONFIG(
418 tables
419 {
420 network_region
421 {
422 /test/regionA
423 /test/regionB/component
424 }
425 }
426 )CONFIG";
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600427
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500428 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000429 BOOST_CHECK_EQUAL(networkRegionTable.size(), 0);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600430
Junxiao Shi9685cc52016-08-29 12:47:05 +0000431 BOOST_CHECK(networkRegionTable.find("/test/regionA") == networkRegionTable.end());
432 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") == networkRegionTable.end());
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600433
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500434 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000435 BOOST_CHECK_EQUAL(networkRegionTable.size(), 2);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600436
Junxiao Shi9685cc52016-08-29 12:47:05 +0000437 BOOST_CHECK(networkRegionTable.find("/test/regionA") != networkRegionTable.end());
438 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") != networkRegionTable.end());
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600439}
440
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500441BOOST_AUTO_TEST_CASE(Reload)
442{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000443 const std::string CONFIG1 = R"CONFIG(
444 tables
445 {
446 network_region
447 {
448 /some/region
449 }
450 }
451 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500452
453 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000454 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500455
456 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000457 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500458
Junxiao Shi9685cc52016-08-29 12:47:05 +0000459 const std::string CONFIG2 = R"CONFIG(
460 tables
461 {
462 network_region
463 {
464 /different/region
465 }
466 }
467 )CONFIG";
468
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500469 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000470 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
471 BOOST_CHECK(networkRegionTable.find("/different/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500472
473 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false));
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
478BOOST_AUTO_TEST_SUITE_END() // NetworkRegion
479
Junxiao Shi0cc125c2016-08-25 21:50:04 +0000480BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500481BOOST_AUTO_TEST_SUITE_END() // Mgmt
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600482
483} // namespace tests
484} // namespace nfd