blob: 25c621c9c5cab5bd3595b2a5c579144706116621 [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"
34#include "../fw/install-strategy.hpp"
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060035
36namespace nfd {
37namespace tests {
38
39class TablesConfigSectionFixture : protected BaseFixture
40{
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)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060047 {
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060048 }
49
50 void
Junxiao Shi9685cc52016-08-29 12:47:05 +000051 runConfig(const std::string& config, bool isDryRun)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060052 {
Junxiao Shi9685cc52016-08-29 12:47:05 +000053 ConfigFile cf;
54 tablesConfig.setConfigFile(cf);
55 cf.parse(config, isDryRun, "dummy-config");
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060056 }
57
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060058protected:
Junxiao Shi9685cc52016-08-29 12:47:05 +000059 Forwarder forwarder;
60 Cs& cs;
61 StrategyChoice& strategyChoice;
62 NetworkRegionTable& networkRegionTable;
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060063
Junxiao Shi9685cc52016-08-29 12:47:05 +000064 TablesConfigSection tablesConfig;
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060065};
66
Junxiao Shi9685cc52016-08-29 12:47:05 +000067BOOST_AUTO_TEST_SUITE(Mgmt)
68BOOST_FIXTURE_TEST_SUITE(TestTablesConfigSection, TablesConfigSectionFixture)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060069
Junxiao Shi9685cc52016-08-29 12:47:05 +000070BOOST_AUTO_TEST_SUITE(CsMaxPackets)
71
72BOOST_AUTO_TEST_CASE(NoSection)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060073{
Junxiao Shi9685cc52016-08-29 12:47:05 +000074 const size_t initialLimit = cs.getLimit();
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060075
Junxiao Shi9685cc52016-08-29 12:47:05 +000076 tablesConfig.ensureConfigured();
77 BOOST_CHECK_NE(cs.getLimit(), initialLimit);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060078}
79
Junxiao Shi9685cc52016-08-29 12:47:05 +000080BOOST_AUTO_TEST_CASE(Default)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060081{
Junxiao Shi9685cc52016-08-29 12:47:05 +000082 const std::string CONFIG = R"CONFIG(
83 tables
84 {
85 }
86 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060087
Junxiao Shi9685cc52016-08-29 12:47:05 +000088 const size_t initialLimit = cs.getLimit();
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060089
90 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +000091 BOOST_CHECK_EQUAL(cs.getLimit(), initialLimit);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060092
93 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +000094 BOOST_CHECK_NE(cs.getLimit(), initialLimit);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060095}
96
Junxiao Shi9685cc52016-08-29 12:47:05 +000097BOOST_AUTO_TEST_CASE(Valid)
Vince Lehman63ab1bb2015-09-04 17:06:58 -050098{
Junxiao Shi9685cc52016-08-29 12:47:05 +000099 const std::string CONFIG = R"CONFIG(
100 tables
101 {
102 cs_max_packets 101
103 }
104 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500105
Junxiao Shi9685cc52016-08-29 12:47:05 +0000106 BOOST_REQUIRE_NE(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600107
108 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000109 BOOST_CHECK_NE(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600110
111 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000112 BOOST_CHECK_EQUAL(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600113
Junxiao Shi9685cc52016-08-29 12:47:05 +0000114 tablesConfig.ensureConfigured();
115 BOOST_CHECK_EQUAL(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600116}
117
Junxiao Shi9685cc52016-08-29 12:47:05 +0000118BOOST_AUTO_TEST_CASE(MissingValue)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600119{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000120 const std::string CONFIG = R"CONFIG(
121 tables
122 {
123 cs_max_packets
124 }
125 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600126
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500127 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
128 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600129}
130
Junxiao Shi9685cc52016-08-29 12:47:05 +0000131BOOST_AUTO_TEST_CASE(InvalidValue)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600132{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000133 const std::string CONFIG = R"CONFIG(
134 tables
135 {
136 cs_max_packets invalid
137 }
138 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600139
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500140 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
141 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600142}
143
Junxiao Shi9685cc52016-08-29 12:47:05 +0000144BOOST_AUTO_TEST_SUITE_END() // CsMaxPackets
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500145
Junxiao Shib4a5acd2016-12-07 19:59:18 +0000146BOOST_AUTO_TEST_SUITE(CsPolicy)
147
148BOOST_AUTO_TEST_CASE(Default)
149{
150 const std::string CONFIG = R"CONFIG(
151 tables
152 {
153 }
154 )CONFIG";
155
156 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
157 cs::Policy* currentPolicy = cs.getPolicy();
158 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy);
159}
160
161BOOST_AUTO_TEST_CASE(Known)
162{
163 const std::string CONFIG = R"CONFIG(
164 tables
165 {
166 cs_policy lru
167 }
168 )CONFIG";
169
170 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
171 cs::Policy* currentPolicy = cs.getPolicy();
172 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::PriorityFifoPolicy);
173
174 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
175 currentPolicy = cs.getPolicy();
176 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, cs::LruPolicy);
177}
178
179BOOST_AUTO_TEST_CASE(Unknown)
180{
181 const std::string CONFIG = R"CONFIG(
182 tables
183 {
184 cs_policy unknown
185 }
186 )CONFIG";
187
188 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
189 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
190}
191
192BOOST_AUTO_TEST_SUITE_END() // CsPolicy
193
Junxiao Shi9685cc52016-08-29 12:47:05 +0000194class CsUnsolicitedPolicyFixture : public TablesConfigSectionFixture
195{
196protected:
197 class DummyUnsolicitedDataPolicy : public fw::AdmitNetworkUnsolicitedDataPolicy
198 {
199 };
200
201 CsUnsolicitedPolicyFixture()
202 {
203 forwarder.setUnsolicitedDataPolicy(make_unique<DummyUnsolicitedDataPolicy>());
204 }
205};
206
207BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture)
208
209BOOST_AUTO_TEST_CASE(NoSection)
210{
211 tablesConfig.ensureConfigured();
212
213 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
214 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
215}
216
217BOOST_AUTO_TEST_CASE(Default)
218{
219 const std::string CONFIG = R"CONFIG(
220 tables
221 {
222 }
223 )CONFIG";
224
225 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
226 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
227 NFD_CHECK_TYPEID_NE(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
228
229 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
230 currentPolicy = &forwarder.getUnsolicitedDataPolicy();
231 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
232}
233
234BOOST_AUTO_TEST_CASE(Known)
235{
236 const std::string CONFIG = R"CONFIG(
237 tables
238 {
239 cs_unsolicited_policy admit-all
240 }
241 )CONFIG";
242
243 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
244 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
245 NFD_CHECK_TYPEID_NE(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
246
247 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
248 currentPolicy = &forwarder.getUnsolicitedDataPolicy();
249 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
250}
251
252BOOST_AUTO_TEST_CASE(Unknown)
253{
254 const std::string CONFIG = R"CONFIG(
255 tables
256 {
257 cs_unsolicited_policy unknown
258 }
259 )CONFIG";
260
261 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
262 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
263}
264
265BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy
266
267BOOST_AUTO_TEST_SUITE(StrategyChoice)
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500268
269BOOST_AUTO_TEST_CASE(Unversioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700270{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000271 const std::string CONFIG = R"CONFIG(
272 tables
273 {
274 strategy_choice
275 {
276 / /localhost/nfd/strategy/test-strategy-a
277 /a /localhost/nfd/strategy/test-strategy-b
278 }
279 }
280 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700281
Junxiao Shi9685cc52016-08-29 12:47:05 +0000282 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a");
283 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700284
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500285 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700286 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000287 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700288 BOOST_REQUIRE_NE(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
289 BOOST_REQUIRE_NE(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
290
Junxiao Shi9685cc52016-08-29 12:47:05 +0000291 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700292 BOOST_REQUIRE_NE(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
293 BOOST_REQUIRE_NE(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
294 }
295
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500296 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700297 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000298 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700299 BOOST_REQUIRE_EQUAL(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
300
Junxiao Shi9685cc52016-08-29 12:47:05 +0000301 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700302 BOOST_REQUIRE_EQUAL(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
303 }
304}
305
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500306BOOST_AUTO_TEST_CASE(Versioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700307{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000308 const std::string CONFIG = R"CONFIG(
309 tables
310 {
311 strategy_choice
312 {
313 /test/latest /localhost/nfd/strategy/test-strategy-a
314 /test/old /localhost/nfd/strategy/test-strategy-a/%FD%01
315 }
316 }
317 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700318
Junxiao Shi9685cc52016-08-29 12:47:05 +0000319 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a/%FD%01");
320 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a/%FD%02");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700321
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500322 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700323 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000324 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700325 BOOST_REQUIRE_NE(testLatestStrategy.getName(),
326 "/localhost/nfd/strategy/test-strategy-a/%FD%01");
327 BOOST_REQUIRE_NE(testLatestStrategy.getName(),
328 "/localhost/nfd/strategy/test-strategy-a/%FD%02");
329
Junxiao Shi9685cc52016-08-29 12:47:05 +0000330 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700331 BOOST_REQUIRE_NE(testOldStrategy.getName(),
332 "/localhost/nfd/strategy/test-strategy-a/%FD%01");
333 BOOST_REQUIRE_NE(testOldStrategy.getName(),
334 "/localhost/nfd/strategy/test-strategy-a/%FD%02");
335 }
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");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700340 BOOST_REQUIRE_EQUAL(testLatestStrategy.getName(),
341 "/localhost/nfd/strategy/test-strategy-a/%FD%02");
342
Junxiao Shi9685cc52016-08-29 12:47:05 +0000343 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700344 BOOST_REQUIRE_EQUAL(testOldStrategy.getName(),
345 "/localhost/nfd/strategy/test-strategy-a/%FD%01");
346 }
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 {
372 /localhost/nfd/strategy/test-strategy-a
373 }
374 }
375 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700376
Junxiao Shi9685cc52016-08-29 12:47:05 +0000377 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700378
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500379 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
380 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700381}
382
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500383BOOST_AUTO_TEST_CASE(Duplicate)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700384{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000385 const std::string CONFIG = R"CONFIG(
386 tables
387 {
388 strategy_choice
389 {
390 / /localhost/nfd/strategy/test-strategy-a
391 /a /localhost/nfd/strategy/test-strategy-b
392 / /localhost/nfd/strategy/test-strategy-b
393 }
394 }
395 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700396
Junxiao Shi9685cc52016-08-29 12:47:05 +0000397 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a");
398 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700399
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500400 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
401 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700402}
403
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500404BOOST_AUTO_TEST_SUITE_END() // StrategyChoice
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600405
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500406BOOST_AUTO_TEST_SUITE(NetworkRegion)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600407
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500408BOOST_AUTO_TEST_CASE(Basic)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600409{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000410 const std::string CONFIG = R"CONFIG(
411 tables
412 {
413 network_region
414 {
415 /test/regionA
416 /test/regionB/component
417 }
418 }
419 )CONFIG";
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600420
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500421 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000422 BOOST_CHECK_EQUAL(networkRegionTable.size(), 0);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600423
Junxiao Shi9685cc52016-08-29 12:47:05 +0000424 BOOST_CHECK(networkRegionTable.find("/test/regionA") == networkRegionTable.end());
425 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") == networkRegionTable.end());
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600426
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500427 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000428 BOOST_CHECK_EQUAL(networkRegionTable.size(), 2);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600429
Junxiao Shi9685cc52016-08-29 12:47:05 +0000430 BOOST_CHECK(networkRegionTable.find("/test/regionA") != networkRegionTable.end());
431 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") != networkRegionTable.end());
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600432}
433
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500434BOOST_AUTO_TEST_CASE(Reload)
435{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000436 const std::string CONFIG1 = R"CONFIG(
437 tables
438 {
439 network_region
440 {
441 /some/region
442 }
443 }
444 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500445
446 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000447 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500448
449 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000450 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500451
Junxiao Shi9685cc52016-08-29 12:47:05 +0000452 const std::string CONFIG2 = R"CONFIG(
453 tables
454 {
455 network_region
456 {
457 /different/region
458 }
459 }
460 )CONFIG";
461
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500462 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000463 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
464 BOOST_CHECK(networkRegionTable.find("/different/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500465
466 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000467 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
468 BOOST_CHECK(networkRegionTable.find("/different/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500469}
470
471BOOST_AUTO_TEST_SUITE_END() // NetworkRegion
472
Junxiao Shi0cc125c2016-08-25 21:50:04 +0000473BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500474BOOST_AUTO_TEST_SUITE_END() // Mgmt
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600475
476} // namespace tests
477} // namespace nfd