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