Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 2 | /* |
Junxiao Shi | a6286a9 | 2021-02-23 06:43:52 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014-2021, Regents of the University of California, |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "face/udp-factory.hpp" |
| 27 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 28 | #include "face-system-fixture.hpp" |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 29 | #include "factory-test-common.hpp" |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 30 | |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 31 | #include <boost/algorithm/string/replace.hpp> |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 34 | namespace face { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 35 | namespace tests { |
| 36 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 37 | class UdpFactoryFixture : public FaceSystemFactoryFixture<UdpFactory> |
| 38 | { |
| 39 | protected: |
| 40 | shared_ptr<UdpChannel> |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 41 | createChannel(const std::string& localIp, uint16_t localPort) |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 42 | { |
Davide Pesavento | 9c33b90 | 2018-05-20 01:30:29 -0400 | [diff] [blame] | 43 | udp::Endpoint endpoint(boost::asio::ip::address::from_string(localIp), localPort); |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 44 | return factory.createChannel(endpoint, 5_min); |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 45 | } |
| 46 | }; |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 47 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 48 | class UdpFactoryMcastFixture : public UdpFactoryFixture |
| 49 | { |
| 50 | protected: |
| 51 | UdpFactoryMcastFixture() |
| 52 | { |
| 53 | for (const auto& netif : collectNetworkInterfaces()) { |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 54 | // same filtering logic as UdpFactory::applyMcastConfigToNetif() |
| 55 | if (netif->isUp() && !netif->isLoopback() && netif->canMulticast()) { |
| 56 | bool hasValidIpAddress = false; |
| 57 | if (hasAddressFamily(*netif, ndn::net::AddressFamily::V4)) { |
| 58 | hasValidIpAddress = true; |
| 59 | netifsV4.push_back(netif); |
| 60 | } |
| 61 | if (hasAddressFamily(*netif, ndn::net::AddressFamily::V6)) { |
| 62 | hasValidIpAddress = true; |
| 63 | netifsV6.push_back(netif); |
| 64 | } |
| 65 | if (hasValidIpAddress) { |
| 66 | netifs.push_back(netif); |
| 67 | } |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 68 | } |
| 69 | } |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 70 | this->copyRealNetifsToNetmon(); |
| 71 | } |
| 72 | |
| 73 | shared_ptr<Face> |
| 74 | createMulticastFace(const std::string& localIp, const std::string& mcastIp, uint16_t mcastPort) |
| 75 | { |
Davide Pesavento | 9c33b90 | 2018-05-20 01:30:29 -0400 | [diff] [blame] | 76 | auto localAddress = boost::asio::ip::address::from_string(localIp); |
| 77 | udp::Endpoint mcastEndpoint(boost::asio::ip::address::from_string(mcastIp), mcastPort); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 78 | |
| 79 | if (localAddress.is_v4()) { |
| 80 | BOOST_ASSERT(!netifsV4.empty()); |
| 81 | return factory.createMulticastFace(netifsV4.front(), localAddress, mcastEndpoint); |
| 82 | } |
| 83 | else { |
| 84 | BOOST_ASSERT(!netifsV6.empty()); |
| 85 | return factory.createMulticastFace(netifsV6.front(), localAddress, mcastEndpoint); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | /** \brief returns a non-loopback IP address suitable for the creation of a UDP multicast face |
| 90 | */ |
| 91 | boost::asio::ip::address |
| 92 | findNonLoopbackAddressForMulticastFace(ndn::net::AddressFamily af) const |
| 93 | { |
| 94 | const auto& netifList = af == ndn::net::AddressFamily::V4 ? netifsV4 : netifsV6; |
| 95 | for (const auto& netif : netifList) { |
| 96 | for (const auto& a : netif->getNetworkAddresses()) { |
| 97 | if (a.getFamily() == af && !a.getIp().is_loopback()) |
| 98 | return a.getIp(); |
| 99 | } |
| 100 | } |
| 101 | return {}; |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | std::vector<const Face*> |
| 105 | listUdp4McastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const |
| 106 | { |
| 107 | return this->listFacesByScheme("udp4", linkType); |
| 108 | } |
| 109 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 110 | std::vector<const Face*> |
| 111 | listUdp6McastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const |
| 112 | { |
| 113 | return this->listFacesByScheme("udp6", linkType); |
| 114 | } |
| 115 | |
| 116 | /** \brief determine whether \p netif has at least one IP address of the given family |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 117 | */ |
| 118 | static bool |
| 119 | hasAddressFamily(const NetworkInterface& netif, ndn::net::AddressFamily af) |
| 120 | { |
| 121 | return std::any_of(netif.getNetworkAddresses().begin(), netif.getNetworkAddresses().end(), |
| 122 | [af] (const NetworkAddress& a) { return a.getFamily() == af; }); |
| 123 | } |
| 124 | |
| 125 | /** \brief determine whether a UDP multicast face is created on \p netif |
| 126 | */ |
| 127 | static bool |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 128 | isFaceOnNetif(const Face& face, const NetworkInterface& netif) |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 129 | { |
Davide Pesavento | 9c33b90 | 2018-05-20 01:30:29 -0400 | [diff] [blame] | 130 | auto ip = boost::asio::ip::address::from_string(face.getLocalUri().getHost()); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 131 | return std::any_of(netif.getNetworkAddresses().begin(), netif.getNetworkAddresses().end(), |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 132 | [ip] (const NetworkAddress& a) { return a.getIp() == ip; }); |
| 133 | } |
| 134 | |
| 135 | protected: |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 136 | /** \brief MulticastUdpTransport-capable network interfaces (IPv4 + IPv6) |
| 137 | * |
| 138 | * This should be used in test cases that do not depend on a specific address family |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 139 | */ |
| 140 | std::vector<shared_ptr<const NetworkInterface>> netifs; |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 141 | |
| 142 | /** \brief MulticastUdpTransport-capable network interfaces (IPv4 only) |
| 143 | */ |
| 144 | std::vector<shared_ptr<const NetworkInterface>> netifsV4; |
| 145 | |
| 146 | /** \brief MulticastUdpTransport-capable network interfaces (IPv6 only) |
| 147 | */ |
| 148 | std::vector<shared_ptr<const NetworkInterface>> netifsV6; |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | #define SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(n) \ |
| 152 | do { \ |
| 153 | if (this->netifs.size() < (n)) { \ |
| 154 | BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \ |
| 155 | " or more MulticastUdpTransport-capable network interfaces"); \ |
| 156 | return; \ |
| 157 | } \ |
| 158 | } while (false) |
| 159 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 160 | #define SKIP_IF_UDP_MCAST_V4_NETIF_COUNT_LT(n) \ |
| 161 | do { \ |
| 162 | if (this->netifsV4.size() < (n)) { \ |
| 163 | BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \ |
| 164 | " or more IPv4 MulticastUdpTransport-capable network interfaces"); \ |
| 165 | return; \ |
| 166 | } \ |
| 167 | } while (false) |
| 168 | |
| 169 | #define SKIP_IF_UDP_MCAST_V6_NETIF_COUNT_LT(n) \ |
| 170 | do { \ |
| 171 | if (this->netifsV6.size() < (n)) { \ |
| 172 | BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \ |
| 173 | " or more IPv6 MulticastUdpTransport-capable network interfaces"); \ |
| 174 | return; \ |
| 175 | } \ |
| 176 | } while (false) |
| 177 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 178 | BOOST_AUTO_TEST_SUITE(Face) |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 179 | BOOST_FIXTURE_TEST_SUITE(TestUdpFactory, UdpFactoryFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 180 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 181 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 182 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 183 | using nfd::Face; |
| 184 | |
| 185 | BOOST_AUTO_TEST_CASE(Defaults) |
| 186 | { |
| 187 | const std::string CONFIG = R"CONFIG( |
| 188 | face_system |
| 189 | { |
| 190 | udp |
| 191 | } |
| 192 | )CONFIG"; |
| 193 | |
| 194 | parseConfig(CONFIG, true); |
| 195 | parseConfig(CONFIG, false); |
| 196 | |
| 197 | checkChannelListEqual(factory, {"udp4://0.0.0.0:6363", "udp6://[::]:6363"}); |
Junxiao Shi | a6286a9 | 2021-02-23 06:43:52 -0700 | [diff] [blame^] | 198 | for (const auto& ch : factory.getChannels()) { |
| 199 | BOOST_CHECK(ch->isListening()); |
| 200 | BOOST_CHECK_EQUAL(ch->getDefaultMtu(), ndn::MAX_NDN_PACKET_SIZE); |
| 201 | } |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | BOOST_AUTO_TEST_CASE(DisableListen) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 205 | { |
| 206 | const std::string CONFIG = R"CONFIG( |
| 207 | face_system |
| 208 | { |
| 209 | udp |
| 210 | { |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 211 | listen no |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 212 | port 7001 |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 213 | mcast no |
| 214 | } |
| 215 | } |
| 216 | )CONFIG"; |
| 217 | |
| 218 | parseConfig(CONFIG, true); |
| 219 | parseConfig(CONFIG, false); |
| 220 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 221 | checkChannelListEqual(factory, {"udp4://0.0.0.0:7001", "udp6://[::]:7001"}); |
Junxiao Shi | a6286a9 | 2021-02-23 06:43:52 -0700 | [diff] [blame^] | 222 | for (const auto& ch : factory.getChannels()) { |
| 223 | BOOST_CHECK(!ch->isListening()); |
| 224 | } |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 227 | BOOST_AUTO_TEST_CASE(DisableV4) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 228 | { |
| 229 | const std::string CONFIG = R"CONFIG( |
| 230 | face_system |
| 231 | { |
| 232 | udp |
| 233 | { |
| 234 | port 7001 |
| 235 | enable_v4 no |
| 236 | enable_v6 yes |
Junxiao Shi | a6286a9 | 2021-02-23 06:43:52 -0700 | [diff] [blame^] | 237 | unicast_mtu 1452 |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 238 | mcast no |
| 239 | } |
| 240 | } |
| 241 | )CONFIG"; |
| 242 | |
| 243 | parseConfig(CONFIG, true); |
| 244 | parseConfig(CONFIG, false); |
| 245 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 246 | checkChannelListEqual(factory, {"udp6://[::]:7001"}); |
Junxiao Shi | a6286a9 | 2021-02-23 06:43:52 -0700 | [diff] [blame^] | 247 | for (const auto& ch : factory.getChannels()) { |
| 248 | BOOST_CHECK_EQUAL(ch->getDefaultMtu(), 1452); |
| 249 | } |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 252 | BOOST_AUTO_TEST_CASE(DisableV6) |
| 253 | { |
| 254 | const std::string CONFIG = R"CONFIG( |
| 255 | face_system |
| 256 | { |
| 257 | udp |
| 258 | { |
| 259 | port 7001 |
| 260 | enable_v4 yes |
| 261 | enable_v6 no |
Junxiao Shi | a6286a9 | 2021-02-23 06:43:52 -0700 | [diff] [blame^] | 262 | unicast_mtu 1452 |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 263 | mcast no |
| 264 | } |
| 265 | } |
| 266 | )CONFIG"; |
| 267 | |
| 268 | parseConfig(CONFIG, true); |
| 269 | parseConfig(CONFIG, false); |
| 270 | |
| 271 | checkChannelListEqual(factory, {"udp4://0.0.0.0:7001"}); |
Junxiao Shi | a6286a9 | 2021-02-23 06:43:52 -0700 | [diff] [blame^] | 272 | for (const auto& ch : factory.getChannels()) { |
| 273 | BOOST_CHECK_EQUAL(ch->getDefaultMtu(), 1452); |
| 274 | } |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 275 | } |
| 276 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 277 | BOOST_FIXTURE_TEST_CASE(EnableDisableMcast, UdpFactoryMcastFixture) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 278 | { |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 279 | const std::string CONFIG_WITH_MCAST = R"CONFIG( |
| 280 | face_system |
| 281 | { |
| 282 | udp |
| 283 | { |
| 284 | mcast yes |
| 285 | } |
| 286 | } |
| 287 | )CONFIG"; |
| 288 | const std::string CONFIG_WITHOUT_MCAST = R"CONFIG( |
| 289 | face_system |
| 290 | { |
| 291 | udp |
| 292 | { |
| 293 | mcast no |
| 294 | } |
| 295 | } |
| 296 | )CONFIG"; |
| 297 | |
| 298 | parseConfig(CONFIG_WITHOUT_MCAST, false); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 299 | BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), 0); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 300 | BOOST_CHECK_EQUAL(this->listUdp6McastFaces().size(), 0); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 301 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 302 | #ifdef __linux__ |
| 303 | // need superuser privileges to create multicast faces on Linux |
| 304 | SKIP_IF_NOT_SUPERUSER(); |
| 305 | #endif // __linux__ |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 306 | |
| 307 | parseConfig(CONFIG_WITH_MCAST, false); |
| 308 | g_io.poll(); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 309 | BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), netifsV4.size()); |
| 310 | BOOST_CHECK_EQUAL(this->listUdp6McastFaces().size(), netifsV6.size()); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 311 | |
Alexander Afanasyev | 3a2339a | 2020-05-27 23:05:06 -0400 | [diff] [blame] | 312 | BOOST_REQUIRE_EQUAL(factory.getChannels().size(), 2); |
| 313 | for (const auto& face : this->listUdp4McastFaces()) { |
| 314 | BOOST_REQUIRE(face->getChannel().lock()); |
| 315 | BOOST_CHECK_EQUAL(face->getChannel().lock()->getUri().getScheme(), "udp4"); |
| 316 | } |
| 317 | |
| 318 | for (const auto& face : this->listUdp6McastFaces()) { |
| 319 | BOOST_REQUIRE(face->getChannel().lock()); |
| 320 | BOOST_CHECK_EQUAL(face->getChannel().lock()->getUri().getScheme(), "udp6"); |
| 321 | } |
| 322 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 323 | parseConfig(CONFIG_WITHOUT_MCAST, false); |
| 324 | g_io.poll(); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 325 | BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), 0); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 326 | BOOST_CHECK_EQUAL(this->listUdp6McastFaces().size(), 0); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 329 | BOOST_FIXTURE_TEST_CASE(McastAdHoc, UdpFactoryMcastFixture) |
Teng Liang | fe4fce3 | 2017-03-29 04:49:38 +0000 | [diff] [blame] | 330 | { |
| 331 | #ifdef __linux__ |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 332 | // need superuser privileges to create multicast faces on Linux |
Teng Liang | fe4fce3 | 2017-03-29 04:49:38 +0000 | [diff] [blame] | 333 | SKIP_IF_NOT_SUPERUSER(); |
| 334 | #endif // __linux__ |
| 335 | SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1); |
| 336 | |
| 337 | const std::string CONFIG = R"CONFIG( |
| 338 | face_system |
| 339 | { |
| 340 | udp |
| 341 | { |
| 342 | mcast_ad_hoc yes |
| 343 | } |
| 344 | } |
| 345 | )CONFIG"; |
| 346 | |
| 347 | parseConfig(CONFIG, false); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 348 | BOOST_CHECK_EQUAL(this->listUdp4McastFaces(ndn::nfd::LINK_TYPE_AD_HOC).size(), netifsV4.size()); |
| 349 | BOOST_CHECK_EQUAL(this->listUdp6McastFaces(ndn::nfd::LINK_TYPE_AD_HOC).size(), netifsV6.size()); |
Teng Liang | fe4fce3 | 2017-03-29 04:49:38 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 352 | BOOST_FIXTURE_TEST_CASE(ChangeMcastEndpointV4, UdpFactoryMcastFixture) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 353 | { |
| 354 | #ifdef __linux__ |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 355 | // need superuser privileges to create multicast faces on Linux |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 356 | SKIP_IF_NOT_SUPERUSER(); |
| 357 | #endif // __linux__ |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 358 | SKIP_IF_UDP_MCAST_V4_NETIF_COUNT_LT(1); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 359 | |
| 360 | const std::string CONFIG1 = R"CONFIG( |
| 361 | face_system |
| 362 | { |
| 363 | udp |
| 364 | { |
| 365 | mcast_group 239.66.30.1 |
| 366 | mcast_port 7011 |
| 367 | } |
| 368 | } |
| 369 | )CONFIG"; |
| 370 | const std::string CONFIG2 = R"CONFIG( |
| 371 | face_system |
| 372 | { |
| 373 | udp |
| 374 | { |
| 375 | mcast_group 239.66.30.2 |
| 376 | mcast_port 7012 |
| 377 | } |
| 378 | } |
| 379 | )CONFIG"; |
| 380 | |
| 381 | parseConfig(CONFIG1, false); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 382 | auto udpMcastFaces = this->listUdp4McastFaces(); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 383 | BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifsV4.size()); |
| 384 | BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), FaceUri("udp4://239.66.30.1:7011")); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 385 | |
| 386 | parseConfig(CONFIG2, false); |
| 387 | g_io.poll(); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 388 | udpMcastFaces = this->listUdp4McastFaces(); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 389 | BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifsV4.size()); |
| 390 | BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), FaceUri("udp4://239.66.30.2:7012")); |
| 391 | } |
| 392 | |
| 393 | BOOST_FIXTURE_TEST_CASE(ChangeMcastEndpointV6, UdpFactoryMcastFixture) |
| 394 | { |
| 395 | #ifdef __linux__ |
| 396 | // need superuser privileges to create multicast faces on Linux |
| 397 | SKIP_IF_NOT_SUPERUSER(); |
| 398 | #endif // __linux__ |
| 399 | SKIP_IF_UDP_MCAST_V6_NETIF_COUNT_LT(1); |
| 400 | |
| 401 | const std::string CONFIG1 = R"CONFIG( |
| 402 | face_system |
| 403 | { |
| 404 | udp |
| 405 | { |
| 406 | mcast_group_v6 ff02::1101 |
| 407 | mcast_port_v6 7011 |
| 408 | } |
| 409 | } |
| 410 | )CONFIG"; |
| 411 | const std::string CONFIG2 = R"CONFIG( |
| 412 | face_system |
| 413 | { |
| 414 | udp |
| 415 | { |
| 416 | mcast_group_v6 ff02::1102 |
| 417 | mcast_port_v6 7012 |
| 418 | } |
| 419 | } |
| 420 | )CONFIG"; |
| 421 | |
| 422 | parseConfig(CONFIG1, false); |
| 423 | auto udpMcastFaces = this->listUdp6McastFaces(); |
| 424 | BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifsV6.size()); |
| 425 | auto expectedAddr = boost::asio::ip::address_v6::from_string("ff02::1101"); |
| 426 | expectedAddr.scope_id(netifsV6.front()->getIndex()); |
| 427 | BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), FaceUri(udp::Endpoint(expectedAddr, 7011))); |
| 428 | |
| 429 | parseConfig(CONFIG2, false); |
| 430 | g_io.poll(); |
| 431 | udpMcastFaces = this->listUdp6McastFaces(); |
| 432 | BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifsV6.size()); |
| 433 | expectedAddr = boost::asio::ip::address_v6::from_string("ff02::1102"); |
| 434 | expectedAddr.scope_id(netifsV6.front()->getIndex()); |
| 435 | BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), FaceUri(udp::Endpoint(expectedAddr, 7012))); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 438 | BOOST_FIXTURE_TEST_CASE(Whitelist, UdpFactoryMcastFixture) |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 439 | { |
| 440 | #ifdef __linux__ |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 441 | // need superuser privileges to create multicast faces on Linux |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 442 | SKIP_IF_NOT_SUPERUSER(); |
| 443 | #endif // __linux__ |
| 444 | SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1); |
| 445 | |
| 446 | std::string CONFIG = R"CONFIG( |
| 447 | face_system |
| 448 | { |
| 449 | udp |
| 450 | { |
| 451 | whitelist |
| 452 | { |
| 453 | ifname %ifname |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | )CONFIG"; |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 458 | boost::replace_first(CONFIG, "%ifname", netifs.front()->getName()); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 459 | |
| 460 | parseConfig(CONFIG, false); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 461 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 462 | auto udpMcastFaces = this->listUdp4McastFaces(); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 463 | BOOST_CHECK_LE(udpMcastFaces.size(), 1); |
| 464 | auto udpMcastFacesV6 = this->listUdp6McastFaces(); |
| 465 | BOOST_CHECK_LE(udpMcastFacesV6.size(), 1); |
| 466 | udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end()); |
| 467 | BOOST_CHECK_GE(udpMcastFaces.size(), 1); |
| 468 | BOOST_CHECK(std::all_of(udpMcastFaces.begin(), udpMcastFaces.end(), |
| 469 | [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.front()); })); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 472 | BOOST_FIXTURE_TEST_CASE(Blacklist, UdpFactoryMcastFixture) |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 473 | { |
| 474 | #ifdef __linux__ |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 475 | // need superuser privileges to create multicast faces on Linux |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 476 | SKIP_IF_NOT_SUPERUSER(); |
| 477 | #endif // __linux__ |
| 478 | SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1); |
| 479 | |
| 480 | std::string CONFIG = R"CONFIG( |
| 481 | face_system |
| 482 | { |
| 483 | udp |
| 484 | { |
| 485 | blacklist |
| 486 | { |
| 487 | ifname %ifname |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | )CONFIG"; |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 492 | boost::replace_first(CONFIG, "%ifname", netifs.front()->getName()); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 493 | |
| 494 | parseConfig(CONFIG, false); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 495 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 496 | auto udpMcastFaces = this->listUdp4McastFaces(); |
Davide Pesavento | 97a0101 | 2018-01-22 19:36:28 -0500 | [diff] [blame] | 497 | if (!netifsV4.empty()) |
| 498 | BOOST_CHECK_GE(udpMcastFaces.size(), netifsV4.size() - 1); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 499 | auto udpMcastFacesV6 = this->listUdp6McastFaces(); |
Davide Pesavento | 97a0101 | 2018-01-22 19:36:28 -0500 | [diff] [blame] | 500 | if (!netifsV6.empty()) |
| 501 | BOOST_CHECK_GE(udpMcastFacesV6.size(), netifsV6.size() - 1); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 502 | udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end()); |
| 503 | BOOST_CHECK_LT(udpMcastFaces.size(), netifsV4.size() + netifsV6.size()); |
| 504 | BOOST_CHECK(std::none_of(udpMcastFaces.begin(), udpMcastFaces.end(), |
| 505 | [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.front()); })); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 508 | BOOST_FIXTURE_TEST_CASE(ChangePredicate, UdpFactoryMcastFixture) |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 509 | { |
| 510 | #ifdef __linux__ |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 511 | // need superuser privileges to create multicast faces on Linux |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 512 | SKIP_IF_NOT_SUPERUSER(); |
| 513 | #endif // __linux__ |
| 514 | SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(2); |
| 515 | |
| 516 | std::string CONFIG1 = R"CONFIG( |
| 517 | face_system |
| 518 | { |
| 519 | udp |
| 520 | { |
| 521 | whitelist |
| 522 | { |
| 523 | ifname %ifname |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | )CONFIG"; |
| 528 | std::string CONFIG2 = CONFIG1; |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 529 | boost::replace_first(CONFIG1, "%ifname", netifs.front()->getName()); |
| 530 | boost::replace_first(CONFIG2, "%ifname", netifs.back()->getName()); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 531 | |
| 532 | parseConfig(CONFIG1, false); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 533 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 534 | auto udpMcastFaces = this->listUdp4McastFaces(); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 535 | auto udpMcastFacesV6 = this->listUdp6McastFaces(); |
| 536 | udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end()); |
| 537 | BOOST_CHECK_GE(udpMcastFaces.size(), 1); |
| 538 | BOOST_CHECK(std::all_of(udpMcastFaces.begin(), udpMcastFaces.end(), |
| 539 | [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.front()); })); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 540 | |
| 541 | parseConfig(CONFIG2, false); |
| 542 | g_io.poll(); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 543 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 544 | udpMcastFaces = this->listUdp4McastFaces(); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 545 | udpMcastFacesV6 = this->listUdp6McastFaces(); |
| 546 | udpMcastFaces.insert(udpMcastFaces.end(), udpMcastFacesV6.begin(), udpMcastFacesV6.end()); |
| 547 | BOOST_CHECK_GE(udpMcastFaces.size(), 1); |
| 548 | BOOST_CHECK(std::all_of(udpMcastFaces.begin(), udpMcastFaces.end(), |
| 549 | [this] (const Face* face) { return isFaceOnNetif(*face, *netifs.back()); })); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 552 | BOOST_AUTO_TEST_CASE(Omitted) |
| 553 | { |
| 554 | const std::string CONFIG = R"CONFIG( |
| 555 | face_system |
| 556 | { |
| 557 | } |
| 558 | )CONFIG"; |
| 559 | |
| 560 | parseConfig(CONFIG, true); |
| 561 | parseConfig(CONFIG, false); |
| 562 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 563 | BOOST_CHECK_EQUAL(factory.getChannels().size(), 0); |
| 564 | BOOST_CHECK_EQUAL(this->listFacesByScheme("udp4", ndn::nfd::LINK_TYPE_MULTI_ACCESS).size(), 0); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 565 | BOOST_CHECK_EQUAL(this->listFacesByScheme("udp6", ndn::nfd::LINK_TYPE_MULTI_ACCESS).size(), 0); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 568 | BOOST_AUTO_TEST_CASE(AllDisabled) |
| 569 | { |
| 570 | const std::string CONFIG = R"CONFIG( |
| 571 | face_system |
| 572 | { |
| 573 | udp |
| 574 | { |
| 575 | enable_v4 no |
| 576 | enable_v6 no |
| 577 | mcast no |
| 578 | } |
| 579 | } |
| 580 | )CONFIG"; |
| 581 | |
| 582 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 583 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 584 | } |
| 585 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 586 | BOOST_AUTO_TEST_CASE(BadListen) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 587 | { |
| 588 | const std::string CONFIG = R"CONFIG( |
| 589 | face_system |
| 590 | { |
| 591 | udp |
| 592 | { |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 593 | listen hello |
| 594 | } |
| 595 | } |
| 596 | )CONFIG"; |
| 597 | |
| 598 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 599 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 600 | } |
| 601 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 602 | BOOST_AUTO_TEST_CASE(BadPort) |
| 603 | { |
| 604 | // not a number |
| 605 | const std::string CONFIG1 = R"CONFIG( |
| 606 | face_system |
| 607 | { |
| 608 | udp |
| 609 | { |
| 610 | port hello |
| 611 | } |
| 612 | } |
| 613 | )CONFIG"; |
| 614 | |
| 615 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 616 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 617 | |
| 618 | // negative number |
| 619 | const std::string CONFIG2 = R"CONFIG( |
| 620 | face_system |
| 621 | { |
| 622 | udp |
| 623 | { |
| 624 | port -1 |
| 625 | } |
| 626 | } |
| 627 | )CONFIG"; |
| 628 | |
| 629 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 630 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
| 631 | |
| 632 | // out of range |
| 633 | const std::string CONFIG3 = R"CONFIG( |
| 634 | face_system |
| 635 | { |
| 636 | udp |
| 637 | { |
| 638 | port 65536 |
| 639 | } |
| 640 | } |
| 641 | )CONFIG"; |
| 642 | |
| 643 | BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error); |
| 644 | BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error); |
| 645 | } |
| 646 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 647 | BOOST_AUTO_TEST_CASE(BadIdleTimeout) |
| 648 | { |
| 649 | // not a number |
| 650 | const std::string CONFIG1 = R"CONFIG( |
| 651 | face_system |
| 652 | { |
| 653 | udp |
| 654 | { |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 655 | idle_timeout hello |
| 656 | } |
| 657 | } |
| 658 | )CONFIG"; |
| 659 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 660 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 661 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 662 | |
| 663 | // negative number |
| 664 | const std::string CONFIG2 = R"CONFIG( |
| 665 | face_system |
| 666 | { |
| 667 | udp |
| 668 | { |
| 669 | idle_timeout -15 |
| 670 | } |
| 671 | } |
| 672 | )CONFIG"; |
| 673 | |
| 674 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 675 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Junxiao Shi | a6286a9 | 2021-02-23 06:43:52 -0700 | [diff] [blame^] | 678 | BOOST_AUTO_TEST_CASE(BadMtu) |
| 679 | { |
| 680 | // not a number |
| 681 | const std::string CONFIG1 = R"CONFIG( |
| 682 | face_system |
| 683 | { |
| 684 | udp |
| 685 | { |
| 686 | unicast_mtu hello |
| 687 | } |
| 688 | } |
| 689 | )CONFIG"; |
| 690 | |
| 691 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 692 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 693 | |
| 694 | // underflow |
| 695 | const std::string CONFIG2 = R"CONFIG( |
| 696 | face_system |
| 697 | { |
| 698 | udp |
| 699 | { |
| 700 | unicast_mtu 63 |
| 701 | } |
| 702 | } |
| 703 | )CONFIG"; |
| 704 | |
| 705 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 706 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
| 707 | |
| 708 | // underflow |
| 709 | const std::string CONFIG3 = R"CONFIG( |
| 710 | face_system |
| 711 | { |
| 712 | udp |
| 713 | { |
| 714 | unicast_mtu 8801 |
| 715 | } |
| 716 | } |
| 717 | )CONFIG"; |
| 718 | |
| 719 | BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error); |
| 720 | BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error); |
| 721 | } |
| 722 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 723 | BOOST_AUTO_TEST_CASE(BadMcast) |
| 724 | { |
| 725 | const std::string CONFIG = R"CONFIG( |
| 726 | face_system |
| 727 | { |
| 728 | udp |
| 729 | { |
| 730 | mcast hello |
| 731 | } |
| 732 | } |
| 733 | )CONFIG"; |
| 734 | |
| 735 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 736 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 737 | } |
| 738 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 739 | BOOST_AUTO_TEST_CASE(BadMcastGroupV4) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 740 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 741 | // not an address |
| 742 | const std::string CONFIG1 = R"CONFIG( |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 743 | face_system |
| 744 | { |
| 745 | udp |
| 746 | { |
| 747 | mcast_group hello |
| 748 | } |
| 749 | } |
| 750 | )CONFIG"; |
| 751 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 752 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 753 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 754 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 755 | // non-multicast address |
| 756 | const std::string CONFIG2 = R"CONFIG( |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 757 | face_system |
| 758 | { |
| 759 | udp |
| 760 | { |
| 761 | mcast_group 10.0.0.1 |
| 762 | } |
| 763 | } |
| 764 | )CONFIG"; |
| 765 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 766 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 767 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 768 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 769 | // wrong address family |
| 770 | const std::string CONFIG3 = R"CONFIG( |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 771 | face_system |
| 772 | { |
| 773 | udp |
| 774 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 775 | mcast_group ff02::1234 |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | )CONFIG"; |
| 779 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 780 | BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error); |
| 781 | BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 782 | } |
| 783 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 784 | BOOST_AUTO_TEST_CASE(BadMcastGroupV6) |
| 785 | { |
| 786 | // not an address |
| 787 | const std::string CONFIG1 = R"CONFIG( |
| 788 | face_system |
| 789 | { |
| 790 | udp |
| 791 | { |
| 792 | mcast_group_v6 foo |
| 793 | } |
| 794 | } |
| 795 | )CONFIG"; |
| 796 | |
| 797 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 798 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 799 | |
| 800 | // non-multicast address |
| 801 | const std::string CONFIG2 = R"CONFIG( |
| 802 | face_system |
| 803 | { |
| 804 | udp |
| 805 | { |
| 806 | mcast_group_v6 fe80::1234 |
| 807 | } |
| 808 | } |
| 809 | )CONFIG"; |
| 810 | |
| 811 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 812 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
| 813 | |
| 814 | // wrong address family |
| 815 | const std::string CONFIG3 = R"CONFIG( |
| 816 | face_system |
| 817 | { |
| 818 | udp |
| 819 | { |
| 820 | mcast_group_v6 224.0.23.170 |
| 821 | } |
| 822 | } |
| 823 | )CONFIG"; |
| 824 | |
| 825 | BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error); |
| 826 | BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error); |
| 827 | } |
| 828 | |
| 829 | BOOST_AUTO_TEST_CASE(BadMcastPortV4) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 830 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 831 | const std::string CONFIG1 = R"CONFIG( |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 832 | face_system |
| 833 | { |
| 834 | udp |
| 835 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 836 | mcast_port hey |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | )CONFIG"; |
| 840 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 841 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 842 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 843 | |
| 844 | const std::string CONFIG2 = R"CONFIG( |
| 845 | face_system |
| 846 | { |
| 847 | udp |
| 848 | { |
| 849 | mcast_port 99999 |
| 850 | } |
| 851 | } |
| 852 | )CONFIG"; |
| 853 | |
| 854 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 855 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 858 | BOOST_AUTO_TEST_CASE(BadMcastPortV6) |
| 859 | { |
| 860 | const std::string CONFIG1 = R"CONFIG( |
| 861 | face_system |
| 862 | { |
| 863 | udp |
| 864 | { |
| 865 | mcast_port_v6 bar |
| 866 | } |
| 867 | } |
| 868 | )CONFIG"; |
| 869 | |
| 870 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 871 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 872 | |
| 873 | const std::string CONFIG2 = R"CONFIG( |
| 874 | face_system |
| 875 | { |
| 876 | udp |
| 877 | { |
| 878 | mcast_port_v6 99999 |
| 879 | } |
| 880 | } |
| 881 | )CONFIG"; |
| 882 | |
| 883 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 884 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
| 885 | } |
| 886 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 887 | BOOST_AUTO_TEST_CASE(UnknownOption) |
| 888 | { |
| 889 | const std::string CONFIG = R"CONFIG( |
| 890 | face_system |
| 891 | { |
| 892 | udp |
| 893 | { |
| 894 | hello |
| 895 | } |
| 896 | } |
| 897 | )CONFIG"; |
| 898 | |
| 899 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 900 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 901 | } |
| 902 | |
| 903 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 904 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 905 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 906 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 907 | BOOST_CHECK_EQUAL(factory.getChannels().empty(), true); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 908 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 909 | std::set<std::string> expected; |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 910 | expected.insert(createChannel("127.0.0.1", 20070)->getUri().toString()); |
| 911 | expected.insert(createChannel("127.0.0.1", 20071)->getUri().toString()); |
| 912 | expected.insert(createChannel("::1", 20071)->getUri().toString()); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 913 | checkChannelListEqual(factory, expected); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 916 | BOOST_FIXTURE_TEST_CASE(CreateChannel, UdpFactoryMcastFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 917 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 918 | auto channel1 = createChannel("127.0.0.1", 20070); |
| 919 | auto channel1a = createChannel("127.0.0.1", 20070); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 920 | BOOST_CHECK_EQUAL(channel1, channel1a); |
| 921 | BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070"); |
| 922 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 923 | auto channel2 = createChannel("127.0.0.1", 20071); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 924 | BOOST_CHECK_NE(channel1, channel2); |
| 925 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 926 | auto channel3 = createChannel("::1", 20071); |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 927 | BOOST_CHECK_NE(channel2, channel3); |
| 928 | BOOST_CHECK_EQUAL(channel3->getUri().toString(), "udp6://[::1]:20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 929 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 930 | #ifdef __linux__ |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 931 | // need superuser privileges to create multicast faces on Linux |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 932 | SKIP_IF_NOT_SUPERUSER(); |
| 933 | #endif // __linux__ |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 934 | |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 935 | // createChannel with a local endpoint that has already been allocated to a UDP multicast face |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 936 | if (!netifsV4.empty()) { |
| 937 | auto mcastFace = createMulticastFace("127.0.0.1", "224.0.0.254", 20072); |
| 938 | BOOST_CHECK_EXCEPTION(createChannel("127.0.0.1", 20072), UdpFactory::Error, |
| 939 | [] (const UdpFactory::Error& e) { |
| 940 | return strcmp(e.what(), |
| 941 | "Cannot create UDP channel on 127.0.0.1:20072, " |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 942 | "endpoint already allocated to a UDP multicast face") == 0; |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 943 | }); |
| 944 | } |
| 945 | if (!netifsV6.empty()) { |
| 946 | auto mcastFace = createMulticastFace("::1", "ff02::114", 20072); |
| 947 | BOOST_CHECK_EXCEPTION(createChannel("::1", 20072), UdpFactory::Error, |
| 948 | [] (const UdpFactory::Error& e) { |
| 949 | return strcmp(e.what(), |
| 950 | "Cannot create UDP channel on [::1]:20072, " |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 951 | "endpoint already allocated to a UDP multicast face") == 0; |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 952 | }); |
| 953 | } |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 954 | } |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 955 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 956 | BOOST_FIXTURE_TEST_CASE(CreateMulticastFaceV4, UdpFactoryMcastFixture) |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 957 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 958 | #ifdef __linux__ |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 959 | // need superuser privileges to create multicast faces on Linux |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 960 | SKIP_IF_NOT_SUPERUSER(); |
| 961 | #endif // __linux__ |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 962 | SKIP_IF_UDP_MCAST_V4_NETIF_COUNT_LT(1); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 963 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 964 | auto multicastFace1 = createMulticastFace("127.0.0.1", "224.0.0.254", 20070); |
| 965 | auto multicastFace1a = createMulticastFace("127.0.0.1", "224.0.0.254", 20070); |
| 966 | auto multicastFace2 = createMulticastFace("127.0.0.1", "224.0.0.254", 20030); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 967 | BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 968 | BOOST_CHECK_NE(multicastFace1, multicastFace2); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 969 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 970 | auto address = findNonLoopbackAddressForMulticastFace(ndn::net::AddressFamily::V4); |
| 971 | if (!address.is_unspecified()) { |
| 972 | auto multicastFace3 = createMulticastFace(address.to_string(), "224.0.0.254", 20070); |
| 973 | BOOST_CHECK_NE(multicastFace1, multicastFace3); |
| 974 | BOOST_CHECK_NE(multicastFace2, multicastFace3); |
| 975 | } |
| 976 | |
| 977 | // create with a local endpoint already used by a channel |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 978 | auto channel = createChannel("127.0.0.1", 20071); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 979 | BOOST_CHECK_EXCEPTION(createMulticastFace("127.0.0.1", "224.0.0.254", 20071), UdpFactory::Error, |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 980 | [] (const UdpFactory::Error& e) { |
| 981 | return strcmp(e.what(), |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 982 | "Cannot create UDP multicast face on 127.0.0.1:20071, " |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 983 | "endpoint already allocated to a UDP channel") == 0; |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 984 | }); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 985 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 986 | // create with a local endpoint already used by a multicast face on a different multicast group |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 987 | BOOST_CHECK_EXCEPTION(createMulticastFace("127.0.0.1", "224.0.0.42", 20070), UdpFactory::Error, |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 988 | [] (const UdpFactory::Error& e) { |
| 989 | return strcmp(e.what(), |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 990 | "Cannot create UDP multicast face on 127.0.0.1:20070, " |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 991 | "endpoint already allocated to a different UDP multicast face") == 0; |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 992 | }); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 993 | } |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 994 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 995 | BOOST_FIXTURE_TEST_CASE(CreateMulticastFaceV6, UdpFactoryMcastFixture) |
| 996 | { |
| 997 | #ifdef __linux__ |
| 998 | // need superuser privileges to create multicast faces on Linux |
| 999 | SKIP_IF_NOT_SUPERUSER(); |
| 1000 | #endif // __linux__ |
| 1001 | SKIP_IF_UDP_MCAST_V6_NETIF_COUNT_LT(1); |
| 1002 | |
| 1003 | auto multicastFace1 = createMulticastFace("::1", "ff02::114", 20070); |
| 1004 | auto multicastFace1a = createMulticastFace("::1", "ff02::114", 20070); |
| 1005 | auto multicastFace2 = createMulticastFace("::1", "ff02::114", 20030); |
| 1006 | BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a); |
| 1007 | BOOST_CHECK_NE(multicastFace1, multicastFace2); |
| 1008 | |
| 1009 | auto address = findNonLoopbackAddressForMulticastFace(ndn::net::AddressFamily::V6); |
| 1010 | if (!address.is_unspecified()) { |
| 1011 | auto multicastFace3 = createMulticastFace(address.to_string(), "ff02::114", 20070); |
| 1012 | BOOST_CHECK_NE(multicastFace1, multicastFace3); |
| 1013 | BOOST_CHECK_NE(multicastFace2, multicastFace3); |
| 1014 | } |
| 1015 | |
| 1016 | // create with a local endpoint already used by a channel |
| 1017 | auto channel = createChannel("::1", 20071); |
| 1018 | BOOST_CHECK_EXCEPTION(createMulticastFace("::1", "ff02::114", 20071), UdpFactory::Error, |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 1019 | [] (const UdpFactory::Error& e) { |
| 1020 | return strcmp(e.what(), |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 1021 | "Cannot create UDP multicast face on [::1]:20071, " |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 1022 | "endpoint already allocated to a UDP channel") == 0; |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 1023 | }); |
| 1024 | |
| 1025 | // create with a local endpoint already used by a multicast face on a different multicast group |
| 1026 | BOOST_CHECK_EXCEPTION(createMulticastFace("::1", "ff02::42", 20070), UdpFactory::Error, |
| 1027 | [] (const UdpFactory::Error& e) { |
| 1028 | return strcmp(e.what(), |
| 1029 | "Cannot create UDP multicast face on [::1]:20070, " |
Davide Pesavento | 19779d8 | 2019-02-14 13:40:04 -0500 | [diff] [blame] | 1030 | "endpoint already allocated to a different UDP multicast face") == 0; |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 1031 | }); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 1034 | BOOST_AUTO_TEST_CASE(CreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1035 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1036 | createFace(factory, |
| 1037 | FaceUri("udp4://127.0.0.1:6363"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 1038 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 1039 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1040 | {CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1041 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 1042 | createChannel("127.0.0.1", 20071); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1043 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1044 | createFace(factory, |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 1045 | FaceUri("udp4://127.0.0.1:6363"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 1046 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 1047 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1048 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 1049 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1050 | createFace(factory, |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 1051 | FaceUri("udp4://127.0.0.1:6363"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 1052 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 1053 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1054 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1055 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1056 | createFace(factory, |
| 1057 | FaceUri("udp4://127.0.0.1:20072"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 1058 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 1059 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 1060 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 1061 | |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 1062 | createFace(factory, |
| 1063 | FaceUri("udp4://127.0.0.1:20073"), |
| 1064 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 1065 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, true, false}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 1066 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 1067 | |
| 1068 | createFace(factory, |
| 1069 | FaceUri("udp4://127.0.0.1:20073"), |
| 1070 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 1071 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, true}, |
| 1072 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 1073 | |
| 1074 | createFace(factory, |
| 1075 | FaceUri("udp4://127.0.0.1:20074"), |
| 1076 | {}, |
| 1077 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, 1000, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1078 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 1081 | BOOST_AUTO_TEST_CASE(UnsupportedCreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1082 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 1083 | createChannel("127.0.0.1", 20071); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1084 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1085 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1086 | FaceUri("udp4://127.0.0.1:20072"), |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 1087 | FaceUri("udp4://127.0.0.1:20071"), |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 1088 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1089 | {CreateFaceExpectedResult::FAILURE, 406, |
| 1090 | "Unicast UDP faces cannot be created with a LocalUri"}); |
| 1091 | |
| 1092 | createFace(factory, |
| 1093 | FaceUri("udp4://127.0.0.1:20072"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 1094 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 1095 | {ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1096 | {CreateFaceExpectedResult::FAILURE, 406, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1097 | "Outgoing UDP faces do not support on-demand persistency"}); |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 1098 | |
| 1099 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1100 | FaceUri("udp4://233.252.0.1:23252"), |
| 1101 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 1102 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 1103 | {CreateFaceExpectedResult::FAILURE, 406, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1104 | "Cannot create multicast UDP faces"}); |
| 1105 | |
| 1106 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1107 | FaceUri("udp4://127.0.0.1:20072"), |
| 1108 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 1109 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, true, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1110 | {CreateFaceExpectedResult::FAILURE, 406, |
| 1111 | "Local fields can only be enabled on faces with local scope"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1114 | BOOST_AUTO_TEST_SUITE_END() // TestUdpFactory |
| 1115 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 1116 | |
| 1117 | } // namespace tests |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 1118 | } // namespace face |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1119 | } // namespace nfd |