Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 24 | */ |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 25 | |
Davide Pesavento | 6ad890a | 2015-03-09 03:43:17 +0100 | [diff] [blame] | 26 | #include "face/udp-channel.hpp" |
| 27 | #include "face/udp-face.hpp" |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 28 | #include "face/udp-factory.hpp" |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 29 | |
Davide Pesavento | 6ad890a | 2015-03-09 03:43:17 +0100 | [diff] [blame] | 30 | #include "core/network-interface.hpp" |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 31 | #include "tests/test-common.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 32 | #include "tests/limited-io.hpp" |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 33 | #include "face-history.hpp" |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 34 | |
| 35 | namespace nfd { |
| 36 | namespace tests { |
| 37 | |
| 38 | BOOST_FIXTURE_TEST_SUITE(FaceUdp, BaseFixture) |
| 39 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 40 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 41 | { |
| 42 | UdpFactory factory; |
| 43 | BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true); |
| 44 | |
| 45 | std::vector<shared_ptr<const Channel> > expectedChannels; |
| 46 | |
| 47 | expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070")); |
| 48 | expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071")); |
| 49 | expectedChannels.push_back(factory.createChannel("::1", "20071")); |
| 50 | |
| 51 | std::list<shared_ptr<const Channel> > channels = factory.getChannels(); |
| 52 | for (std::list<shared_ptr<const Channel> >::const_iterator i = channels.begin(); |
| 53 | i != channels.end(); ++i) |
| 54 | { |
| 55 | std::vector<shared_ptr<const Channel> >::iterator pos = |
| 56 | std::find(expectedChannels.begin(), expectedChannels.end(), *i); |
| 57 | |
| 58 | BOOST_REQUIRE(pos != expectedChannels.end()); |
| 59 | expectedChannels.erase(pos); |
| 60 | } |
| 61 | |
| 62 | BOOST_CHECK_EQUAL(expectedChannels.size(), 0); |
| 63 | } |
| 64 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 65 | class FactoryErrorCheck : protected BaseFixture |
| 66 | { |
| 67 | public: |
Alexander Afanasyev | 86bc91a | 2014-08-28 22:29:16 -0700 | [diff] [blame] | 68 | bool |
| 69 | isTheSameMulticastEndpoint(const UdpFactory::Error& e) { |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 70 | return strcmp(e.what(), |
| 71 | "Cannot create the requested UDP unicast channel, local " |
| 72 | "endpoint is already allocated for a UDP multicast face") == 0; |
| 73 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 74 | |
Alexander Afanasyev | 86bc91a | 2014-08-28 22:29:16 -0700 | [diff] [blame] | 75 | bool |
| 76 | isNotMulticastAddress(const UdpFactory::Error& e) { |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 77 | return strcmp(e.what(), |
| 78 | "Cannot create the requested UDP multicast face, " |
| 79 | "the multicast group given as input is not a multicast address") == 0; |
| 80 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 81 | |
Alexander Afanasyev | 86bc91a | 2014-08-28 22:29:16 -0700 | [diff] [blame] | 82 | bool |
| 83 | isTheSameUnicastEndpoint(const UdpFactory::Error& e) { |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 84 | return strcmp(e.what(), |
| 85 | "Cannot create the requested UDP multicast face, local " |
| 86 | "endpoint is already allocated for a UDP unicast channel") == 0; |
| 87 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 88 | |
Alexander Afanasyev | 86bc91a | 2014-08-28 22:29:16 -0700 | [diff] [blame] | 89 | bool |
| 90 | isLocalEndpointOnDifferentGroup(const UdpFactory::Error& e) { |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 91 | return strcmp(e.what(), |
| 92 | "Cannot create the requested UDP multicast face, local " |
| 93 | "endpoint is already allocated for a UDP multicast face " |
| 94 | "on a different multicast group") == 0; |
| 95 | } |
| 96 | }; |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 97 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 98 | BOOST_FIXTURE_TEST_CASE(ChannelMapUdp, FactoryErrorCheck) |
| 99 | { |
| 100 | using boost::asio::ip::udp; |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 101 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 102 | UdpFactory factory = UdpFactory(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 103 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 104 | //to instantiate multicast face on a specific ip address, change interfaceIp |
| 105 | std::string interfaceIp = "0.0.0.0"; |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 106 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 107 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 108 | shared_ptr<UdpChannel> channel1a = factory.createChannel("127.0.0.1", "20070"); |
| 109 | BOOST_CHECK_EQUAL(channel1, channel1a); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 110 | BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 111 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 112 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
| 113 | BOOST_CHECK_NE(channel1, channel2); |
| 114 | |
| 115 | shared_ptr<UdpChannel> channel3 = factory.createChannel(interfaceIp, "20070"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 116 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 117 | shared_ptr<UdpChannel> channel4 = factory.createChannel("::1", "20071"); |
| 118 | BOOST_CHECK_NE(channel2, channel4); |
| 119 | BOOST_CHECK_EQUAL(channel4->getUri().toString(), "udp6://[::1]:20071"); |
| 120 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 121 | //same endpoint of a unicast channel |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 122 | BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, "224.0.0.1", "20070"), |
| 123 | UdpFactory::Error, isTheSameUnicastEndpoint); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 124 | |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 125 | auto multicastFace1 = factory.createMulticastFace(interfaceIp, "224.0.0.1", "20072"); |
| 126 | auto multicastFace1a = factory.createMulticastFace(interfaceIp, "224.0.0.1", "20072"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 127 | BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a); |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 128 | BOOST_CHECK_EQUAL(multicastFace1->isLocal(), false); |
Yukai Tu | 731f0d7 | 2015-07-04 11:14:44 +0800 | [diff] [blame] | 129 | BOOST_CHECK_EQUAL(multicastFace1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 130 | BOOST_CHECK_EQUAL(multicastFace1->isMultiAccess(), true); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 131 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 132 | //same endpoint of a multicast face |
| 133 | BOOST_CHECK_EXCEPTION(factory.createChannel(interfaceIp, "20072"), |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 134 | UdpFactory::Error, isTheSameMulticastEndpoint); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 135 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 136 | //same multicast endpoint, different group |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 137 | BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, "224.0.0.42", "20072"), |
| 138 | UdpFactory::Error, isLocalEndpointOnDifferentGroup); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 139 | |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 140 | BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, "192.168.10.15", "20025"), |
| 141 | UdpFactory::Error, isNotMulticastAddress); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 142 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 143 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 144 | // //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 145 | // shared_ptr<UdpChannel> channel1v6 = factory.createChannel(//"::1", |
| 146 | // "fe80::5e96:9dff:fe7d:9c8d%en1", |
| 147 | // //"fe80::aa54:b2ff:fe08:27b8%wlan0", |
| 148 | // "20070"); |
| 149 | // |
| 150 | // //the creation of multicastFace2 works properly. It has been disable because it needs an IP address of |
| 151 | // //an available network interface (different from the first one used) |
| 152 | // shared_ptr<MulticastUdpFace> multicastFace2 = factory.createMulticastFace("192.168.1.17", |
| 153 | // "224.0.0.1", |
| 154 | // "20073"); |
| 155 | // BOOST_CHECK_NE(multicastFace1, multicastFace2); |
| 156 | // |
| 157 | // |
| 158 | // //ipv6 - work in progress |
| 159 | // shared_ptr<MulticastUdpFace> multicastFace3 = factory.createMulticastFace("fe80::5e96:9dff:fe7d:9c8d%en1", |
| 160 | // "FF01:0:0:0:0:0:0:2", |
| 161 | // "20073"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 162 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 163 | // shared_ptr<MulticastUdpFace> multicastFace4 = factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0", |
| 164 | // "FF01:0:0:0:0:0:0:2", |
| 165 | // "20073"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 166 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 167 | // BOOST_CHECK_EQUAL(multicastFace3, multicastFace4); |
| 168 | // |
| 169 | // shared_ptr<MulticastUdpFace> multicastFace5 = factory.createMulticastFace("::1", |
| 170 | // "FF01:0:0:0:0:0:0:2", |
| 171 | // "20073"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 172 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 173 | // BOOST_CHECK_NE(multicastFace3, multicastFace5); |
| 174 | // |
| 175 | // //same local ipv6 endpoint for a different multicast group |
| 176 | // BOOST_CHECK_THROW(factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0", |
| 177 | // "FE01:0:0:0:0:0:0:2", |
| 178 | // "20073"), |
| 179 | // UdpFactory::Error); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 180 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 181 | // //same local ipv6 (expect for th port number) endpoint for a different multicast group |
| 182 | // BOOST_CHECK_THROW(factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0", |
| 183 | // "FE01:0:0:0:0:0:0:2", |
| 184 | // "20075"), |
| 185 | // UdpFactory::Error); |
| 186 | // |
| 187 | // BOOST_CHECK_THROW(factory.createMulticastFace("fa80::20a:9dff:fef6:12ff", |
| 188 | // "FE12:0:0:0:0:0:0:2", |
| 189 | // "20075"), |
| 190 | // UdpFactory::Error); |
| 191 | // |
| 192 | // //not a multicast ipv6 |
| 193 | // BOOST_CHECK_THROW(factory.createMulticastFace("fa80::20a:9dff:fef6:12ff", |
| 194 | // "A112:0:0:0:0:0:0:2", |
| 195 | // "20075"), |
| 196 | // UdpFactory::Error); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 197 | } |
| 198 | |
Alexander Afanasyev | 86bc91a | 2014-08-28 22:29:16 -0700 | [diff] [blame] | 199 | class FaceCreateFixture : protected BaseFixture |
| 200 | { |
| 201 | public: |
| 202 | void |
Alexander Afanasyev | 86bc91a | 2014-08-28 22:29:16 -0700 | [diff] [blame] | 203 | checkError(const std::string& errorActual, const std::string& errorExpected) |
| 204 | { |
| 205 | BOOST_CHECK_EQUAL(errorActual, errorExpected); |
| 206 | } |
| 207 | |
| 208 | void |
| 209 | failIfError(const std::string& errorActual) |
| 210 | { |
| 211 | BOOST_FAIL("No error expected, but got: [" << errorActual << "]"); |
| 212 | } |
| 213 | }; |
| 214 | |
| 215 | BOOST_FIXTURE_TEST_CASE(FaceCreate, FaceCreateFixture) |
| 216 | { |
| 217 | UdpFactory factory = UdpFactory(); |
| 218 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 219 | factory.createFace(FaceUri("udp4://127.0.0.1:6363"), |
Yukai Tu | 7c90e6d | 2015-07-11 12:21:46 +0800 | [diff] [blame] | 220 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 221 | bind([]{}), |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 222 | bind(&FaceCreateFixture::checkError, this, _1, |
| 223 | "No channels available to connect to 127.0.0.1:6363")); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 224 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 225 | factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 226 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 227 | factory.createFace(FaceUri("udp4://127.0.0.1:20070"), |
Yukai Tu | 7c90e6d | 2015-07-11 12:21:46 +0800 | [diff] [blame] | 228 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 229 | bind([]{}), |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 230 | bind(&FaceCreateFixture::failIfError, this, _1)); |
Yukai Tu | 375dcb0 | 2015-08-01 13:04:43 +0800 | [diff] [blame] | 231 | //test the upgrade |
| 232 | factory.createFace(FaceUri("udp4://127.0.0.1:20070"), |
| 233 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
| 234 | bind([]{}), |
| 235 | bind(&FaceCreateFixture::failIfError, this, _1)); |
| 236 | |
| 237 | factory.createFace(FaceUri("udp4://127.0.0.1:20072"), |
| 238 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
| 239 | bind([]{}), |
| 240 | bind(&FaceCreateFixture::failIfError, this, _1)); |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 241 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 242 | |
Yukai Tu | 375dcb0 | 2015-08-01 13:04:43 +0800 | [diff] [blame] | 243 | BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) |
Yukai Tu | 7c90e6d | 2015-07-11 12:21:46 +0800 | [diff] [blame] | 244 | { |
| 245 | UdpFactory factory; |
| 246 | |
| 247 | factory.createChannel("127.0.0.1", "20070"); |
Yukai Tu | 7c90e6d | 2015-07-11 12:21:46 +0800 | [diff] [blame] | 248 | |
| 249 | BOOST_CHECK_THROW(factory.createFace(FaceUri("udp4://127.0.0.1:20070"), |
Yukai Tu | 7c90e6d | 2015-07-11 12:21:46 +0800 | [diff] [blame] | 250 | ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, |
| 251 | bind([]{}), |
| 252 | bind([]{})), |
| 253 | ProtocolFactory::Error); |
| 254 | } |
| 255 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 256 | class EndToEndIpv4 |
| 257 | { |
| 258 | public: |
| 259 | static const std::string |
| 260 | getScheme() |
| 261 | { |
| 262 | return "udp4"; |
| 263 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 264 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 265 | static const std::string |
| 266 | getLocalIp() |
| 267 | { |
| 268 | return "127.0.0.1"; |
| 269 | } |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 270 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 271 | static const std::string |
| 272 | getPort1() |
| 273 | { |
| 274 | return "20071"; |
| 275 | } |
| 276 | |
| 277 | static const std::string |
| 278 | getPort2() |
| 279 | { |
| 280 | return "20072"; |
| 281 | } |
| 282 | |
| 283 | static const std::string |
| 284 | getPort3() |
| 285 | { |
| 286 | return "20073"; |
| 287 | } |
| 288 | |
| 289 | static const FaceUri |
| 290 | getFaceUri1() |
| 291 | { |
| 292 | return FaceUri("udp4://127.0.0.1:20071"); |
| 293 | } |
| 294 | |
| 295 | static const FaceUri |
| 296 | getFaceUri2() |
| 297 | { |
| 298 | return FaceUri("udp4://127.0.0.1:20072"); |
| 299 | } |
| 300 | |
| 301 | static const FaceUri |
| 302 | getFaceUri3() |
| 303 | { |
| 304 | return FaceUri("udp4://127.0.0.1:20073"); |
| 305 | } |
| 306 | }; |
| 307 | |
| 308 | class EndToEndIpv6 |
| 309 | { |
| 310 | public: |
| 311 | static const std::string |
| 312 | getScheme() |
| 313 | { |
| 314 | return "udp6"; |
| 315 | } |
| 316 | |
| 317 | static const std::string |
| 318 | getLocalIp() |
| 319 | { |
| 320 | return "::1"; |
| 321 | } |
| 322 | |
| 323 | static const std::string |
| 324 | getPort1() |
| 325 | { |
| 326 | return "20071"; |
| 327 | } |
| 328 | |
| 329 | static const std::string |
| 330 | getPort2() |
| 331 | { |
| 332 | return "20072"; |
| 333 | } |
| 334 | |
| 335 | static const std::string |
| 336 | getPort3() |
| 337 | { |
| 338 | return "20073"; |
| 339 | } |
| 340 | |
| 341 | static const FaceUri |
| 342 | getFaceUri1() |
| 343 | { |
| 344 | return FaceUri("udp6://[::1]:20071"); |
| 345 | } |
| 346 | |
| 347 | static const FaceUri |
| 348 | getFaceUri2() |
| 349 | { |
| 350 | return FaceUri("udp6://[::1]:20072"); |
| 351 | } |
| 352 | |
| 353 | static const FaceUri |
| 354 | getFaceUri3() |
| 355 | { |
| 356 | return FaceUri("udp6://[::1]:20073"); |
| 357 | } |
| 358 | }; |
| 359 | |
| 360 | typedef boost::mpl::list<EndToEndIpv4, EndToEndIpv6> EndToEndAddresses; |
| 361 | |
| 362 | // end to end communication |
| 363 | BOOST_AUTO_TEST_CASE_TEMPLATE(EndToEnd, A, EndToEndAddresses) |
| 364 | { |
| 365 | LimitedIo limitedIo; |
| 366 | UdpFactory factory; |
| 367 | |
| 368 | shared_ptr<UdpChannel> channel1 = factory.createChannel(A::getLocalIp(), A::getPort1()); |
| 369 | |
| 370 | // face1 (on channel1) connects to face2 (on channel2, to be created) |
| 371 | shared_ptr<Face> face1; |
| 372 | unique_ptr<FaceHistory> history1; |
| 373 | factory.createFace(A::getFaceUri2(), |
Yukai Tu | 7c90e6d | 2015-07-11 12:21:46 +0800 | [diff] [blame] | 374 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 375 | [&] (shared_ptr<Face> newFace) { |
| 376 | face1 = newFace; |
| 377 | history1.reset(new FaceHistory(*face1, limitedIo)); |
| 378 | limitedIo.afterOp(); |
| 379 | }, |
| 380 | [] (const std::string& reason) { BOOST_ERROR(reason); }); |
| 381 | |
| 382 | limitedIo.run(1, time::seconds(1)); |
| 383 | BOOST_REQUIRE(face1 != nullptr); |
| 384 | BOOST_CHECK_EQUAL(face1->getRemoteUri(), A::getFaceUri2()); |
| 385 | BOOST_CHECK_EQUAL(face1->getLocalUri(), A::getFaceUri1()); |
| 386 | BOOST_CHECK_EQUAL(face1->isLocal(), false); // UdpFace is never local |
| 387 | BOOST_CHECK_EQUAL(face1->getCounters().getNInBytes(), 0); |
| 388 | BOOST_CHECK_EQUAL(face1->getCounters().getNOutBytes(), 0); |
| 389 | |
| 390 | // channel2 creation must be after face1 creation, |
| 391 | // otherwise channel2's endpoint would be prohibited |
| 392 | shared_ptr<UdpChannel> channel2 = factory.createChannel(A::getLocalIp(), A::getPort2()); |
| 393 | shared_ptr<Face> face2; |
| 394 | unique_ptr<FaceHistory> history2; |
| 395 | channel2->listen([&] (shared_ptr<Face> newFace) { |
| 396 | BOOST_CHECK(face2 == nullptr); |
| 397 | face2 = newFace; |
| 398 | history2.reset(new FaceHistory(*face2, limitedIo)); |
| 399 | limitedIo.afterOp(); |
| 400 | }, |
| 401 | [] (const std::string& reason) { BOOST_ERROR(reason); }); |
| 402 | |
| 403 | limitedIo.run(1, time::seconds(1)); |
| 404 | BOOST_CHECK(face2 == nullptr); // face2 shouldn't be created until face1 sends something |
| 405 | |
| 406 | shared_ptr<Interest> interest1 = makeInterest("/I1"); |
| 407 | shared_ptr<Interest> interest2 = makeInterest("/I2"); |
| 408 | shared_ptr<Data> data1 = makeData("/D1"); |
| 409 | shared_ptr<Data> data2 = makeData("/D2"); |
| 410 | |
| 411 | // face1 sends to channel2, creates face2 |
| 412 | face1->sendInterest(*interest1); |
| 413 | face1->sendData(*data1); |
| 414 | face1->sendData(*data1); |
| 415 | face1->sendData(*data1); |
| 416 | size_t nBytesSent1 = interest1->wireEncode().size() + 3 * data1->wireEncode().size(); |
| 417 | |
| 418 | limitedIo.run(5, time::seconds(1)); // 1 accept, 4 receives |
| 419 | |
| 420 | BOOST_REQUIRE(face2 != nullptr); |
| 421 | BOOST_CHECK_EQUAL(face2->getRemoteUri(), A::getFaceUri1()); |
| 422 | BOOST_CHECK_EQUAL(face2->getLocalUri(), A::getFaceUri2()); |
| 423 | BOOST_CHECK_EQUAL(face2->isLocal(), false); // UdpFace is never local |
| 424 | BOOST_CHECK_EQUAL(face2->getCounters().getNInBytes(), nBytesSent1); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 425 | BOOST_CHECK_EQUAL(face2->getCounters().getNOutBytes(), 0); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 426 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 427 | BOOST_REQUIRE_EQUAL(history2->receivedInterests.size(), 1); |
| 428 | BOOST_CHECK_EQUAL(history2->receivedInterests.front().getName(), interest1->getName()); |
| 429 | BOOST_REQUIRE_EQUAL(history2->receivedData.size(), 3); |
| 430 | BOOST_CHECK_EQUAL(history2->receivedData.front().getName(), data1->getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 431 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 432 | // face2 sends to face1 |
| 433 | face2->sendInterest(*interest2); |
| 434 | face2->sendInterest(*interest2); |
| 435 | face2->sendInterest(*interest2); |
| 436 | face2->sendData(*data2); |
| 437 | size_t nBytesSent2 = 3 * interest2->wireEncode().size() + data2->wireEncode().size(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 438 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 439 | limitedIo.run(4, time::seconds(1)); // 4 receives |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 440 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 441 | BOOST_REQUIRE_EQUAL(history1->receivedInterests.size(), 3); |
| 442 | BOOST_CHECK_EQUAL(history1->receivedInterests.front().getName(), interest2->getName()); |
| 443 | BOOST_REQUIRE_EQUAL(history1->receivedData.size(), 1); |
| 444 | BOOST_CHECK_EQUAL(history1->receivedData.front().getName(), data2->getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 445 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 446 | // counters |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 447 | const FaceCounters& counters1 = face1->getCounters(); |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 448 | BOOST_CHECK_EQUAL(counters1.getNInInterests(), 3); |
| 449 | BOOST_CHECK_EQUAL(counters1.getNInDatas(), 1); |
| 450 | BOOST_CHECK_EQUAL(counters1.getNOutInterests(), 1); |
| 451 | BOOST_CHECK_EQUAL(counters1.getNOutDatas(), 3); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 452 | BOOST_CHECK_EQUAL(counters1.getNInBytes(), nBytesSent2); |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 453 | BOOST_CHECK_EQUAL(counters1.getNOutBytes(), nBytesSent1); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 454 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 455 | const FaceCounters& counters2 = face2->getCounters(); |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 456 | BOOST_CHECK_EQUAL(counters2.getNInInterests(), 1); |
| 457 | BOOST_CHECK_EQUAL(counters2.getNInDatas(), 3); |
| 458 | BOOST_CHECK_EQUAL(counters2.getNOutInterests(), 3); |
| 459 | BOOST_CHECK_EQUAL(counters2.getNOutDatas(), 1); |
| 460 | BOOST_CHECK_EQUAL(counters2.getNInBytes(), nBytesSent1); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 461 | BOOST_CHECK_EQUAL(counters2.getNOutBytes(), nBytesSent2); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 462 | } |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 463 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 464 | // channel accepting multiple incoming connections |
| 465 | BOOST_AUTO_TEST_CASE_TEMPLATE(MultipleAccepts, A, EndToEndAddresses) |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 466 | { |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 467 | LimitedIo limitedIo; |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 468 | UdpFactory factory; |
| 469 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 470 | // channel1 is listening |
| 471 | shared_ptr<UdpChannel> channel1 = factory.createChannel(A::getLocalIp(), A::getPort1()); |
| 472 | std::vector<shared_ptr<Face>> faces1; |
| 473 | channel1->listen([&] (shared_ptr<Face> newFace) { |
| 474 | faces1.push_back(newFace); |
| 475 | limitedIo.afterOp(); |
| 476 | }, |
| 477 | [] (const std::string& reason) { BOOST_ERROR(reason); }); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 478 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 479 | // face2 (on channel2) connects to channel1 |
| 480 | shared_ptr<UdpChannel> channel2 = factory.createChannel(A::getLocalIp(), A::getPort2()); |
| 481 | BOOST_CHECK_NE(channel1, channel2); |
| 482 | shared_ptr<Face> face2; |
| 483 | boost::asio::ip::address ipAddress2 = boost::asio::ip::address::from_string(A::getLocalIp()); |
| 484 | udp::Endpoint endpoint2(ipAddress2, boost::lexical_cast<uint16_t>(A::getPort1())); |
| 485 | channel2->connect(endpoint2, |
Yukai Tu | 375dcb0 | 2015-08-01 13:04:43 +0800 | [diff] [blame] | 486 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 487 | [&] (shared_ptr<Face> newFace) { |
| 488 | face2 = newFace; |
| 489 | limitedIo.afterOp(); |
| 490 | }, |
| 491 | [] (const std::string& reason) { BOOST_ERROR(reason); }); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 492 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 493 | limitedIo.run(1, time::seconds(1)); // 1 create (on channel2) |
| 494 | BOOST_REQUIRE(face2 != nullptr); |
| 495 | BOOST_CHECK_EQUAL(faces1.size(), 0); // channel1 won't create face until face2 sends something |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 496 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 497 | // face3 (on channel3) connects to channel1 |
| 498 | shared_ptr<UdpChannel> channel3 = factory.createChannel(A::getLocalIp(), A::getPort3()); |
| 499 | BOOST_CHECK_NE(channel1, channel3); |
| 500 | shared_ptr<Face> face3; |
| 501 | boost::asio::ip::address ipAddress3 = boost::asio::ip::address::from_string(A::getLocalIp()); |
| 502 | udp::Endpoint endpoint3(ipAddress3, boost::lexical_cast<uint16_t>(A::getPort1())); |
| 503 | channel3->connect(endpoint3, |
Yukai Tu | 375dcb0 | 2015-08-01 13:04:43 +0800 | [diff] [blame] | 504 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 505 | [&] (shared_ptr<Face> newFace) { |
| 506 | face3 = newFace; |
| 507 | limitedIo.afterOp(); |
| 508 | }, |
| 509 | [] (const std::string& reason) { BOOST_ERROR(reason); }); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 510 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 511 | limitedIo.run(1, time::seconds(1)); // 1 create (on channel3) |
| 512 | BOOST_REQUIRE(face3 != nullptr); |
| 513 | BOOST_CHECK_EQUAL(faces1.size(), 0); // channel1 won't create face until face3 sends something |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 514 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 515 | // face2 sends to channel1 |
| 516 | shared_ptr<Interest> interest2 = makeInterest("/I2"); |
| 517 | face2->sendInterest(*interest2); |
| 518 | limitedIo.run(1, time::milliseconds(100)); // 1 accept (on channel1) |
| 519 | BOOST_REQUIRE_EQUAL(faces1.size(), 1); |
| 520 | BOOST_CHECK_EQUAL(channel1->size(), 1); |
| 521 | BOOST_CHECK_EQUAL(faces1.at(0)->getRemoteUri(), A::getFaceUri2()); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 522 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 523 | // face3 sends to channel1 |
| 524 | shared_ptr<Data> data3 = makeData("/D3"); |
| 525 | face3->sendData(*data3); |
| 526 | limitedIo.run(1, time::milliseconds(100)); // 1 accept (on channel1) |
| 527 | BOOST_REQUIRE_EQUAL(faces1.size(), 2); |
| 528 | BOOST_CHECK_EQUAL(channel1->size(), 2); |
| 529 | BOOST_CHECK_EQUAL(faces1.at(1)->getRemoteUri(), A::getFaceUri3()); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 530 | } |
| 531 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 532 | // manually close a face |
| 533 | BOOST_AUTO_TEST_CASE_TEMPLATE(ManualClose, A, EndToEndAddresses) |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 534 | { |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 535 | LimitedIo limitedIo; |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 536 | UdpFactory factory; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 537 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 538 | shared_ptr<UdpChannel> channel1 = factory.createChannel(A::getLocalIp(), A::getPort1()); |
| 539 | shared_ptr<Face> face1; |
| 540 | unique_ptr<FaceHistory> history1; |
| 541 | factory.createFace(A::getFaceUri2(), |
Yukai Tu | 7c90e6d | 2015-07-11 12:21:46 +0800 | [diff] [blame] | 542 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 543 | [&] (shared_ptr<Face> newFace) { |
| 544 | face1 = newFace; |
| 545 | history1.reset(new FaceHistory(*face1, limitedIo)); |
| 546 | limitedIo.afterOp(); |
| 547 | }, |
| 548 | [] (const std::string& reason) { BOOST_ERROR(reason); }); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 549 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 550 | limitedIo.run(1, time::milliseconds(100)); |
| 551 | BOOST_REQUIRE(face1 != nullptr); |
| 552 | BOOST_CHECK_EQUAL(channel1->size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 553 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 554 | face1->close(); |
| 555 | getGlobalIoService().poll(); |
| 556 | BOOST_CHECK_EQUAL(history1->failures.size(), 1); |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 557 | BOOST_CHECK_EQUAL(channel1->size(), 0); |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 558 | } |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 559 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 560 | // automatically close an idle incoming face |
| 561 | BOOST_AUTO_TEST_CASE_TEMPLATE(IdleClose, A, EndToEndAddresses) |
| 562 | { |
| 563 | LimitedIo limitedIo; |
| 564 | UdpFactory factory; |
| 565 | |
| 566 | // channel1 is listening |
| 567 | shared_ptr<UdpChannel> channel1 = factory.createChannel(A::getLocalIp(), A::getPort1(), |
| 568 | time::seconds(2)); |
| 569 | shared_ptr<Face> face1; |
| 570 | unique_ptr<FaceHistory> history1; |
| 571 | channel1->listen([&] (shared_ptr<Face> newFace) { |
| 572 | BOOST_CHECK(face1 == nullptr); |
| 573 | face1 = newFace; |
| 574 | history1.reset(new FaceHistory(*face1, limitedIo)); |
| 575 | limitedIo.afterOp(); |
| 576 | }, |
| 577 | [] (const std::string& reason) { BOOST_ERROR(reason); }); |
| 578 | |
| 579 | // face2 (on channel2) connects to channel1 |
| 580 | shared_ptr<UdpChannel> channel2 = factory.createChannel(A::getLocalIp(), A::getPort2(), |
| 581 | time::seconds(2)); |
| 582 | shared_ptr<Face> face2; |
| 583 | unique_ptr<FaceHistory> history2; |
| 584 | boost::asio::ip::address ipAddress = boost::asio::ip::address::from_string(A::getLocalIp()); |
| 585 | udp::Endpoint endpoint(ipAddress, boost::lexical_cast<uint16_t>(A::getPort1())); |
| 586 | channel2->connect(endpoint, |
Yukai Tu | 375dcb0 | 2015-08-01 13:04:43 +0800 | [diff] [blame] | 587 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 588 | [&] (shared_ptr<Face> newFace) { |
| 589 | face2 = newFace; |
| 590 | history2.reset(new FaceHistory(*face2, limitedIo)); |
| 591 | limitedIo.afterOp(); |
| 592 | }, |
| 593 | [] (const std::string& reason) { BOOST_ERROR(reason); }); |
| 594 | |
| 595 | limitedIo.run(1, time::milliseconds(100)); // 1 create (on channel2) |
| 596 | BOOST_REQUIRE(face2 != nullptr); |
Yukai Tu | 731f0d7 | 2015-07-04 11:14:44 +0800 | [diff] [blame] | 597 | BOOST_CHECK_EQUAL(face2->getPersistency(), ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 598 | BOOST_CHECK_EQUAL(face2->isMultiAccess(), false); |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 599 | |
| 600 | // face2 sends to channel1, creates face1 |
| 601 | shared_ptr<Interest> interest2 = makeInterest("/I2"); |
| 602 | face2->sendInterest(*interest2); |
| 603 | |
| 604 | limitedIo.run(2, time::seconds(1)); // 1 accept (on channel1), 1 receive (on face1) |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 605 | BOOST_CHECK_EQUAL(channel1->size(), 1); |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 606 | BOOST_REQUIRE(face1 != nullptr); |
Yukai Tu | 731f0d7 | 2015-07-04 11:14:44 +0800 | [diff] [blame] | 607 | BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 608 | BOOST_CHECK_EQUAL(face1->isMultiAccess(), false); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 609 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 610 | limitedIo.defer(time::seconds(1)); |
| 611 | BOOST_CHECK_EQUAL(history1->failures.size(), 0); // face1 is not idle |
| 612 | BOOST_CHECK_EQUAL(history2->failures.size(), 0); // face2 is outgoing face and never closed |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 613 | |
Chengyu Fan | 4381fb6 | 2015-01-14 11:37:04 -0700 | [diff] [blame] | 614 | limitedIo.defer(time::seconds(4)); |
| 615 | BOOST_CHECK_EQUAL(history1->failures.size(), 1); // face1 is idle and automatically closed |
| 616 | BOOST_CHECK_EQUAL(channel1->size(), 0); |
| 617 | BOOST_CHECK_EQUAL(history2->failures.size(), 0); // face2 is outgoing face and never closed |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 618 | } |
| 619 | |
Alexander Afanasyev | 70aaf8a | 2014-12-13 00:44:22 -0800 | [diff] [blame] | 620 | class FakeNetworkInterfaceFixture : public BaseFixture |
| 621 | { |
| 622 | public: |
| 623 | FakeNetworkInterfaceFixture() |
| 624 | { |
| 625 | using namespace boost::asio::ip; |
| 626 | |
| 627 | auto fakeInterfaces = make_shared<std::vector<NetworkInterfaceInfo>>(); |
| 628 | |
| 629 | fakeInterfaces->push_back( |
| 630 | NetworkInterfaceInfo {0, "eth0", |
| 631 | ethernet::Address::fromString("3e:15:c2:8b:65:00"), |
| 632 | {address_v4::from_string("0.0.0.0")}, |
| 633 | {address_v6::from_string("::")}, |
| 634 | address_v4(), |
| 635 | IFF_UP}); |
| 636 | fakeInterfaces->push_back( |
| 637 | NetworkInterfaceInfo {1, "eth0", |
| 638 | ethernet::Address::fromString("3e:15:c2:8b:65:00"), |
| 639 | {address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.2")}, |
| 640 | {}, |
| 641 | address_v4::from_string("192.168.2.255"), |
| 642 | 0}); |
| 643 | fakeInterfaces->push_back( |
| 644 | NetworkInterfaceInfo {2, "eth1", |
| 645 | ethernet::Address::fromString("3e:15:c2:8b:65:00"), |
| 646 | {address_v4::from_string("198.51.100.1")}, |
| 647 | {address_v6::from_string("2001:db8::2"), address_v6::from_string("2001:db8::3")}, |
| 648 | address_v4::from_string("198.51.100.255"), |
| 649 | IFF_MULTICAST | IFF_BROADCAST | IFF_UP}); |
| 650 | |
| 651 | setDebugNetworkInterfaces(fakeInterfaces); |
| 652 | } |
| 653 | |
| 654 | ~FakeNetworkInterfaceFixture() |
| 655 | { |
| 656 | setDebugNetworkInterfaces(nullptr); |
| 657 | } |
| 658 | }; |
| 659 | |
| 660 | BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture) |
| 661 | { |
| 662 | using namespace boost::asio::ip; |
| 663 | |
| 664 | UdpFactory factory; |
| 665 | factory.prohibitEndpoint(udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024)); |
| 666 | BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1); |
| 667 | BOOST_CHECK((factory.m_prohibitedEndpoints == |
| 668 | std::set<udp::Endpoint> { |
| 669 | udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024), |
| 670 | })); |
| 671 | |
| 672 | factory.m_prohibitedEndpoints.clear(); |
| 673 | factory.prohibitEndpoint(udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048)); |
| 674 | BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1); |
| 675 | BOOST_CHECK((factory.m_prohibitedEndpoints == |
| 676 | std::set<udp::Endpoint> { |
| 677 | udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048), |
| 678 | })); |
| 679 | |
| 680 | factory.m_prohibitedEndpoints.clear(); |
| 681 | factory.prohibitEndpoint(udp::Endpoint(address_v4(), 1024)); |
| 682 | BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 6); |
| 683 | BOOST_CHECK((factory.m_prohibitedEndpoints == |
| 684 | std::set<udp::Endpoint> { |
| 685 | udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024), |
| 686 | udp::Endpoint(address_v4::from_string("192.168.2.2"), 1024), |
| 687 | udp::Endpoint(address_v4::from_string("198.51.100.1"), 1024), |
| 688 | udp::Endpoint(address_v4::from_string("198.51.100.255"), 1024), |
| 689 | udp::Endpoint(address_v4::from_string("255.255.255.255"), 1024), |
| 690 | udp::Endpoint(address_v4::from_string("0.0.0.0"), 1024) |
| 691 | })); |
| 692 | |
| 693 | factory.m_prohibitedEndpoints.clear(); |
| 694 | factory.prohibitEndpoint(udp::Endpoint(address_v6(), 2048)); |
| 695 | BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 3); |
| 696 | BOOST_CHECK((factory.m_prohibitedEndpoints == |
| 697 | std::set<udp::Endpoint> { |
| 698 | udp::Endpoint(address_v6::from_string("2001:db8::2"), 2048), |
| 699 | udp::Endpoint(address_v6::from_string("2001:db8::3"), 2048), |
| 700 | udp::Endpoint(address_v6::from_string("::"), 2048), |
| 701 | })); |
| 702 | } |
| 703 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 704 | BOOST_AUTO_TEST_SUITE_END() |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 705 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 706 | } // namespace tests |
| 707 | } // namespace nfd |