blob: 139d61c076298773a5ad0c10b444a177d1a64ca4 [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"
28
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060029#include "tests/test-common.hpp"
Junxiao Shi9685cc52016-08-29 12:47:05 +000030#include "tests/check-typeid.hpp"
Junxiao Shia49a1ab2016-07-15 18:24:36 +000031#include "../fw/dummy-strategy.hpp"
32#include "../fw/install-strategy.hpp"
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060033
34namespace nfd {
35namespace tests {
36
37class TablesConfigSectionFixture : protected BaseFixture
38{
Junxiao Shi9685cc52016-08-29 12:47:05 +000039protected:
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060040 TablesConfigSectionFixture()
Junxiao Shi9685cc52016-08-29 12:47:05 +000041 : cs(forwarder.getCs())
42 , strategyChoice(forwarder.getStrategyChoice())
43 , networkRegionTable(forwarder.getNetworkRegionTable())
44 , tablesConfig(forwarder)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060045 {
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060046 }
47
48 void
Junxiao Shi9685cc52016-08-29 12:47:05 +000049 runConfig(const std::string& config, bool isDryRun)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060050 {
Junxiao Shi9685cc52016-08-29 12:47:05 +000051 ConfigFile cf;
52 tablesConfig.setConfigFile(cf);
53 cf.parse(config, isDryRun, "dummy-config");
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060054 }
55
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060056protected:
Junxiao Shi9685cc52016-08-29 12:47:05 +000057 Forwarder forwarder;
58 Cs& cs;
59 StrategyChoice& strategyChoice;
60 NetworkRegionTable& networkRegionTable;
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060061
Junxiao Shi9685cc52016-08-29 12:47:05 +000062 TablesConfigSection tablesConfig;
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060063};
64
Junxiao Shi9685cc52016-08-29 12:47:05 +000065BOOST_AUTO_TEST_SUITE(Mgmt)
66BOOST_FIXTURE_TEST_SUITE(TestTablesConfigSection, TablesConfigSectionFixture)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060067
Junxiao Shi9685cc52016-08-29 12:47:05 +000068BOOST_AUTO_TEST_SUITE(CsMaxPackets)
69
70BOOST_AUTO_TEST_CASE(NoSection)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060071{
Junxiao Shi9685cc52016-08-29 12:47:05 +000072 const size_t initialLimit = cs.getLimit();
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060073
Junxiao Shi9685cc52016-08-29 12:47:05 +000074 tablesConfig.ensureConfigured();
75 BOOST_CHECK_NE(cs.getLimit(), initialLimit);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060076}
77
Junxiao Shi9685cc52016-08-29 12:47:05 +000078BOOST_AUTO_TEST_CASE(Default)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060079{
Junxiao Shi9685cc52016-08-29 12:47:05 +000080 const std::string CONFIG = R"CONFIG(
81 tables
82 {
83 }
84 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060085
Junxiao Shi9685cc52016-08-29 12:47:05 +000086 const size_t initialLimit = cs.getLimit();
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060087
88 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +000089 BOOST_CHECK_EQUAL(cs.getLimit(), initialLimit);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060090
91 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +000092 BOOST_CHECK_NE(cs.getLimit(), initialLimit);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060093}
94
Junxiao Shi9685cc52016-08-29 12:47:05 +000095BOOST_AUTO_TEST_CASE(Valid)
Vince Lehman63ab1bb2015-09-04 17:06:58 -050096{
Junxiao Shi9685cc52016-08-29 12:47:05 +000097 const std::string CONFIG = R"CONFIG(
98 tables
99 {
100 cs_max_packets 101
101 }
102 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500103
Junxiao Shi9685cc52016-08-29 12:47:05 +0000104 BOOST_REQUIRE_NE(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600105
106 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000107 BOOST_CHECK_NE(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600108
109 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000110 BOOST_CHECK_EQUAL(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600111
Junxiao Shi9685cc52016-08-29 12:47:05 +0000112 tablesConfig.ensureConfigured();
113 BOOST_CHECK_EQUAL(cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600114}
115
Junxiao Shi9685cc52016-08-29 12:47:05 +0000116BOOST_AUTO_TEST_CASE(MissingValue)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600117{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000118 const std::string CONFIG = R"CONFIG(
119 tables
120 {
121 cs_max_packets
122 }
123 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600124
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500125 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
126 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600127}
128
Junxiao Shi9685cc52016-08-29 12:47:05 +0000129BOOST_AUTO_TEST_CASE(InvalidValue)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600130{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000131 const std::string CONFIG = R"CONFIG(
132 tables
133 {
134 cs_max_packets invalid
135 }
136 )CONFIG";
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600137
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500138 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
139 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600140}
141
Junxiao Shi9685cc52016-08-29 12:47:05 +0000142BOOST_AUTO_TEST_SUITE_END() // CsMaxPackets
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500143
Junxiao Shi9685cc52016-08-29 12:47:05 +0000144class CsUnsolicitedPolicyFixture : public TablesConfigSectionFixture
145{
146protected:
147 class DummyUnsolicitedDataPolicy : public fw::AdmitNetworkUnsolicitedDataPolicy
148 {
149 };
150
151 CsUnsolicitedPolicyFixture()
152 {
153 forwarder.setUnsolicitedDataPolicy(make_unique<DummyUnsolicitedDataPolicy>());
154 }
155};
156
157BOOST_FIXTURE_TEST_SUITE(CsUnsolicitedPolicy, CsUnsolicitedPolicyFixture)
158
159BOOST_AUTO_TEST_CASE(NoSection)
160{
161 tablesConfig.ensureConfigured();
162
163 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
164 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
165}
166
167BOOST_AUTO_TEST_CASE(Default)
168{
169 const std::string CONFIG = R"CONFIG(
170 tables
171 {
172 }
173 )CONFIG";
174
175 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
176 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
177 NFD_CHECK_TYPEID_NE(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
178
179 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
180 currentPolicy = &forwarder.getUnsolicitedDataPolicy();
181 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::DefaultUnsolicitedDataPolicy);
182}
183
184BOOST_AUTO_TEST_CASE(Known)
185{
186 const std::string CONFIG = R"CONFIG(
187 tables
188 {
189 cs_unsolicited_policy admit-all
190 }
191 )CONFIG";
192
193 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
194 fw::UnsolicitedDataPolicy* currentPolicy = &forwarder.getUnsolicitedDataPolicy();
195 NFD_CHECK_TYPEID_NE(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
196
197 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
198 currentPolicy = &forwarder.getUnsolicitedDataPolicy();
199 NFD_CHECK_TYPEID_EQUAL(*currentPolicy, fw::AdmitAllUnsolicitedDataPolicy);
200}
201
202BOOST_AUTO_TEST_CASE(Unknown)
203{
204 const std::string CONFIG = R"CONFIG(
205 tables
206 {
207 cs_unsolicited_policy unknown
208 }
209 )CONFIG";
210
211 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
212 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
213}
214
215BOOST_AUTO_TEST_SUITE_END() // CsUnsolicitedPolicy
216
217BOOST_AUTO_TEST_SUITE(StrategyChoice)
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500218
219BOOST_AUTO_TEST_CASE(Unversioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700220{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000221 const std::string CONFIG = R"CONFIG(
222 tables
223 {
224 strategy_choice
225 {
226 / /localhost/nfd/strategy/test-strategy-a
227 /a /localhost/nfd/strategy/test-strategy-b
228 }
229 }
230 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700231
Junxiao Shi9685cc52016-08-29 12:47:05 +0000232 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a");
233 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700234
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500235 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700236 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000237 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700238 BOOST_REQUIRE_NE(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
239 BOOST_REQUIRE_NE(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
240
Junxiao Shi9685cc52016-08-29 12:47:05 +0000241 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700242 BOOST_REQUIRE_NE(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
243 BOOST_REQUIRE_NE(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
244 }
245
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500246 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700247 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000248 fw::Strategy& rootStrategy = strategyChoice.findEffectiveStrategy("/");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700249 BOOST_REQUIRE_EQUAL(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
250
Junxiao Shi9685cc52016-08-29 12:47:05 +0000251 fw::Strategy& aStrategy = strategyChoice.findEffectiveStrategy("/a");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700252 BOOST_REQUIRE_EQUAL(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
253 }
254}
255
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500256BOOST_AUTO_TEST_CASE(Versioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700257{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000258 const std::string CONFIG = R"CONFIG(
259 tables
260 {
261 strategy_choice
262 {
263 /test/latest /localhost/nfd/strategy/test-strategy-a
264 /test/old /localhost/nfd/strategy/test-strategy-a/%FD%01
265 }
266 }
267 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700268
Junxiao Shi9685cc52016-08-29 12:47:05 +0000269 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a/%FD%01");
270 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a/%FD%02");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700271
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500272 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700273 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000274 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700275 BOOST_REQUIRE_NE(testLatestStrategy.getName(),
276 "/localhost/nfd/strategy/test-strategy-a/%FD%01");
277 BOOST_REQUIRE_NE(testLatestStrategy.getName(),
278 "/localhost/nfd/strategy/test-strategy-a/%FD%02");
279
Junxiao Shi9685cc52016-08-29 12:47:05 +0000280 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700281 BOOST_REQUIRE_NE(testOldStrategy.getName(),
282 "/localhost/nfd/strategy/test-strategy-a/%FD%01");
283 BOOST_REQUIRE_NE(testOldStrategy.getName(),
284 "/localhost/nfd/strategy/test-strategy-a/%FD%02");
285 }
286
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500287 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700288 {
Junxiao Shi9685cc52016-08-29 12:47:05 +0000289 fw::Strategy& testLatestStrategy = strategyChoice.findEffectiveStrategy("/test/latest");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700290 BOOST_REQUIRE_EQUAL(testLatestStrategy.getName(),
291 "/localhost/nfd/strategy/test-strategy-a/%FD%02");
292
Junxiao Shi9685cc52016-08-29 12:47:05 +0000293 fw::Strategy& testOldStrategy = strategyChoice.findEffectiveStrategy("/test/old");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700294 BOOST_REQUIRE_EQUAL(testOldStrategy.getName(),
295 "/localhost/nfd/strategy/test-strategy-a/%FD%01");
296 }
297}
298
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500299BOOST_AUTO_TEST_CASE(NonExisting)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700300{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000301 const std::string CONFIG = R"CONFIG(
302 tables
303 {
304 strategy_choice
305 {
306 / /localhost/nfd/strategy/test-doesnotexist
307 }
308 }
309 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700310
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500311 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
312 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700313}
314
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500315BOOST_AUTO_TEST_CASE(MissingPrefix)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700316{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000317 const std::string CONFIG = R"CONFIG(
318 tables
319 {
320 strategy_choice
321 {
322 /localhost/nfd/strategy/test-strategy-a
323 }
324 }
325 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700326
Junxiao Shi9685cc52016-08-29 12:47:05 +0000327 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700328
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500329 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
330 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700331}
332
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500333BOOST_AUTO_TEST_CASE(Duplicate)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700334{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000335 const std::string CONFIG = R"CONFIG(
336 tables
337 {
338 strategy_choice
339 {
340 / /localhost/nfd/strategy/test-strategy-a
341 /a /localhost/nfd/strategy/test-strategy-b
342 / /localhost/nfd/strategy/test-strategy-b
343 }
344 }
345 )CONFIG";
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700346
Junxiao Shi9685cc52016-08-29 12:47:05 +0000347 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-a");
348 install<DummyStrategy>(forwarder, "/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700349
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500350 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
351 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700352}
353
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500354BOOST_AUTO_TEST_SUITE_END() // StrategyChoice
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600355
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500356BOOST_AUTO_TEST_SUITE(NetworkRegion)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600357
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500358BOOST_AUTO_TEST_CASE(Basic)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600359{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000360 const std::string CONFIG = R"CONFIG(
361 tables
362 {
363 network_region
364 {
365 /test/regionA
366 /test/regionB/component
367 }
368 }
369 )CONFIG";
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600370
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500371 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000372 BOOST_CHECK_EQUAL(networkRegionTable.size(), 0);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600373
Junxiao Shi9685cc52016-08-29 12:47:05 +0000374 BOOST_CHECK(networkRegionTable.find("/test/regionA") == networkRegionTable.end());
375 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") == networkRegionTable.end());
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600376
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500377 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000378 BOOST_CHECK_EQUAL(networkRegionTable.size(), 2);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600379
Junxiao Shi9685cc52016-08-29 12:47:05 +0000380 BOOST_CHECK(networkRegionTable.find("/test/regionA") != networkRegionTable.end());
381 BOOST_CHECK(networkRegionTable.find("/test/regionB/component") != networkRegionTable.end());
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600382}
383
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500384BOOST_AUTO_TEST_CASE(Reload)
385{
Junxiao Shi9685cc52016-08-29 12:47:05 +0000386 const std::string CONFIG1 = R"CONFIG(
387 tables
388 {
389 network_region
390 {
391 /some/region
392 }
393 }
394 )CONFIG";
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500395
396 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000397 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500398
399 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000400 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500401
Junxiao Shi9685cc52016-08-29 12:47:05 +0000402 const std::string CONFIG2 = R"CONFIG(
403 tables
404 {
405 network_region
406 {
407 /different/region
408 }
409 }
410 )CONFIG";
411
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500412 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000413 BOOST_CHECK(networkRegionTable.find("/some/region") != networkRegionTable.end());
414 BOOST_CHECK(networkRegionTable.find("/different/region") == networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500415
416 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false));
Junxiao Shi9685cc52016-08-29 12:47:05 +0000417 BOOST_CHECK(networkRegionTable.find("/some/region") == networkRegionTable.end());
418 BOOST_CHECK(networkRegionTable.find("/different/region") != networkRegionTable.end());
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500419}
420
421BOOST_AUTO_TEST_SUITE_END() // NetworkRegion
422
Junxiao Shi0cc125c2016-08-25 21:50:04 +0000423BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500424BOOST_AUTO_TEST_SUITE_END() // Mgmt
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600425
426} // namespace tests
427} // namespace nfd