blob: cfcc3baa5f2d7a0e535315e2980999e785981e43 [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 Pesaventocf7db2f2019-03-24 23:17:28 -04003 * Copyright (c) 2014-2019, 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()
Junxiao Shi9685cc52016-08-29 12:47:05 +000043 : cs(forwarder.getCs())
44 , strategyChoice(forwarder.getStrategyChoice())
45 , networkRegionTable(forwarder.getNetworkRegionTable())
46 , tablesConfig(forwarder)
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000047 , strategyP("/tables-config-section-strategy-P/%FD%02")
48 , strategyP1("/tables-config-section-strategy-P/%FD%01")
49 , strategyQ("/tables-config-section-strategy-Q/%FD%02")
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060050 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000051 DummyStrategy::registerAs(strategyP);
52 DummyStrategy::registerAs(strategyP1);
53 DummyStrategy::registerAs(strategyQ);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060054 }
55
56 void
Junxiao Shi9685cc52016-08-29 12:47:05 +000057 runConfig(const std::string& config, bool isDryRun)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060058 {
Junxiao Shi9685cc52016-08-29 12:47:05 +000059 ConfigFile cf;
60 tablesConfig.setConfigFile(cf);
61 cf.parse(config, isDryRun, "dummy-config");
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060062 }
63
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060064protected:
Junxiao Shi9685cc52016-08-29 12:47:05 +000065 Forwarder forwarder;
66 Cs& cs;
67 StrategyChoice& strategyChoice;
68 NetworkRegionTable& networkRegionTable;
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060069
Junxiao Shi9685cc52016-08-29 12:47:05 +000070 TablesConfigSection tablesConfig;
Junxiao Shi0e4a1f12016-12-24 02:39:01 +000071
72 const Name strategyP;
73 const Name strategyP1;
74 const Name strategyQ;
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060075};
76
Junxiao Shi9685cc52016-08-29 12:47:05 +000077BOOST_AUTO_TEST_SUITE(Mgmt)
78BOOST_FIXTURE_TEST_SUITE(TestTablesConfigSection, TablesConfigSectionFixture)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060079
Junxiao Shi9685cc52016-08-29 12:47:05 +000080BOOST_AUTO_TEST_SUITE(CsMaxPackets)
81
82BOOST_AUTO_TEST_CASE(NoSection)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060083{
Junxiao Shi9685cc52016-08-29 12:47:05 +000084 const size_t initialLimit = cs.getLimit();
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060085
Junxiao Shi9685cc52016-08-29 12:47:05 +000086 tablesConfig.ensureConfigured();
87 BOOST_CHECK_NE(cs.getLimit(), initialLimit);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060088}
89
Junxiao Shi9685cc52016-08-29 12:47:05 +000090BOOST_AUTO_TEST_CASE(Default)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060091{
Junxiao Shi9685cc52016-08-29 12:47:05 +000092 const std::string CONFIG = R"CONFIG(
93 tables
94 {
95 }
96 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060097
Junxiao Shi9685cc52016-08-29 12:47:05 +000098 const size_t initialLimit = cs.getLimit();
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060099
100 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000101 BOOST_CHECK_EQUAL(cs.getLimit(), initialLimit);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600102
103 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000104 BOOST_CHECK_NE(cs.getLimit(), initialLimit);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600105}
106
Junxiao Shi9685cc52016-08-29 12:47:05 +0000107BOOST_AUTO_TEST_CASE(Valid)
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500108{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000109 const std::string CONFIG = R"CONFIG(
110 tables
111 {
112 cs_max_packets 101
113 }
114 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500115
Junxiao Shi9685cc52016-08-29 12:47:05 +0000116 BOOST_REQUIRE_NE(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600117
118 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000119 BOOST_CHECK_NE(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600120
121 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000122 BOOST_CHECK_EQUAL(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600123
Junxiao Shi9685cc52016-08-29 12:47:05 +0000124 tablesConfig.ensureConfigured();
125 BOOST_CHECK_EQUAL(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600126}
127
Junxiao Shi9685cc52016-08-29 12:47:05 +0000128BOOST_AUTO_TEST_CASE(MissingValue)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600129{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000130 const std::string CONFIG = R"CONFIG(
131 tables
132 {
133 cs_max_packets
134 }
135 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600136
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500137 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
138 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600139}
140
Junxiao Shi9685cc52016-08-29 12:47:05 +0000141BOOST_AUTO_TEST_CASE(InvalidValue)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600142{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000143 const std::string CONFIG = R"CONFIG(
144 tables
145 {
146 cs_max_packets invalid
147 }
148 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600149
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500150 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
151 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600152}
153
Junxiao Shi9685cc52016-08-29 12:47:05 +0000154BOOST_AUTO_TEST_SUITE_END() // CsMaxPackets
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500155
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000156BOOST_AUTO_TEST_SUITE(CsPolicy)
157
158BOOST_AUTO_TEST_CASE(Default)
159{
160 const std::string CONFIG = R"CONFIG(
161 tables
162 {
163 }
164 )CONFIG";
165
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700166 runConfig(CONFIG, false);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000167 cs::Policy* currentPolicy = cs.getPolicy();
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700168 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000169}
170
171BOOST_AUTO_TEST_CASE(Known)
172{
173 const std::string CONFIG = R"CONFIG(
174 tables
175 {
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700176 cs_policy priority_fifo
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000177 }
178 )CONFIG";
179
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700180 runConfig(CONFIG, true);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000181 cs::Policy* currentPolicy = cs.getPolicy();
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000182 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy);
Chavoosh Ghasemi32e76092018-09-10 14:51:33 -0700183
184 runConfig(CONFIG, false);
185 currentPolicy = cs.getPolicy();
186 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy);
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000187}
188
189BOOST_AUTO_TEST_CASE(Unknown)
190{
191 const std::string CONFIG = R"CONFIG(
192 tables
193 {
194 cs_policy unknown
195 }
196 )CONFIG";
197
198 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
199 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
200}
201
202BOOST_AUTO_TEST_SUITE_END() // CsPolicy
203
Junxiao Shi9685cc52016-08-29 12:47:05 +0000204class CsUnsolicitedPolicyFixture : public TablesConfigSectionFixture
205{
206protected:
207 class DummyUnsolicitedDataPolicy : public fw::AdmitNetworkUnsolicitedDataPolicy
208 {
209 };
210
211 CsUnsolicitedPolicyFixture()
212 {
213 forwarder.setUnsolicitedDataPolicy(make_unique<DummyUnsolicitedDataPolicy>());
214 }
215};
216
217BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture)
218
219BOOST_AUTO_TEST_CASE(NoSection)
220{
221 tablesConfig.ensureConfigured();
222
223 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
224 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
225}
226
227BOOST_AUTO_TEST_CASE(Default)
228{
229 const std::string CONFIG = R"CONFIG(
230 tables
231 {
232 }
233 )CONFIG";
234
235 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
236 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
237 NFD_CHECK_TYPEID_NE(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
238
239 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
240 currentPolicy = &forwarder.getUnsolicitedDataPolicy();
241 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
242}
243
244BOOST_AUTO_TEST_CASE(Known)
245{
246 const std::string CONFIG = R"CONFIG(
247 tables
248 {
249 cs_unsolicited_policy admit-all
250 }
251 )CONFIG";
252
253 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
254 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
255 NFD_CHECK_TYPEID_NE(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
256
257 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
258 currentPolicy = &forwarder.getUnsolicitedDataPolicy();
259 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
260}
261
262BOOST_AUTO_TEST_CASE(Unknown)
263{
264 const std::string CONFIG = R"CONFIG(
265 tables
266 {
267 cs_unsolicited_policy unknown
268 }
269 )CONFIG";
270
271 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
272 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
273}
274
275BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy
276
277BOOST_AUTO_TEST_SUITE(StrategyChoice)
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500278
279BOOST_AUTO_TEST_CASE(Unversioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700280{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000281 const std::string CONFIG = R"CONFIG(
282 tables
283 {
284 strategy_choice
285 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000286 / /tables-config-section-strategy-P
287 /a /tables-config-section-strategy-Q
Junxiao Shi9685cc52016-08-29 12:47:05 +0000288 }
289 }
290 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700291
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500292 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700293 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000294 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000295 BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyP.getPrefix(-1));
296 BOOST_CHECK_NE(rootStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700297
Junxiao Shi9685cc52016-08-29 12:47:05 +0000298 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000299 BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyP.getPrefix(-1));
300 BOOST_CHECK_NE(aStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700301 }
302
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500303 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700304 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000305 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000306 BOOST_CHECK_EQUAL(rootStrategy.getInstanceName(), strategyP.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700307
Junxiao Shi9685cc52016-08-29 12:47:05 +0000308 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000309 BOOST_CHECK_EQUAL(aStrategy.getInstanceName(), strategyQ.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700310 }
311}
312
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500313BOOST_AUTO_TEST_CASE(Versioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700314{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000315 const std::string CONFIG = R"CONFIG(
316 tables
317 {
318 strategy_choice
319 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000320 /test/latest /tables-config-section-strategy-P
321 /test/old /tables-config-section-strategy-P/%FD%01
Junxiao Shi9685cc52016-08-29 12:47:05 +0000322 }
323 }
324 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700325
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500326 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700327 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000328 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000329 BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1));
330 BOOST_CHECK_NE(testLatestStrategy.getInstanceName(), strategyP1);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700331
Junxiao Shi9685cc52016-08-29 12:47:05 +0000332 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000333 BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP.getPrefix(-1));
334 BOOST_CHECK_NE(testOldStrategy.getInstanceName(), strategyP1);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700335 }
336
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500337 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700338 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000339 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000340 BOOST_CHECK_EQUAL(testLatestStrategy.getInstanceName(), strategyP.getPrefix(-1));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700341
Junxiao Shi9685cc52016-08-29 12:47:05 +0000342 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000343 BOOST_CHECK_EQUAL(testOldStrategy.getInstanceName(), strategyP1);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700344 }
345}
346
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500347BOOST_AUTO_TEST_CASE(NonExisting)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700348{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000349 const std::string CONFIG = R"CONFIG(
350 tables
351 {
352 strategy_choice
353 {
354 / /localhost/nfd/strategy/test-doesnotexist
355 }
356 }
357 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700358
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500359 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
360 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700361}
362
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500363BOOST_AUTO_TEST_CASE(MissingPrefix)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700364{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000365 const std::string CONFIG = R"CONFIG(
366 tables
367 {
368 strategy_choice
369 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000370 /tables-config-section-strategy-P
Junxiao Shi9685cc52016-08-29 12:47:05 +0000371 }
372 }
373 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700374
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500375 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
376 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700377}
378
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500379BOOST_AUTO_TEST_CASE(Duplicate)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700380{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000381 const std::string CONFIG = R"CONFIG(
382 tables
383 {
384 strategy_choice
385 {
Junxiao Shi0e4a1f12016-12-24 02:39:01 +0000386 / /tables-config-section-strategy-P
387 /a /tables-config-section-strategy-Q
388 / /tables-config-section-strategy-Q
Junxiao Shi9685cc52016-08-29 12:47:05 +0000389 }
390 }
391 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700392
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500393 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
394 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700395}
396
Junxiao Shi593887c2016-12-24 02:39:29 +0000397BOOST_AUTO_TEST_CASE(UnacceptableParameters)
398{
399 const std::string CONFIG = R"CONFIG(
400 tables
401 {
402 strategy_choice
403 {
404 / /localhost/nfd/strategy/best-route/%FD%01/param
405 }
406 }
407 )CONFIG";
408
409 BOOST_CHECK_NO_THROW(runConfig(CONFIG, true));
410 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
411}
412
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500413BOOST_AUTO_TEST_SUITE_END() // StrategyChoice
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600414
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500415BOOST_AUTO_TEST_SUITE(NetworkRegion)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600416
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500417BOOST_AUTO_TEST_CASE(Basic)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600418{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000419 const std::string CONFIG = R"CONFIG(
420 tables
421 {
422 network_region
423 {
424 /test/regionA
425 /test/regionB/component
426 }
427 }
428 )CONFIG";
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600429
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500430 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000431 BOOST_CHECK_EQUAL(networkRegionTable.size(), 0);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600432
Junxiao Shi9685cc52016-08-29 12:47:05 +0000433 BOOST_CHECK(networkRegionTable.find("/test/regionA") == networkRegionTable.end());
434 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") == networkRegionTable.end());
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600435
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500436 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000437 BOOST_CHECK_EQUAL(networkRegionTable.size(), 2);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600438
Junxiao Shi9685cc52016-08-29 12:47:05 +0000439 BOOST_CHECK(networkRegionTable.find("/test/regionA") != networkRegionTable.end());
440 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") != networkRegionTable.end());
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600441}
442
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500443BOOST_AUTO_TEST_CASE(Reload)
444{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000445 const std::string CONFIG1 = R"CONFIG(
446 tables
447 {
448 network_region
449 {
450 /some/region
451 }
452 }
453 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500454
455 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000456 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500457
458 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000459 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500460
Junxiao Shi9685cc52016-08-29 12:47:05 +0000461 const std::string CONFIG2 = R"CONFIG(
462 tables
463 {
464 network_region
465 {
466 /different/region
467 }
468 }
469 )CONFIG";
470
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500471 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000472 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
473 BOOST_CHECK(networkRegionTable.find("/different/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500474
475 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000476 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
477 BOOST_CHECK(networkRegionTable.find("/different/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500478}
479
480BOOST_AUTO_TEST_SUITE_END() // NetworkRegion
481
Junxiao Shi0cc125c2016-08-25 21:50:04 +0000482BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500483BOOST_AUTO_TEST_SUITE_END() // Mgmt
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600484
485} // namespace tests
486} // namespace nfd