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 | /* |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | */ |
| 25 | |
| 26 | #include "face/udp-factory.hpp" |
| 27 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 28 | #include "face-system-fixture.hpp" |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 29 | #include "factory-test-common.hpp" |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 30 | |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 31 | #include <boost/algorithm/string/replace.hpp> |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 32 | #include <boost/range/algorithm/count_if.hpp> |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 33 | #include <ndn-cxx/net/address-converter.hpp> |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 34 | |
| 35 | namespace nfd { |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 36 | namespace face { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 37 | namespace tests { |
| 38 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 39 | class UdpFactoryFixture : public FaceSystemFactoryFixture<UdpFactory> |
| 40 | { |
| 41 | protected: |
| 42 | shared_ptr<UdpChannel> |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 43 | createChannel(const std::string& localIp, uint16_t localPort) |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 44 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 45 | udp::Endpoint endpoint(ndn::ip::addressFromString(localIp), localPort); |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 46 | return factory.createChannel(endpoint, time::minutes(5)); |
| 47 | } |
| 48 | }; |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 49 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 50 | class UdpFactoryMcastFixture : public UdpFactoryFixture |
| 51 | { |
| 52 | protected: |
| 53 | UdpFactoryMcastFixture() |
| 54 | { |
| 55 | for (const auto& netif : collectNetworkInterfaces()) { |
| 56 | if (netif->isUp() && netif->canMulticast() && |
| 57 | hasAddressFamily(*netif, ndn::net::AddressFamily::V4)) { |
| 58 | netifs.push_back(netif); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | this->copyRealNetifsToNetmon(); |
| 63 | } |
| 64 | |
| 65 | shared_ptr<Face> |
| 66 | createMulticastFace(const std::string& localIp, const std::string& mcastIp, uint16_t mcastPort) |
| 67 | { |
| 68 | BOOST_ASSERT(!netifs.empty()); |
| 69 | udp::Endpoint localEndpoint(ndn::ip::addressFromString(localIp), mcastPort); |
| 70 | udp::Endpoint mcastEndpoint(ndn::ip::addressFromString(mcastIp), mcastPort); |
| 71 | return factory.createMulticastFace(localEndpoint, mcastEndpoint, *netifs.front()); |
| 72 | } |
| 73 | |
| 74 | std::vector<const Face*> |
| 75 | listUdp4McastFaces(ndn::nfd::LinkType linkType = ndn::nfd::LINK_TYPE_MULTI_ACCESS) const |
| 76 | { |
| 77 | return this->listFacesByScheme("udp4", linkType); |
| 78 | } |
| 79 | |
| 80 | /** \brief determine whether \p netif has at least one address of the given family |
| 81 | */ |
| 82 | static bool |
| 83 | hasAddressFamily(const NetworkInterface& netif, ndn::net::AddressFamily af) |
| 84 | { |
| 85 | return std::any_of(netif.getNetworkAddresses().begin(), netif.getNetworkAddresses().end(), |
| 86 | [af] (const NetworkAddress& a) { return a.getFamily() == af; }); |
| 87 | } |
| 88 | |
| 89 | /** \brief determine whether a UDP multicast face is created on \p netif |
| 90 | */ |
| 91 | static bool |
| 92 | isFaceOnNetif(const Face& face, const shared_ptr<const NetworkInterface>& netif) |
| 93 | { |
| 94 | auto ip = boost::asio::ip::address_v4::from_string(face.getLocalUri().getHost()); |
| 95 | return std::any_of(netif->getNetworkAddresses().begin(), netif->getNetworkAddresses().end(), |
| 96 | [ip] (const NetworkAddress& a) { return a.getIp() == ip; }); |
| 97 | } |
| 98 | |
| 99 | protected: |
| 100 | /** \brief MulticastUdpTransport-capable network interfaces |
| 101 | */ |
| 102 | std::vector<shared_ptr<const NetworkInterface>> netifs; |
| 103 | }; |
| 104 | |
| 105 | #define SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(n) \ |
| 106 | do { \ |
| 107 | if (this->netifs.size() < (n)) { \ |
| 108 | BOOST_WARN_MESSAGE(false, "skipping assertions that require " #n \ |
| 109 | " or more MulticastUdpTransport-capable network interfaces"); \ |
| 110 | return; \ |
| 111 | } \ |
| 112 | } while (false) |
| 113 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 114 | BOOST_AUTO_TEST_SUITE(Face) |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 115 | BOOST_FIXTURE_TEST_SUITE(TestUdpFactory, UdpFactoryFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 116 | |
| 117 | using nfd::Face; |
| 118 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 119 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 120 | |
| 121 | BOOST_AUTO_TEST_CASE(Channels) |
| 122 | { |
| 123 | const std::string CONFIG = R"CONFIG( |
| 124 | face_system |
| 125 | { |
| 126 | udp |
| 127 | { |
| 128 | port 7001 |
| 129 | enable_v4 yes |
| 130 | enable_v6 yes |
| 131 | idle_timeout 30 |
| 132 | mcast no |
| 133 | } |
| 134 | } |
| 135 | )CONFIG"; |
| 136 | |
| 137 | parseConfig(CONFIG, true); |
| 138 | parseConfig(CONFIG, false); |
| 139 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 140 | checkChannelListEqual(factory, {"udp4://0.0.0.0:7001", "udp6://[::]:7001"}); |
| 141 | } |
| 142 | |
| 143 | BOOST_AUTO_TEST_CASE(ChannelV4) |
| 144 | { |
| 145 | const std::string CONFIG = R"CONFIG( |
| 146 | face_system |
| 147 | { |
| 148 | udp |
| 149 | { |
| 150 | port 7001 |
| 151 | enable_v4 yes |
| 152 | enable_v6 no |
| 153 | mcast no |
| 154 | } |
| 155 | } |
| 156 | )CONFIG"; |
| 157 | |
| 158 | parseConfig(CONFIG, true); |
| 159 | parseConfig(CONFIG, false); |
| 160 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 161 | checkChannelListEqual(factory, {"udp4://0.0.0.0:7001"}); |
| 162 | } |
| 163 | |
| 164 | BOOST_AUTO_TEST_CASE(ChannelV6) |
| 165 | { |
| 166 | const std::string CONFIG = R"CONFIG( |
| 167 | face_system |
| 168 | { |
| 169 | udp |
| 170 | { |
| 171 | port 7001 |
| 172 | enable_v4 no |
| 173 | enable_v6 yes |
| 174 | mcast no |
| 175 | } |
| 176 | } |
| 177 | )CONFIG"; |
| 178 | |
| 179 | parseConfig(CONFIG, true); |
| 180 | parseConfig(CONFIG, false); |
| 181 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 182 | checkChannelListEqual(factory, {"udp6://[::]:7001"}); |
| 183 | } |
| 184 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 185 | BOOST_FIXTURE_TEST_CASE(EnableDisableMcast, UdpFactoryMcastFixture) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 186 | { |
| 187 | #ifdef __linux__ |
Junxiao Shi | bbace1d | 2017-08-06 20:03:37 +0000 | [diff] [blame] | 188 | // need superuser privilege for creating multicast faces on Linux |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 189 | SKIP_IF_NOT_SUPERUSER(); |
| 190 | #endif // __linux__ |
| 191 | |
| 192 | const std::string CONFIG_WITH_MCAST = R"CONFIG( |
| 193 | face_system |
| 194 | { |
| 195 | udp |
| 196 | { |
| 197 | mcast yes |
| 198 | } |
| 199 | } |
| 200 | )CONFIG"; |
| 201 | const std::string CONFIG_WITHOUT_MCAST = R"CONFIG( |
| 202 | face_system |
| 203 | { |
| 204 | udp |
| 205 | { |
| 206 | mcast no |
| 207 | } |
| 208 | } |
| 209 | )CONFIG"; |
| 210 | |
| 211 | parseConfig(CONFIG_WITHOUT_MCAST, false); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 212 | BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), 0); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 213 | |
| 214 | SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1); |
| 215 | |
| 216 | parseConfig(CONFIG_WITH_MCAST, false); |
| 217 | g_io.poll(); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 218 | BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), netifs.size()); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 219 | |
| 220 | parseConfig(CONFIG_WITHOUT_MCAST, false); |
| 221 | g_io.poll(); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 222 | BOOST_CHECK_EQUAL(this->listUdp4McastFaces().size(), 0); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 225 | BOOST_FIXTURE_TEST_CASE(McastAdHoc, UdpFactoryMcastFixture) |
Teng Liang | fe4fce3 | 2017-03-29 04:49:38 +0000 | [diff] [blame] | 226 | { |
| 227 | #ifdef __linux__ |
Junxiao Shi | bbace1d | 2017-08-06 20:03:37 +0000 | [diff] [blame] | 228 | // need superuser privilege for creating multicast faces on Linux |
Teng Liang | fe4fce3 | 2017-03-29 04:49:38 +0000 | [diff] [blame] | 229 | SKIP_IF_NOT_SUPERUSER(); |
| 230 | #endif // __linux__ |
| 231 | SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1); |
| 232 | |
| 233 | const std::string CONFIG = R"CONFIG( |
| 234 | face_system |
| 235 | { |
| 236 | udp |
| 237 | { |
| 238 | mcast_ad_hoc yes |
| 239 | } |
| 240 | } |
| 241 | )CONFIG"; |
| 242 | |
| 243 | parseConfig(CONFIG, false); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 244 | BOOST_CHECK_EQUAL(this->listUdp4McastFaces(ndn::nfd::LINK_TYPE_AD_HOC).size(), netifs.size()); |
Teng Liang | fe4fce3 | 2017-03-29 04:49:38 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 247 | BOOST_FIXTURE_TEST_CASE(ChangeMcastEndpoint, UdpFactoryMcastFixture) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 248 | { |
| 249 | #ifdef __linux__ |
Junxiao Shi | bbace1d | 2017-08-06 20:03:37 +0000 | [diff] [blame] | 250 | // need superuser privilege for creating multicast faces on Linux |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 251 | SKIP_IF_NOT_SUPERUSER(); |
| 252 | #endif // __linux__ |
| 253 | SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1); |
| 254 | |
| 255 | const std::string CONFIG1 = R"CONFIG( |
| 256 | face_system |
| 257 | { |
| 258 | udp |
| 259 | { |
| 260 | mcast_group 239.66.30.1 |
| 261 | mcast_port 7011 |
| 262 | } |
| 263 | } |
| 264 | )CONFIG"; |
| 265 | const std::string CONFIG2 = R"CONFIG( |
| 266 | face_system |
| 267 | { |
| 268 | udp |
| 269 | { |
| 270 | mcast_group 239.66.30.2 |
| 271 | mcast_port 7012 |
| 272 | } |
| 273 | } |
| 274 | )CONFIG"; |
| 275 | |
| 276 | parseConfig(CONFIG1, false); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 277 | auto udpMcastFaces = this->listUdp4McastFaces(); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 278 | BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifs.size()); |
| 279 | BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), |
| 280 | FaceUri("udp4://239.66.30.1:7011")); |
| 281 | |
| 282 | parseConfig(CONFIG2, false); |
| 283 | g_io.poll(); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 284 | udpMcastFaces = this->listUdp4McastFaces(); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 285 | BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), netifs.size()); |
| 286 | BOOST_CHECK_EQUAL(udpMcastFaces.front()->getRemoteUri(), |
| 287 | FaceUri("udp4://239.66.30.2:7012")); |
| 288 | } |
| 289 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 290 | BOOST_FIXTURE_TEST_CASE(Whitelist, UdpFactoryMcastFixture) |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 291 | { |
| 292 | #ifdef __linux__ |
Junxiao Shi | bbace1d | 2017-08-06 20:03:37 +0000 | [diff] [blame] | 293 | // need superuser privilege for creating multicast faces on Linux |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 294 | SKIP_IF_NOT_SUPERUSER(); |
| 295 | #endif // __linux__ |
| 296 | SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1); |
| 297 | |
| 298 | std::string CONFIG = R"CONFIG( |
| 299 | face_system |
| 300 | { |
| 301 | udp |
| 302 | { |
| 303 | whitelist |
| 304 | { |
| 305 | ifname %ifname |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | )CONFIG"; |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 310 | boost::replace_first(CONFIG, "%ifname", netifs.front()->getName()); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 311 | |
| 312 | parseConfig(CONFIG, false); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 313 | auto udpMcastFaces = this->listUdp4McastFaces(); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 314 | BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), 1); |
| 315 | BOOST_CHECK(isFaceOnNetif(*udpMcastFaces.front(), netifs.front())); |
| 316 | } |
| 317 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 318 | BOOST_FIXTURE_TEST_CASE(Blacklist, UdpFactoryMcastFixture) |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 319 | { |
| 320 | #ifdef __linux__ |
Junxiao Shi | bbace1d | 2017-08-06 20:03:37 +0000 | [diff] [blame] | 321 | // need superuser privilege for creating multicast faces on Linux |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 322 | SKIP_IF_NOT_SUPERUSER(); |
| 323 | #endif // __linux__ |
| 324 | SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1); |
| 325 | |
| 326 | std::string CONFIG = R"CONFIG( |
| 327 | face_system |
| 328 | { |
| 329 | udp |
| 330 | { |
| 331 | blacklist |
| 332 | { |
| 333 | ifname %ifname |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | )CONFIG"; |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 338 | boost::replace_first(CONFIG, "%ifname", netifs.front()->getName()); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 339 | |
| 340 | parseConfig(CONFIG, false); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 341 | auto udpMcastFaces = this->listUdp4McastFaces(); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 342 | BOOST_CHECK_EQUAL(udpMcastFaces.size(), netifs.size() - 1); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 343 | BOOST_CHECK_EQUAL(boost::count_if(udpMcastFaces, [this] (const Face* face) { |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 344 | return isFaceOnNetif(*face, netifs.front()); |
| 345 | }), 0); |
| 346 | } |
| 347 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 348 | BOOST_FIXTURE_TEST_CASE(ChangePredicate, UdpFactoryMcastFixture) |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 349 | { |
| 350 | #ifdef __linux__ |
Junxiao Shi | bbace1d | 2017-08-06 20:03:37 +0000 | [diff] [blame] | 351 | // need superuser privilege for creating multicast faces on Linux |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 352 | SKIP_IF_NOT_SUPERUSER(); |
| 353 | #endif // __linux__ |
| 354 | SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(2); |
| 355 | |
| 356 | std::string CONFIG1 = R"CONFIG( |
| 357 | face_system |
| 358 | { |
| 359 | udp |
| 360 | { |
| 361 | whitelist |
| 362 | { |
| 363 | ifname %ifname |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | )CONFIG"; |
| 368 | std::string CONFIG2 = CONFIG1; |
Junxiao Shi | 84d62cb | 2017-07-12 16:15:18 +0000 | [diff] [blame] | 369 | boost::replace_first(CONFIG1, "%ifname", netifs.front()->getName()); |
| 370 | boost::replace_first(CONFIG2, "%ifname", netifs.back()->getName()); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 371 | |
| 372 | parseConfig(CONFIG1, false); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 373 | auto udpMcastFaces = this->listUdp4McastFaces(); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 374 | BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), 1); |
| 375 | BOOST_CHECK(isFaceOnNetif(*udpMcastFaces.front(), netifs.front())); |
| 376 | |
| 377 | parseConfig(CONFIG2, false); |
| 378 | g_io.poll(); |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 379 | udpMcastFaces = this->listUdp4McastFaces(); |
Junxiao Shi | c31080d | 2017-01-24 15:10:12 +0000 | [diff] [blame] | 380 | BOOST_REQUIRE_EQUAL(udpMcastFaces.size(), 1); |
| 381 | BOOST_CHECK(isFaceOnNetif(*udpMcastFaces.front(), netifs.back())); |
| 382 | } |
| 383 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 384 | BOOST_AUTO_TEST_CASE(Omitted) |
| 385 | { |
| 386 | const std::string CONFIG = R"CONFIG( |
| 387 | face_system |
| 388 | { |
| 389 | } |
| 390 | )CONFIG"; |
| 391 | |
| 392 | parseConfig(CONFIG, true); |
| 393 | parseConfig(CONFIG, false); |
| 394 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 395 | BOOST_CHECK_EQUAL(factory.getChannels().size(), 0); |
| 396 | BOOST_CHECK_EQUAL(this->listFacesByScheme("udp4", ndn::nfd::LINK_TYPE_MULTI_ACCESS).size(), 0); |
| 397 | } |
| 398 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 399 | BOOST_AUTO_TEST_CASE(AllDisabled) |
| 400 | { |
| 401 | const std::string CONFIG = R"CONFIG( |
| 402 | face_system |
| 403 | { |
| 404 | udp |
| 405 | { |
| 406 | enable_v4 no |
| 407 | enable_v6 no |
| 408 | mcast no |
| 409 | } |
| 410 | } |
| 411 | )CONFIG"; |
| 412 | |
| 413 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 414 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 415 | } |
| 416 | |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 417 | BOOST_AUTO_TEST_CASE(BadIdleTimeout) |
| 418 | { |
| 419 | const std::string CONFIG = R"CONFIG( |
| 420 | face_system |
| 421 | { |
| 422 | udp |
| 423 | { |
| 424 | idle_timeout hello |
| 425 | } |
| 426 | } |
| 427 | )CONFIG"; |
| 428 | |
| 429 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 430 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 431 | } |
| 432 | |
| 433 | BOOST_AUTO_TEST_CASE(BadMcast) |
| 434 | { |
| 435 | const std::string CONFIG = R"CONFIG( |
| 436 | face_system |
| 437 | { |
| 438 | udp |
| 439 | { |
| 440 | mcast hello |
| 441 | } |
| 442 | } |
| 443 | )CONFIG"; |
| 444 | |
| 445 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 446 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 447 | } |
| 448 | |
| 449 | BOOST_AUTO_TEST_CASE(BadMcastGroup) |
| 450 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 451 | // not an address |
| 452 | const std::string CONFIG1 = R"CONFIG( |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 453 | face_system |
| 454 | { |
| 455 | udp |
| 456 | { |
| 457 | mcast_group hello |
| 458 | } |
| 459 | } |
| 460 | )CONFIG"; |
| 461 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 462 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 463 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 464 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 465 | // non-multicast address |
| 466 | const std::string CONFIG2 = R"CONFIG( |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 467 | face_system |
| 468 | { |
| 469 | udp |
| 470 | { |
| 471 | mcast_group 10.0.0.1 |
| 472 | } |
| 473 | } |
| 474 | )CONFIG"; |
| 475 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 476 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 477 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 478 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 479 | // wrong address family |
| 480 | const std::string CONFIG3 = R"CONFIG( |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 481 | face_system |
| 482 | { |
| 483 | udp |
| 484 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 485 | mcast_group ff02::1234 |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | )CONFIG"; |
| 489 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 490 | BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error); |
| 491 | BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 492 | } |
| 493 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 494 | BOOST_AUTO_TEST_CASE(BadMcastPort) |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 495 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 496 | const std::string CONFIG1 = R"CONFIG( |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 497 | face_system |
| 498 | { |
| 499 | udp |
| 500 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 501 | mcast_port hey |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | )CONFIG"; |
| 505 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 506 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 507 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 508 | |
| 509 | const std::string CONFIG2 = R"CONFIG( |
| 510 | face_system |
| 511 | { |
| 512 | udp |
| 513 | { |
| 514 | mcast_port 99999 |
| 515 | } |
| 516 | } |
| 517 | )CONFIG"; |
| 518 | |
| 519 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 520 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | BOOST_AUTO_TEST_CASE(UnknownOption) |
| 524 | { |
| 525 | const std::string CONFIG = R"CONFIG( |
| 526 | face_system |
| 527 | { |
| 528 | udp |
| 529 | { |
| 530 | hello |
| 531 | } |
| 532 | } |
| 533 | )CONFIG"; |
| 534 | |
| 535 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 536 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 537 | } |
| 538 | |
| 539 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 540 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 541 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 542 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 543 | BOOST_CHECK_EQUAL(factory.getChannels().empty(), true); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 544 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 545 | std::set<std::string> expected; |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 546 | expected.insert(createChannel("127.0.0.1", 20070)->getUri().toString()); |
| 547 | expected.insert(createChannel("127.0.0.1", 20071)->getUri().toString()); |
| 548 | expected.insert(createChannel("::1", 20071)->getUri().toString()); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 549 | checkChannelListEqual(factory, expected); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 550 | } |
| 551 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 552 | BOOST_FIXTURE_TEST_CASE(CreateChannel, UdpFactoryMcastFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 553 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 554 | auto channel1 = createChannel("127.0.0.1", 20070); |
| 555 | auto channel1a = createChannel("127.0.0.1", 20070); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 556 | BOOST_CHECK_EQUAL(channel1, channel1a); |
| 557 | BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070"); |
| 558 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 559 | auto channel2 = createChannel("127.0.0.1", 20071); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 560 | BOOST_CHECK_NE(channel1, channel2); |
| 561 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 562 | auto channel3 = createChannel("::1", 20071); |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 563 | BOOST_CHECK_NE(channel2, channel3); |
| 564 | BOOST_CHECK_EQUAL(channel3->getUri().toString(), "udp6://[::1]:20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 565 | |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 566 | // createChannel with multicast address |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 567 | BOOST_CHECK_EXCEPTION(createChannel("224.0.0.1", 20070), UdpFactory::Error, |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 568 | [] (const UdpFactory::Error& e) { |
| 569 | return strcmp(e.what(), |
| 570 | "createChannel is only for unicast channels. The provided endpoint " |
| 571 | "is multicast. Use createMulticastFace to create a multicast face") == 0; |
| 572 | }); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 573 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 574 | #ifdef __linux__ |
| 575 | // need superuser privilege for creating multicast faces on Linux |
| 576 | SKIP_IF_NOT_SUPERUSER(); |
| 577 | #endif // __linux__ |
| 578 | SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1); |
| 579 | |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 580 | // createChannel with a local endpoint that has already been allocated for a UDP multicast face |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 581 | auto multicastFace = createMulticastFace("127.0.0.1", "224.0.0.1", 20072); |
| 582 | BOOST_CHECK_EXCEPTION(createChannel("127.0.0.1", 20072), UdpFactory::Error, |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 583 | [] (const UdpFactory::Error& e) { |
| 584 | return strcmp(e.what(), |
| 585 | "Cannot create the requested UDP unicast channel, local " |
| 586 | "endpoint is already allocated for a UDP multicast face") == 0; |
| 587 | }); |
| 588 | } |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 589 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 590 | BOOST_FIXTURE_TEST_CASE(CreateMulticastFace, UdpFactoryMcastFixture) |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 591 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 592 | #ifdef __linux__ |
| 593 | // need superuser privilege for creating multicast faces on Linux |
| 594 | SKIP_IF_NOT_SUPERUSER(); |
| 595 | #endif // __linux__ |
| 596 | SKIP_IF_UDP_MCAST_NETIF_COUNT_LT(1); |
| 597 | |
| 598 | auto multicastFace1 = createMulticastFace("127.0.0.1", "224.0.0.1", 20070); |
| 599 | auto multicastFace1a = createMulticastFace("127.0.0.1", "224.0.0.1", 20070); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 600 | BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a); |
| 601 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 602 | // createMulticastFace with an IPv4 local endpoint already used by a channel |
| 603 | auto channel = createChannel("127.0.0.1", 20071); |
| 604 | BOOST_CHECK_EXCEPTION(createMulticastFace("127.0.0.1", "224.0.0.1", 20071), UdpFactory::Error, |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 605 | [] (const UdpFactory::Error& e) { |
| 606 | return strcmp(e.what(), |
| 607 | "Cannot create the requested UDP multicast face, local " |
| 608 | "endpoint is already allocated for a UDP unicast channel") == 0; |
| 609 | }); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 610 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 611 | // createMulticastFace with an IPv4 local endpoint already |
Davide Pesavento | eee53aa | 2016-04-11 17:20:21 +0200 | [diff] [blame] | 612 | // used by a multicast face on a different multicast group |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 613 | 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] | 614 | [] (const UdpFactory::Error& e) { |
| 615 | return strcmp(e.what(), |
| 616 | "Cannot create the requested UDP multicast face, local " |
| 617 | "endpoint is already allocated for a UDP multicast face " |
| 618 | "on a different multicast group") == 0; |
| 619 | }); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 620 | |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 621 | // createMulticastFace with an IPv6 multicast address |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 622 | BOOST_CHECK_EXCEPTION(createMulticastFace("::1", "ff01::114", 20073), UdpFactory::Error, |
Weiwei Liu | 72cee94 | 2016-02-04 16:49:19 -0700 | [diff] [blame] | 623 | [] (const UdpFactory::Error& e) { |
| 624 | return strcmp(e.what(), |
| 625 | "IPv6 multicast is not supported yet. Please provide an IPv4 " |
| 626 | "address") == 0; |
| 627 | }); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 630 | BOOST_AUTO_TEST_CASE(CreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 631 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 632 | createFace(factory, |
| 633 | FaceUri("udp4://127.0.0.1:6363"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 634 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 635 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 636 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 637 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 638 | {CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 639 | |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 640 | createChannel("127.0.0.1", 20071); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 641 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 642 | createFace(factory, |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 643 | FaceUri("udp4://127.0.0.1:6363"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 644 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 645 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 646 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 647 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 648 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 649 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 650 | createFace(factory, |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 651 | FaceUri("udp4://127.0.0.1:6363"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 652 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 653 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 654 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 655 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 656 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 657 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 658 | createFace(factory, |
| 659 | FaceUri("udp4://127.0.0.1:20072"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 660 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 661 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 662 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 663 | false, |
| 664 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 665 | |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 666 | createFace(factory, |
| 667 | FaceUri("udp4://127.0.0.1:20073"), |
| 668 | {}, |
| 669 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
| 670 | false, |
| 671 | true, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 672 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 675 | BOOST_AUTO_TEST_CASE(UnsupportedCreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 676 | { |
Davide Pesavento | bb734df | 2017-10-24 18:05:36 -0400 | [diff] [blame] | 677 | createChannel("127.0.0.1", 20071); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 678 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 679 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 680 | FaceUri("udp4://127.0.0.1:20072"), |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 681 | FaceUri("udp4://127.0.0.1:20071"), |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 682 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 683 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 684 | false, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 685 | {CreateFaceExpectedResult::FAILURE, 406, |
| 686 | "Unicast UDP faces cannot be created with a LocalUri"}); |
| 687 | |
| 688 | createFace(factory, |
| 689 | FaceUri("udp4://127.0.0.1:20072"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 690 | {}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 691 | ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 692 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 693 | false, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 694 | {CreateFaceExpectedResult::FAILURE, 406, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 695 | "Outgoing UDP faces do not support on-demand persistency"}); |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 696 | |
| 697 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 698 | FaceUri("udp4://233.252.0.1:23252"), |
| 699 | {}, |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 700 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 701 | false, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 702 | false, |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 703 | {CreateFaceExpectedResult::FAILURE, 406, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 704 | "Cannot create multicast UDP faces"}); |
| 705 | |
| 706 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 707 | FaceUri("udp4://127.0.0.1:20072"), |
| 708 | {}, |
| 709 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 710 | true, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 711 | false, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 712 | {CreateFaceExpectedResult::FAILURE, 406, |
| 713 | "Local fields can only be enabled on faces with local scope"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 716 | BOOST_AUTO_TEST_SUITE_END() // TestUdpFactory |
| 717 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 718 | |
| 719 | } // namespace tests |
Junxiao Shi | 64d99f2 | 2017-01-21 23:06:36 +0000 | [diff] [blame] | 720 | } // namespace face |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 721 | } // namespace nfd |