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