blob: c0edbabae6b296a6290e78cb97bac150625631c6 [file] [log] [blame]
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shia49a1ab2016-07-15 18:24:36 +00003 * Copyright (c) 2014-2016, 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
165 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
166 cs::Policy* currentPolicy = cs.getPolicy();
167 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy);
168}
169
170BOOST_AUTO_TEST_CASE(Known)
171{
172 const std::string CONFIG = R"CONFIG(
173 tables
174 {
175 cs_policy lru
176 }
177 )CONFIG";
178
179 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
180 cs::Policy* currentPolicy = cs.getPolicy();
181 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy);
182
183 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
184 currentPolicy = cs.getPolicy();
185 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy);
186}
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
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500396BOOST_AUTO_TEST_SUITE_END() // StrategyChoice
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600397
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500398BOOST_AUTO_TEST_SUITE(NetworkRegion)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600399
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500400BOOST_AUTO_TEST_CASE(Basic)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600401{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000402 const std::string CONFIG = R"CONFIG(
403 tables
404 {
405 network_region
406 {
407 /test/regionA
408 /test/regionB/component
409 }
410 }
411 )CONFIG";
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600412
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500413 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000414 BOOST_CHECK_EQUAL(networkRegionTable.size(), 0);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600415
Junxiao Shi9685cc52016-08-29 12:47:05 +0000416 BOOST_CHECK(networkRegionTable.find("/test/regionA") == networkRegionTable.end());
417 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") == networkRegionTable.end());
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600418
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500419 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000420 BOOST_CHECK_EQUAL(networkRegionTable.size(), 2);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600421
Junxiao Shi9685cc52016-08-29 12:47:05 +0000422 BOOST_CHECK(networkRegionTable.find("/test/regionA") != networkRegionTable.end());
423 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") != networkRegionTable.end());
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600424}
425
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500426BOOST_AUTO_TEST_CASE(Reload)
427{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000428 const std::string CONFIG1 = R"CONFIG(
429 tables
430 {
431 network_region
432 {
433 /some/region
434 }
435 }
436 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500437
438 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000439 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500440
441 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000442 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500443
Junxiao Shi9685cc52016-08-29 12:47:05 +0000444 const std::string CONFIG2 = R"CONFIG(
445 tables
446 {
447 network_region
448 {
449 /different/region
450 }
451 }
452 )CONFIG";
453
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500454 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000455 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
456 BOOST_CHECK(networkRegionTable.find("/different/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500457
458 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000459 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
460 BOOST_CHECK(networkRegionTable.find("/different/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500461}
462
463BOOST_AUTO_TEST_SUITE_END() // NetworkRegion
464
Junxiao Shi0cc125c2016-08-25 21:50:04 +0000465BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500466BOOST_AUTO_TEST_SUITE_END() // Mgmt
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600467
468} // namespace tests
469} // namespace nfd