blob: 9463ac4cb3199b2a7534e294d7683a56debc9fd6 [file] [log] [blame]
Yanbiao Li73860e32015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * 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.
10 *
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/face-manager.hpp"
27#include "face/udp-factory.hpp"
28
29#ifdef HAVE_LIBPCAP
30#include "face/ethernet-factory.hpp"
31#endif // HAVE_LIBPCAP
32
33#include "manager-common-fixture.hpp"
34
35namespace nfd {
36namespace tests {
37
38BOOST_AUTO_TEST_SUITE(Mgmt)
39BOOST_AUTO_TEST_SUITE(TestFaceManager)
40
41class FaceManagerProcessConfigFixture : public ManagerCommonFixture
42{
43public:
44 FaceManagerProcessConfigFixture()
45 : m_manager(m_forwarder.getFaceTable(), m_dispatcher, m_validator)
46 {
47 m_manager.setConfigFile(m_config);
48 }
49
50public:
51 void
52 parseConfig(const std::string& type, bool isDryRun)
53 {
54 m_config.parse(type, isDryRun, "test-config");
55 }
56
57protected:
58 FaceManager m_manager;
59 ConfigFile m_config;
60};
61
62
63BOOST_FIXTURE_TEST_SUITE(ProcessConfig, FaceManagerProcessConfigFixture)
64
65#ifdef HAVE_UNIX_SOCKETS
66
67BOOST_AUTO_TEST_CASE(ProcessSectionUnix)
68{
69 const std::string CONFIG =
70 "face_system\n"
71 "{\n"
72 " unix\n"
73 " {\n"
74 " path /tmp/nfd.sock\n"
75 " }\n"
76 "}\n";
77 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
78 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
79}
80
81BOOST_AUTO_TEST_CASE(ProcessSectionUnixUnknownOption)
82{
83 const std::string CONFIG =
84 "face_system\n"
85 "{\n"
86 " unix\n"
87 " {\n"
88 " hello\n"
89 " }\n"
90 "}\n";
91 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
92 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
93}
94
95#endif // HAVE_UNIX_SOCKETS
96
97BOOST_AUTO_TEST_CASE(ProcessSectionTcp)
98{
99 const std::string CONFIG =
100 "face_system\n"
101 "{\n"
102 " tcp\n"
103 " {\n"
104 " listen yes\n"
105 " port 16363\n"
106 " enable_v4 yes\n"
107 " enable_v6 yes\n"
108 " }\n"
109 "}\n";
110 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
111 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
112}
113
114BOOST_AUTO_TEST_CASE(ProcessSectionTcpBadListen)
115{
116 const std::string CONFIG =
117 "face_system\n"
118 "{\n"
119 " tcp\n"
120 " {\n"
121 " listen hello\n"
122 " }\n"
123 "}\n";
124
125 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
126 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
127}
128
129BOOST_AUTO_TEST_CASE(ProcessSectionTcpChannelsDisabled)
130{
131 const std::string CONFIG =
132 "face_system\n"
133 "{\n"
134 " tcp\n"
135 " {\n"
136 " port 6363\n"
137 " enable_v4 no\n"
138 " enable_v6 no\n"
139 " }\n"
140 "}\n";
141 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
142 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
143}
144
145BOOST_AUTO_TEST_CASE(ProcessSectionTcpUnknownOption)
146{
147 const std::string CONFIG =
148 "face_system\n"
149 "{\n"
150 " tcp\n"
151 " {\n"
152 " hello\n"
153 " }\n"
154 "}\n";
155 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
156 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
157}
158
159BOOST_AUTO_TEST_CASE(ProcessSectionUdp)
160{
161 const std::string CONFIG =
162 "face_system\n"
163 "{\n"
164 " udp\n"
165 " {\n"
166 " port 6363\n"
167 " enable_v4 yes\n"
168 " enable_v6 yes\n"
169 " idle_timeout 30\n"
170 " keep_alive_interval 25\n"
171 " mcast yes\n"
172 " mcast_port 56363\n"
173 " mcast_group 224.0.23.170\n"
174 " }\n"
175 "}\n";
176 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
177 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
178}
179
180BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadIdleTimeout)
181{
182 const std::string CONFIG =
183 "face_system\n"
184 "{\n"
185 " udp\n"
186 " {\n"
187 " idle_timeout hello\n"
188 " }\n"
189 "}\n";
190 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
191 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
192}
193
194BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcast)
195{
196 const std::string CONFIG =
197 "face_system\n"
198 "{\n"
199 " udp\n"
200 " {\n"
201 " mcast hello\n"
202 " }\n"
203 "}\n";
204 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
205 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
206}
207
208BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcastGroup)
209{
210 const std::string CONFIG =
211 "face_system\n"
212 "{\n"
213 " udp\n"
214 " {\n"
215 " mcast no\n"
216 " mcast_port 50\n"
217 " mcast_group hello\n"
218 " }\n"
219 "}\n";
220 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
221 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
222}
223
224BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcastGroupV6)
225{
226 const std::string CONFIG =
227 "face_system\n"
228 "{\n"
229 " udp\n"
230 " {\n"
231 " mcast no\n"
232 " mcast_port 50\n"
233 " mcast_group ::1\n"
234 " }\n"
235 "}\n";
236 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
237 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
238}
239
240BOOST_AUTO_TEST_CASE(ProcessSectionUdpChannelsDisabled)
241{
242 const std::string CONFIG =
243 "face_system\n"
244 "{\n"
245 " udp\n"
246 " {\n"
247 " port 6363\n"
248 " enable_v4 no\n"
249 " enable_v6 no\n"
250 " idle_timeout 30\n"
251 " keep_alive_interval 25\n"
252 " mcast yes\n"
253 " mcast_port 56363\n"
254 " mcast_group 224.0.23.170\n"
255 " }\n"
256 "}\n";
257 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
258 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
259}
260
261BOOST_AUTO_TEST_CASE(ProcessSectionUdpConflictingMcast)
262{
263 const std::string CONFIG =
264 "face_system\n"
265 "{\n"
266 " udp\n"
267 " {\n"
268 " port 6363\n"
269 " enable_v4 no\n"
270 " enable_v6 yes\n"
271 " idle_timeout 30\n"
272 " keep_alive_interval 25\n"
273 " mcast yes\n"
274 " mcast_port 56363\n"
275 " mcast_group 224.0.23.170\n"
276 " }\n"
277 "}\n";
278 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
279 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
280}
281
282
283
284BOOST_AUTO_TEST_CASE(ProcessSectionUdpUnknownOption)
285{
286 const std::string CONFIG =
287 "face_system\n"
288 "{\n"
289 " udp\n"
290 " {\n"
291 " hello\n"
292 " }\n"
293 "}\n";
294 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
295 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
296}
297
298
299BOOST_AUTO_TEST_CASE(ProcessSectionUdpMulticastReinit)
300{
301 const std::string CONFIG_WITH_MCAST =
302 "face_system\n"
303 "{\n"
304 " udp\n"
305 " {\n"
306 " mcast yes\n"
307 " }\n"
308 "}\n";
309 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false));
310
311 BOOST_REQUIRE(m_manager.m_factories.find("udp") != m_manager.m_factories.end());
312 auto factory = dynamic_pointer_cast<UdpFactory>(m_manager.m_factories.find("udp")->second);
313 BOOST_REQUIRE(factory != nullptr);
314
315 if (factory->getMulticastFaces().size() == 0) {
316 BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
317 "no UDP multicast faces are available");
318 return;
319 }
320 BOOST_CHECK_GT(factory->getMulticastFaces().size(), 0);
321
322 const std::string CONFIG_WITHOUT_MCAST =
323 "face_system\n"
324 "{\n"
325 " udp\n"
326 " {\n"
327 " mcast no\n"
328 " }\n"
329 "}\n";
330 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
331 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
332}
333
334#ifdef HAVE_LIBPCAP
335
336BOOST_AUTO_TEST_CASE(ProcessSectionEther)
337{
338
339 const std::string CONFIG =
340 "face_system\n"
341 "{\n"
342 " ether\n"
343 " {\n"
344 " mcast yes\n"
345 " mcast_group 01:00:5E:00:17:AA\n"
346 " }\n"
347 "}\n";
348
349 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
350 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
351}
352
353BOOST_AUTO_TEST_CASE(ProcessSectionEtherBadMcast)
354{
355 const std::string CONFIG =
356 "face_system\n"
357 "{\n"
358 " ether\n"
359 " {\n"
360 " mcast hello\n"
361 " }\n"
362 "}\n";
363 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
364 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
365}
366
367BOOST_AUTO_TEST_CASE(ProcessSectionEtherBadMcastGroup)
368{
369 const std::string CONFIG =
370 "face_system\n"
371 "{\n"
372 " ether\n"
373 " {\n"
374 " mcast yes\n"
375 " mcast_group\n"
376 " }\n"
377 "}\n";
378 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
379 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
380}
381
382BOOST_AUTO_TEST_CASE(ProcessSectionEtherUnknownOption)
383{
384 const std::string CONFIG =
385 "face_system\n"
386 "{\n"
387 " ether\n"
388 " {\n"
389 " hello\n"
390 " }\n"
391 "}\n";
392 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
393 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
394}
395
396BOOST_AUTO_TEST_CASE(ProcessSectionEtherMulticastReinit)
397{
398 const std::string CONFIG_WITH_MCAST =
399 "face_system\n"
400 "{\n"
401 " ether\n"
402 " {\n"
403 " mcast yes\n"
404 " }\n"
405 "}\n";
406 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITH_MCAST, false));
407
408 BOOST_REQUIRE(m_manager.m_factories.find("ether") != m_manager.m_factories.end());
409 auto factory = dynamic_pointer_cast<EthernetFactory>(m_manager.m_factories.find("ether")->second);
410 BOOST_REQUIRE(factory != nullptr);
411
412 if (factory->getMulticastFaces().size() == 0) {
413 BOOST_TEST_MESSAGE("Destroying multicast faces is not tested because "
414 "no Ethernet multicast faces are available");
415 return;
416 }
417 BOOST_CHECK_GT(factory->getMulticastFaces().size(), 0);
418
419 const std::string CONFIG_WITHOUT_MCAST =
420 "face_system\n"
421 "{\n"
422 " ether\n"
423 " {\n"
424 " mcast no\n"
425 " }\n"
426 "}\n";
427 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
428 BOOST_CHECK_EQUAL(factory->getMulticastFaces().size(), 0);
429}
430
431#endif // HAVE_LIBPCAP
432
433BOOST_AUTO_TEST_SUITE_END() // ProcessConfig
434BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
435BOOST_AUTO_TEST_SUITE_END() // Mgmt
436
437} // namespace tests
438} // namespace nfd