blob: 01a24a002b856ad9ed1943358e73674f7d8b9f65 [file] [log] [blame]
Junxiao Shicde37ad2015-12-24 01:02:05 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi84d62cb2017-07-12 16:15:18 +00002/*
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -05003 * Copyright (c) 2014-2018, 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
Junxiao Shi64d99f22017-01-21 23:06:36 +000028#include "face-system-fixture.hpp"
Davide Pesaventob15276f2017-07-15 16:27:13 -040029#include "factory-test-common.hpp"
Davide Pesaventob15276f2017-07-15 16:27:13 -040030
Junxiao Shic31080d2017-01-24 15:10:12 +000031#include <boost/algorithm/string/replace.hpp>
Davide Pesavento4b89a6e2017-10-07 15:29:50 -040032#include <ndn-cxx/net/address-converter.hpp>
Junxiao Shicde37ad2015-12-24 01:02:05 -070033
34namespace nfd {
Junxiao Shi64d99f22017-01-21 23:06:36 +000035namespace face {
Junxiao Shicde37ad2015-12-24 01:02:05 -070036namespace tests {
37
Davide Pesavento4b89a6e2017-10-07 15:29:50 -040038class UdpFactoryFixture : public FaceSystemFactoryFixture<UdpFactory>
39{
40protected:
41 shared_ptr<UdpChannel>
Davide Pesaventobb734df2017-10-24 18:05:36 -040042 createChannel(const std::string& localIp, uint16_t localPort)
Davide Pesavento4b89a6e2017-10-07 15:29:50 -040043 {
Davide Pesaventobb734df2017-10-24 18:05:36 -040044 udp::Endpoint endpoint(ndn::ip::addressFromString(localIp), localPort);
Davide Pesavento4b89a6e2017-10-07 15:29:50 -040045 return factory.createChannel(endpoint, time::minutes(5));
46 }
47};
Junxiao Shi0ba6d642017-07-17 00:53:22 +000048
Davide Pesaventobb734df2017-10-24 18:05:36 -040049class UdpFactoryMcastFixture : public UdpFactoryFixture
50{
51protected:
52 UdpFactoryMcastFixture()
53 {
54 for (const auto& netif : collectNetworkInterfaces()) {
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -050055 // same filtering logic as UdpFactory::applyMcastConfigToNetif()
56 if (netif->isUp() && !netif->isLoopback() && netif->canMulticast()) {
57 bool hasValidIpAddress = false;
58 if (hasAddressFamily(*netif, ndn::net::AddressFamily::V4)) {
59 hasValidIpAddress = true;
60 netifsV4.push_back(netif);
61 }
62 if (hasAddressFamily(*netif, ndn::net::AddressFamily::V6)) {
63 hasValidIpAddress = true;
64 netifsV6.push_back(netif);
65 }
66 if (hasValidIpAddress) {
67 netifs.push_back(netif);
68 }
Davide Pesaventobb734df2017-10-24 18:05:36 -040069 }
70 }
Davide Pesaventobb734df2017-10-24 18:05:36 -040071 this->copyRealNetifsToNetmon();
72 }
73
74 shared_ptr<Face>
75 createMulticastFace(const std::string& localIp, const std::string& mcastIp, uint16_t mcastPort)
76 {
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -050077 auto localAddress = ndn::ip::addressFromString(localIp);
Davide Pesaventobb734df2017-10-24 18:05:36 -040078 udp::Endpoint mcastEndpoint(ndn::ip::addressFromString(mcastIp), mcastPort);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -050079
80 if (localAddress.is_v4()) {
81 BOOST_ASSERT(!netifsV4.empty());
82 return factory.createMulticastFace(netifsV4.front(), localAddress, mcastEndpoint);
83 }
84 else {
85 BOOST_ASSERT(!netifsV6.empty());
86 return factory.createMulticastFace(netifsV6.front(), localAddress, mcastEndpoint);
87 }
88 }
89
90 /** \brief returns a non-loopback IP address suitable for the creation of a UDP multicast face
91 */
92 boost::asio::ip::address
93 findNonLoopbackAddressForMulticastFace(ndn::net::AddressFamily af) const
94 {
95 const auto& netifList = af == ndn::net::AddressFamily::V4 ? netifsV4 : netifsV6;
96 for (const auto& netif : netifList) {
97 for (const auto& a : netif->getNetworkAddresses()) {
98 if (a.getFamily() == af && !a.getIp().is_loopback())
99 return a.getIp();
100 }
101 }
102 return {};
Davide Pesaventobb734df2017-10-24 18:05:36 -0400103 }
104
105 std::vector<const Face*>
106 listUdp4McastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const
107 {
108 return this->listFacesByScheme("udp4", linkType);
109 }
110
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500111 std::vector<const Face*>
112 listUdp6McastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const
113 {
114 return this->listFacesByScheme("udp6", linkType);
115 }
116
117 /** \brief determine whether \p netif has at least one IP address of the given family
Davide Pesaventobb734df2017-10-24 18:05:36 -0400118 */
119 static bool
120 hasAddressFamily(const NetworkInterface& netif, ndn::net::AddressFamily af)
121 {
122 return std::any_of(netif.getNetworkAddresses().begin(), netif.getNetworkAddresses().end(),
123 [af] (const NetworkAddress& a) { return a.getFamily() == af; });
124 }
125
126 /** \brief determine whether a UDP multicast face is created on \p netif
127 */
128 static bool
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500129 isFaceOnNetif(const Face& face, const NetworkInterface& netif)
Davide Pesaventobb734df2017-10-24 18:05:36 -0400130 {
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500131 auto ip = ndn::ip::addressFromString(face.getLocalUri().getHost());
132 return std::any_of(netif.getNetworkAddresses().begin(), netif.getNetworkAddresses().end(),
Davide Pesaventobb734df2017-10-24 18:05:36 -0400133 [ip] (const NetworkAddress& a) { return a.getIp() == ip; });
134 }
135
136protected:
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500137 /** \brief MulticastUdpTransport-capable network interfaces (IPv4 + IPv6)
138 *
139 * This should be used in test cases that do not depend on a specific address family
Davide Pesaventobb734df2017-10-24 18:05:36 -0400140 */
141 std::vector<shared_ptr<const NetworkInterface>> netifs;
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500142
143 /** \brief MulticastUdpTransport-capable network interfaces (IPv4 only)
144 */
145 std::vector<shared_ptr<const NetworkInterface>> netifsV4;
146
147 /** \brief MulticastUdpTransport-capable network interfaces (IPv6 only)
148 */
149 std::vector<shared_ptr<const NetworkInterface>> netifsV6;
Davide Pesaventobb734df2017-10-24 18:05:36 -0400150};
151
152#define SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(n) \
153 do { \
154 if (this->netifs.size() < (n)) { \
155 BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \
156 " or more MulticastUdpTransport-capable network interfaces"); \
157 return; \
158 } \
159 } while (false)
160
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500161#define SKIP_IF_UDP_MCAST_V4_NETIF_COUNT_LT(n) \
162 do { \
163 if (this->netifsV4.size() < (n)) { \
164 BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \
165 " or more IPv4 MulticastUdpTransport-capable network interfaces"); \
166 return; \
167 } \
168 } while (false)
169
170#define SKIP_IF_UDP_MCAST_V6_NETIF_COUNT_LT(n) \
171 do { \
172 if (this->netifsV6.size() < (n)) { \
173 BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \
174 " or more IPv6 MulticastUdpTransport-capable network interfaces"); \
175 return; \
176 } \
177 } while (false)
178
Junxiao Shicde37ad2015-12-24 01:02:05 -0700179BOOST_AUTO_TEST_SUITE(Face)
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000180BOOST_FIXTURE_TEST_SUITE(TestUdpFactory, UdpFactoryFixture)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700181
182using nfd::Face;
183
Junxiao Shi0ba6d642017-07-17 00:53:22 +0000184BOOST_AUTO_TEST_SUITE(ProcessConfig)
Junxiao Shi64d99f22017-01-21 23:06:36 +0000185
186BOOST_AUTO_TEST_CASE(Channels)
187{
188 const std::string CONFIG = R"CONFIG(
189 face_system
190 {
191 udp
192 {
193 port 7001
194 enable_v4 yes
195 enable_v6 yes
196 idle_timeout 30
197 mcast no
198 }
199 }
200 )CONFIG";
201
202 parseConfig(CONFIG, true);
203 parseConfig(CONFIG, false);
204
Junxiao Shi64d99f22017-01-21 23:06:36 +0000205 checkChannelListEqual(factory, {"udp4://0.0.0.0:7001", "udp6://[::]:7001"});
206}
207
208BOOST_AUTO_TEST_CASE(ChannelV4)
209{
210 const std::string CONFIG = R"CONFIG(
211 face_system
212 {
213 udp
214 {
215 port 7001
216 enable_v4 yes
217 enable_v6 no
218 mcast no
219 }
220 }
221 )CONFIG";
222
223 parseConfig(CONFIG, true);
224 parseConfig(CONFIG, false);
225
Junxiao Shi64d99f22017-01-21 23:06:36 +0000226 checkChannelListEqual(factory, {"udp4://0.0.0.0:7001"});
227}
228
229BOOST_AUTO_TEST_CASE(ChannelV6)
230{
231 const std::string CONFIG = R"CONFIG(
232 face_system
233 {
234 udp
235 {
236 port 7001
237 enable_v4 no
238 enable_v6 yes
239 mcast no
240 }
241 }
242 )CONFIG";
243
244 parseConfig(CONFIG, true);
245 parseConfig(CONFIG, false);
246
Junxiao Shi64d99f22017-01-21 23:06:36 +0000247 checkChannelListEqual(factory, {"udp6://[::]:7001"});
248}
249
Davide Pesaventobb734df2017-10-24 18:05:36 -0400250BOOST_FIXTURE_TEST_CASE(EnableDisableMcast, UdpFactoryMcastFixture)
Junxiao Shi64d99f22017-01-21 23:06:36 +0000251{
Junxiao Shi64d99f22017-01-21 23:06:36 +0000252 const std::string CONFIG_WITH_MCAST = R"CONFIG(
253 face_system
254 {
255 udp
256 {
257 mcast yes
258 }
259 }
260 )CONFIG";
261 const std::string CONFIG_WITHOUT_MCAST = R"CONFIG(
262 face_system
263 {
264 udp
265 {
266 mcast no
267 }
268 }
269 )CONFIG";
270
271 parseConfig(CONFIG_WITHOUT_MCAST, false);
Davide Pesaventobb734df2017-10-24 18:05:36 -0400272 BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), 0);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500273 BOOST_CHECK_EQUAL(this->listUdp6McastFaces().size(), 0);
Junxiao Shi64d99f22017-01-21 23:06:36 +0000274
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500275#ifdef __linux__
276 // need superuser privileges to create multicast faces on Linux
277 SKIP_IF_NOT_SUPERUSER();
278#endif // __linux__
Junxiao Shi64d99f22017-01-21 23:06:36 +0000279
280 parseConfig(CONFIG_WITH_MCAST, false);
281 g_io.poll();
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500282 BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), netifsV4.size());
283 BOOST_CHECK_EQUAL(this->listUdp6McastFaces().size(), netifsV6.size());
Junxiao Shi64d99f22017-01-21 23:06:36 +0000284
285 parseConfig(CONFIG_WITHOUT_MCAST, false);
286 g_io.poll();
Davide Pesaventobb734df2017-10-24 18:05:36 -0400287 BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), 0);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500288 BOOST_CHECK_EQUAL(this->listUdp6McastFaces().size(), 0);
Junxiao Shi64d99f22017-01-21 23:06:36 +0000289}
290
Davide Pesaventobb734df2017-10-24 18:05:36 -0400291BOOST_FIXTURE_TEST_CASE(McastAdHoc, UdpFactoryMcastFixture)
Teng Liangfe4fce32017-03-29 04:49:38 +0000292{
293#ifdef __linux__
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500294 // need superuser privileges to create multicast faces on Linux
Teng Liangfe4fce32017-03-29 04:49:38 +0000295 SKIP_IF_NOT_SUPERUSER();
296#endif // __linux__
297 SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1);
298
299 const std::string CONFIG = R"CONFIG(
300 face_system
301 {
302 udp
303 {
304 mcast_ad_hoc yes
305 }
306 }
307 )CONFIG";
308
309 parseConfig(CONFIG, false);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500310 BOOST_CHECK_EQUAL(this->listUdp4McastFaces(ndn::nfd::LINK_TYPE_AD_HOC).size(), netifsV4.size());
311 BOOST_CHECK_EQUAL(this->listUdp6McastFaces(ndn::nfd::LINK_TYPE_AD_HOC).size(), netifsV6.size());
Teng Liangfe4fce32017-03-29 04:49:38 +0000312}
313
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500314BOOST_FIXTURE_TEST_CASE(ChangeMcastEndpointV4, UdpFactoryMcastFixture)
Junxiao Shi64d99f22017-01-21 23:06:36 +0000315{
316#ifdef __linux__
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500317 // need superuser privileges to create multicast faces on Linux
Junxiao Shi64d99f22017-01-21 23:06:36 +0000318 SKIP_IF_NOT_SUPERUSER();
319#endif // __linux__
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500320 SKIP_IF_UDP_MCAST_V4_NETIF_COUNT_LT(1);
Junxiao Shi64d99f22017-01-21 23:06:36 +0000321
322 const std::string CONFIG1 = R"CONFIG(
323 face_system
324 {
325 udp
326 {
327 mcast_group 239.66.30.1
328 mcast_port 7011
329 }
330 }
331 )CONFIG";
332 const std::string CONFIG2 = R"CONFIG(
333 face_system
334 {
335 udp
336 {
337 mcast_group 239.66.30.2
338 mcast_port 7012
339 }
340 }
341 )CONFIG";
342
343 parseConfig(CONFIG1, false);
Davide Pesaventobb734df2017-10-24 18:05:36 -0400344 auto udpMcastFaces = this->listUdp4McastFaces();
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500345 BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifsV4.size());
346 BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), FaceUri("udp4://239.66.30.1:7011"));
Junxiao Shi64d99f22017-01-21 23:06:36 +0000347
348 parseConfig(CONFIG2, false);
349 g_io.poll();
Davide Pesaventobb734df2017-10-24 18:05:36 -0400350 udpMcastFaces = this->listUdp4McastFaces();
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500351 BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifsV4.size());
352 BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), FaceUri("udp4://239.66.30.2:7012"));
353}
354
355BOOST_FIXTURE_TEST_CASE(ChangeMcastEndpointV6, UdpFactoryMcastFixture)
356{
357#ifdef __linux__
358 // need superuser privileges to create multicast faces on Linux
359 SKIP_IF_NOT_SUPERUSER();
360#endif // __linux__
361 SKIP_IF_UDP_MCAST_V6_NETIF_COUNT_LT(1);
362
363 const std::string CONFIG1 = R"CONFIG(
364 face_system
365 {
366 udp
367 {
368 mcast_group_v6 ff02::1101
369 mcast_port_v6 7011
370 }
371 }
372 )CONFIG";
373 const std::string CONFIG2 = R"CONFIG(
374 face_system
375 {
376 udp
377 {
378 mcast_group_v6 ff02::1102
379 mcast_port_v6 7012
380 }
381 }
382 )CONFIG";
383
384 parseConfig(CONFIG1, false);
385 auto udpMcastFaces = this->listUdp6McastFaces();
386 BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifsV6.size());
387 auto expectedAddr = boost::asio::ip::address_v6::from_string("ff02::1101");
388 expectedAddr.scope_id(netifsV6.front()->getIndex());
389 BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), FaceUri(udp::Endpoint(expectedAddr, 7011)));
390
391 parseConfig(CONFIG2, false);
392 g_io.poll();
393 udpMcastFaces = this->listUdp6McastFaces();
394 BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifsV6.size());
395 expectedAddr = boost::asio::ip::address_v6::from_string("ff02::1102");
396 expectedAddr.scope_id(netifsV6.front()->getIndex());
397 BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), FaceUri(udp::Endpoint(expectedAddr, 7012)));
Junxiao Shi64d99f22017-01-21 23:06:36 +0000398}
399
Davide Pesaventobb734df2017-10-24 18:05:36 -0400400BOOST_FIXTURE_TEST_CASE(Whitelist, UdpFactoryMcastFixture)
Junxiao Shic31080d2017-01-24 15:10:12 +0000401{
402#ifdef __linux__
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500403 // need superuser privileges to create multicast faces on Linux
Junxiao Shic31080d2017-01-24 15:10:12 +0000404 SKIP_IF_NOT_SUPERUSER();
405#endif // __linux__
406 SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1);
407
408 std::string CONFIG = R"CONFIG(
409 face_system
410 {
411 udp
412 {
413 whitelist
414 {
415 ifname %ifname
416 }
417 }
418 }
419 )CONFIG";
Junxiao Shi84d62cb2017-07-12 16:15:18 +0000420 boost::replace_first(CONFIG, "%ifname", netifs.front()->getName());
Junxiao Shic31080d2017-01-24 15:10:12 +0000421
422 parseConfig(CONFIG, false);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500423
Davide Pesaventobb734df2017-10-24 18:05:36 -0400424 auto udpMcastFaces = this->listUdp4McastFaces();
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500425 BOOST_CHECK_LE(udpMcastFaces.size(), 1);
426 auto udpMcastFacesV6 = this->listUdp6McastFaces();
427 BOOST_CHECK_LE(udpMcastFacesV6.size(), 1);
428 udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end());
429 BOOST_CHECK_GE(udpMcastFaces.size(), 1);
430 BOOST_CHECK(std::all_of(udpMcastFaces.begin(), udpMcastFaces.end(),
431 [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.front()); }));
Junxiao Shic31080d2017-01-24 15:10:12 +0000432}
433
Davide Pesaventobb734df2017-10-24 18:05:36 -0400434BOOST_FIXTURE_TEST_CASE(Blacklist, UdpFactoryMcastFixture)
Junxiao Shic31080d2017-01-24 15:10:12 +0000435{
436#ifdef __linux__
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500437 // need superuser privileges to create multicast faces on Linux
Junxiao Shic31080d2017-01-24 15:10:12 +0000438 SKIP_IF_NOT_SUPERUSER();
439#endif // __linux__
440 SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1);
441
442 std::string CONFIG = R"CONFIG(
443 face_system
444 {
445 udp
446 {
447 blacklist
448 {
449 ifname %ifname
450 }
451 }
452 }
453 )CONFIG";
Junxiao Shi84d62cb2017-07-12 16:15:18 +0000454 boost::replace_first(CONFIG, "%ifname", netifs.front()->getName());
Junxiao Shic31080d2017-01-24 15:10:12 +0000455
456 parseConfig(CONFIG, false);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500457
Davide Pesaventobb734df2017-10-24 18:05:36 -0400458 auto udpMcastFaces = this->listUdp4McastFaces();
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500459 BOOST_CHECK_GE(udpMcastFaces.size(), netifsV4.size() - 1);
460 auto udpMcastFacesV6 = this->listUdp6McastFaces();
461 BOOST_CHECK_GE(udpMcastFacesV6.size(), netifsV6.size() - 1);
462 udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end());
463 BOOST_CHECK_LT(udpMcastFaces.size(), netifsV4.size() + netifsV6.size());
464 BOOST_CHECK(std::none_of(udpMcastFaces.begin(), udpMcastFaces.end(),
465 [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.front()); }));
Junxiao Shic31080d2017-01-24 15:10:12 +0000466}
467
Davide Pesaventobb734df2017-10-24 18:05:36 -0400468BOOST_FIXTURE_TEST_CASE(ChangePredicate, UdpFactoryMcastFixture)
Junxiao Shic31080d2017-01-24 15:10:12 +0000469{
470#ifdef __linux__
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500471 // need superuser privileges to create multicast faces on Linux
Junxiao Shic31080d2017-01-24 15:10:12 +0000472 SKIP_IF_NOT_SUPERUSER();
473#endif // __linux__
474 SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(2);
475
476 std::string CONFIG1 = R"CONFIG(
477 face_system
478 {
479 udp
480 {
481 whitelist
482 {
483 ifname %ifname
484 }
485 }
486 }
487 )CONFIG";
488 std::string CONFIG2 = CONFIG1;
Junxiao Shi84d62cb2017-07-12 16:15:18 +0000489 boost::replace_first(CONFIG1, "%ifname", netifs.front()->getName());
490 boost::replace_first(CONFIG2, "%ifname", netifs.back()->getName());
Junxiao Shic31080d2017-01-24 15:10:12 +0000491
492 parseConfig(CONFIG1, false);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500493
Davide Pesaventobb734df2017-10-24 18:05:36 -0400494 auto udpMcastFaces = this->listUdp4McastFaces();
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500495 auto udpMcastFacesV6 = this->listUdp6McastFaces();
496 udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end());
497 BOOST_CHECK_GE(udpMcastFaces.size(), 1);
498 BOOST_CHECK(std::all_of(udpMcastFaces.begin(), udpMcastFaces.end(),
499 [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.front()); }));
Junxiao Shic31080d2017-01-24 15:10:12 +0000500
501 parseConfig(CONFIG2, false);
502 g_io.poll();
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500503
Davide Pesaventobb734df2017-10-24 18:05:36 -0400504 udpMcastFaces = this->listUdp4McastFaces();
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500505 udpMcastFacesV6 = this->listUdp6McastFaces();
506 udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end());
507 BOOST_CHECK_GE(udpMcastFaces.size(), 1);
508 BOOST_CHECK(std::all_of(udpMcastFaces.begin(), udpMcastFaces.end(),
509 [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.back()); }));
Junxiao Shic31080d2017-01-24 15:10:12 +0000510}
511
Junxiao Shi64d99f22017-01-21 23:06:36 +0000512BOOST_AUTO_TEST_CASE(Omitted)
513{
514 const std::string CONFIG = R"CONFIG(
515 face_system
516 {
517 }
518 )CONFIG";
519
520 parseConfig(CONFIG, true);
521 parseConfig(CONFIG, false);
522
Junxiao Shi64d99f22017-01-21 23:06:36 +0000523 BOOST_CHECK_EQUAL(factory.getChannels().size(), 0);
524 BOOST_CHECK_EQUAL(this->listFacesByScheme("udp4", ndn::nfd::LINK_TYPE_MULTI_ACCESS).size(), 0);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500525 BOOST_CHECK_EQUAL(this->listFacesByScheme("udp6", ndn::nfd::LINK_TYPE_MULTI_ACCESS).size(), 0);
Junxiao Shi64d99f22017-01-21 23:06:36 +0000526}
527
Davide Pesaventobb734df2017-10-24 18:05:36 -0400528BOOST_AUTO_TEST_CASE(AllDisabled)
529{
530 const std::string CONFIG = R"CONFIG(
531 face_system
532 {
533 udp
534 {
535 enable_v4 no
536 enable_v6 no
537 mcast no
538 }
539 }
540 )CONFIG";
541
542 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
543 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
544}
545
Junxiao Shi64d99f22017-01-21 23:06:36 +0000546BOOST_AUTO_TEST_CASE(BadIdleTimeout)
547{
548 const std::string CONFIG = R"CONFIG(
549 face_system
550 {
551 udp
552 {
553 idle_timeout hello
554 }
555 }
556 )CONFIG";
557
558 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
559 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
560}
561
562BOOST_AUTO_TEST_CASE(BadMcast)
563{
564 const std::string CONFIG = R"CONFIG(
565 face_system
566 {
567 udp
568 {
569 mcast hello
570 }
571 }
572 )CONFIG";
573
574 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
575 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
576}
577
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500578BOOST_AUTO_TEST_CASE(BadMcastGroupV4)
Junxiao Shi64d99f22017-01-21 23:06:36 +0000579{
Davide Pesaventobb734df2017-10-24 18:05:36 -0400580 // not an address
581 const std::string CONFIG1 = R"CONFIG(
Junxiao Shi64d99f22017-01-21 23:06:36 +0000582 face_system
583 {
584 udp
585 {
586 mcast_group hello
587 }
588 }
589 )CONFIG";
590
Davide Pesaventobb734df2017-10-24 18:05:36 -0400591 BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error);
592 BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error);
Junxiao Shi64d99f22017-01-21 23:06:36 +0000593
Davide Pesaventobb734df2017-10-24 18:05:36 -0400594 // non-multicast address
595 const std::string CONFIG2 = R"CONFIG(
Junxiao Shi64d99f22017-01-21 23:06:36 +0000596 face_system
597 {
598 udp
599 {
600 mcast_group 10.0.0.1
601 }
602 }
603 )CONFIG";
604
Davide Pesaventobb734df2017-10-24 18:05:36 -0400605 BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error);
606 BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error);
Junxiao Shi64d99f22017-01-21 23:06:36 +0000607
Davide Pesaventobb734df2017-10-24 18:05:36 -0400608 // wrong address family
609 const std::string CONFIG3 = R"CONFIG(
Junxiao Shi64d99f22017-01-21 23:06:36 +0000610 face_system
611 {
612 udp
613 {
Davide Pesaventobb734df2017-10-24 18:05:36 -0400614 mcast_group ff02::1234
Junxiao Shi64d99f22017-01-21 23:06:36 +0000615 }
616 }
617 )CONFIG";
618
Davide Pesaventobb734df2017-10-24 18:05:36 -0400619 BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error);
620 BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error);
Junxiao Shi64d99f22017-01-21 23:06:36 +0000621}
622
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500623BOOST_AUTO_TEST_CASE(BadMcastGroupV6)
624{
625 // not an address
626 const std::string CONFIG1 = R"CONFIG(
627 face_system
628 {
629 udp
630 {
631 mcast_group_v6 foo
632 }
633 }
634 )CONFIG";
635
636 BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error);
637 BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error);
638
639 // non-multicast address
640 const std::string CONFIG2 = R"CONFIG(
641 face_system
642 {
643 udp
644 {
645 mcast_group_v6 fe80::1234
646 }
647 }
648 )CONFIG";
649
650 BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error);
651 BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error);
652
653 // wrong address family
654 const std::string CONFIG3 = R"CONFIG(
655 face_system
656 {
657 udp
658 {
659 mcast_group_v6 224.0.23.170
660 }
661 }
662 )CONFIG";
663
664 BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error);
665 BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error);
666}
667
668BOOST_AUTO_TEST_CASE(BadMcastPortV4)
Junxiao Shi64d99f22017-01-21 23:06:36 +0000669{
Davide Pesaventobb734df2017-10-24 18:05:36 -0400670 const std::string CONFIG1 = R"CONFIG(
Junxiao Shi64d99f22017-01-21 23:06:36 +0000671 face_system
672 {
673 udp
674 {
Davide Pesaventobb734df2017-10-24 18:05:36 -0400675 mcast_port hey
Junxiao Shi64d99f22017-01-21 23:06:36 +0000676 }
677 }
678 )CONFIG";
679
Davide Pesaventobb734df2017-10-24 18:05:36 -0400680 BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error);
681 BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error);
682
683 const std::string CONFIG2 = R"CONFIG(
684 face_system
685 {
686 udp
687 {
688 mcast_port 99999
689 }
690 }
691 )CONFIG";
692
693 BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error);
694 BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error);
Junxiao Shi64d99f22017-01-21 23:06:36 +0000695}
696
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500697BOOST_AUTO_TEST_CASE(BadMcastPortV6)
698{
699 const std::string CONFIG1 = R"CONFIG(
700 face_system
701 {
702 udp
703 {
704 mcast_port_v6 bar
705 }
706 }
707 )CONFIG";
708
709 BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error);
710 BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error);
711
712 const std::string CONFIG2 = R"CONFIG(
713 face_system
714 {
715 udp
716 {
717 mcast_port_v6 99999
718 }
719 }
720 )CONFIG";
721
722 BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error);
723 BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error);
724}
725
Junxiao Shi64d99f22017-01-21 23:06:36 +0000726BOOST_AUTO_TEST_CASE(UnknownOption)
727{
728 const std::string CONFIG = R"CONFIG(
729 face_system
730 {
731 udp
732 {
733 hello
734 }
735 }
736 )CONFIG";
737
738 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
739 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
740}
741
742BOOST_AUTO_TEST_SUITE_END() // ProcessConfig
743
Junxiao Shicde37ad2015-12-24 01:02:05 -0700744BOOST_AUTO_TEST_CASE(GetChannels)
745{
Davide Pesaventob15276f2017-07-15 16:27:13 -0400746 BOOST_CHECK_EQUAL(factory.getChannels().empty(), true);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700747
Davide Pesaventob15276f2017-07-15 16:27:13 -0400748 std::set<std::string> expected;
Davide Pesaventobb734df2017-10-24 18:05:36 -0400749 expected.insert(createChannel("127.0.0.1", 20070)->getUri().toString());
750 expected.insert(createChannel("127.0.0.1", 20071)->getUri().toString());
751 expected.insert(createChannel("::1", 20071)->getUri().toString());
Davide Pesaventob15276f2017-07-15 16:27:13 -0400752 checkChannelListEqual(factory, expected);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700753}
754
Davide Pesaventobb734df2017-10-24 18:05:36 -0400755BOOST_FIXTURE_TEST_CASE(CreateChannel, UdpFactoryMcastFixture)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700756{
Davide Pesaventobb734df2017-10-24 18:05:36 -0400757 auto channel1 = createChannel("127.0.0.1", 20070);
758 auto channel1a = createChannel("127.0.0.1", 20070);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700759 BOOST_CHECK_EQUAL(channel1, channel1a);
760 BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070");
761
Davide Pesaventobb734df2017-10-24 18:05:36 -0400762 auto channel2 = createChannel("127.0.0.1", 20071);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700763 BOOST_CHECK_NE(channel1, channel2);
764
Davide Pesaventobb734df2017-10-24 18:05:36 -0400765 auto channel3 = createChannel("::1", 20071);
Weiwei Liu72cee942016-02-04 16:49:19 -0700766 BOOST_CHECK_NE(channel2, channel3);
767 BOOST_CHECK_EQUAL(channel3->getUri().toString(), "udp6://[::1]:20071");
Junxiao Shicde37ad2015-12-24 01:02:05 -0700768
Davide Pesaventobb734df2017-10-24 18:05:36 -0400769#ifdef __linux__
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500770 // need superuser privileges to create multicast faces on Linux
Davide Pesaventobb734df2017-10-24 18:05:36 -0400771 SKIP_IF_NOT_SUPERUSER();
772#endif // __linux__
Davide Pesaventobb734df2017-10-24 18:05:36 -0400773
Weiwei Liu72cee942016-02-04 16:49:19 -0700774 // createChannel with a local endpoint that has already been allocated for a UDP multicast face
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500775 if (!netifsV4.empty()) {
776 auto mcastFace = createMulticastFace("127.0.0.1", "224.0.0.254", 20072);
777 BOOST_CHECK_EXCEPTION(createChannel("127.0.0.1", 20072), UdpFactory::Error,
778 [] (const UdpFactory::Error& e) {
779 return strcmp(e.what(),
780 "Cannot create UDP channel on 127.0.0.1:20072, "
781 "endpoint already allocated for a UDP multicast face") == 0;
782 });
783 }
784 if (!netifsV6.empty()) {
785 auto mcastFace = createMulticastFace("::1", "ff02::114", 20072);
786 BOOST_CHECK_EXCEPTION(createChannel("::1", 20072), UdpFactory::Error,
787 [] (const UdpFactory::Error& e) {
788 return strcmp(e.what(),
789 "Cannot create UDP channel on [::1]:20072, "
790 "endpoint already allocated for a UDP multicast face") == 0;
791 });
792 }
Weiwei Liu72cee942016-02-04 16:49:19 -0700793}
Junxiao Shicde37ad2015-12-24 01:02:05 -0700794
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500795BOOST_FIXTURE_TEST_CASE(CreateMulticastFaceV4, UdpFactoryMcastFixture)
Weiwei Liu72cee942016-02-04 16:49:19 -0700796{
Davide Pesaventobb734df2017-10-24 18:05:36 -0400797#ifdef __linux__
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500798 // need superuser privileges to create multicast faces on Linux
Davide Pesaventobb734df2017-10-24 18:05:36 -0400799 SKIP_IF_NOT_SUPERUSER();
800#endif // __linux__
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500801 SKIP_IF_UDP_MCAST_V4_NETIF_COUNT_LT(1);
Davide Pesaventobb734df2017-10-24 18:05:36 -0400802
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500803 auto multicastFace1 = createMulticastFace("127.0.0.1", "224.0.0.254", 20070);
804 auto multicastFace1a = createMulticastFace("127.0.0.1", "224.0.0.254", 20070);
805 auto multicastFace2 = createMulticastFace("127.0.0.1", "224.0.0.254", 20030);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700806 BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500807 BOOST_CHECK_NE(multicastFace1, multicastFace2);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700808
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500809 auto address = findNonLoopbackAddressForMulticastFace(ndn::net::AddressFamily::V4);
810 if (!address.is_unspecified()) {
811 auto multicastFace3 = createMulticastFace(address.to_string(), "224.0.0.254", 20070);
812 BOOST_CHECK_NE(multicastFace1, multicastFace3);
813 BOOST_CHECK_NE(multicastFace2, multicastFace3);
814 }
815
816 // create with a local endpoint already used by a channel
Davide Pesaventobb734df2017-10-24 18:05:36 -0400817 auto channel = createChannel("127.0.0.1", 20071);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500818 BOOST_CHECK_EXCEPTION(createMulticastFace("127.0.0.1", "224.0.0.254", 20071), UdpFactory::Error,
Weiwei Liu72cee942016-02-04 16:49:19 -0700819 [] (const UdpFactory::Error& e) {
820 return strcmp(e.what(),
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500821 "Cannot create UDP multicast face on 127.0.0.1:20071, "
822 "endpoint already allocated for a UDP channel") == 0;
Weiwei Liu72cee942016-02-04 16:49:19 -0700823 });
Junxiao Shicde37ad2015-12-24 01:02:05 -0700824
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500825 // create with a local endpoint already used by a multicast face on a different multicast group
Davide Pesaventobb734df2017-10-24 18:05:36 -0400826 BOOST_CHECK_EXCEPTION(createMulticastFace("127.0.0.1", "224.0.0.42", 20070), UdpFactory::Error,
Weiwei Liu72cee942016-02-04 16:49:19 -0700827 [] (const UdpFactory::Error& e) {
828 return strcmp(e.what(),
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500829 "Cannot create UDP multicast face on 127.0.0.1:20070, "
830 "endpoint already allocated for a different UDP multicast face") == 0;
Weiwei Liu72cee942016-02-04 16:49:19 -0700831 });
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500832}
Junxiao Shicde37ad2015-12-24 01:02:05 -0700833
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500834BOOST_FIXTURE_TEST_CASE(CreateMulticastFaceV6, UdpFactoryMcastFixture)
835{
836#ifdef __linux__
837 // need superuser privileges to create multicast faces on Linux
838 SKIP_IF_NOT_SUPERUSER();
839#endif // __linux__
840 SKIP_IF_UDP_MCAST_V6_NETIF_COUNT_LT(1);
841
842 auto multicastFace1 = createMulticastFace("::1", "ff02::114", 20070);
843 auto multicastFace1a = createMulticastFace("::1", "ff02::114", 20070);
844 auto multicastFace2 = createMulticastFace("::1", "ff02::114", 20030);
845 BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
846 BOOST_CHECK_NE(multicastFace1, multicastFace2);
847
848 auto address = findNonLoopbackAddressForMulticastFace(ndn::net::AddressFamily::V6);
849 if (!address.is_unspecified()) {
850 auto multicastFace3 = createMulticastFace(address.to_string(), "ff02::114", 20070);
851 BOOST_CHECK_NE(multicastFace1, multicastFace3);
852 BOOST_CHECK_NE(multicastFace2, multicastFace3);
853 }
854
855 // create with a local endpoint already used by a channel
856 auto channel = createChannel("::1", 20071);
857 BOOST_CHECK_EXCEPTION(createMulticastFace("::1", "ff02::114", 20071), UdpFactory::Error,
Weiwei Liu72cee942016-02-04 16:49:19 -0700858 [] (const UdpFactory::Error& e) {
859 return strcmp(e.what(),
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500860 "Cannot create UDP multicast face on [::1]:20071, "
861 "endpoint already allocated for a UDP channel") == 0;
862 });
863
864 // create with a local endpoint already used by a multicast face on a different multicast group
865 BOOST_CHECK_EXCEPTION(createMulticastFace("::1", "ff02::42", 20070), UdpFactory::Error,
866 [] (const UdpFactory::Error& e) {
867 return strcmp(e.what(),
868 "Cannot create UDP multicast face on [::1]:20070, "
869 "endpoint already allocated for a different UDP multicast face") == 0;
Weiwei Liu72cee942016-02-04 16:49:19 -0700870 });
Junxiao Shicde37ad2015-12-24 01:02:05 -0700871}
872
Davide Pesaventob15276f2017-07-15 16:27:13 -0400873BOOST_AUTO_TEST_CASE(CreateFace)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700874{
Eric Newberry42602412016-08-27 09:33:18 -0700875 createFace(factory,
876 FaceUri("udp4://127.0.0.1:6363"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000877 {},
Eric Newberry42602412016-08-27 09:33:18 -0700878 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Eric Newberryf40551a2016-09-05 15:41:16 -0700879 false,
Eric Newberry2642cd22017-07-13 21:34:53 -0400880 false,
Eric Newberry42602412016-08-27 09:33:18 -0700881 {CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700882
Davide Pesaventobb734df2017-10-24 18:05:36 -0400883 createChannel("127.0.0.1", 20071);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700884
Eric Newberry42602412016-08-27 09:33:18 -0700885 createFace(factory,
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400886 FaceUri("udp4://127.0.0.1:6363"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000887 {},
Eric Newberry42602412016-08-27 09:33:18 -0700888 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Eric Newberryf40551a2016-09-05 15:41:16 -0700889 false,
Eric Newberry2642cd22017-07-13 21:34:53 -0400890 false,
Eric Newberry42602412016-08-27 09:33:18 -0700891 {CreateFaceExpectedResult::SUCCESS, 0, ""});
Eric Newberry78e32b02017-04-01 14:34:44 +0000892
Eric Newberry42602412016-08-27 09:33:18 -0700893 createFace(factory,
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400894 FaceUri("udp4://127.0.0.1:6363"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000895 {},
Eric Newberry42602412016-08-27 09:33:18 -0700896 ndn::nfd::FACE_PERSISTENCY_PERMANENT,
Eric Newberryf40551a2016-09-05 15:41:16 -0700897 false,
Eric Newberry2642cd22017-07-13 21:34:53 -0400898 false,
Eric Newberry42602412016-08-27 09:33:18 -0700899 {CreateFaceExpectedResult::SUCCESS, 0, ""});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700900
Eric Newberry42602412016-08-27 09:33:18 -0700901 createFace(factory,
902 FaceUri("udp4://127.0.0.1:20072"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000903 {},
Eric Newberry42602412016-08-27 09:33:18 -0700904 ndn::nfd::FACE_PERSISTENCY_PERMANENT,
Eric Newberryf40551a2016-09-05 15:41:16 -0700905 false,
Eric Newberry2642cd22017-07-13 21:34:53 -0400906 false,
907 {CreateFaceExpectedResult::SUCCESS, 0, ""});
908
Eric Newberry2642cd22017-07-13 21:34:53 -0400909 createFace(factory,
910 FaceUri("udp4://127.0.0.1:20073"),
911 {},
912 ndn::nfd::FACE_PERSISTENCY_PERMANENT,
913 false,
914 true,
Eric Newberry42602412016-08-27 09:33:18 -0700915 {CreateFaceExpectedResult::SUCCESS, 0, ""});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700916}
917
Davide Pesaventob15276f2017-07-15 16:27:13 -0400918BOOST_AUTO_TEST_CASE(UnsupportedCreateFace)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700919{
Davide Pesaventobb734df2017-10-24 18:05:36 -0400920 createChannel("127.0.0.1", 20071);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700921
Eric Newberry42602412016-08-27 09:33:18 -0700922 createFace(factory,
Davide Pesavento46afec42017-05-28 14:28:47 -0400923 FaceUri("udp4://127.0.0.1:20072"),
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400924 FaceUri("udp4://127.0.0.1:20071"),
Davide Pesavento46afec42017-05-28 14:28:47 -0400925 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
926 false,
Eric Newberry2642cd22017-07-13 21:34:53 -0400927 false,
Davide Pesavento46afec42017-05-28 14:28:47 -0400928 {CreateFaceExpectedResult::FAILURE, 406,
929 "Unicast UDP faces cannot be created with a LocalUri"});
930
931 createFace(factory,
932 FaceUri("udp4://127.0.0.1:20072"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000933 {},
Eric Newberry42602412016-08-27 09:33:18 -0700934 ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
Eric Newberryf40551a2016-09-05 15:41:16 -0700935 false,
Eric Newberry2642cd22017-07-13 21:34:53 -0400936 false,
Eric Newberry42602412016-08-27 09:33:18 -0700937 {CreateFaceExpectedResult::FAILURE, 406,
Davide Pesavento46afec42017-05-28 14:28:47 -0400938 "Outgoing UDP faces do not support on-demand persistency"});
Eric Newberry78e32b02017-04-01 14:34:44 +0000939
940 createFace(factory,
Davide Pesavento46afec42017-05-28 14:28:47 -0400941 FaceUri("udp4://233.252.0.1:23252"),
942 {},
Eric Newberry78e32b02017-04-01 14:34:44 +0000943 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
944 false,
Eric Newberry2642cd22017-07-13 21:34:53 -0400945 false,
Eric Newberry78e32b02017-04-01 14:34:44 +0000946 {CreateFaceExpectedResult::FAILURE, 406,
Davide Pesavento46afec42017-05-28 14:28:47 -0400947 "Cannot create multicast UDP faces"});
948
949 createFace(factory,
Davide Pesavento46afec42017-05-28 14:28:47 -0400950 FaceUri("udp4://127.0.0.1:20072"),
951 {},
952 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
953 true,
Eric Newberry2642cd22017-07-13 21:34:53 -0400954 false,
Davide Pesavento46afec42017-05-28 14:28:47 -0400955 {CreateFaceExpectedResult::FAILURE, 406,
956 "Local fields can only be enabled on faces with local scope"});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700957}
958
Junxiao Shicde37ad2015-12-24 01:02:05 -0700959BOOST_AUTO_TEST_SUITE_END() // TestUdpFactory
960BOOST_AUTO_TEST_SUITE_END() // Face
961
962} // namespace tests
Junxiao Shi64d99f22017-01-21 23:06:36 +0000963} // namespace face
Junxiao Shicde37ad2015-12-24 01:02:05 -0700964} // namespace nfd