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> |
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(), |
| 200 | [] (const shared_ptr<const Channel>& ch) { return ch->isListening(); })); |
| 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(), |
| 223 | [] (const shared_ptr<const Channel>& 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 | |
| 582 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(BadPort, 2) // Bug #4489 |
| 583 | BOOST_AUTO_TEST_CASE(BadPort) |
| 584 | { |
| 585 | // not a number |
| 586 | const std::string CONFIG1 = R"CONFIG( |
| 587 | face_system |
| 588 | { |
| 589 | udp |
| 590 | { |
| 591 | port hello |
| 592 | } |
| 593 | } |
| 594 | )CONFIG"; |
| 595 | |
| 596 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 597 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 598 | |
| 599 | // negative number |
| 600 | const std::string CONFIG2 = R"CONFIG( |
| 601 | face_system |
| 602 | { |
| 603 | udp |
| 604 | { |
| 605 | port -1 |
| 606 | } |
| 607 | } |
| 608 | )CONFIG"; |
| 609 | |
| 610 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 611 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
| 612 | |
| 613 | // out of range |
| 614 | const std::string CONFIG3 = R"CONFIG( |
| 615 | face_system |
| 616 | { |
| 617 | udp |
| 618 | { |
| 619 | port 65536 |
| 620 | } |
| 621 | } |
| 622 | )CONFIG"; |
| 623 | |
| 624 | BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error); |
| 625 | BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error); |
| 626 | } |
| 627 | |
| 628 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(BadIdleTimeout, 2) // Bug #4489 |
| 629 | BOOST_AUTO_TEST_CASE(BadIdleTimeout) |
| 630 | { |
| 631 | // not a number |
| 632 | const std::string CONFIG1 = R"CONFIG( |
| 633 | face_system |
| 634 | { |
| 635 | udp |
| 636 | { |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 637 | idle_timeout hello |
| 638 | } |
| 639 | } |
| 640 | )CONFIG"; |
| 641 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 642 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 643 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 644 | |
| 645 | // negative number |
| 646 | const std::string CONFIG2 = R"CONFIG( |
| 647 | face_system |
| 648 | { |
| 649 | udp |
| 650 | { |
| 651 | idle_timeout -15 |
| 652 | } |
| 653 | } |
| 654 | )CONFIG"; |
| 655 | |
| 656 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 657 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | BOOST_AUTO_TEST_CASE(BadMcast) |
| 661 | { |
| 662 | const std::string CONFIG = R"CONFIG( |
| 663 | face_system |
| 664 | { |
| 665 | udp |
| 666 | { |
| 667 | mcast hello |
| 668 | } |
| 669 | } |
| 670 | )CONFIG"; |
| 671 | |
| 672 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 673 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 674 | } |
| 675 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 676 | BOOST_AUTO_TEST_CASE(BadMcastGroupV4) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 677 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 678 | // not an address |
| 679 | const std::string CONFIG1 = R"CONFIG( |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 680 | face_system |
| 681 | { |
| 682 | udp |
| 683 | { |
| 684 | mcast_group hello |
| 685 | } |
| 686 | } |
| 687 | )CONFIG"; |
| 688 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 689 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 690 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 691 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 692 | // non-multicast address |
| 693 | const std::string CONFIG2 = R"CONFIG( |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 694 | face_system |
| 695 | { |
| 696 | udp |
| 697 | { |
| 698 | mcast_group 10.0.0.1 |
| 699 | } |
| 700 | } |
| 701 | )CONFIG"; |
| 702 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 703 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 704 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 705 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 706 | // wrong address family |
| 707 | const std::string CONFIG3 = R"CONFIG( |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 708 | face_system |
| 709 | { |
| 710 | udp |
| 711 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 712 | mcast_group ff02::1234 |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 713 | } |
| 714 | } |
| 715 | )CONFIG"; |
| 716 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 717 | BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error); |
| 718 | BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 719 | } |
| 720 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 721 | BOOST_AUTO_TEST_CASE(BadMcastGroupV6) |
| 722 | { |
| 723 | // not an address |
| 724 | const std::string CONFIG1 = R"CONFIG( |
| 725 | face_system |
| 726 | { |
| 727 | udp |
| 728 | { |
| 729 | mcast_group_v6 foo |
| 730 | } |
| 731 | } |
| 732 | )CONFIG"; |
| 733 | |
| 734 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 735 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 736 | |
| 737 | // non-multicast address |
| 738 | const std::string CONFIG2 = R"CONFIG( |
| 739 | face_system |
| 740 | { |
| 741 | udp |
| 742 | { |
| 743 | mcast_group_v6 fe80::1234 |
| 744 | } |
| 745 | } |
| 746 | )CONFIG"; |
| 747 | |
| 748 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 749 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
| 750 | |
| 751 | // wrong address family |
| 752 | const std::string CONFIG3 = R"CONFIG( |
| 753 | face_system |
| 754 | { |
| 755 | udp |
| 756 | { |
| 757 | mcast_group_v6 224.0.23.170 |
| 758 | } |
| 759 | } |
| 760 | )CONFIG"; |
| 761 | |
| 762 | BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error); |
| 763 | BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error); |
| 764 | } |
| 765 | |
| 766 | BOOST_AUTO_TEST_CASE(BadMcastPortV4) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 767 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 768 | const std::string CONFIG1 = R"CONFIG( |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 769 | face_system |
| 770 | { |
| 771 | udp |
| 772 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 773 | mcast_port hey |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | )CONFIG"; |
| 777 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 778 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 779 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 780 | |
| 781 | const std::string CONFIG2 = R"CONFIG( |
| 782 | face_system |
| 783 | { |
| 784 | udp |
| 785 | { |
| 786 | mcast_port 99999 |
| 787 | } |
| 788 | } |
| 789 | )CONFIG"; |
| 790 | |
| 791 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 792 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 795 | BOOST_AUTO_TEST_CASE(BadMcastPortV6) |
| 796 | { |
| 797 | const std::string CONFIG1 = R"CONFIG( |
| 798 | face_system |
| 799 | { |
| 800 | udp |
| 801 | { |
| 802 | mcast_port_v6 bar |
| 803 | } |
| 804 | } |
| 805 | )CONFIG"; |
| 806 | |
| 807 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 808 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 809 | |
| 810 | const std::string CONFIG2 = R"CONFIG( |
| 811 | face_system |
| 812 | { |
| 813 | udp |
| 814 | { |
| 815 | mcast_port_v6 99999 |
| 816 | } |
| 817 | } |
| 818 | )CONFIG"; |
| 819 | |
| 820 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 821 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
| 822 | } |
| 823 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 824 | BOOST_AUTO_TEST_CASE(UnknownOption) |
| 825 | { |
| 826 | const std::string CONFIG = R"CONFIG( |
| 827 | face_system |
| 828 | { |
| 829 | udp |
| 830 | { |
| 831 | hello |
| 832 | } |
| 833 | } |
| 834 | )CONFIG"; |
| 835 | |
| 836 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 837 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 838 | } |
| 839 | |
| 840 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 841 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 842 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 843 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 844 | BOOST_CHECK_EQUAL(factory.getChannels().empty(), true); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 845 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 846 | std::set<std::string> expected; |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 847 | expected.insert(createChannel("127.0.0.1", 20070)->getUri().toString()); |
| 848 | expected.insert(createChannel("127.0.0.1", 20071)->getUri().toString()); |
| 849 | expected.insert(createChannel("::1", 20071)->getUri().toString()); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 850 | checkChannelListEqual(factory, expected); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 853 | BOOST_FIXTURE_TEST_CASE(CreateChannel, UdpFactoryMcastFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 854 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 855 | auto channel1 = createChannel("127.0.0.1", 20070); |
| 856 | auto channel1a = createChannel("127.0.0.1", 20070); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 857 | BOOST_CHECK_EQUAL(channel1, channel1a); |
| 858 | BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070"); |
| 859 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 860 | auto channel2 = createChannel("127.0.0.1", 20071); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 861 | BOOST_CHECK_NE(channel1, channel2); |
| 862 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 863 | auto channel3 = createChannel("::1", 20071); |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 864 | BOOST_CHECK_NE(channel2, channel3); |
| 865 | BOOST_CHECK_EQUAL(channel3->getUri().toString(), "udp6://[::1]:20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 866 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 867 | #ifdef __linux__ |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 868 | // need superuser privileges to create multicast faces on Linux |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 869 | SKIP_IF_NOT_SUPERUSER(); |
| 870 | #endif // __linux__ |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 871 | |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 872 | // 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] | 873 | if (!netifsV4.empty()) { |
| 874 | auto mcastFace = createMulticastFace("127.0.0.1", "224.0.0.254", 20072); |
| 875 | BOOST_CHECK_EXCEPTION(createChannel("127.0.0.1", 20072), UdpFactory::Error, |
| 876 | [] (const UdpFactory::Error& e) { |
| 877 | return strcmp(e.what(), |
| 878 | "Cannot create UDP channel on 127.0.0.1:20072, " |
| 879 | "endpoint already allocated for a UDP multicast face") == 0; |
| 880 | }); |
| 881 | } |
| 882 | if (!netifsV6.empty()) { |
| 883 | auto mcastFace = createMulticastFace("::1", "ff02::114", 20072); |
| 884 | BOOST_CHECK_EXCEPTION(createChannel("::1", 20072), UdpFactory::Error, |
| 885 | [] (const UdpFactory::Error& e) { |
| 886 | return strcmp(e.what(), |
| 887 | "Cannot create UDP channel on [::1]:20072, " |
| 888 | "endpoint already allocated for a UDP multicast face") == 0; |
| 889 | }); |
| 890 | } |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 891 | } |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 892 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 893 | BOOST_FIXTURE_TEST_CASE(CreateMulticastFaceV4, UdpFactoryMcastFixture) |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 894 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 895 | #ifdef __linux__ |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 896 | // need superuser privileges to create multicast faces on Linux |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 897 | SKIP_IF_NOT_SUPERUSER(); |
| 898 | #endif // __linux__ |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 899 | SKIP_IF_UDP_MCAST_V4_NETIF_COUNT_LT(1); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 900 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 901 | auto multicastFace1 = createMulticastFace("127.0.0.1", "224.0.0.254", 20070); |
| 902 | auto multicastFace1a = createMulticastFace("127.0.0.1", "224.0.0.254", 20070); |
| 903 | auto multicastFace2 = createMulticastFace("127.0.0.1", "224.0.0.254", 20030); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 904 | BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 905 | BOOST_CHECK_NE(multicastFace1, multicastFace2); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 906 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 907 | auto address = findNonLoopbackAddressForMulticastFace(ndn::net::AddressFamily::V4); |
| 908 | if (!address.is_unspecified()) { |
| 909 | auto multicastFace3 = createMulticastFace(address.to_string(), "224.0.0.254", 20070); |
| 910 | BOOST_CHECK_NE(multicastFace1, multicastFace3); |
| 911 | BOOST_CHECK_NE(multicastFace2, multicastFace3); |
| 912 | } |
| 913 | |
| 914 | // create with a local endpoint already used by a channel |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 915 | auto channel = createChannel("127.0.0.1", 20071); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 916 | 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] | 917 | [] (const UdpFactory::Error& e) { |
| 918 | return strcmp(e.what(), |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 919 | "Cannot create UDP multicast face on 127.0.0.1:20071, " |
| 920 | "endpoint already allocated for a UDP channel") == 0; |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 921 | }); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 922 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 923 | // 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] | 924 | 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] | 925 | [] (const UdpFactory::Error& e) { |
| 926 | return strcmp(e.what(), |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 927 | "Cannot create UDP multicast face on 127.0.0.1:20070, " |
| 928 | "endpoint already allocated for a different UDP multicast face") == 0; |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 929 | }); |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 930 | } |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 931 | |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 932 | BOOST_FIXTURE_TEST_CASE(CreateMulticastFaceV6, UdpFactoryMcastFixture) |
| 933 | { |
| 934 | #ifdef __linux__ |
| 935 | // need superuser privileges to create multicast faces on Linux |
| 936 | SKIP_IF_NOT_SUPERUSER(); |
| 937 | #endif // __linux__ |
| 938 | SKIP_IF_UDP_MCAST_V6_NETIF_COUNT_LT(1); |
| 939 | |
| 940 | auto multicastFace1 = createMulticastFace("::1", "ff02::114", 20070); |
| 941 | auto multicastFace1a = createMulticastFace("::1", "ff02::114", 20070); |
| 942 | auto multicastFace2 = createMulticastFace("::1", "ff02::114", 20030); |
| 943 | BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a); |
| 944 | BOOST_CHECK_NE(multicastFace1, multicastFace2); |
| 945 | |
| 946 | auto address = findNonLoopbackAddressForMulticastFace(ndn::net::AddressFamily::V6); |
| 947 | if (!address.is_unspecified()) { |
| 948 | auto multicastFace3 = createMulticastFace(address.to_string(), "ff02::114", 20070); |
| 949 | BOOST_CHECK_NE(multicastFace1, multicastFace3); |
| 950 | BOOST_CHECK_NE(multicastFace2, multicastFace3); |
| 951 | } |
| 952 | |
| 953 | // create with a local endpoint already used by a channel |
| 954 | auto channel = createChannel("::1", 20071); |
| 955 | BOOST_CHECK_EXCEPTION(createMulticastFace("::1", "ff02::114", 20071), UdpFactory::Error, |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 956 | [] (const UdpFactory::Error& e) { |
| 957 | return strcmp(e.what(), |
Md Ashiqur Rahman | 8ce0903 | 2018-01-14 22:43:13 -0500 | [diff] [blame] | 958 | "Cannot create UDP multicast face on [::1]:20071, " |
| 959 | "endpoint already allocated for a UDP channel") == 0; |
| 960 | }); |
| 961 | |
| 962 | // create with a local endpoint already used by a multicast face on a different multicast group |
| 963 | BOOST_CHECK_EXCEPTION(createMulticastFace("::1", "ff02::42", 20070), UdpFactory::Error, |
| 964 | [] (const UdpFactory::Error& e) { |
| 965 | return strcmp(e.what(), |
| 966 | "Cannot create UDP multicast face on [::1]:20070, " |
| 967 | "endpoint already allocated for a different UDP multicast face") == 0; |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 968 | }); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 969 | } |
| 970 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 971 | BOOST_AUTO_TEST_CASE(CreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 972 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 973 | createFace(factory, |
| 974 | FaceUri("udp4://127.0.0.1:6363"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 975 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame^] | 976 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 977 | {CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 978 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 979 | createChannel("127.0.0.1", 20071); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 980 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 981 | createFace(factory, |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 982 | FaceUri("udp4://127.0.0.1:6363"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 983 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame^] | 984 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 985 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 986 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 987 | createFace(factory, |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 988 | FaceUri("udp4://127.0.0.1:6363"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 989 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame^] | 990 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 991 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 992 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 993 | createFace(factory, |
| 994 | FaceUri("udp4://127.0.0.1:20072"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 995 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame^] | 996 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 997 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 998 | |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 999 | createFace(factory, |
| 1000 | FaceUri("udp4://127.0.0.1:20073"), |
| 1001 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame^] | 1002 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, true, false}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 1003 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 1004 | |
| 1005 | createFace(factory, |
| 1006 | FaceUri("udp4://127.0.0.1:20073"), |
| 1007 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame^] | 1008 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, true}, |
| 1009 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 1010 | |
| 1011 | createFace(factory, |
| 1012 | FaceUri("udp4://127.0.0.1:20074"), |
| 1013 | {}, |
| 1014 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, 1000, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1015 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 1018 | BOOST_AUTO_TEST_CASE(UnsupportedCreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1019 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 1020 | createChannel("127.0.0.1", 20071); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1021 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1022 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1023 | FaceUri("udp4://127.0.0.1:20072"), |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 1024 | FaceUri("udp4://127.0.0.1:20071"), |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame^] | 1025 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1026 | {CreateFaceExpectedResult::FAILURE, 406, |
| 1027 | "Unicast UDP faces cannot be created with a LocalUri"}); |
| 1028 | |
| 1029 | createFace(factory, |
| 1030 | FaceUri("udp4://127.0.0.1:20072"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 1031 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame^] | 1032 | {ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 1033 | {CreateFaceExpectedResult::FAILURE, 406, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1034 | "Outgoing UDP faces do not support on-demand persistency"}); |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 1035 | |
| 1036 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1037 | FaceUri("udp4://233.252.0.1:23252"), |
| 1038 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame^] | 1039 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 1040 | {CreateFaceExpectedResult::FAILURE, 406, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1041 | "Cannot create multicast UDP faces"}); |
| 1042 | |
| 1043 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1044 | FaceUri("udp4://127.0.0.1:20072"), |
| 1045 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame^] | 1046 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, true, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 1047 | {CreateFaceExpectedResult::FAILURE, 406, |
| 1048 | "Local fields can only be enabled on faces with local scope"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1051 | BOOST_AUTO_TEST_SUITE_END() // TestUdpFactory |
| 1052 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 1053 | |
| 1054 | } // namespace tests |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 1055 | } // namespace face |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1056 | } // namespace nfd |