blob: ac468cb1d50e231f6b026c296b3ddd854b5926d0 [file] [log] [blame]
Junxiao Shicde37ad2015-12-24 01:02:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi38b24c72017-01-05 02:59:31 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shicde37ad2015-12-24 01:02:05 -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 "face/udp-factory.hpp"
27
Eric Newberry42602412016-08-27 09:33:18 -070028#include "factory-test-common.hpp"
Junxiao Shi64d99f22017-01-21 23:06:36 +000029#include "face-system-fixture.hpp"
Junxiao Shicde37ad2015-12-24 01:02:05 -070030#include "tests/limited-io.hpp"
31
32namespace nfd {
Junxiao Shi64d99f22017-01-21 23:06:36 +000033namespace face {
Junxiao Shicde37ad2015-12-24 01:02:05 -070034namespace tests {
35
Junxiao Shi64d99f22017-01-21 23:06:36 +000036using namespace nfd::tests;
37
Junxiao Shicde37ad2015-12-24 01:02:05 -070038BOOST_AUTO_TEST_SUITE(Face)
39BOOST_FIXTURE_TEST_SUITE(TestUdpFactory, BaseFixture)
40
41using nfd::Face;
42
Junxiao Shi64d99f22017-01-21 23:06:36 +000043BOOST_FIXTURE_TEST_SUITE(ProcessConfig, FaceSystemFixture)
44
45BOOST_AUTO_TEST_CASE(Channels)
46{
47 const std::string CONFIG = R"CONFIG(
48 face_system
49 {
50 udp
51 {
52 port 7001
53 enable_v4 yes
54 enable_v6 yes
55 idle_timeout 30
56 mcast no
57 }
58 }
59 )CONFIG";
60
61 parseConfig(CONFIG, true);
62 parseConfig(CONFIG, false);
63
64 auto& factory = this->getFactoryById<UdpFactory>("udp");
65 checkChannelListEqual(factory, {"udp4://0.0.0.0:7001", "udp6://[::]:7001"});
66}
67
68BOOST_AUTO_TEST_CASE(ChannelV4)
69{
70 const std::string CONFIG = R"CONFIG(
71 face_system
72 {
73 udp
74 {
75 port 7001
76 enable_v4 yes
77 enable_v6 no
78 mcast no
79 }
80 }
81 )CONFIG";
82
83 parseConfig(CONFIG, true);
84 parseConfig(CONFIG, false);
85
86 auto& factory = this->getFactoryById<UdpFactory>("udp");
87 checkChannelListEqual(factory, {"udp4://0.0.0.0:7001"});
88}
89
90BOOST_AUTO_TEST_CASE(ChannelV6)
91{
92 const std::string CONFIG = R"CONFIG(
93 face_system
94 {
95 udp
96 {
97 port 7001
98 enable_v4 no
99 enable_v6 yes
100 mcast no
101 }
102 }
103 )CONFIG";
104
105 parseConfig(CONFIG, true);
106 parseConfig(CONFIG, false);
107
108 auto& factory = this->getFactoryById<UdpFactory>("udp");
109 checkChannelListEqual(factory, {"udp6://[::]:7001"});
110}
111
112class UdpMcastConfigFixture : public FaceSystemFixture
113{
114protected:
115 UdpMcastConfigFixture()
116 {
117 for (const auto& netif : listNetworkInterfaces()) {
118 if (netif.isUp() && netif.isMulticastCapable() && !netif.ipv4Addresses.empty()) {
119 netifs.push_back(netif);
120 }
121 }
122 }
123
124 std::vector<const Face*>
125 listUdpMcastFaces() const
126 {
127 return this->listFacesByScheme("udp4", ndn::nfd::LINK_TYPE_MULTI_ACCESS);
128 }
129
130 size_t
131 countUdpMcastFaces() const
132 {
133 return this->listUdpMcastFaces().size();
134 }
135
136protected:
137 /** \brief MulticastUdpTransport-capable network interfaces
138 */
139 std::vector<NetworkInterfaceInfo> netifs;
140};
141
142#define SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(n) \
143 do { \
144 if (this->netifs.size() < (n)) { \
145 BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \
146 " or more MulticastUdpTransport-capable network interfaces"); \
147 return; \
148 } \
149 } while (false)
150
151BOOST_FIXTURE_TEST_CASE(EnableDisableMcast, UdpMcastConfigFixture)
152{
153#ifdef __linux__
154 // need superuser privilege for creating multicast faces on linux
155 SKIP_IF_NOT_SUPERUSER();
156#endif // __linux__
157
158 const std::string CONFIG_WITH_MCAST = R"CONFIG(
159 face_system
160 {
161 udp
162 {
163 mcast yes
164 }
165 }
166 )CONFIG";
167 const std::string CONFIG_WITHOUT_MCAST = R"CONFIG(
168 face_system
169 {
170 udp
171 {
172 mcast no
173 }
174 }
175 )CONFIG";
176
177 parseConfig(CONFIG_WITHOUT_MCAST, false);
178 BOOST_CHECK_EQUAL(this->countUdpMcastFaces(), 0);
179
180 SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1);
181
182 parseConfig(CONFIG_WITH_MCAST, false);
183 g_io.poll();
184 BOOST_CHECK_EQUAL(this->countUdpMcastFaces(), netifs.size());
185
186 parseConfig(CONFIG_WITHOUT_MCAST, false);
187 g_io.poll();
188 BOOST_CHECK_EQUAL(this->countUdpMcastFaces(), 0);
189}
190
191BOOST_FIXTURE_TEST_CASE(ChangeMcastEndpoint, UdpMcastConfigFixture)
192{
193#ifdef __linux__
194 // need superuser privilege for creating multicast faces on linux
195 SKIP_IF_NOT_SUPERUSER();
196#endif // __linux__
197 SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1);
198
199 const std::string CONFIG1 = R"CONFIG(
200 face_system
201 {
202 udp
203 {
204 mcast_group 239.66.30.1
205 mcast_port 7011
206 }
207 }
208 )CONFIG";
209 const std::string CONFIG2 = R"CONFIG(
210 face_system
211 {
212 udp
213 {
214 mcast_group 239.66.30.2
215 mcast_port 7012
216 }
217 }
218 )CONFIG";
219
220 parseConfig(CONFIG1, false);
221 auto udpMcastFaces = this->listUdpMcastFaces();
222 BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifs.size());
223 BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(),
224 FaceUri("udp4://239.66.30.1:7011"));
225
226 parseConfig(CONFIG2, false);
227 g_io.poll();
228 udpMcastFaces = this->listUdpMcastFaces();
229 BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifs.size());
230 BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(),
231 FaceUri("udp4://239.66.30.2:7012"));
232}
233
234BOOST_AUTO_TEST_CASE(Omitted)
235{
236 const std::string CONFIG = R"CONFIG(
237 face_system
238 {
239 }
240 )CONFIG";
241
242 parseConfig(CONFIG, true);
243 parseConfig(CONFIG, false);
244
245 auto& factory = this->getFactoryById<UdpFactory>("udp");
246 BOOST_CHECK_EQUAL(factory.getChannels().size(), 0);
247 BOOST_CHECK_EQUAL(this->listFacesByScheme("udp4", ndn::nfd::LINK_TYPE_MULTI_ACCESS).size(), 0);
248}
249
250BOOST_AUTO_TEST_CASE(BadIdleTimeout)
251{
252 const std::string CONFIG = R"CONFIG(
253 face_system
254 {
255 udp
256 {
257 idle_timeout hello
258 }
259 }
260 )CONFIG";
261
262 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
263 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
264}
265
266BOOST_AUTO_TEST_CASE(BadMcast)
267{
268 const std::string CONFIG = R"CONFIG(
269 face_system
270 {
271 udp
272 {
273 mcast hello
274 }
275 }
276 )CONFIG";
277
278 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
279 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
280}
281
282BOOST_AUTO_TEST_CASE(BadMcastGroup)
283{
284 const std::string CONFIG = R"CONFIG(
285 face_system
286 {
287 udp
288 {
289 mcast_group hello
290 }
291 }
292 )CONFIG";
293
294 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
295 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
296}
297
298BOOST_AUTO_TEST_CASE(BadMcastGroupV4Unicast)
299{
300 const std::string CONFIG = R"CONFIG(
301 face_system
302 {
303 udp
304 {
305 mcast_group 10.0.0.1
306 }
307 }
308 )CONFIG";
309
310 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
311 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
312}
313
314BOOST_AUTO_TEST_CASE(BadMcastGroupV6)
315{
316 const std::string CONFIG = R"CONFIG(
317 face_system
318 {
319 udp
320 {
321 mcast_group ff00::1
322 }
323 }
324 )CONFIG";
325
326 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
327 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
328}
329
330BOOST_AUTO_TEST_CASE(AllDisabled)
331{
332 const std::string CONFIG = R"CONFIG(
333 face_system
334 {
335 udp
336 {
337 enable_v4 no
338 enable_v6 no
339 mcast no
340 }
341 }
342 )CONFIG";
343
344 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
345 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
346}
347
348BOOST_AUTO_TEST_CASE(UnknownOption)
349{
350 const std::string CONFIG = R"CONFIG(
351 face_system
352 {
353 udp
354 {
355 hello
356 }
357 }
358 )CONFIG";
359
360 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
361 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
362}
363
364BOOST_AUTO_TEST_SUITE_END() // ProcessConfig
365
Junxiao Shicde37ad2015-12-24 01:02:05 -0700366BOOST_AUTO_TEST_CASE(GetChannels)
367{
368 UdpFactory factory;
369 BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true);
370
371 std::vector<shared_ptr<const Channel>> expectedChannels;
372 expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070"));
373 expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071"));
374 expectedChannels.push_back(factory.createChannel("::1", "20071"));
375
376 for (const auto& i : factory.getChannels()) {
377 auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), i);
378 BOOST_REQUIRE(pos != expectedChannels.end());
379 expectedChannels.erase(pos);
380 }
381
382 BOOST_CHECK_EQUAL(expectedChannels.size(), 0);
383}
384
Weiwei Liu72cee942016-02-04 16:49:19 -0700385BOOST_AUTO_TEST_CASE(CreateChannel)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700386{
Weiwei Liu72cee942016-02-04 16:49:19 -0700387 UdpFactory factory;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700388
Weiwei Liu72cee942016-02-04 16:49:19 -0700389 auto channel1 = factory.createChannel("127.0.0.1", "20070");
390 auto channel1a = factory.createChannel("127.0.0.1", "20070");
Junxiao Shicde37ad2015-12-24 01:02:05 -0700391 BOOST_CHECK_EQUAL(channel1, channel1a);
392 BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070");
393
Weiwei Liu72cee942016-02-04 16:49:19 -0700394 auto channel2 = factory.createChannel("127.0.0.1", "20071");
Junxiao Shicde37ad2015-12-24 01:02:05 -0700395 BOOST_CHECK_NE(channel1, channel2);
396
Weiwei Liu72cee942016-02-04 16:49:19 -0700397 auto channel3 = factory.createChannel("::1", "20071");
398 BOOST_CHECK_NE(channel2, channel3);
399 BOOST_CHECK_EQUAL(channel3->getUri().toString(), "udp6://[::1]:20071");
Junxiao Shicde37ad2015-12-24 01:02:05 -0700400
Weiwei Liu72cee942016-02-04 16:49:19 -0700401 // createChannel with multicast address
402 BOOST_CHECK_EXCEPTION(factory.createChannel("224.0.0.1", "20070"), UdpFactory::Error,
403 [] (const UdpFactory::Error& e) {
404 return strcmp(e.what(),
405 "createChannel is only for unicast channels. The provided endpoint "
406 "is multicast. Use createMulticastFace to create a multicast face") == 0;
407 });
Junxiao Shicde37ad2015-12-24 01:02:05 -0700408
Weiwei Liu72cee942016-02-04 16:49:19 -0700409 // createChannel with a local endpoint that has already been allocated for a UDP multicast face
410 auto multicastFace = factory.createMulticastFace("127.0.0.1", "224.0.0.1", "20072");
411 BOOST_CHECK_EXCEPTION(factory.createChannel("127.0.0.1", "20072"), UdpFactory::Error,
412 [] (const UdpFactory::Error& e) {
413 return strcmp(e.what(),
414 "Cannot create the requested UDP unicast channel, local "
415 "endpoint is already allocated for a UDP multicast face") == 0;
416 });
417}
Junxiao Shicde37ad2015-12-24 01:02:05 -0700418
Weiwei Liu72cee942016-02-04 16:49:19 -0700419BOOST_AUTO_TEST_CASE(CreateMulticastFace)
420{
Weiwei Liu72cee942016-02-04 16:49:19 -0700421 UdpFactory factory;
422
423 auto multicastFace1 = factory.createMulticastFace("127.0.0.1", "224.0.0.1", "20070");
424 auto multicastFace1a = factory.createMulticastFace("127.0.0.1", "224.0.0.1", "20070");
Junxiao Shicde37ad2015-12-24 01:02:05 -0700425 BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
426
Davide Pesaventoeee53aa2016-04-11 17:20:21 +0200427 // createMulticastFace with a local endpoint that is already used by a channel
Weiwei Liu72cee942016-02-04 16:49:19 -0700428 auto channel = factory.createChannel("127.0.0.1", "20071");
429 BOOST_CHECK_EXCEPTION(factory.createMulticastFace("127.0.0.1", "224.0.0.1", "20071"), UdpFactory::Error,
430 [] (const UdpFactory::Error& e) {
431 return strcmp(e.what(),
432 "Cannot create the requested UDP multicast face, local "
433 "endpoint is already allocated for a UDP unicast channel") == 0;
434 });
Junxiao Shicde37ad2015-12-24 01:02:05 -0700435
Davide Pesaventoeee53aa2016-04-11 17:20:21 +0200436 // createMulticastFace with a local endpoint that is already
437 // used by a multicast face on a different multicast group
Weiwei Liu72cee942016-02-04 16:49:19 -0700438 BOOST_CHECK_EXCEPTION(factory.createMulticastFace("127.0.0.1", "224.0.0.42", "20070"), UdpFactory::Error,
439 [] (const UdpFactory::Error& e) {
440 return strcmp(e.what(),
441 "Cannot create the requested UDP multicast face, local "
442 "endpoint is already allocated for a UDP multicast face "
443 "on a different multicast group") == 0;
444 });
Junxiao Shicde37ad2015-12-24 01:02:05 -0700445
Weiwei Liu72cee942016-02-04 16:49:19 -0700446 // createMulticastFace with an IPv4 unicast address
447 BOOST_CHECK_EXCEPTION(factory.createMulticastFace("127.0.0.1", "192.168.10.15", "20072"), UdpFactory::Error,
448 [] (const UdpFactory::Error& e) {
449 return strcmp(e.what(),
450 "Cannot create the requested UDP multicast face, "
451 "the multicast group given as input is not a multicast address") == 0;
452 });
Junxiao Shicde37ad2015-12-24 01:02:05 -0700453
Weiwei Liu72cee942016-02-04 16:49:19 -0700454 // createMulticastFace with an IPv6 multicast address
455 BOOST_CHECK_EXCEPTION(factory.createMulticastFace("::1", "ff01::114", "20073"), UdpFactory::Error,
456 [] (const UdpFactory::Error& e) {
457 return strcmp(e.what(),
458 "IPv6 multicast is not supported yet. Please provide an IPv4 "
459 "address") == 0;
460 });
Junxiao Shicde37ad2015-12-24 01:02:05 -0700461
Weiwei Liu72cee942016-02-04 16:49:19 -0700462 // createMulticastFace with different local and remote port numbers
Davide Pesaventoeee53aa2016-04-11 17:20:21 +0200463 udp::Endpoint localEndpoint(boost::asio::ip::address_v4::loopback(), 20074);
464 udp::Endpoint multicastEndpoint(boost::asio::ip::address::from_string("224.0.0.1"), 20075);
Weiwei Liu72cee942016-02-04 16:49:19 -0700465 BOOST_CHECK_EXCEPTION(factory.createMulticastFace(localEndpoint, multicastEndpoint), UdpFactory::Error,
466 [] (const UdpFactory::Error& e) {
467 return strcmp(e.what(),
468 "Cannot create the requested UDP multicast face, "
469 "both endpoints should have the same port number. ") == 0;
470 });
Junxiao Shicde37ad2015-12-24 01:02:05 -0700471}
472
Eric Newberry42602412016-08-27 09:33:18 -0700473BOOST_AUTO_TEST_CASE(FaceCreate)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700474{
Junxiao Shi38b24c72017-01-05 02:59:31 +0000475 UdpFactory factory;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700476
Eric Newberry42602412016-08-27 09:33:18 -0700477 createFace(factory,
478 FaceUri("udp4://127.0.0.1:6363"),
479 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Eric Newberryf40551a2016-09-05 15:41:16 -0700480 false,
Eric Newberry42602412016-08-27 09:33:18 -0700481 {CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700482
483 factory.createChannel("127.0.0.1", "20071");
484
Eric Newberry42602412016-08-27 09:33:18 -0700485 createFace(factory,
486 FaceUri("udp4://127.0.0.1:20070"),
487 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Eric Newberryf40551a2016-09-05 15:41:16 -0700488 false,
Eric Newberry42602412016-08-27 09:33:18 -0700489 {CreateFaceExpectedResult::SUCCESS, 0, ""});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700490 //test the upgrade
Eric Newberry42602412016-08-27 09:33:18 -0700491 createFace(factory,
492 FaceUri("udp4://127.0.0.1:20070"),
493 ndn::nfd::FACE_PERSISTENCY_PERMANENT,
Eric Newberryf40551a2016-09-05 15:41:16 -0700494 false,
Eric Newberry42602412016-08-27 09:33:18 -0700495 {CreateFaceExpectedResult::SUCCESS, 0, ""});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700496
Eric Newberry42602412016-08-27 09:33:18 -0700497 createFace(factory,
498 FaceUri("udp4://127.0.0.1:20072"),
499 ndn::nfd::FACE_PERSISTENCY_PERMANENT,
Eric Newberryf40551a2016-09-05 15:41:16 -0700500 false,
Eric Newberry42602412016-08-27 09:33:18 -0700501 {CreateFaceExpectedResult::SUCCESS, 0, ""});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700502}
503
504BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
505{
Junxiao Shi38b24c72017-01-05 02:59:31 +0000506 UdpFactory factory;
Junxiao Shicde37ad2015-12-24 01:02:05 -0700507
508 factory.createChannel("127.0.0.1", "20070");
509
Eric Newberry42602412016-08-27 09:33:18 -0700510 createFace(factory,
511 FaceUri("udp4://127.0.0.1:20070"),
512 ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
Eric Newberryf40551a2016-09-05 15:41:16 -0700513 false,
Eric Newberry42602412016-08-27 09:33:18 -0700514 {CreateFaceExpectedResult::FAILURE, 406,
515 "Outgoing unicast UDP faces do not support on-demand persistency"});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700516}
517
518class FakeNetworkInterfaceFixture : public BaseFixture
519{
520public:
521 FakeNetworkInterfaceFixture()
522 {
523 using namespace boost::asio::ip;
524
525 auto fakeInterfaces = make_shared<std::vector<NetworkInterfaceInfo>>();
526
527 fakeInterfaces->push_back(
528 NetworkInterfaceInfo {0, "eth0",
529 ethernet::Address::fromString("3e:15:c2:8b:65:00"),
530 {address_v4::from_string("0.0.0.0")},
531 {address_v6::from_string("::")},
532 address_v4(),
533 IFF_UP});
534 fakeInterfaces->push_back(
535 NetworkInterfaceInfo {1, "eth0",
536 ethernet::Address::fromString("3e:15:c2:8b:65:00"),
537 {address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.2")},
538 {},
539 address_v4::from_string("192.168.2.255"),
540 0});
541 fakeInterfaces->push_back(
542 NetworkInterfaceInfo {2, "eth1",
543 ethernet::Address::fromString("3e:15:c2:8b:65:00"),
544 {address_v4::from_string("198.51.100.1")},
545 {address_v6::from_string("2001:db8::2"), address_v6::from_string("2001:db8::3")},
546 address_v4::from_string("198.51.100.255"),
547 IFF_MULTICAST | IFF_BROADCAST | IFF_UP});
548
549 setDebugNetworkInterfaces(fakeInterfaces);
550 }
551
552 ~FakeNetworkInterfaceFixture()
553 {
554 setDebugNetworkInterfaces(nullptr);
555 }
556};
557
558BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture)
559{
560 using namespace boost::asio::ip;
561
562 UdpFactory factory;
563 factory.prohibitEndpoint(udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024));
564 BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
565 BOOST_CHECK((factory.m_prohibitedEndpoints ==
566 std::set<udp::Endpoint> {
567 udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
568 }));
569
570 factory.m_prohibitedEndpoints.clear();
571 factory.prohibitEndpoint(udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048));
572 BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
573 BOOST_CHECK((factory.m_prohibitedEndpoints ==
574 std::set<udp::Endpoint> {
575 udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048),
576 }));
577
578 factory.m_prohibitedEndpoints.clear();
579 factory.prohibitEndpoint(udp::Endpoint(address_v4(), 1024));
580 BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 6);
581 BOOST_CHECK((factory.m_prohibitedEndpoints ==
582 std::set<udp::Endpoint> {
583 udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
584 udp::Endpoint(address_v4::from_string("192.168.2.2"), 1024),
585 udp::Endpoint(address_v4::from_string("198.51.100.1"), 1024),
586 udp::Endpoint(address_v4::from_string("198.51.100.255"), 1024),
587 udp::Endpoint(address_v4::from_string("255.255.255.255"), 1024),
588 udp::Endpoint(address_v4::from_string("0.0.0.0"), 1024)
589 }));
590
591 factory.m_prohibitedEndpoints.clear();
592 factory.prohibitEndpoint(udp::Endpoint(address_v6(), 2048));
593 BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 3);
594 BOOST_CHECK((factory.m_prohibitedEndpoints ==
595 std::set<udp::Endpoint> {
596 udp::Endpoint(address_v6::from_string("2001:db8::2"), 2048),
597 udp::Endpoint(address_v6::from_string("2001:db8::3"), 2048),
598 udp::Endpoint(address_v6::from_string("::"), 2048),
599 }));
600}
601
602BOOST_AUTO_TEST_SUITE_END() // TestUdpFactory
603BOOST_AUTO_TEST_SUITE_END() // Face
604
605} // namespace tests
Junxiao Shi64d99f22017-01-21 23:06:36 +0000606} // namespace face
Junxiao Shicde37ad2015-12-24 01:02:05 -0700607} // namespace nfd