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