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