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