blob: a52b688f5d521915da6ec8fc48710fe7d63e97e0 [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/*
3 * Copyright (c) 2014-2018, 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"
Junxiao Shia49a1ab2016-07-15 18:24:36 +000033#include "../fw/dummy-strategy.hpp"
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060034
35namespace nfd {
36namespace tests {
37
38class TablesConfigSectionFixture : protected BaseFixture
39{
Junxiao Shi9685cc52016-08-29 12:47:05 +000040protected:
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060041 TablesConfigSectionFixture()
Junxiao Shi9685cc52016-08-29 12:47:05 +000042 : cs(forwarder.getCs())
43 , strategyChoice(forwarder.getStrategyChoice())
44 , networkRegionTable(forwarder.getNetworkRegionTable())
45 , tablesConfig(forwarder)
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000046 , strategyP("/tables-config-section-strategy-P/%FD%02")
47 , strategyP1("/tables-config-section-strategy-P/%FD%01")
48 , strategyQ("/tables-config-section-strategy-Q/%FD%02")
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060049 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000050 DummyStrategy::registerAs(strategyP);
51 DummyStrategy::registerAs(strategyP1);
52 DummyStrategy::registerAs(strategyQ);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060053 }
54
55 void
Junxiao Shi9685cc52016-08-29 12:47:05 +000056 runConfig(const std::string& config, bool isDryRun)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060057 {
Junxiao Shi9685cc52016-08-29 12:47:05 +000058 ConfigFile cf;
59 tablesConfig.setConfigFile(cf);
60 cf.parse(config, isDryRun, "dummy-config");
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060061 }
62
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060063protected:
Junxiao Shi9685cc52016-08-29 12:47:05 +000064 Forwarder forwarder;
65 Cs& cs;
66 StrategyChoice& strategyChoice;
67 NetworkRegionTable& networkRegionTable;
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060068
Junxiao Shi9685cc52016-08-29 12:47:05 +000069 TablesConfigSection tablesConfig;
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000070
71 const Name strategyP;
72 const Name strategyP1;
73 const Name strategyQ;
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:
206 class DummyUnsolicitedDataPolicy : public fw::AdmitNetworkUnsolicitedDataPolicy
207 {
208 };
209
210 CsUnsolicitedPolicyFixture()
211 {
212 forwarder.setUnsolicitedDataPolicy(make_unique<DummyUnsolicitedDataPolicy>());
213 }
214};
215
216BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture)
217
218BOOST_AUTO_TEST_CASE(NoSection)
219{
220 tablesConfig.ensureConfigured();
221
222 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
223 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
224}
225
226BOOST_AUTO_TEST_CASE(Default)
227{
228 const std::string CONFIG = R"CONFIG(
229 tables
230 {
231 }
232 )CONFIG";
233
234 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
235 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
236 NFD_CHECK_TYPEID_NE(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
237
238 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
239 currentPolicy = &forwarder.getUnsolicitedDataPolicy();
240 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
241}
242
243BOOST_AUTO_TEST_CASE(Known)
244{
245 const std::string CONFIG = R"CONFIG(
246 tables
247 {
248 cs_unsolicited_policy admit-all
249 }
250 )CONFIG";
251
252 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
253 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
254 NFD_CHECK_TYPEID_NE(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
255
256 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
257 currentPolicy = &forwarder.getUnsolicitedDataPolicy();
258 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
259}
260
261BOOST_AUTO_TEST_CASE(Unknown)
262{
263 const std::string CONFIG = R"CONFIG(
264 tables
265 {
266 cs_unsolicited_policy unknown
267 }
268 )CONFIG";
269
270 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
271 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
272}
273
274BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy
275
276BOOST_AUTO_TEST_SUITE(StrategyChoice)
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500277
278BOOST_AUTO_TEST_CASE(Unversioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700279{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000280 const std::string CONFIG = R"CONFIG(
281 tables
282 {
283 strategy_choice
284 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000285 / /tables-config-section-strategy-P
286 /a /tables-config-section-strategy-Q
Junxiao Shi9685cc52016-08-29 12:47:05 +0000287 }
288 }
289 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700290
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500291 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700292 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000293 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000294 BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyP.getPrefix(-1));
295 BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700296
Junxiao Shi9685cc52016-08-29 12:47:05 +0000297 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000298 BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyP.getPrefix(-1));
299 BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700300 }
301
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500302 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700303 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000304 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000305 BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), strategyP.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700306
Junxiao Shi9685cc52016-08-29 12:47:05 +0000307 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000308 BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700309 }
310}
311
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500312BOOST_AUTO_TEST_CASE(Versioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700313{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000314 const std::string CONFIG = R"CONFIG(
315 tables
316 {
317 strategy_choice
318 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000319 /test/latest /tables-config-section-strategy-P
320 /test/old /tables-config-section-strategy-P/%FD%01
Junxiao Shi9685cc52016-08-29 12:47:05 +0000321 }
322 }
323 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700324
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500325 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700326 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000327 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000328 BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1));
329 BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP1);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700330
Junxiao Shi9685cc52016-08-29 12:47:05 +0000331 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000332 BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP.getPrefix(-1));
333 BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP1);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700334 }
335
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500336 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700337 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000338 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000339 BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700340
Junxiao Shi9685cc52016-08-29 12:47:05 +0000341 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000342 BOOST_CHECK_EQUAL(testOldStrategy.getInstanceName(), strategyP1);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700343 }
344}
345
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500346BOOST_AUTO_TEST_CASE(NonExisting)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700347{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000348 const std::string CONFIG = R"CONFIG(
349 tables
350 {
351 strategy_choice
352 {
353 / /localhost/nfd/strategy/test-doesnotexist
354 }
355 }
356 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700357
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500358 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
359 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700360}
361
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500362BOOST_AUTO_TEST_CASE(MissingPrefix)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700363{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000364 const std::string CONFIG = R"CONFIG(
365 tables
366 {
367 strategy_choice
368 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000369 /tables-config-section-strategy-P
Junxiao Shi9685cc52016-08-29 12:47:05 +0000370 }
371 }
372 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700373
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500374 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
375 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700376}
377
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500378BOOST_AUTO_TEST_CASE(Duplicate)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700379{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000380 const std::string CONFIG = R"CONFIG(
381 tables
382 {
383 strategy_choice
384 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000385 / /tables-config-section-strategy-P
386 /a /tables-config-section-strategy-Q
387 / /tables-config-section-strategy-Q
Junxiao Shi9685cc52016-08-29 12:47:05 +0000388 }
389 }
390 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700391
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500392 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
393 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700394}
395
Junxiao Shi593887c2016-12-24 02:39:29 +0000396BOOST_AUTO_TEST_CASE(UnacceptableParameters)
397{
398 const std::string CONFIG = R"CONFIG(
399 tables
400 {
401 strategy_choice
402 {
403 / /localhost/nfd/strategy/best-route/%FD%01/param
404 }
405 }
406 )CONFIG";
407
408 BOOST_CHECK_NO_THROW(runConfig(CONFIG, true));
409 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
410}
411
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500412BOOST_AUTO_TEST_SUITE_END() // StrategyChoice
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600413
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500414BOOST_AUTO_TEST_SUITE(NetworkRegion)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600415
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500416BOOST_AUTO_TEST_CASE(Basic)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600417{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000418 const std::string CONFIG = R"CONFIG(
419 tables
420 {
421 network_region
422 {
423 /test/regionA
424 /test/regionB/component
425 }
426 }
427 )CONFIG";
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600428
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500429 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000430 BOOST_CHECK_EQUAL(networkRegionTable.size(), 0);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600431
Junxiao Shi9685cc52016-08-29 12:47:05 +0000432 BOOST_CHECK(networkRegionTable.find("/test/regionA") == networkRegionTable.end());
433 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") == networkRegionTable.end());
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600434
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500435 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000436 BOOST_CHECK_EQUAL(networkRegionTable.size(), 2);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600437
Junxiao Shi9685cc52016-08-29 12:47:05 +0000438 BOOST_CHECK(networkRegionTable.find("/test/regionA") != networkRegionTable.end());
439 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") != networkRegionTable.end());
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600440}
441
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500442BOOST_AUTO_TEST_CASE(Reload)
443{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000444 const std::string CONFIG1 = R"CONFIG(
445 tables
446 {
447 network_region
448 {
449 /some/region
450 }
451 }
452 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500453
454 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000455 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500456
457 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000458 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500459
Junxiao Shi9685cc52016-08-29 12:47:05 +0000460 const std::string CONFIG2 = R"CONFIG(
461 tables
462 {
463 network_region
464 {
465 /different/region
466 }
467 }
468 )CONFIG";
469
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500470 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000471 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
472 BOOST_CHECK(networkRegionTable.find("/different/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500473
474 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false));
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
479BOOST_AUTO_TEST_SUITE_END() // NetworkRegion
480
Junxiao Shi0cc125c2016-08-25 21:50:04 +0000481BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500482BOOST_AUTO_TEST_SUITE_END() // Mgmt
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600483
484} // namespace tests
485} // namespace nfd