blob: 5d9b636c1a6cfb452a81cf2ae3af5edc4339973a [file] [log] [blame]
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Spyridon Mastorakisd0381c02015-02-19 10:29:41 -08003 * Copyright (c) 2014-2015, Regents of the University of California,
4 * 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
29
30#include "tests/test-common.hpp"
Steve DiBenedettoc0640f52014-11-03 15:55:43 -070031#include "tests/daemon/fw/dummy-strategy.hpp"
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060032
33namespace nfd {
34namespace tests {
35
36class TablesConfigSectionFixture : protected BaseFixture
37{
38public:
39
40 TablesConfigSectionFixture()
41 : m_cs(m_forwarder.getCs())
42 , m_pit(m_forwarder.getPit())
43 , m_fib(m_forwarder.getFib())
44 , m_strategyChoice(m_forwarder.getStrategyChoice())
45 , m_measurements(m_forwarder.getMeasurements())
Vince Lehman63ab1bb2015-09-04 17:06:58 -050046 , m_networkRegionTable(m_forwarder.getNetworkRegionTable())
47 , m_tablesConfig(m_cs, m_pit, m_fib, m_strategyChoice, m_measurements, m_networkRegionTable)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060048 {
49 m_tablesConfig.setConfigFile(m_config);
50 }
51
52 void
53 runConfig(const std::string& CONFIG, bool isDryRun)
54 {
55 m_config.parse(CONFIG, isDryRun, "dummy-config");
56 }
57
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060058protected:
59 Forwarder m_forwarder;
60
61 Cs& m_cs;
62 Pit& m_pit;
63 Fib& m_fib;
64 StrategyChoice& m_strategyChoice;
65 Measurements& m_measurements;
Vince Lehman63ab1bb2015-09-04 17:06:58 -050066 NetworkRegionTable& m_networkRegionTable;
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060067
68 TablesConfigSection m_tablesConfig;
69 ConfigFile m_config;
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060070};
71
Vince Lehman63ab1bb2015-09-04 17:06:58 -050072BOOST_FIXTURE_TEST_SUITE(Mgmt, TablesConfigSectionFixture)
73BOOST_AUTO_TEST_SUITE(TestTablesConfigSection)
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060074
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060075BOOST_AUTO_TEST_CASE(ConfigureTablesWithDefaults)
76{
77 const size_t initialLimit = m_cs.getLimit();
78
79 m_tablesConfig.ensureTablesAreConfigured();
80 BOOST_CHECK_NE(initialLimit, m_cs.getLimit());
81}
82
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060083BOOST_AUTO_TEST_CASE(EmptyTablesSection)
84{
85 const std::string CONFIG =
86 "tables\n"
87 "{\n"
88 "}\n";
89
90 const size_t nCsMaxPackets = m_cs.getLimit();
91
92 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060093 BOOST_CHECK_EQUAL(m_cs.getLimit(), nCsMaxPackets);
94
95 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060096 BOOST_CHECK_NE(m_cs.getLimit(), nCsMaxPackets);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -060097
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060098 const size_t defaultLimit = m_cs.getLimit();
99
100 m_tablesConfig.ensureTablesAreConfigured();
101 BOOST_CHECK_EQUAL(defaultLimit, m_cs.getLimit());
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600102}
103
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500104BOOST_AUTO_TEST_CASE(MissingTablesSection)
105{
106 const std::string CONFIG =
107 "not_tables\n"
108 "{\n"
109 " some_other_field 0\n"
110 "}\n";
111
112 ConfigFile passiveConfig(&ConfigFile::ignoreUnknownSection);
113
114 const size_t initialLimit = m_cs.getLimit();
115
116 passiveConfig.parse(CONFIG, true, "dummy-config");
117 BOOST_REQUIRE_EQUAL(initialLimit, m_cs.getLimit());
118
119 passiveConfig.parse(CONFIG, false, "dummy-config");
120 BOOST_REQUIRE_EQUAL(initialLimit, m_cs.getLimit());
121
122 m_tablesConfig.ensureTablesAreConfigured();
123 BOOST_CHECK_NE(initialLimit, m_cs.getLimit());
124}
125
126BOOST_AUTO_TEST_SUITE(Cs)
127
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600128BOOST_AUTO_TEST_CASE(ValidCsMaxPackets)
129{
130 const std::string CONFIG =
131 "tables\n"
132 "{\n"
133 " cs_max_packets 101\n"
134 "}\n";
135
136 BOOST_REQUIRE_NE(m_cs.getLimit(), 101);
137
138 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600139 BOOST_CHECK_NE(m_cs.getLimit(), 101);
140
141 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600142 BOOST_CHECK_EQUAL(m_cs.getLimit(), 101);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600143
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600144 m_tablesConfig.ensureTablesAreConfigured();
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600145 BOOST_CHECK_EQUAL(m_cs.getLimit(), 101);
146}
147
148BOOST_AUTO_TEST_CASE(MissingValueCsMaxPackets)
149{
150 const std::string CONFIG =
151 "tables\n"
152 "{\n"
153 " cs_max_packets\n"
154 "}\n";
155
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500156 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
157 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600158}
159
160BOOST_AUTO_TEST_CASE(InvalidValueCsMaxPackets)
161{
162 const std::string CONFIG =
163 "tables\n"
164 "{\n"
165 " cs_max_packets invalid\n"
166 "}\n";
167
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500168 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
169 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600170}
171
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500172BOOST_AUTO_TEST_SUITE_END() // Cs
173
174BOOST_AUTO_TEST_SUITE(ConfigStrategy)
175
176BOOST_AUTO_TEST_CASE(Unversioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700177{
178 const std::string CONFIG =
179 "tables\n"
180 "{\n"
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500181 " strategy_choice\n"
182 " {\n"
183 " / /localhost/nfd/strategy/test-strategy-a\n"
184 " /a /localhost/nfd/strategy/test-strategy-b\n"
185 " }\n"
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700186 "}\n";
187
188 m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
189 "/localhost/nfd/strategy/test-strategy-a"));
190 m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
191 "/localhost/nfd/strategy/test-strategy-b"));
192
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500193 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700194 {
195 fw::Strategy& rootStrategy = m_strategyChoice.findEffectiveStrategy("/");
196 BOOST_REQUIRE_NE(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
197 BOOST_REQUIRE_NE(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
198
199 fw::Strategy& aStrategy = m_strategyChoice.findEffectiveStrategy("/a");
200 BOOST_REQUIRE_NE(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
201 BOOST_REQUIRE_NE(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
202 }
203
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500204 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700205 {
206 fw::Strategy& rootStrategy = m_strategyChoice.findEffectiveStrategy("/");
207 BOOST_REQUIRE_EQUAL(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
208
209 fw::Strategy& aStrategy = m_strategyChoice.findEffectiveStrategy("/a");
210 BOOST_REQUIRE_EQUAL(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
211 }
212}
213
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500214BOOST_AUTO_TEST_CASE(Versioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700215{
216 const std::string CONFIG =
217 "tables\n"
218 "{\n"
219 "strategy_choice\n"
220 "{\n"
221 " /test/latest /localhost/nfd/strategy/test-strategy-a\n"
222 " /test/old /localhost/nfd/strategy/test-strategy-a/%FD%01\n"
223 "}\n"
224 "}\n";
225
226
227 auto version1 = make_shared<DummyStrategy>(ref(m_forwarder),
228 "/localhost/nfd/strategy/test-strategy-a/%FD%01");
229
230 auto version2 = make_shared<DummyStrategy>(ref(m_forwarder),
231 "/localhost/nfd/strategy/test-strategy-a/%FD%02");
232 m_strategyChoice.install(version1);
233 m_strategyChoice.install(version2);
234
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500235 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700236 {
237 fw::Strategy& testLatestStrategy = m_strategyChoice.findEffectiveStrategy("/test/latest");
238 BOOST_REQUIRE_NE(testLatestStrategy.getName(),
239 "/localhost/nfd/strategy/test-strategy-a/%FD%01");
240 BOOST_REQUIRE_NE(testLatestStrategy.getName(),
241 "/localhost/nfd/strategy/test-strategy-a/%FD%02");
242
243 fw::Strategy& testOldStrategy = m_strategyChoice.findEffectiveStrategy("/test/old");
244 BOOST_REQUIRE_NE(testOldStrategy.getName(),
245 "/localhost/nfd/strategy/test-strategy-a/%FD%01");
246 BOOST_REQUIRE_NE(testOldStrategy.getName(),
247 "/localhost/nfd/strategy/test-strategy-a/%FD%02");
248 }
249
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500250 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700251 {
252 fw::Strategy& testLatestStrategy = m_strategyChoice.findEffectiveStrategy("/test/latest");
253 BOOST_REQUIRE_EQUAL(testLatestStrategy.getName(),
254 "/localhost/nfd/strategy/test-strategy-a/%FD%02");
255
256 fw::Strategy& testOldStrategy = m_strategyChoice.findEffectiveStrategy("/test/old");
257 BOOST_REQUIRE_EQUAL(testOldStrategy.getName(),
258 "/localhost/nfd/strategy/test-strategy-a/%FD%01");
259 }
260}
261
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500262BOOST_AUTO_TEST_CASE(NonExisting)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700263{
264 const std::string CONFIG =
265 "tables\n"
266 "{\n"
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500267 " strategy_choice\n"
268 " {\n"
269 " / /localhost/nfd/strategy/test-doesnotexist\n"
270 " }\n"
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700271 "}\n";
272
273
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500274 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
275 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700276}
277
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500278BOOST_AUTO_TEST_CASE(MissingPrefix)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700279{
280 const std::string CONFIG =
281 "tables\n"
282 "{\n"
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500283 " strategy_choice\n"
284 " {\n"
285 " /localhost/nfd/strategy/test-strategy-a\n"
286 " }\n"
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700287 "}\n";
288
289
290 m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
291 "/localhost/nfd/strategy/test-strategy-a"));
292
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500293 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
294 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700295}
296
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500297BOOST_AUTO_TEST_CASE(Duplicate)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700298{
299 const std::string CONFIG =
300 "tables\n"
301 "{\n"
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500302 " strategy_choice\n"
303 " {\n"
304 " / /localhost/nfd/strategy/test-strategy-a\n"
305 " /a /localhost/nfd/strategy/test-strategy-b\n"
306 " / /localhost/nfd/strategy/test-strategy-b\n"
307 " }\n"
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700308 "}\n";
309
310 m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
311 "/localhost/nfd/strategy/test-strategy-a"));
312 m_strategyChoice.install(make_shared<DummyStrategy>(ref(m_forwarder),
313 "/localhost/nfd/strategy/test-strategy-b"));
314
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500315 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
316 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700317}
318
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500319BOOST_AUTO_TEST_SUITE_END() // StrategyChoice
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600320
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500321BOOST_AUTO_TEST_SUITE(NetworkRegion)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600322
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500323BOOST_AUTO_TEST_CASE(Basic)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600324{
325 const std::string CONFIG =
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500326 "tables\n"
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600327 "{\n"
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500328 " network_region\n"
329 " {\n"
330 " /test/regionA\n"
331 " /test/regionB/component\n"
332 " }\n"
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600333 "}\n";
334
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500335 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
336 BOOST_CHECK_EQUAL(m_networkRegionTable.size(), 0);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600337
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500338 BOOST_CHECK(m_networkRegionTable.find("/test/regionA") == m_networkRegionTable.end());
339 BOOST_CHECK(m_networkRegionTable.find("/test/regionB/component") == m_networkRegionTable.end());
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600340
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500341 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
342 BOOST_CHECK_EQUAL(m_networkRegionTable.size(), 2);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600343
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500344 BOOST_CHECK(m_networkRegionTable.find("/test/regionA") != m_networkRegionTable.end());
345 BOOST_CHECK(m_networkRegionTable.find("/test/regionB/component") != m_networkRegionTable.end());
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600346}
347
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500348BOOST_AUTO_TEST_CASE(Reload)
349{
350 const std::string CONFIG1 =
351 "tables\n"
352 "{\n"
353 " network_region\n"
354 " {\n"
355 " /some/region\n"
356 " }\n"
357 "}\n";
358
359 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true));
360 BOOST_CHECK(m_networkRegionTable.find("/some/region") == m_networkRegionTable.end());
361
362 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false));
363 BOOST_CHECK(m_networkRegionTable.find("/some/region") != m_networkRegionTable.end());
364
365 const std::string CONFIG2 =
366 "tables\n"
367 "{\n"
368 " network_region\n"
369 " {\n"
370 " /different/region\n"
371 " }\n"
372 "}\n";
373 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true));
374 BOOST_CHECK(m_networkRegionTable.find("/some/region") != m_networkRegionTable.end());
375 BOOST_CHECK(m_networkRegionTable.find("/different/region") == m_networkRegionTable.end());
376
377 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false));
378 BOOST_CHECK(m_networkRegionTable.find("/some/region") == m_networkRegionTable.end());
379 BOOST_CHECK(m_networkRegionTable.find("/different/region") != m_networkRegionTable.end());
380}
381
382BOOST_AUTO_TEST_SUITE_END() // NetworkRegion
383
384BOOST_AUTO_TEST_SUITE_END() // TestTableConfigSection
385BOOST_AUTO_TEST_SUITE_END() // Mgmt
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600386
387} // namespace tests
388} // namespace nfd