blob: d87c6e60cfe06da766901c9c9990d96c586d48e9 [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 Shia49a1ab2016-07-15 18:24:36 +000030#include "../fw/dummy-strategy.hpp"
31#include "../fw/install-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())
Junxiao Shi0cc125c2016-08-25 21:50:04 +000047 , m_tablesConfig(m_forwarder)
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
Junxiao Shi0cc125c2016-08-25 21:50:04 +000079 m_tablesConfig.ensureConfigured();
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -060080 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
Junxiao Shi0cc125c2016-08-25 21:50:04 +0000100 m_tablesConfig.ensureConfigured();
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600101 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
Junxiao Shi0cc125c2016-08-25 21:50:04 +0000122 m_tablesConfig.ensureConfigured();
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500123 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
Junxiao Shi0cc125c2016-08-25 21:50:04 +0000144 m_tablesConfig.ensureConfigured();
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
Junxiao Shia49a1ab2016-07-15 18:24:36 +0000188 install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a");
189 install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700190
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500191 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700192 {
193 fw::Strategy& rootStrategy = m_strategyChoice.findEffectiveStrategy("/");
194 BOOST_REQUIRE_NE(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
195 BOOST_REQUIRE_NE(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
196
197 fw::Strategy& aStrategy = m_strategyChoice.findEffectiveStrategy("/a");
198 BOOST_REQUIRE_NE(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
199 BOOST_REQUIRE_NE(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
200 }
201
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500202 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700203 {
204 fw::Strategy& rootStrategy = m_strategyChoice.findEffectiveStrategy("/");
205 BOOST_REQUIRE_EQUAL(rootStrategy.getName(), "/localhost/nfd/strategy/test-strategy-a");
206
207 fw::Strategy& aStrategy = m_strategyChoice.findEffectiveStrategy("/a");
208 BOOST_REQUIRE_EQUAL(aStrategy.getName(), "/localhost/nfd/strategy/test-strategy-b");
209 }
210}
211
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500212BOOST_AUTO_TEST_CASE(Versioned)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700213{
214 const std::string CONFIG =
215 "tables\n"
216 "{\n"
217 "strategy_choice\n"
218 "{\n"
219 " /test/latest /localhost/nfd/strategy/test-strategy-a\n"
220 " /test/old /localhost/nfd/strategy/test-strategy-a/%FD%01\n"
221 "}\n"
222 "}\n";
223
224
Junxiao Shia49a1ab2016-07-15 18:24:36 +0000225 install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a/%FD%01");
226 install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a/%FD%02");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700227
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500228 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700229 {
230 fw::Strategy& testLatestStrategy = m_strategyChoice.findEffectiveStrategy("/test/latest");
231 BOOST_REQUIRE_NE(testLatestStrategy.getName(),
232 "/localhost/nfd/strategy/test-strategy-a/%FD%01");
233 BOOST_REQUIRE_NE(testLatestStrategy.getName(),
234 "/localhost/nfd/strategy/test-strategy-a/%FD%02");
235
236 fw::Strategy& testOldStrategy = m_strategyChoice.findEffectiveStrategy("/test/old");
237 BOOST_REQUIRE_NE(testOldStrategy.getName(),
238 "/localhost/nfd/strategy/test-strategy-a/%FD%01");
239 BOOST_REQUIRE_NE(testOldStrategy.getName(),
240 "/localhost/nfd/strategy/test-strategy-a/%FD%02");
241 }
242
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500243 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700244 {
245 fw::Strategy& testLatestStrategy = m_strategyChoice.findEffectiveStrategy("/test/latest");
246 BOOST_REQUIRE_EQUAL(testLatestStrategy.getName(),
247 "/localhost/nfd/strategy/test-strategy-a/%FD%02");
248
249 fw::Strategy& testOldStrategy = m_strategyChoice.findEffectiveStrategy("/test/old");
250 BOOST_REQUIRE_EQUAL(testOldStrategy.getName(),
251 "/localhost/nfd/strategy/test-strategy-a/%FD%01");
252 }
253}
254
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500255BOOST_AUTO_TEST_CASE(NonExisting)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700256{
257 const std::string CONFIG =
258 "tables\n"
259 "{\n"
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500260 " strategy_choice\n"
261 " {\n"
262 " / /localhost/nfd/strategy/test-doesnotexist\n"
263 " }\n"
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700264 "}\n";
265
266
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500267 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
268 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700269}
270
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500271BOOST_AUTO_TEST_CASE(MissingPrefix)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700272{
273 const std::string CONFIG =
274 "tables\n"
275 "{\n"
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500276 " strategy_choice\n"
277 " {\n"
278 " /localhost/nfd/strategy/test-strategy-a\n"
279 " }\n"
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700280 "}\n";
281
282
Junxiao Shia49a1ab2016-07-15 18:24:36 +0000283 install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700284
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500285 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
286 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700287}
288
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500289BOOST_AUTO_TEST_CASE(Duplicate)
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700290{
291 const std::string CONFIG =
292 "tables\n"
293 "{\n"
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500294 " strategy_choice\n"
295 " {\n"
296 " / /localhost/nfd/strategy/test-strategy-a\n"
297 " /a /localhost/nfd/strategy/test-strategy-b\n"
298 " / /localhost/nfd/strategy/test-strategy-b\n"
299 " }\n"
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700300 "}\n";
301
Junxiao Shia49a1ab2016-07-15 18:24:36 +0000302 install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-a");
303 install<DummyStrategy>(m_forwarder, "/localhost/nfd/strategy/test-strategy-b");
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700304
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500305 BOOST_CHECK_THROW(runConfig(CONFIG, true), ConfigFile::Error);
306 BOOST_CHECK_THROW(runConfig(CONFIG, false), ConfigFile::Error);
Steve DiBenedettoc0640f52014-11-03 15:55:43 -0700307}
308
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500309BOOST_AUTO_TEST_SUITE_END() // StrategyChoice
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600310
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500311BOOST_AUTO_TEST_SUITE(NetworkRegion)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600312
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500313BOOST_AUTO_TEST_CASE(Basic)
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600314{
315 const std::string CONFIG =
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500316 "tables\n"
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600317 "{\n"
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500318 " network_region\n"
319 " {\n"
320 " /test/regionA\n"
321 " /test/regionB/component\n"
322 " }\n"
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600323 "}\n";
324
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500325 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, true));
326 BOOST_CHECK_EQUAL(m_networkRegionTable.size(), 0);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600327
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500328 BOOST_CHECK(m_networkRegionTable.find("/test/regionA") == m_networkRegionTable.end());
329 BOOST_CHECK(m_networkRegionTable.find("/test/regionB/component") == m_networkRegionTable.end());
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600330
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500331 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG, false));
332 BOOST_CHECK_EQUAL(m_networkRegionTable.size(), 2);
Steve DiBenedetto9bcc88f2014-07-08 09:52:13 -0600333
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500334 BOOST_CHECK(m_networkRegionTable.find("/test/regionA") != m_networkRegionTable.end());
335 BOOST_CHECK(m_networkRegionTable.find("/test/regionB/component") != m_networkRegionTable.end());
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600336}
337
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500338BOOST_AUTO_TEST_CASE(Reload)
339{
340 const std::string CONFIG1 =
341 "tables\n"
342 "{\n"
343 " network_region\n"
344 " {\n"
345 " /some/region\n"
346 " }\n"
347 "}\n";
348
349 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, true));
350 BOOST_CHECK(m_networkRegionTable.find("/some/region") == m_networkRegionTable.end());
351
352 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG1, false));
353 BOOST_CHECK(m_networkRegionTable.find("/some/region") != m_networkRegionTable.end());
354
355 const std::string CONFIG2 =
356 "tables\n"
357 "{\n"
358 " network_region\n"
359 " {\n"
360 " /different/region\n"
361 " }\n"
362 "}\n";
363 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, true));
364 BOOST_CHECK(m_networkRegionTable.find("/some/region") != m_networkRegionTable.end());
365 BOOST_CHECK(m_networkRegionTable.find("/different/region") == m_networkRegionTable.end());
366
367 BOOST_REQUIRE_NO_THROW(runConfig(CONFIG2, false));
368 BOOST_CHECK(m_networkRegionTable.find("/some/region") == m_networkRegionTable.end());
369 BOOST_CHECK(m_networkRegionTable.find("/different/region") != m_networkRegionTable.end());
370}
371
372BOOST_AUTO_TEST_SUITE_END() // NetworkRegion
373
Junxiao Shi0cc125c2016-08-25 21:50:04 +0000374BOOST_AUTO_TEST_SUITE_END() // TestTablesConfigSection
Vince Lehman63ab1bb2015-09-04 17:06:58 -0500375BOOST_AUTO_TEST_SUITE_END() // Mgmt
Steve DiBenedetto3a4f83d2014-06-02 14:58:54 -0600376
377} // namespace tests
378} // namespace nfd