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