blob: 16996b89edc1594615d6d732fd3f01d1fd456597 [file] [log] [blame]
Yanbiao Li73860e32015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yanbiao Lidf846e52016-01-30 21:53:47 -08003 * Copyright (c) 2014-2016, Regents of the University of California,
Yanbiao Li73860e32015-08-19 16:30:16 -07004 * 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
Yanbiao Lidf846e52016-01-30 21:53:47 -080033#include "nfd-manager-common-fixture.hpp"
Yanbiao Li73860e32015-08-19 16:30:16 -070034
35namespace nfd {
36namespace tests {
37
38BOOST_AUTO_TEST_SUITE(Mgmt)
39BOOST_AUTO_TEST_SUITE(TestFaceManager)
40
Yanbiao Lidf846e52016-01-30 21:53:47 -080041class FaceManagerProcessConfigFixture : public NfdManagerCommonFixture
Yanbiao Li73860e32015-08-19 16:30:16 -070042{
43public:
44 FaceManagerProcessConfigFixture()
Junxiao Shi9ddf1b52016-08-22 03:58:55 +000045 : m_manager(m_forwarder.getFaceTable(), m_dispatcher, *m_authenticator)
Yanbiao Li73860e32015-08-19 16:30:16 -070046 {
47 m_manager.setConfigFile(m_config);
48 }
49
Yanbiao Li73860e32015-08-19 16:30:16 -070050 void
51 parseConfig(const std::string& type, bool isDryRun)
52 {
53 m_config.parse(type, isDryRun, "test-config");
54 }
55
56protected:
57 FaceManager m_manager;
58 ConfigFile m_config;
59};
60
61
62BOOST_FIXTURE_TEST_SUITE(ProcessConfig, FaceManagerProcessConfigFixture)
63
64#ifdef HAVE_UNIX_SOCKETS
65
66BOOST_AUTO_TEST_CASE(ProcessSectionUnix)
67{
68 const std::string CONFIG =
69 "face_system\n"
70 "{\n"
71 " unix\n"
72 " {\n"
73 " path /tmp/nfd.sock\n"
74 " }\n"
75 "}\n";
76 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
77 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
78}
79
80BOOST_AUTO_TEST_CASE(ProcessSectionUnixUnknownOption)
81{
82 const std::string CONFIG =
83 "face_system\n"
84 "{\n"
85 " unix\n"
86 " {\n"
87 " hello\n"
88 " }\n"
89 "}\n";
90 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
91 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
92}
93
94#endif // HAVE_UNIX_SOCKETS
95
96BOOST_AUTO_TEST_CASE(ProcessSectionTcp)
97{
98 const std::string CONFIG =
99 "face_system\n"
100 "{\n"
101 " tcp\n"
102 " {\n"
103 " listen yes\n"
104 " port 16363\n"
105 " enable_v4 yes\n"
106 " enable_v6 yes\n"
107 " }\n"
108 "}\n";
109 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
110 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
111}
112
113BOOST_AUTO_TEST_CASE(ProcessSectionTcpBadListen)
114{
115 const std::string CONFIG =
116 "face_system\n"
117 "{\n"
118 " tcp\n"
119 " {\n"
120 " listen hello\n"
121 " }\n"
122 "}\n";
123
124 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
125 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
126}
127
128BOOST_AUTO_TEST_CASE(ProcessSectionTcpChannelsDisabled)
129{
130 const std::string CONFIG =
131 "face_system\n"
132 "{\n"
133 " tcp\n"
134 " {\n"
135 " port 6363\n"
136 " enable_v4 no\n"
137 " enable_v6 no\n"
138 " }\n"
139 "}\n";
140 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
141 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
142}
143
144BOOST_AUTO_TEST_CASE(ProcessSectionTcpUnknownOption)
145{
146 const std::string CONFIG =
147 "face_system\n"
148 "{\n"
149 " tcp\n"
150 " {\n"
151 " hello\n"
152 " }\n"
153 "}\n";
154 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
155 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
156}
157
158BOOST_AUTO_TEST_CASE(ProcessSectionUdp)
159{
Weiwei Liuf5aee942016-03-19 07:00:42 +0000160 SKIP_IF_NOT_SUPERUSER();
161
Yanbiao Li73860e32015-08-19 16:30:16 -0700162 const std::string CONFIG =
163 "face_system\n"
164 "{\n"
165 " udp\n"
166 " {\n"
167 " port 6363\n"
168 " enable_v4 yes\n"
169 " enable_v6 yes\n"
170 " idle_timeout 30\n"
171 " keep_alive_interval 25\n"
172 " mcast yes\n"
173 " mcast_port 56363\n"
174 " mcast_group 224.0.23.170\n"
175 " }\n"
176 "}\n";
177 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, true));
178 BOOST_CHECK_NO_THROW(parseConfig(CONFIG, false));
179}
180
181BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadIdleTimeout)
182{
183 const std::string CONFIG =
184 "face_system\n"
185 "{\n"
186 " udp\n"
187 " {\n"
188 " idle_timeout hello\n"
189 " }\n"
190 "}\n";
191 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
192 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
193}
194
195BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcast)
196{
197 const std::string CONFIG =
198 "face_system\n"
199 "{\n"
200 " udp\n"
201 " {\n"
202 " mcast hello\n"
203 " }\n"
204 "}\n";
205 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
206 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
207}
208
209BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcastGroup)
210{
211 const std::string CONFIG =
212 "face_system\n"
213 "{\n"
214 " udp\n"
215 " {\n"
216 " mcast no\n"
217 " mcast_port 50\n"
218 " mcast_group hello\n"
219 " }\n"
220 "}\n";
221 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
222 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
223}
224
225BOOST_AUTO_TEST_CASE(ProcessSectionUdpBadMcastGroupV6)
226{
227 const std::string CONFIG =
228 "face_system\n"
229 "{\n"
230 " udp\n"
231 " {\n"
232 " mcast no\n"
233 " mcast_port 50\n"
234 " mcast_group ::1\n"
235 " }\n"
236 "}\n";
237 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
238 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
239}
240
241BOOST_AUTO_TEST_CASE(ProcessSectionUdpChannelsDisabled)
242{
243 const std::string CONFIG =
244 "face_system\n"
245 "{\n"
246 " udp\n"
247 " {\n"
248 " port 6363\n"
249 " enable_v4 no\n"
250 " enable_v6 no\n"
251 " idle_timeout 30\n"
252 " keep_alive_interval 25\n"
253 " mcast yes\n"
254 " mcast_port 56363\n"
255 " mcast_group 224.0.23.170\n"
256 " }\n"
257 "}\n";
258 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
259 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
260}
261
262BOOST_AUTO_TEST_CASE(ProcessSectionUdpConflictingMcast)
263{
264 const std::string CONFIG =
265 "face_system\n"
266 "{\n"
267 " udp\n"
268 " {\n"
269 " port 6363\n"
270 " enable_v4 no\n"
271 " enable_v6 yes\n"
272 " idle_timeout 30\n"
273 " keep_alive_interval 25\n"
274 " mcast yes\n"
275 " mcast_port 56363\n"
276 " mcast_group 224.0.23.170\n"
277 " }\n"
278 "}\n";
279 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
280 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
281}
282
Yanbiao Li73860e32015-08-19 16:30:16 -0700283BOOST_AUTO_TEST_CASE(ProcessSectionUdpUnknownOption)
284{
285 const std::string CONFIG =
286 "face_system\n"
287 "{\n"
288 " udp\n"
289 " {\n"
290 " hello\n"
291 " }\n"
292 "}\n";
293 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
294 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
295}
296
Yanbiao Li73860e32015-08-19 16:30:16 -0700297BOOST_AUTO_TEST_CASE(ProcessSectionUdpMulticastReinit)
298{
Weiwei Liuf5aee942016-03-19 07:00:42 +0000299 SKIP_IF_NOT_SUPERUSER();
300
Yanbiao Li73860e32015-08-19 16:30:16 -0700301 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 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700320
321 const std::string CONFIG_WITHOUT_MCAST =
322 "face_system\n"
323 "{\n"
324 " udp\n"
325 " {\n"
326 " mcast no\n"
327 " }\n"
328 "}\n";
329 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
Yukai Tu0a49d342015-09-13 12:54:22 +0800330 BOOST_REQUIRE_NO_THROW(g_io.poll());
Yanbiao Li73860e32015-08-19 16:30:16 -0700331 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 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700417
418 const std::string CONFIG_WITHOUT_MCAST =
419 "face_system\n"
420 "{\n"
421 " ether\n"
422 " {\n"
423 " mcast no\n"
424 " }\n"
425 "}\n";
426 BOOST_CHECK_NO_THROW(parseConfig(CONFIG_WITHOUT_MCAST, false));
Davide Pesavento35120ea2015-11-17 21:13:18 +0100427 BOOST_REQUIRE_NO_THROW(g_io.poll());
Yanbiao Li73860e32015-08-19 16:30:16 -0700428 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