blob: ee5a3f4eb45edea463cb5a192370c83a1e36a2e6 [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();
Davide Pesavento97a01012018-01-22 19:36:28 -0500459 if (!netifsV4.empty())
460 BOOST_CHECK_GE(udpMcastFaces.size(), netifsV4.size() - 1);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500461 auto udpMcastFacesV6 = this->listUdp6McastFaces();
Davide Pesavento97a01012018-01-22 19:36:28 -0500462 if (!netifsV6.empty())
463 BOOST_CHECK_GE(udpMcastFacesV6.size(), netifsV6.size() - 1);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500464 udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end());
465 BOOST_CHECK_LT(udpMcastFaces.size(), netifsV4.size() + netifsV6.size());
466 BOOST_CHECK(std::none_of(udpMcastFaces.begin(), udpMcastFaces.end(),
467 [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.front()); }));
Junxiao Shic31080d2017-01-24 15:10:12 +0000468}
469
Davide Pesaventobb734df2017-10-24 18:05:36 -0400470BOOST_FIXTURE_TEST_CASE(ChangePredicate, UdpFactoryMcastFixture)
Junxiao Shic31080d2017-01-24 15:10:12 +0000471{
472#ifdef __linux__
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500473 // need superuser privileges to create multicast faces on Linux
Junxiao Shic31080d2017-01-24 15:10:12 +0000474 SKIP_IF_NOT_SUPERUSER();
475#endif // __linux__
476 SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(2);
477
478 std::string CONFIG1 = R"CONFIG(
479 face_system
480 {
481 udp
482 {
483 whitelist
484 {
485 ifname %ifname
486 }
487 }
488 }
489 )CONFIG";
490 std::string CONFIG2 = CONFIG1;
Junxiao Shi84d62cb2017-07-12 16:15:18 +0000491 boost::replace_first(CONFIG1, "%ifname", netifs.front()->getName());
492 boost::replace_first(CONFIG2, "%ifname", netifs.back()->getName());
Junxiao Shic31080d2017-01-24 15:10:12 +0000493
494 parseConfig(CONFIG1, false);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500495
Davide Pesaventobb734df2017-10-24 18:05:36 -0400496 auto udpMcastFaces = this->listUdp4McastFaces();
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500497 auto udpMcastFacesV6 = this->listUdp6McastFaces();
498 udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end());
499 BOOST_CHECK_GE(udpMcastFaces.size(), 1);
500 BOOST_CHECK(std::all_of(udpMcastFaces.begin(), udpMcastFaces.end(),
501 [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.front()); }));
Junxiao Shic31080d2017-01-24 15:10:12 +0000502
503 parseConfig(CONFIG2, false);
504 g_io.poll();
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500505
Davide Pesaventobb734df2017-10-24 18:05:36 -0400506 udpMcastFaces = this->listUdp4McastFaces();
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500507 udpMcastFacesV6 = this->listUdp6McastFaces();
508 udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end());
509 BOOST_CHECK_GE(udpMcastFaces.size(), 1);
510 BOOST_CHECK(std::all_of(udpMcastFaces.begin(), udpMcastFaces.end(),
511 [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.back()); }));
Junxiao Shic31080d2017-01-24 15:10:12 +0000512}
513
Junxiao Shi64d99f22017-01-21 23:06:36 +0000514BOOST_AUTO_TEST_CASE(Omitted)
515{
516 const std::string CONFIG = R"CONFIG(
517 face_system
518 {
519 }
520 )CONFIG";
521
522 parseConfig(CONFIG, true);
523 parseConfig(CONFIG, false);
524
Junxiao Shi64d99f22017-01-21 23:06:36 +0000525 BOOST_CHECK_EQUAL(factory.getChannels().size(), 0);
526 BOOST_CHECK_EQUAL(this->listFacesByScheme("udp4", ndn::nfd::LINK_TYPE_MULTI_ACCESS).size(), 0);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500527 BOOST_CHECK_EQUAL(this->listFacesByScheme("udp6", ndn::nfd::LINK_TYPE_MULTI_ACCESS).size(), 0);
Junxiao Shi64d99f22017-01-21 23:06:36 +0000528}
529
Davide Pesaventobb734df2017-10-24 18:05:36 -0400530BOOST_AUTO_TEST_CASE(AllDisabled)
531{
532 const std::string CONFIG = R"CONFIG(
533 face_system
534 {
535 udp
536 {
537 enable_v4 no
538 enable_v6 no
539 mcast no
540 }
541 }
542 )CONFIG";
543
544 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
545 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
546}
547
Junxiao Shi64d99f22017-01-21 23:06:36 +0000548BOOST_AUTO_TEST_CASE(BadIdleTimeout)
549{
550 const std::string CONFIG = R"CONFIG(
551 face_system
552 {
553 udp
554 {
555 idle_timeout hello
556 }
557 }
558 )CONFIG";
559
560 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
561 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
562}
563
564BOOST_AUTO_TEST_CASE(BadMcast)
565{
566 const std::string CONFIG = R"CONFIG(
567 face_system
568 {
569 udp
570 {
571 mcast hello
572 }
573 }
574 )CONFIG";
575
576 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
577 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
578}
579
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500580BOOST_AUTO_TEST_CASE(BadMcastGroupV4)
Junxiao Shi64d99f22017-01-21 23:06:36 +0000581{
Davide Pesaventobb734df2017-10-24 18:05:36 -0400582 // not an address
583 const std::string CONFIG1 = R"CONFIG(
Junxiao Shi64d99f22017-01-21 23:06:36 +0000584 face_system
585 {
586 udp
587 {
588 mcast_group hello
589 }
590 }
591 )CONFIG";
592
Davide Pesaventobb734df2017-10-24 18:05:36 -0400593 BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error);
594 BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error);
Junxiao Shi64d99f22017-01-21 23:06:36 +0000595
Davide Pesaventobb734df2017-10-24 18:05:36 -0400596 // non-multicast address
597 const std::string CONFIG2 = R"CONFIG(
Junxiao Shi64d99f22017-01-21 23:06:36 +0000598 face_system
599 {
600 udp
601 {
602 mcast_group 10.0.0.1
603 }
604 }
605 )CONFIG";
606
Davide Pesaventobb734df2017-10-24 18:05:36 -0400607 BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error);
608 BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error);
Junxiao Shi64d99f22017-01-21 23:06:36 +0000609
Davide Pesaventobb734df2017-10-24 18:05:36 -0400610 // wrong address family
611 const std::string CONFIG3 = R"CONFIG(
Junxiao Shi64d99f22017-01-21 23:06:36 +0000612 face_system
613 {
614 udp
615 {
Davide Pesaventobb734df2017-10-24 18:05:36 -0400616 mcast_group ff02::1234
Junxiao Shi64d99f22017-01-21 23:06:36 +0000617 }
618 }
619 )CONFIG";
620
Davide Pesaventobb734df2017-10-24 18:05:36 -0400621 BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error);
622 BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error);
Junxiao Shi64d99f22017-01-21 23:06:36 +0000623}
624
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500625BOOST_AUTO_TEST_CASE(BadMcastGroupV6)
626{
627 // not an address
628 const std::string CONFIG1 = R"CONFIG(
629 face_system
630 {
631 udp
632 {
633 mcast_group_v6 foo
634 }
635 }
636 )CONFIG";
637
638 BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error);
639 BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error);
640
641 // non-multicast address
642 const std::string CONFIG2 = R"CONFIG(
643 face_system
644 {
645 udp
646 {
647 mcast_group_v6 fe80::1234
648 }
649 }
650 )CONFIG";
651
652 BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error);
653 BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error);
654
655 // wrong address family
656 const std::string CONFIG3 = R"CONFIG(
657 face_system
658 {
659 udp
660 {
661 mcast_group_v6 224.0.23.170
662 }
663 }
664 )CONFIG";
665
666 BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error);
667 BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error);
668}
669
670BOOST_AUTO_TEST_CASE(BadMcastPortV4)
Junxiao Shi64d99f22017-01-21 23:06:36 +0000671{
Davide Pesaventobb734df2017-10-24 18:05:36 -0400672 const std::string CONFIG1 = R"CONFIG(
Junxiao Shi64d99f22017-01-21 23:06:36 +0000673 face_system
674 {
675 udp
676 {
Davide Pesaventobb734df2017-10-24 18:05:36 -0400677 mcast_port hey
Junxiao Shi64d99f22017-01-21 23:06:36 +0000678 }
679 }
680 )CONFIG";
681
Davide Pesaventobb734df2017-10-24 18:05:36 -0400682 BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error);
683 BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error);
684
685 const std::string CONFIG2 = R"CONFIG(
686 face_system
687 {
688 udp
689 {
690 mcast_port 99999
691 }
692 }
693 )CONFIG";
694
695 BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error);
696 BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error);
Junxiao Shi64d99f22017-01-21 23:06:36 +0000697}
698
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500699BOOST_AUTO_TEST_CASE(BadMcastPortV6)
700{
701 const std::string CONFIG1 = R"CONFIG(
702 face_system
703 {
704 udp
705 {
706 mcast_port_v6 bar
707 }
708 }
709 )CONFIG";
710
711 BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error);
712 BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error);
713
714 const std::string CONFIG2 = R"CONFIG(
715 face_system
716 {
717 udp
718 {
719 mcast_port_v6 99999
720 }
721 }
722 )CONFIG";
723
724 BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error);
725 BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error);
726}
727
Junxiao Shi64d99f22017-01-21 23:06:36 +0000728BOOST_AUTO_TEST_CASE(UnknownOption)
729{
730 const std::string CONFIG = R"CONFIG(
731 face_system
732 {
733 udp
734 {
735 hello
736 }
737 }
738 )CONFIG";
739
740 BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error);
741 BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error);
742}
743
744BOOST_AUTO_TEST_SUITE_END() // ProcessConfig
745
Junxiao Shicde37ad2015-12-24 01:02:05 -0700746BOOST_AUTO_TEST_CASE(GetChannels)
747{
Davide Pesaventob15276f2017-07-15 16:27:13 -0400748 BOOST_CHECK_EQUAL(factory.getChannels().empty(), true);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700749
Davide Pesaventob15276f2017-07-15 16:27:13 -0400750 std::set<std::string> expected;
Davide Pesaventobb734df2017-10-24 18:05:36 -0400751 expected.insert(createChannel("127.0.0.1", 20070)->getUri().toString());
752 expected.insert(createChannel("127.0.0.1", 20071)->getUri().toString());
753 expected.insert(createChannel("::1", 20071)->getUri().toString());
Davide Pesaventob15276f2017-07-15 16:27:13 -0400754 checkChannelListEqual(factory, expected);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700755}
756
Davide Pesaventobb734df2017-10-24 18:05:36 -0400757BOOST_FIXTURE_TEST_CASE(CreateChannel, UdpFactoryMcastFixture)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700758{
Davide Pesaventobb734df2017-10-24 18:05:36 -0400759 auto channel1 = createChannel("127.0.0.1", 20070);
760 auto channel1a = createChannel("127.0.0.1", 20070);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700761 BOOST_CHECK_EQUAL(channel1, channel1a);
762 BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070");
763
Davide Pesaventobb734df2017-10-24 18:05:36 -0400764 auto channel2 = createChannel("127.0.0.1", 20071);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700765 BOOST_CHECK_NE(channel1, channel2);
766
Davide Pesaventobb734df2017-10-24 18:05:36 -0400767 auto channel3 = createChannel("::1", 20071);
Weiwei Liu72cee942016-02-04 16:49:19 -0700768 BOOST_CHECK_NE(channel2, channel3);
769 BOOST_CHECK_EQUAL(channel3->getUri().toString(), "udp6://[::1]:20071");
Junxiao Shicde37ad2015-12-24 01:02:05 -0700770
Davide Pesaventobb734df2017-10-24 18:05:36 -0400771#ifdef __linux__
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500772 // need superuser privileges to create multicast faces on Linux
Davide Pesaventobb734df2017-10-24 18:05:36 -0400773 SKIP_IF_NOT_SUPERUSER();
774#endif // __linux__
Davide Pesaventobb734df2017-10-24 18:05:36 -0400775
Weiwei Liu72cee942016-02-04 16:49:19 -0700776 // createChannel with a local endpoint that has already been allocated for a UDP multicast face
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500777 if (!netifsV4.empty()) {
778 auto mcastFace = createMulticastFace("127.0.0.1", "224.0.0.254", 20072);
779 BOOST_CHECK_EXCEPTION(createChannel("127.0.0.1", 20072), UdpFactory::Error,
780 [] (const UdpFactory::Error& e) {
781 return strcmp(e.what(),
782 "Cannot create UDP channel on 127.0.0.1:20072, "
783 "endpoint already allocated for a UDP multicast face") == 0;
784 });
785 }
786 if (!netifsV6.empty()) {
787 auto mcastFace = createMulticastFace("::1", "ff02::114", 20072);
788 BOOST_CHECK_EXCEPTION(createChannel("::1", 20072), UdpFactory::Error,
789 [] (const UdpFactory::Error& e) {
790 return strcmp(e.what(),
791 "Cannot create UDP channel on [::1]:20072, "
792 "endpoint already allocated for a UDP multicast face") == 0;
793 });
794 }
Weiwei Liu72cee942016-02-04 16:49:19 -0700795}
Junxiao Shicde37ad2015-12-24 01:02:05 -0700796
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500797BOOST_FIXTURE_TEST_CASE(CreateMulticastFaceV4, UdpFactoryMcastFixture)
Weiwei Liu72cee942016-02-04 16:49:19 -0700798{
Davide Pesaventobb734df2017-10-24 18:05:36 -0400799#ifdef __linux__
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500800 // need superuser privileges to create multicast faces on Linux
Davide Pesaventobb734df2017-10-24 18:05:36 -0400801 SKIP_IF_NOT_SUPERUSER();
802#endif // __linux__
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500803 SKIP_IF_UDP_MCAST_V4_NETIF_COUNT_LT(1);
Davide Pesaventobb734df2017-10-24 18:05:36 -0400804
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500805 auto multicastFace1 = createMulticastFace("127.0.0.1", "224.0.0.254", 20070);
806 auto multicastFace1a = createMulticastFace("127.0.0.1", "224.0.0.254", 20070);
807 auto multicastFace2 = createMulticastFace("127.0.0.1", "224.0.0.254", 20030);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700808 BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500809 BOOST_CHECK_NE(multicastFace1, multicastFace2);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700810
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500811 auto address = findNonLoopbackAddressForMulticastFace(ndn::net::AddressFamily::V4);
812 if (!address.is_unspecified()) {
813 auto multicastFace3 = createMulticastFace(address.to_string(), "224.0.0.254", 20070);
814 BOOST_CHECK_NE(multicastFace1, multicastFace3);
815 BOOST_CHECK_NE(multicastFace2, multicastFace3);
816 }
817
818 // create with a local endpoint already used by a channel
Davide Pesaventobb734df2017-10-24 18:05:36 -0400819 auto channel = createChannel("127.0.0.1", 20071);
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500820 BOOST_CHECK_EXCEPTION(createMulticastFace("127.0.0.1", "224.0.0.254", 20071), UdpFactory::Error,
Weiwei Liu72cee942016-02-04 16:49:19 -0700821 [] (const UdpFactory::Error& e) {
822 return strcmp(e.what(),
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500823 "Cannot create UDP multicast face on 127.0.0.1:20071, "
824 "endpoint already allocated for a UDP channel") == 0;
Weiwei Liu72cee942016-02-04 16:49:19 -0700825 });
Junxiao Shicde37ad2015-12-24 01:02:05 -0700826
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500827 // create with a local endpoint already used by a multicast face on a different multicast group
Davide Pesaventobb734df2017-10-24 18:05:36 -0400828 BOOST_CHECK_EXCEPTION(createMulticastFace("127.0.0.1", "224.0.0.42", 20070), UdpFactory::Error,
Weiwei Liu72cee942016-02-04 16:49:19 -0700829 [] (const UdpFactory::Error& e) {
830 return strcmp(e.what(),
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500831 "Cannot create UDP multicast face on 127.0.0.1:20070, "
832 "endpoint already allocated for a different UDP multicast face") == 0;
Weiwei Liu72cee942016-02-04 16:49:19 -0700833 });
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500834}
Junxiao Shicde37ad2015-12-24 01:02:05 -0700835
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500836BOOST_FIXTURE_TEST_CASE(CreateMulticastFaceV6, UdpFactoryMcastFixture)
837{
838#ifdef __linux__
839 // need superuser privileges to create multicast faces on Linux
840 SKIP_IF_NOT_SUPERUSER();
841#endif // __linux__
842 SKIP_IF_UDP_MCAST_V6_NETIF_COUNT_LT(1);
843
844 auto multicastFace1 = createMulticastFace("::1", "ff02::114", 20070);
845 auto multicastFace1a = createMulticastFace("::1", "ff02::114", 20070);
846 auto multicastFace2 = createMulticastFace("::1", "ff02::114", 20030);
847 BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
848 BOOST_CHECK_NE(multicastFace1, multicastFace2);
849
850 auto address = findNonLoopbackAddressForMulticastFace(ndn::net::AddressFamily::V6);
851 if (!address.is_unspecified()) {
852 auto multicastFace3 = createMulticastFace(address.to_string(), "ff02::114", 20070);
853 BOOST_CHECK_NE(multicastFace1, multicastFace3);
854 BOOST_CHECK_NE(multicastFace2, multicastFace3);
855 }
856
857 // create with a local endpoint already used by a channel
858 auto channel = createChannel("::1", 20071);
859 BOOST_CHECK_EXCEPTION(createMulticastFace("::1", "ff02::114", 20071), UdpFactory::Error,
Weiwei Liu72cee942016-02-04 16:49:19 -0700860 [] (const UdpFactory::Error& e) {
861 return strcmp(e.what(),
Md Ashiqur Rahman8ce09032018-01-14 22:43:13 -0500862 "Cannot create UDP multicast face on [::1]:20071, "
863 "endpoint already allocated for a UDP channel") == 0;
864 });
865
866 // create with a local endpoint already used by a multicast face on a different multicast group
867 BOOST_CHECK_EXCEPTION(createMulticastFace("::1", "ff02::42", 20070), UdpFactory::Error,
868 [] (const UdpFactory::Error& e) {
869 return strcmp(e.what(),
870 "Cannot create UDP multicast face on [::1]:20070, "
871 "endpoint already allocated for a different UDP multicast face") == 0;
Weiwei Liu72cee942016-02-04 16:49:19 -0700872 });
Junxiao Shicde37ad2015-12-24 01:02:05 -0700873}
874
Davide Pesaventob15276f2017-07-15 16:27:13 -0400875BOOST_AUTO_TEST_CASE(CreateFace)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700876{
Eric Newberry42602412016-08-27 09:33:18 -0700877 createFace(factory,
878 FaceUri("udp4://127.0.0.1:6363"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000879 {},
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700880 {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, false, false, 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 Newberry0c3e57b2018-01-25 20:54:46 -0700888 {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, false, false, false},
Eric Newberry42602412016-08-27 09:33:18 -0700889 {CreateFaceExpectedResult::SUCCESS, 0, ""});
Eric Newberry78e32b02017-04-01 14:34:44 +0000890
Eric Newberry42602412016-08-27 09:33:18 -0700891 createFace(factory,
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400892 FaceUri("udp4://127.0.0.1:6363"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000893 {},
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700894 {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, false, false, false},
Eric Newberry42602412016-08-27 09:33:18 -0700895 {CreateFaceExpectedResult::SUCCESS, 0, ""});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700896
Eric Newberry42602412016-08-27 09:33:18 -0700897 createFace(factory,
898 FaceUri("udp4://127.0.0.1:20072"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000899 {},
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700900 {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, false, false, false},
Eric Newberry2642cd22017-07-13 21:34:53 -0400901 {CreateFaceExpectedResult::SUCCESS, 0, ""});
902
Eric Newberry2642cd22017-07-13 21:34:53 -0400903 createFace(factory,
904 FaceUri("udp4://127.0.0.1:20073"),
905 {},
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700906 {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, false, true, false},
907 {CreateFaceExpectedResult::SUCCESS, 0, ""});
908
909 createFace(factory,
910 FaceUri("udp4://127.0.0.1:20073"),
911 {},
912 {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, false, false, true},
Eric Newberry42602412016-08-27 09:33:18 -0700913 {CreateFaceExpectedResult::SUCCESS, 0, ""});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700914}
915
Davide Pesaventob15276f2017-07-15 16:27:13 -0400916BOOST_AUTO_TEST_CASE(UnsupportedCreateFace)
Junxiao Shicde37ad2015-12-24 01:02:05 -0700917{
Davide Pesaventobb734df2017-10-24 18:05:36 -0400918 createChannel("127.0.0.1", 20071);
Junxiao Shicde37ad2015-12-24 01:02:05 -0700919
Eric Newberry42602412016-08-27 09:33:18 -0700920 createFace(factory,
Davide Pesavento46afec42017-05-28 14:28:47 -0400921 FaceUri("udp4://127.0.0.1:20072"),
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400922 FaceUri("udp4://127.0.0.1:20071"),
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700923 {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, false, false, false},
Davide Pesavento46afec42017-05-28 14:28:47 -0400924 {CreateFaceExpectedResult::FAILURE, 406,
925 "Unicast UDP faces cannot be created with a LocalUri"});
926
927 createFace(factory,
928 FaceUri("udp4://127.0.0.1:20072"),
Eric Newberry78e32b02017-04-01 14:34:44 +0000929 {},
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700930 {ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, {}, {}, false, false, false},
Eric Newberry42602412016-08-27 09:33:18 -0700931 {CreateFaceExpectedResult::FAILURE, 406,
Davide Pesavento46afec42017-05-28 14:28:47 -0400932 "Outgoing UDP faces do not support on-demand persistency"});
Eric Newberry78e32b02017-04-01 14:34:44 +0000933
934 createFace(factory,
Davide Pesavento46afec42017-05-28 14:28:47 -0400935 FaceUri("udp4://233.252.0.1:23252"),
936 {},
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700937 {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, false, false, false},
Eric Newberry78e32b02017-04-01 14:34:44 +0000938 {CreateFaceExpectedResult::FAILURE, 406,
Davide Pesavento46afec42017-05-28 14:28:47 -0400939 "Cannot create multicast UDP faces"});
940
941 createFace(factory,
Davide Pesavento46afec42017-05-28 14:28:47 -0400942 FaceUri("udp4://127.0.0.1:20072"),
943 {},
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700944 {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, true, false, false},
Davide Pesavento46afec42017-05-28 14:28:47 -0400945 {CreateFaceExpectedResult::FAILURE, 406,
946 "Local fields can only be enabled on faces with local scope"});
Junxiao Shicde37ad2015-12-24 01:02:05 -0700947}
948
Junxiao Shicde37ad2015-12-24 01:02:05 -0700949BOOST_AUTO_TEST_SUITE_END() // TestUdpFactory
950BOOST_AUTO_TEST_SUITE_END() // Face
951
952} // namespace tests
Junxiao Shi64d99f22017-01-21 23:06:36 +0000953} // namespace face
Junxiao Shicde37ad2015-12-24 01:02:05 -0700954} // namespace nfd