Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014, 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 | |
| 26 | #include "face/udp-factory.hpp" |
Alexander Afanasyev | 70aaf8a | 2014-12-13 00:44:22 -0800 | [diff] [blame] | 27 | #include "core/network-interface.hpp" |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 28 | |
| 29 | #include "tests/test-common.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 30 | #include "tests/limited-io.hpp" |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | namespace tests { |
| 34 | |
| 35 | BOOST_FIXTURE_TEST_SUITE(FaceUdp, BaseFixture) |
| 36 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 37 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 38 | { |
| 39 | UdpFactory factory; |
| 40 | BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true); |
| 41 | |
| 42 | std::vector<shared_ptr<const Channel> > expectedChannels; |
| 43 | |
| 44 | expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070")); |
| 45 | expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071")); |
| 46 | expectedChannels.push_back(factory.createChannel("::1", "20071")); |
| 47 | |
| 48 | std::list<shared_ptr<const Channel> > channels = factory.getChannels(); |
| 49 | for (std::list<shared_ptr<const Channel> >::const_iterator i = channels.begin(); |
| 50 | i != channels.end(); ++i) |
| 51 | { |
| 52 | std::vector<shared_ptr<const Channel> >::iterator pos = |
| 53 | std::find(expectedChannels.begin(), expectedChannels.end(), *i); |
| 54 | |
| 55 | BOOST_REQUIRE(pos != expectedChannels.end()); |
| 56 | expectedChannels.erase(pos); |
| 57 | } |
| 58 | |
| 59 | BOOST_CHECK_EQUAL(expectedChannels.size(), 0); |
| 60 | } |
| 61 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 62 | class FactoryErrorCheck : protected BaseFixture |
| 63 | { |
| 64 | public: |
Alexander Afanasyev | 86bc91a | 2014-08-28 22:29:16 -0700 | [diff] [blame] | 65 | bool |
| 66 | isTheSameMulticastEndpoint(const UdpFactory::Error& e) { |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 67 | return strcmp(e.what(), |
| 68 | "Cannot create the requested UDP unicast channel, local " |
| 69 | "endpoint is already allocated for a UDP multicast face") == 0; |
| 70 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 71 | |
Alexander Afanasyev | 86bc91a | 2014-08-28 22:29:16 -0700 | [diff] [blame] | 72 | bool |
| 73 | isNotMulticastAddress(const UdpFactory::Error& e) { |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 74 | return strcmp(e.what(), |
| 75 | "Cannot create the requested UDP multicast face, " |
| 76 | "the multicast group given as input is not a multicast address") == 0; |
| 77 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 78 | |
Alexander Afanasyev | 86bc91a | 2014-08-28 22:29:16 -0700 | [diff] [blame] | 79 | bool |
| 80 | isTheSameUnicastEndpoint(const UdpFactory::Error& e) { |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 81 | return strcmp(e.what(), |
| 82 | "Cannot create the requested UDP multicast face, local " |
| 83 | "endpoint is already allocated for a UDP unicast channel") == 0; |
| 84 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 85 | |
Alexander Afanasyev | 86bc91a | 2014-08-28 22:29:16 -0700 | [diff] [blame] | 86 | bool |
| 87 | isLocalEndpointOnDifferentGroup(const UdpFactory::Error& e) { |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 88 | return strcmp(e.what(), |
| 89 | "Cannot create the requested UDP multicast face, local " |
| 90 | "endpoint is already allocated for a UDP multicast face " |
| 91 | "on a different multicast group") == 0; |
| 92 | } |
| 93 | }; |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 94 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 95 | BOOST_FIXTURE_TEST_CASE(ChannelMapUdp, FactoryErrorCheck) |
| 96 | { |
| 97 | using boost::asio::ip::udp; |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 98 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 99 | UdpFactory factory = UdpFactory(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 100 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 101 | //to instantiate multicast face on a specific ip address, change interfaceIp |
| 102 | std::string interfaceIp = "0.0.0.0"; |
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 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 105 | shared_ptr<UdpChannel> channel1a = factory.createChannel("127.0.0.1", "20070"); |
| 106 | BOOST_CHECK_EQUAL(channel1, channel1a); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 107 | BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070"); |
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> channel2 = factory.createChannel("127.0.0.1", "20071"); |
| 110 | BOOST_CHECK_NE(channel1, channel2); |
| 111 | |
| 112 | shared_ptr<UdpChannel> channel3 = factory.createChannel(interfaceIp, "20070"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 113 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 114 | shared_ptr<UdpChannel> channel4 = factory.createChannel("::1", "20071"); |
| 115 | BOOST_CHECK_NE(channel2, channel4); |
| 116 | BOOST_CHECK_EQUAL(channel4->getUri().toString(), "udp6://[::1]:20071"); |
| 117 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 118 | //same endpoint of a unicast channel |
| 119 | BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, |
| 120 | "224.0.0.1", |
| 121 | "20070"), |
| 122 | UdpFactory::Error, |
| 123 | isTheSameUnicastEndpoint); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 124 | |
| 125 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 126 | shared_ptr<MulticastUdpFace> multicastFace1 = factory.createMulticastFace(interfaceIp, |
| 127 | "224.0.0.1", |
| 128 | "20072"); |
| 129 | shared_ptr<MulticastUdpFace> multicastFace1a = factory.createMulticastFace(interfaceIp, |
| 130 | "224.0.0.1", |
| 131 | "20072"); |
| 132 | BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 133 | |
| 134 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 135 | //same endpoint of a multicast face |
| 136 | BOOST_CHECK_EXCEPTION(factory.createChannel(interfaceIp, "20072"), |
| 137 | UdpFactory::Error, |
| 138 | isTheSameMulticastEndpoint); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 139 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 140 | //same multicast endpoint, different group |
| 141 | BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, |
| 142 | "224.0.0.42", |
| 143 | "20072"), |
| 144 | UdpFactory::Error, |
| 145 | isLocalEndpointOnDifferentGroup); |
| 146 | |
| 147 | BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, |
| 148 | "192.168.10.15", |
| 149 | "20025"), |
| 150 | UdpFactory::Error, |
| 151 | isNotMulticastAddress); |
| 152 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 153 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 154 | // //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 155 | // shared_ptr<UdpChannel> channel1v6 = factory.createChannel(//"::1", |
| 156 | // "fe80::5e96:9dff:fe7d:9c8d%en1", |
| 157 | // //"fe80::aa54:b2ff:fe08:27b8%wlan0", |
| 158 | // "20070"); |
| 159 | // |
| 160 | // //the creation of multicastFace2 works properly. It has been disable because it needs an IP address of |
| 161 | // //an available network interface (different from the first one used) |
| 162 | // shared_ptr<MulticastUdpFace> multicastFace2 = factory.createMulticastFace("192.168.1.17", |
| 163 | // "224.0.0.1", |
| 164 | // "20073"); |
| 165 | // BOOST_CHECK_NE(multicastFace1, multicastFace2); |
| 166 | // |
| 167 | // |
| 168 | // //ipv6 - work in progress |
| 169 | // shared_ptr<MulticastUdpFace> multicastFace3 = factory.createMulticastFace("fe80::5e96:9dff:fe7d:9c8d%en1", |
| 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 | // shared_ptr<MulticastUdpFace> multicastFace4 = factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0", |
| 174 | // "FF01:0:0:0:0:0:0:2", |
| 175 | // "20073"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 176 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 177 | // BOOST_CHECK_EQUAL(multicastFace3, multicastFace4); |
| 178 | // |
| 179 | // shared_ptr<MulticastUdpFace> multicastFace5 = factory.createMulticastFace("::1", |
| 180 | // "FF01:0:0:0:0:0:0:2", |
| 181 | // "20073"); |
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 | // BOOST_CHECK_NE(multicastFace3, multicastFace5); |
| 184 | // |
| 185 | // //same local ipv6 endpoint for a different multicast group |
| 186 | // BOOST_CHECK_THROW(factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0", |
| 187 | // "FE01:0:0:0:0:0:0:2", |
| 188 | // "20073"), |
| 189 | // UdpFactory::Error); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 190 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 191 | // //same local ipv6 (expect for th port number) endpoint for a different multicast group |
| 192 | // BOOST_CHECK_THROW(factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0", |
| 193 | // "FE01:0:0:0:0:0:0:2", |
| 194 | // "20075"), |
| 195 | // UdpFactory::Error); |
| 196 | // |
| 197 | // BOOST_CHECK_THROW(factory.createMulticastFace("fa80::20a:9dff:fef6:12ff", |
| 198 | // "FE12:0:0:0:0:0:0:2", |
| 199 | // "20075"), |
| 200 | // UdpFactory::Error); |
| 201 | // |
| 202 | // //not a multicast ipv6 |
| 203 | // BOOST_CHECK_THROW(factory.createMulticastFace("fa80::20a:9dff:fef6:12ff", |
| 204 | // "A112:0:0:0:0:0:0:2", |
| 205 | // "20075"), |
| 206 | // UdpFactory::Error); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 207 | } |
| 208 | |
Alexander Afanasyev | 86bc91a | 2014-08-28 22:29:16 -0700 | [diff] [blame] | 209 | class FaceCreateFixture : protected BaseFixture |
| 210 | { |
| 211 | public: |
| 212 | void |
| 213 | ignore() |
| 214 | { |
| 215 | } |
| 216 | |
| 217 | void |
| 218 | checkError(const std::string& errorActual, const std::string& errorExpected) |
| 219 | { |
| 220 | BOOST_CHECK_EQUAL(errorActual, errorExpected); |
| 221 | } |
| 222 | |
| 223 | void |
| 224 | failIfError(const std::string& errorActual) |
| 225 | { |
| 226 | BOOST_FAIL("No error expected, but got: [" << errorActual << "]"); |
| 227 | } |
| 228 | }; |
| 229 | |
| 230 | BOOST_FIXTURE_TEST_CASE(FaceCreate, FaceCreateFixture) |
| 231 | { |
| 232 | UdpFactory factory = UdpFactory(); |
| 233 | |
| 234 | factory.createFace(FaceUri("udp4://127.0.0.1"), |
| 235 | bind(&FaceCreateFixture::ignore, this), |
| 236 | bind(&FaceCreateFixture::failIfError, this, _1)); |
| 237 | |
| 238 | factory.createFace(FaceUri("udp4://127.0.0.1/"), |
| 239 | bind(&FaceCreateFixture::ignore, this), |
| 240 | bind(&FaceCreateFixture::failIfError, this, _1)); |
| 241 | |
| 242 | factory.createFace(FaceUri("udp4://127.0.0.1/path"), |
| 243 | bind(&FaceCreateFixture::ignore, this), |
| 244 | bind(&FaceCreateFixture::checkError, this, _1, "Invalid URI")); |
| 245 | |
| 246 | } |
| 247 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 248 | class EndToEndFixture : protected BaseFixture |
| 249 | { |
| 250 | public: |
| 251 | void |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 252 | channel1_onFaceCreated(const shared_ptr<Face>& newFace) |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 253 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 254 | BOOST_CHECK(!static_cast<bool>(face1)); |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 255 | channel1_onFaceCreatedNoCheck(newFace); |
| 256 | } |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 257 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 258 | void |
| 259 | channel1_onFaceCreatedNoCheck(const shared_ptr<Face>& newFace) |
| 260 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 261 | face1 = newFace; |
| 262 | face1->onReceiveInterest += |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 263 | bind(&EndToEndFixture::face1_onReceiveInterest, this, _1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 264 | face1->onReceiveData += |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 265 | bind(&EndToEndFixture::face1_onReceiveData, this, _1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 266 | face1->onFail += |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 267 | bind(&EndToEndFixture::face1_onFail, this); |
| 268 | BOOST_CHECK_MESSAGE(true, "channel 1 face created"); |
| 269 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 270 | faces.push_back(face1); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 271 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 272 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | void |
| 276 | channel1_onConnectFailed(const std::string& reason) |
| 277 | { |
| 278 | BOOST_CHECK_MESSAGE(false, reason); |
| 279 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 280 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 281 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 282 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 283 | void |
| 284 | face1_onReceiveInterest(const Interest& interest) |
| 285 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 286 | face1_receivedInterests.push_back(interest); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 287 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 288 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 289 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 290 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 291 | void |
| 292 | face1_onReceiveData(const Data& data) |
| 293 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 294 | face1_receivedDatas.push_back(data); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 295 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 296 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | void |
| 300 | face1_onFail() |
| 301 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 302 | face1.reset(); |
| 303 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | void |
| 307 | channel2_onFaceCreated(const shared_ptr<Face>& newFace) |
| 308 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 309 | BOOST_CHECK(!static_cast<bool>(face2)); |
| 310 | face2 = newFace; |
| 311 | face2->onReceiveInterest += |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 312 | bind(&EndToEndFixture::face2_onReceiveInterest, this, _1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 313 | face2->onReceiveData += |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 314 | bind(&EndToEndFixture::face2_onReceiveData, this, _1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 315 | face2->onFail += |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 316 | bind(&EndToEndFixture::face2_onFail, this); |
| 317 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 318 | faces.push_back(face2); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 319 | |
| 320 | BOOST_CHECK_MESSAGE(true, "channel 2 face created"); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 321 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 322 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 323 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 324 | void |
| 325 | channel2_onConnectFailed(const std::string& reason) |
| 326 | { |
| 327 | BOOST_CHECK_MESSAGE(false, reason); |
| 328 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 329 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 330 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 331 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 332 | void |
| 333 | face2_onReceiveInterest(const Interest& interest) |
| 334 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 335 | face2_receivedInterests.push_back(interest); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 336 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 337 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 338 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 339 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 340 | void |
| 341 | face2_onReceiveData(const Data& data) |
| 342 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 343 | face2_receivedDatas.push_back(data); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 344 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 345 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | void |
| 349 | face2_onFail() |
| 350 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 351 | face2.reset(); |
| 352 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | void |
| 356 | channel3_onFaceCreated(const shared_ptr<Face>& newFace) |
| 357 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 358 | BOOST_CHECK(!static_cast<bool>(face1)); |
| 359 | face3 = newFace; |
| 360 | faces.push_back(newFace); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 361 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 362 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 363 | } |
| 364 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 365 | void |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 366 | channel_onFaceCreated(const shared_ptr<Face>& newFace) |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 367 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 368 | faces.push_back(newFace); |
| 369 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | void |
| 373 | channel_onConnectFailed(const std::string& reason) |
| 374 | { |
| 375 | BOOST_CHECK_MESSAGE(false, reason); |
| 376 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 377 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | void |
| 381 | channel_onConnectFailedOk(const std::string& reason) |
| 382 | { |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame] | 383 | // it's ok, it was supposed to fail |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 384 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | void |
| 388 | checkFaceList(size_t shouldBe) |
| 389 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 390 | BOOST_CHECK_EQUAL(faces.size(), shouldBe); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 391 | } |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 392 | |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame] | 393 | void |
| 394 | connect(const shared_ptr<UdpChannel>& channel, |
| 395 | const std::string& remoteHost, |
| 396 | const std::string& remotePort) |
| 397 | { |
| 398 | channel->connect(remoteHost, remotePort, |
| 399 | bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 400 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
| 401 | } |
| 402 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 403 | public: |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 404 | LimitedIo limitedIo; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 405 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 406 | shared_ptr<Face> face1; |
| 407 | std::vector<Interest> face1_receivedInterests; |
| 408 | std::vector<Data> face1_receivedDatas; |
| 409 | shared_ptr<Face> face2; |
| 410 | std::vector<Interest> face2_receivedInterests; |
| 411 | std::vector<Data> face2_receivedDatas; |
| 412 | shared_ptr<Face> face3; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 413 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 414 | std::list< shared_ptr<Face> > faces; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 415 | }; |
| 416 | |
| 417 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 418 | BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture) |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 419 | { |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 420 | UdpFactory factory; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 421 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 422 | factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 423 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 424 | factory.createFace(FaceUri("udp4://127.0.0.1:20070"), |
| 425 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 426 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 427 | |
| 428 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 429 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 430 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 431 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 432 | BOOST_REQUIRE(static_cast<bool>(face2)); |
| 433 | BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "udp4://127.0.0.1:20070"); |
| 434 | BOOST_CHECK_EQUAL(face2->getLocalUri().toString(), "udp4://127.0.0.1:20071"); |
| 435 | BOOST_CHECK_EQUAL(face2->isLocal(), false); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 436 | BOOST_CHECK_EQUAL(face2->getCounters().getNOutBytes(), 0); |
| 437 | BOOST_CHECK_EQUAL(face2->getCounters().getNInBytes(), 0); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 438 | // face1 is not created yet |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 439 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 440 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 441 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 442 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 443 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 444 | Interest interest1("ndn:/TpnzGvW9R"); |
| 445 | Data data1 ("ndn:/KfczhUqVix"); |
| 446 | data1.setContent(0, 0); |
| 447 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 448 | Data data2 ("ndn:/XNBV796f"); |
| 449 | data2.setContent(0, 0); |
| 450 | Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 451 | Data data3 ("ndn:/XNBV794f"); |
| 452 | data3.setContent(0, 0); |
| 453 | |
| 454 | |
| 455 | ndn::SignatureSha256WithRsa fakeSignature; |
| 456 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 457 | reinterpret_cast<const uint8_t*>(0), |
| 458 | 0)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 459 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 460 | // set fake signature on data1 and data2 |
| 461 | data1.setSignature(fakeSignature); |
| 462 | data2.setSignature(fakeSignature); |
| 463 | data3.setSignature(fakeSignature); |
| 464 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 465 | face2->sendInterest(interest2); |
| 466 | face2->sendData (data2 ); |
| 467 | face2->sendData (data2 ); |
| 468 | face2->sendData (data2 ); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 469 | size_t nBytesSent2 = interest2.wireEncode().size() + data2.wireEncode().size() * 3; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 470 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 471 | BOOST_CHECK_MESSAGE(limitedIo.run(5,//4 send + 1 listen return |
Alexander Afanasyev | 6f5ff63 | 2014-03-07 16:40:10 +0000 | [diff] [blame] | 472 | time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 473 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 474 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 475 | BOOST_REQUIRE(static_cast<bool>(face1)); |
| 476 | BOOST_CHECK_EQUAL(face1->getRemoteUri().toString(), "udp4://127.0.0.1:20071"); |
| 477 | BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "udp4://127.0.0.1:20070"); |
| 478 | BOOST_CHECK_EQUAL(face1->isLocal(), false); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 479 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 480 | face1->sendInterest(interest1); |
| 481 | face1->sendInterest(interest1); |
| 482 | face1->sendInterest(interest1); |
| 483 | face1->sendData (data1 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 484 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 485 | BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 486 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 487 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 488 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 489 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3); |
| 490 | BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 3); |
| 491 | BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 492 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 493 | BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName()); |
| 494 | BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName()); |
| 495 | BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName()); |
| 496 | BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 497 | |
| 498 | |
| 499 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 500 | //checking if the connection accepting mechanism works properly. |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 501 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 502 | face2->sendData (data3 ); |
| 503 | face2->sendInterest(interest3); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 504 | nBytesSent2 += data3.wireEncode().size() + interest3.wireEncode().size(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 505 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 506 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 507 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 508 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 509 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 2); |
| 510 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 511 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 512 | BOOST_CHECK_EQUAL(face1_receivedInterests[1].getName(), interest3.getName()); |
| 513 | BOOST_CHECK_EQUAL(face1_receivedDatas [3].getName(), data3.getName()); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 514 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 515 | const FaceCounters& counters1 = face1->getCounters(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 516 | BOOST_CHECK_EQUAL(counters1.getNInInterests() , 2); |
| 517 | BOOST_CHECK_EQUAL(counters1.getNInDatas() , 4); |
| 518 | BOOST_CHECK_EQUAL(counters1.getNOutInterests(), 3); |
| 519 | BOOST_CHECK_EQUAL(counters1.getNOutDatas() , 1); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 520 | BOOST_CHECK_EQUAL(counters1.getNInBytes(), nBytesSent2); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 521 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 522 | const FaceCounters& counters2 = face2->getCounters(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 523 | BOOST_CHECK_EQUAL(counters2.getNInInterests() , 3); |
| 524 | BOOST_CHECK_EQUAL(counters2.getNInDatas() , 1); |
| 525 | BOOST_CHECK_EQUAL(counters2.getNOutInterests(), 2); |
| 526 | BOOST_CHECK_EQUAL(counters2.getNOutDatas() , 4); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 527 | BOOST_CHECK_EQUAL(counters2.getNOutBytes(), nBytesSent2); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 528 | } |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 529 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 530 | BOOST_FIXTURE_TEST_CASE(EndToEnd6, EndToEndFixture) |
| 531 | { |
| 532 | UdpFactory factory; |
| 533 | |
| 534 | factory.createChannel("::1", "20071"); |
| 535 | |
| 536 | factory.createFace(FaceUri("udp://[::1]:20070"), |
| 537 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 538 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
| 539 | |
| 540 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 541 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 542 | "UdpChannel error: cannot connect or cannot accept connection"); |
| 543 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 544 | BOOST_REQUIRE(static_cast<bool>(face2)); |
| 545 | BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "udp6://[::1]:20070"); |
| 546 | BOOST_CHECK_EQUAL(face2->getLocalUri().toString(), "udp6://[::1]:20071"); |
| 547 | BOOST_CHECK_EQUAL(face2->isLocal(), false); |
| 548 | // face1 is not created yet |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 549 | |
| 550 | shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 551 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 552 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 553 | |
| 554 | Interest interest1("ndn:/TpnzGvW9R"); |
| 555 | Data data1 ("ndn:/KfczhUqVix"); |
| 556 | data1.setContent(0, 0); |
| 557 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 558 | Data data2 ("ndn:/XNBV796f"); |
| 559 | data2.setContent(0, 0); |
| 560 | Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 561 | Data data3 ("ndn:/XNBV794f"); |
| 562 | data3.setContent(0, 0); |
| 563 | |
| 564 | |
| 565 | ndn::SignatureSha256WithRsa fakeSignature; |
| 566 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 567 | reinterpret_cast<const uint8_t*>(0), |
| 568 | 0)); |
| 569 | |
| 570 | // set fake signature on data1 and data2 |
| 571 | data1.setSignature(fakeSignature); |
| 572 | data2.setSignature(fakeSignature); |
| 573 | data3.setSignature(fakeSignature); |
| 574 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 575 | face2->sendInterest(interest2); |
| 576 | face2->sendData (data2 ); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 577 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 578 | BOOST_CHECK_MESSAGE(limitedIo.run(3,//2 send + 1 listen return |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 579 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 580 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 581 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 582 | BOOST_REQUIRE(static_cast<bool>(face1)); |
| 583 | BOOST_CHECK_EQUAL(face1->getRemoteUri().toString(), "udp6://[::1]:20071"); |
| 584 | BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "udp6://[::1]:20070"); |
| 585 | BOOST_CHECK_EQUAL(face1->isLocal(), false); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 586 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 587 | face1->sendInterest(interest1); |
| 588 | face1->sendData (data1 ); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 589 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 590 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 591 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 592 | |
| 593 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 594 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 595 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1); |
| 596 | BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1); |
| 597 | BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 598 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 599 | BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName()); |
| 600 | BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName()); |
| 601 | BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName()); |
| 602 | BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName()); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 603 | |
| 604 | |
| 605 | |
| 606 | //checking if the connection accepting mechanism works properly. |
| 607 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 608 | face2->sendData (data3 ); |
| 609 | face2->sendInterest(interest3); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 610 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 611 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 612 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 613 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 614 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 2); |
| 615 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 2); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 616 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 617 | BOOST_CHECK_EQUAL(face1_receivedInterests[1].getName(), interest3.getName()); |
| 618 | BOOST_CHECK_EQUAL(face1_receivedDatas [1].getName(), data3.getName()); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) |
| 622 | { |
| 623 | Interest interest1("ndn:/TpnzGvW9R"); |
| 624 | Interest interest2("ndn:/QWiIMfj5sL"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 625 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 626 | UdpFactory factory; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 627 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 628 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 629 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 630 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 631 | channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 632 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 633 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 634 | channel2->connect("127.0.0.1", "20070", |
| 635 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 636 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 637 | |
| 638 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 639 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 640 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 641 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 642 | BOOST_CHECK_EQUAL(faces.size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 643 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 644 | shared_ptr<UdpChannel> channel3 = factory.createChannel("127.0.0.1", "20072"); |
| 645 | channel3->connect("127.0.0.1", "20070", |
| 646 | bind(&EndToEndFixture::channel3_onFaceCreated, this, _1), |
| 647 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 648 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 649 | shared_ptr<UdpChannel> channel4 = factory.createChannel("127.0.0.1", "20073"); |
| 650 | |
| 651 | BOOST_CHECK_NE(channel3, channel4); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 652 | |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 653 | scheduler::schedule(time::milliseconds(500), |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame] | 654 | bind(&EndToEndFixture::connect, this, channel4, "127.0.0.1", "20070")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 655 | |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 656 | scheduler::schedule(time::milliseconds(400), bind(&EndToEndFixture::checkFaceList, this, 2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 657 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 658 | BOOST_CHECK_MESSAGE(limitedIo.run(2,// 2 connects |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 659 | time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 660 | "UdpChannel error: cannot connect or cannot accept multiple connections"); |
| 661 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 662 | BOOST_CHECK_EQUAL(faces.size(), 3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 663 | |
| 664 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 665 | face2->sendInterest(interest1); |
| 666 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 667 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 668 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 669 | BOOST_CHECK_EQUAL(faces.size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 670 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 671 | face3->sendInterest(interest2); |
| 672 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 673 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 674 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 675 | //channel1 should have created 2 faces, one when face2 sent an interest, one when face3 sent an interest |
| 676 | BOOST_CHECK_EQUAL(faces.size(), 5); |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 677 | BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 678 | bind(&EndToEndFixture::channel_onConnectFailedOk, this, _1)), |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 679 | UdpChannel::Error); |
| 680 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 681 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 682 | //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 683 | //BOOST_FIXTURE_TEST_CASE(EndToEndIpv6, EndToEndFixture) |
| 684 | //{ |
| 685 | // UdpFactory factory = UdpFactory(); |
| 686 | // Scheduler scheduler(g_io); // to limit the amount of time the test may take |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 687 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 688 | // EventId abortEvent = |
| 689 | // scheduler.scheduleEvent(time::seconds(1), |
| 690 | // bind(&EndToEndFixture::abortTestCase, this, |
| 691 | // "UdpChannel error: cannot connect or cannot accept connection")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 692 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 693 | // limitedIoRemaining = 1; |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 694 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 695 | // shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 696 | // shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 697 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 698 | // channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 699 | // bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 700 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 701 | // channel2->connect("::1", "20070", |
| 702 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 703 | // bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
| 704 | // g_io.run(); |
| 705 | // g_io.reset(); |
| 706 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 707 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 708 | // BOOST_REQUIRE(static_cast<bool>(face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 709 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 710 | // abortEvent = |
| 711 | // scheduler.scheduleEvent(time::seconds(1), |
| 712 | // bind(&EndToEndFixture::abortTestCase, this, |
| 713 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 714 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 715 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 716 | // Data data1 ("ndn:/KfczhUqVix"); |
| 717 | // data1.setContent(0, 0); |
| 718 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 719 | // Data data2 ("ndn:/XNBV796f"); |
| 720 | // data2.setContent(0, 0); |
| 721 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 722 | // Data data3 ("ndn:/XNBV794f"); |
| 723 | // data3.setContent(0, 0); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 724 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 725 | // ndn::SignatureSha256WithRsa fakeSignature; |
| 726 | // fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 727 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 728 | // // set fake signature on data1 and data2 |
| 729 | // data1.setSignature(fakeSignature); |
| 730 | // data2.setSignature(fakeSignature); |
| 731 | // data3.setSignature(fakeSignature); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 732 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 733 | // face2->sendInterest(interest2); |
| 734 | // face2->sendData (data2 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 735 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 736 | // limitedIoRemaining = 3; //2 send + 1 listen return |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 737 | // g_io.run(); |
| 738 | // g_io.reset(); |
| 739 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 740 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 741 | // BOOST_REQUIRE(static_cast<bool>(face1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 742 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 743 | // face1->sendInterest(interest1); |
| 744 | // face1->sendData (data1 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 745 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 746 | // abortEvent = |
| 747 | // scheduler.scheduleEvent(time::seconds(1), |
| 748 | // bind(&EndToEndFixture::abortTestCase, this, |
| 749 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 750 | // limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 751 | // g_io.run(); |
| 752 | // g_io.reset(); |
| 753 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 754 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 755 | // BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 756 | // BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1); |
| 757 | // BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1); |
| 758 | // BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 759 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 760 | // BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName()); |
| 761 | // BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName()); |
| 762 | // BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName()); |
| 763 | // BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 764 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 765 | // //checking if the connection accepting mechanism works properly. |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 766 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 767 | // face2->sendData (data3 ); |
| 768 | // face2->sendInterest(interest3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 769 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 770 | // abortEvent = |
| 771 | // scheduler.scheduleEvent(time::seconds(1), |
| 772 | // bind(&EndToEndFixture::abortTestCase, this, |
| 773 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 774 | // limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 775 | // g_io.run(); |
| 776 | // g_io.reset(); |
| 777 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 778 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 779 | // BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 2); |
| 780 | // BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 2); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 781 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 782 | // BOOST_CHECK_EQUAL(face1_receivedInterests[1].getName(), interest3.getName()); |
| 783 | // BOOST_CHECK_EQUAL(face1_receivedDatas [1].getName(), data3.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 784 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 785 | //} |
| 786 | |
| 787 | |
| 788 | //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 789 | //BOOST_FIXTURE_TEST_CASE(MultipleAcceptsIpv6, EndToEndFixture) |
| 790 | //{ |
| 791 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 792 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 793 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 794 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 795 | // UdpFactory factory = UdpFactory(); |
| 796 | // Scheduler scheduler(g_io); // to limit the amount of time the test may take |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 797 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 798 | // EventId abortEvent = |
| 799 | // scheduler.scheduleEvent(time::seconds(4), |
| 800 | // bind(&EndToEndFixture::abortTestCase, this, |
| 801 | // "UdpChannel error: cannot connect or cannot accept connection")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 802 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 803 | // shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 804 | // shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 805 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 806 | // channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 807 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 808 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 809 | // channel2->connect("::1", "20070", |
| 810 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 811 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 812 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 813 | // limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 814 | // g_io.run(); |
| 815 | // g_io.reset(); |
| 816 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 817 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 818 | // BOOST_CHECK_EQUAL(faces.size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 819 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 820 | // shared_ptr<UdpChannel> channel3 = factory.createChannel("::1", "20072"); |
| 821 | // channel3->connect("::1", "20070", |
| 822 | // bind(&EndToEndFixture::channel3_onFaceCreated, this, _1), |
| 823 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 824 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 825 | // shared_ptr<UdpChannel> channel4 = factory.createChannel("::1", "20073"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 826 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 827 | // BOOST_CHECK_NE(channel3, channel4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 828 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 829 | // scheduler |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 830 | // .scheduleEvent(time::milliseconds(500), |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 831 | // bind(&UdpChannel::connect, channel4, |
| 832 | // "::1", "20070", |
| 833 | // static_cast<UdpChannel::FaceCreatedCallback>(bind(&EndToEndFixture:: |
| 834 | // channel_onFaceCreated, this, _1)), |
| 835 | // static_cast<UdpChannel::ConnectFailedCallback>(bind(&EndToEndFixture:: |
| 836 | // channel_onConnectFailed, this, _1)))); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 837 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 838 | // limitedIoRemaining = 2; // 2 connects |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 839 | // abortEvent = |
| 840 | // scheduler.scheduleEvent(time::seconds(4), |
| 841 | // bind(&EndToEndFixture::abortTestCase, this, |
| 842 | // "UdpChannel error: cannot connect or cannot accept multiple connections")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 843 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 844 | // scheduler.scheduleEvent(time::seconds(0.4), |
| 845 | // bind(&EndToEndFixture::checkFaceList, this, 2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 846 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 847 | // g_io.run(); |
| 848 | // g_io.reset(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 849 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 850 | // BOOST_CHECK_EQUAL(faces.size(), 3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 851 | // |
| 852 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 853 | // face2->sendInterest(interest1); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 854 | // abortEvent = |
| 855 | // scheduler.scheduleEvent(time::seconds(1), |
| 856 | // bind(&EndToEndFixture::abortTestCase, this, |
| 857 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 858 | // limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 859 | // g_io.run(); |
| 860 | // g_io.reset(); |
| 861 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 862 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 863 | // BOOST_CHECK_EQUAL(faces.size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 864 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 865 | // face3->sendInterest(interest2); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 866 | // abortEvent = |
| 867 | // scheduler.scheduleEvent(time::seconds(1), |
| 868 | // bind(&EndToEndFixture::abortTestCase, this, |
| 869 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 870 | // limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 871 | // g_io.run(); |
| 872 | // g_io.reset(); |
| 873 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 874 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 875 | // //channel1 should have created 2 faces, one when face2 sent an interest, one when face3 sent an interest |
| 876 | // BOOST_CHECK_EQUAL(faces.size(), 5); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 877 | // BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, |
| 878 | // this, |
| 879 | // _1), |
| 880 | // bind(&EndToEndFixture::channel_onConnectFailedOk, |
| 881 | // this, |
| 882 | // _1)), |
| 883 | // UdpChannel::Error); |
| 884 | //} |
| 885 | |
| 886 | |
| 887 | BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture) |
| 888 | { |
| 889 | UdpFactory factory = UdpFactory(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 890 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 891 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 892 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 893 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 894 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 895 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 896 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 897 | channel2->connect("127.0.0.1", "20070", |
| 898 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 899 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 900 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 901 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 902 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 903 | |
| 904 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
| 905 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 906 | BOOST_CHECK(static_cast<bool>(face2)); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 907 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 908 | // Face::close must be invoked during io run to be counted as an op |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 909 | scheduler::schedule(time::milliseconds(100), bind(&Face::close, face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 910 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 911 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 912 | "FaceClosing error: cannot properly close faces"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 913 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 914 | BOOST_CHECK(!static_cast<bool>(face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 915 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 916 | BOOST_CHECK_EQUAL(channel2->size(), 0); |
| 917 | } |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 918 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 919 | BOOST_FIXTURE_TEST_CASE(ClosingIdleFace, EndToEndFixture) |
| 920 | { |
| 921 | Interest interest1("ndn:/TpnzGvW9R"); |
| 922 | Interest interest2("ndn:/QWiIMfj5sL"); |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 923 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 924 | UdpFactory factory; |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 925 | |
| 926 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070", |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 927 | time::seconds(2)); |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 928 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071", |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 929 | time::seconds(2)); |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 930 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 931 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 932 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 933 | |
| 934 | channel2->connect("127.0.0.1", "20070", |
| 935 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 936 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 937 | |
| 938 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 939 | "UdpChannel error: cannot connect or cannot accept connection"); |
| 940 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 941 | face2->sendInterest(interest1); |
| 942 | BOOST_CHECK(!face2->isOnDemand()); |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 943 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 944 | BOOST_CHECK_MESSAGE(limitedIo.run(2,//1 send + 1 listen return |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 945 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 946 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 947 | |
| 948 | BOOST_CHECK_EQUAL(faces.size(), 2); |
| 949 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(2)) == LimitedIo::EXCEED_TIME, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 950 | "Idle face should be still open because has been used recently"); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 951 | BOOST_CHECK_EQUAL(faces.size(), 2); |
| 952 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 953 | "Closing idle face error: face should be closed by now"); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 954 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 955 | //the face on listen should be closed now |
| 956 | BOOST_CHECK_EQUAL(channel1->size(), 0); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 957 | //checking that face2 has not been closed |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 958 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 959 | BOOST_REQUIRE(static_cast<bool>(face2)); |
| 960 | |
| 961 | face2->sendInterest(interest2); |
| 962 | BOOST_CHECK_MESSAGE(limitedIo.run(2,//1 send + 1 listen return |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 963 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 964 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 965 | //channel1 should have created a new face by now |
| 966 | BOOST_CHECK_EQUAL(channel1->size(), 1); |
| 967 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 968 | BOOST_REQUIRE(static_cast<bool>(face1)); |
| 969 | BOOST_CHECK(face1->isOnDemand()); |
| 970 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 971 | channel1->connect("127.0.0.1", "20071", |
| 972 | bind(&EndToEndFixture::channel1_onFaceCreatedNoCheck, this, _1), |
| 973 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 974 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 975 | BOOST_CHECK_MESSAGE(limitedIo.run(1,//1 connect |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 976 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 977 | "UdpChannel error: cannot connect"); |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 978 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 979 | BOOST_CHECK(!face1->isOnDemand()); |
| 980 | |
| 981 | //the connect should have set face1 as permanent face, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 982 | //but it shouln't have created any additional faces |
| 983 | BOOST_CHECK_EQUAL(channel1->size(), 1); |
| 984 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 985 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_TIME, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 986 | "Idle face should be still open because it's permanent now"); |
| 987 | //both faces are permanent, nothing should have changed |
| 988 | BOOST_CHECK_EQUAL(channel1->size(), 1); |
| 989 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
| 990 | } |
| 991 | |
Alexander Afanasyev | 70aaf8a | 2014-12-13 00:44:22 -0800 | [diff] [blame] | 992 | class FakeNetworkInterfaceFixture : public BaseFixture |
| 993 | { |
| 994 | public: |
| 995 | FakeNetworkInterfaceFixture() |
| 996 | { |
| 997 | using namespace boost::asio::ip; |
| 998 | |
| 999 | auto fakeInterfaces = make_shared<std::vector<NetworkInterfaceInfo>>(); |
| 1000 | |
| 1001 | fakeInterfaces->push_back( |
| 1002 | NetworkInterfaceInfo {0, "eth0", |
| 1003 | ethernet::Address::fromString("3e:15:c2:8b:65:00"), |
| 1004 | {address_v4::from_string("0.0.0.0")}, |
| 1005 | {address_v6::from_string("::")}, |
| 1006 | address_v4(), |
| 1007 | IFF_UP}); |
| 1008 | fakeInterfaces->push_back( |
| 1009 | NetworkInterfaceInfo {1, "eth0", |
| 1010 | ethernet::Address::fromString("3e:15:c2:8b:65:00"), |
| 1011 | {address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.2")}, |
| 1012 | {}, |
| 1013 | address_v4::from_string("192.168.2.255"), |
| 1014 | 0}); |
| 1015 | fakeInterfaces->push_back( |
| 1016 | NetworkInterfaceInfo {2, "eth1", |
| 1017 | ethernet::Address::fromString("3e:15:c2:8b:65:00"), |
| 1018 | {address_v4::from_string("198.51.100.1")}, |
| 1019 | {address_v6::from_string("2001:db8::2"), address_v6::from_string("2001:db8::3")}, |
| 1020 | address_v4::from_string("198.51.100.255"), |
| 1021 | IFF_MULTICAST | IFF_BROADCAST | IFF_UP}); |
| 1022 | |
| 1023 | setDebugNetworkInterfaces(fakeInterfaces); |
| 1024 | } |
| 1025 | |
| 1026 | ~FakeNetworkInterfaceFixture() |
| 1027 | { |
| 1028 | setDebugNetworkInterfaces(nullptr); |
| 1029 | } |
| 1030 | }; |
| 1031 | |
| 1032 | BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture) |
| 1033 | { |
| 1034 | using namespace boost::asio::ip; |
| 1035 | |
| 1036 | UdpFactory factory; |
| 1037 | factory.prohibitEndpoint(udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024)); |
| 1038 | BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1); |
| 1039 | BOOST_CHECK((factory.m_prohibitedEndpoints == |
| 1040 | std::set<udp::Endpoint> { |
| 1041 | udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024), |
| 1042 | })); |
| 1043 | |
| 1044 | factory.m_prohibitedEndpoints.clear(); |
| 1045 | factory.prohibitEndpoint(udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048)); |
| 1046 | BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1); |
| 1047 | BOOST_CHECK((factory.m_prohibitedEndpoints == |
| 1048 | std::set<udp::Endpoint> { |
| 1049 | udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048), |
| 1050 | })); |
| 1051 | |
| 1052 | factory.m_prohibitedEndpoints.clear(); |
| 1053 | factory.prohibitEndpoint(udp::Endpoint(address_v4(), 1024)); |
| 1054 | BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 6); |
| 1055 | BOOST_CHECK((factory.m_prohibitedEndpoints == |
| 1056 | std::set<udp::Endpoint> { |
| 1057 | udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024), |
| 1058 | udp::Endpoint(address_v4::from_string("192.168.2.2"), 1024), |
| 1059 | udp::Endpoint(address_v4::from_string("198.51.100.1"), 1024), |
| 1060 | udp::Endpoint(address_v4::from_string("198.51.100.255"), 1024), |
| 1061 | udp::Endpoint(address_v4::from_string("255.255.255.255"), 1024), |
| 1062 | udp::Endpoint(address_v4::from_string("0.0.0.0"), 1024) |
| 1063 | })); |
| 1064 | |
| 1065 | factory.m_prohibitedEndpoints.clear(); |
| 1066 | factory.prohibitEndpoint(udp::Endpoint(address_v6(), 2048)); |
| 1067 | BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 3); |
| 1068 | BOOST_CHECK((factory.m_prohibitedEndpoints == |
| 1069 | std::set<udp::Endpoint> { |
| 1070 | udp::Endpoint(address_v6::from_string("2001:db8::2"), 2048), |
| 1071 | udp::Endpoint(address_v6::from_string("2001:db8::3"), 2048), |
| 1072 | udp::Endpoint(address_v6::from_string("::"), 2048), |
| 1073 | })); |
| 1074 | } |
| 1075 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 1076 | BOOST_AUTO_TEST_SUITE_END() |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 1077 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 1078 | } // namespace tests |
| 1079 | } // namespace nfd |