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