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