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 | |
| 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; |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 262 | face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1)); |
| 263 | face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1)); |
| 264 | face1->onFail.connect(bind(&EndToEndFixture::face1_onFail, this)); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 265 | BOOST_CHECK_MESSAGE(true, "channel 1 face created"); |
| 266 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 267 | faces.push_back(face1); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 268 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 269 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | void |
| 273 | channel1_onConnectFailed(const std::string& reason) |
| 274 | { |
| 275 | BOOST_CHECK_MESSAGE(false, reason); |
| 276 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 277 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 278 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 279 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 280 | void |
| 281 | face1_onReceiveInterest(const Interest& interest) |
| 282 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 283 | face1_receivedInterests.push_back(interest); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 284 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 285 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 286 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 287 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 288 | void |
| 289 | face1_onReceiveData(const Data& data) |
| 290 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 291 | face1_receivedDatas.push_back(data); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 292 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 293 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void |
| 297 | face1_onFail() |
| 298 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 299 | face1.reset(); |
| 300 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void |
| 304 | channel2_onFaceCreated(const shared_ptr<Face>& newFace) |
| 305 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 306 | BOOST_CHECK(!static_cast<bool>(face2)); |
| 307 | face2 = newFace; |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 308 | face2->onReceiveInterest.connect(bind(&EndToEndFixture::face2_onReceiveInterest, this, _1)); |
| 309 | face2->onReceiveData.connect(bind(&EndToEndFixture::face2_onReceiveData, this, _1)); |
| 310 | face2->onFail.connect(bind(&EndToEndFixture::face2_onFail, this)); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 311 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 312 | faces.push_back(face2); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 313 | |
| 314 | BOOST_CHECK_MESSAGE(true, "channel 2 face created"); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 315 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 316 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 317 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 318 | void |
| 319 | channel2_onConnectFailed(const std::string& reason) |
| 320 | { |
| 321 | BOOST_CHECK_MESSAGE(false, reason); |
| 322 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 323 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 324 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 325 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 326 | void |
| 327 | face2_onReceiveInterest(const Interest& interest) |
| 328 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 329 | face2_receivedInterests.push_back(interest); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 330 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 331 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 332 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 333 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 334 | void |
| 335 | face2_onReceiveData(const Data& data) |
| 336 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 337 | face2_receivedDatas.push_back(data); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 338 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 339 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | void |
| 343 | face2_onFail() |
| 344 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 345 | face2.reset(); |
| 346 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | void |
| 350 | channel3_onFaceCreated(const shared_ptr<Face>& newFace) |
| 351 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 352 | BOOST_CHECK(!static_cast<bool>(face1)); |
| 353 | face3 = newFace; |
| 354 | faces.push_back(newFace); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 355 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 356 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 357 | } |
| 358 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 359 | void |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 360 | channel_onFaceCreated(const shared_ptr<Face>& newFace) |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 361 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 362 | faces.push_back(newFace); |
| 363 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | void |
| 367 | channel_onConnectFailed(const std::string& reason) |
| 368 | { |
| 369 | BOOST_CHECK_MESSAGE(false, reason); |
| 370 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 371 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | void |
| 375 | channel_onConnectFailedOk(const std::string& reason) |
| 376 | { |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame] | 377 | // it's ok, it was supposed to fail |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 378 | limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | void |
| 382 | checkFaceList(size_t shouldBe) |
| 383 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 384 | BOOST_CHECK_EQUAL(faces.size(), shouldBe); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 385 | } |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 386 | |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame] | 387 | void |
| 388 | connect(const shared_ptr<UdpChannel>& channel, |
| 389 | const std::string& remoteHost, |
| 390 | const std::string& remotePort) |
| 391 | { |
| 392 | channel->connect(remoteHost, remotePort, |
| 393 | bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 394 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
| 395 | } |
| 396 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 397 | public: |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 398 | LimitedIo limitedIo; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 399 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 400 | shared_ptr<Face> face1; |
| 401 | std::vector<Interest> face1_receivedInterests; |
| 402 | std::vector<Data> face1_receivedDatas; |
| 403 | shared_ptr<Face> face2; |
| 404 | std::vector<Interest> face2_receivedInterests; |
| 405 | std::vector<Data> face2_receivedDatas; |
| 406 | shared_ptr<Face> face3; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 407 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 408 | std::list< shared_ptr<Face> > faces; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 409 | }; |
| 410 | |
| 411 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 412 | BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture) |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 413 | { |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 414 | UdpFactory factory; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 415 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 416 | factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 417 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 418 | factory.createFace(FaceUri("udp4://127.0.0.1:20070"), |
| 419 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 420 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 421 | |
| 422 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 423 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 424 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 425 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 426 | BOOST_REQUIRE(static_cast<bool>(face2)); |
| 427 | BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "udp4://127.0.0.1:20070"); |
| 428 | BOOST_CHECK_EQUAL(face2->getLocalUri().toString(), "udp4://127.0.0.1:20071"); |
| 429 | BOOST_CHECK_EQUAL(face2->isLocal(), false); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 430 | BOOST_CHECK_EQUAL(face2->getCounters().getNOutBytes(), 0); |
| 431 | BOOST_CHECK_EQUAL(face2->getCounters().getNInBytes(), 0); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 432 | // face1 is not created yet |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 433 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 434 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 435 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 436 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 437 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 438 | Interest interest1("ndn:/TpnzGvW9R"); |
| 439 | Data data1 ("ndn:/KfczhUqVix"); |
| 440 | data1.setContent(0, 0); |
| 441 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 442 | Data data2 ("ndn:/XNBV796f"); |
| 443 | data2.setContent(0, 0); |
| 444 | Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 445 | Data data3 ("ndn:/XNBV794f"); |
| 446 | data3.setContent(0, 0); |
| 447 | |
| 448 | |
| 449 | ndn::SignatureSha256WithRsa fakeSignature; |
| 450 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 451 | reinterpret_cast<const uint8_t*>(0), |
| 452 | 0)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 453 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 454 | // set fake signature on data1 and data2 |
| 455 | data1.setSignature(fakeSignature); |
| 456 | data2.setSignature(fakeSignature); |
| 457 | data3.setSignature(fakeSignature); |
| 458 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 459 | face2->sendInterest(interest2); |
| 460 | face2->sendData (data2 ); |
| 461 | face2->sendData (data2 ); |
| 462 | face2->sendData (data2 ); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 463 | size_t nBytesSent2 = interest2.wireEncode().size() + data2.wireEncode().size() * 3; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 464 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 465 | BOOST_CHECK_MESSAGE(limitedIo.run(5,//4 send + 1 listen return |
Alexander Afanasyev | 6f5ff63 | 2014-03-07 16:40:10 +0000 | [diff] [blame] | 466 | time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 467 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 468 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 469 | BOOST_REQUIRE(static_cast<bool>(face1)); |
| 470 | BOOST_CHECK_EQUAL(face1->getRemoteUri().toString(), "udp4://127.0.0.1:20071"); |
| 471 | BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "udp4://127.0.0.1:20070"); |
| 472 | BOOST_CHECK_EQUAL(face1->isLocal(), false); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 473 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 474 | face1->sendInterest(interest1); |
| 475 | face1->sendInterest(interest1); |
| 476 | face1->sendInterest(interest1); |
| 477 | face1->sendData (data1 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 478 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 479 | BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 480 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 481 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 482 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 483 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3); |
| 484 | BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 3); |
| 485 | BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 486 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 487 | BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName()); |
| 488 | BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName()); |
| 489 | BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName()); |
| 490 | BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 491 | |
| 492 | |
| 493 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 494 | //checking if the connection accepting mechanism works properly. |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 495 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 496 | face2->sendData (data3 ); |
| 497 | face2->sendInterest(interest3); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 498 | nBytesSent2 += data3.wireEncode().size() + interest3.wireEncode().size(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 499 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 500 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 501 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 502 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 503 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 2); |
| 504 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 505 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 506 | BOOST_CHECK_EQUAL(face1_receivedInterests[1].getName(), interest3.getName()); |
| 507 | BOOST_CHECK_EQUAL(face1_receivedDatas [3].getName(), data3.getName()); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 508 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 509 | const FaceCounters& counters1 = face1->getCounters(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 510 | BOOST_CHECK_EQUAL(counters1.getNInInterests() , 2); |
| 511 | BOOST_CHECK_EQUAL(counters1.getNInDatas() , 4); |
| 512 | BOOST_CHECK_EQUAL(counters1.getNOutInterests(), 3); |
| 513 | BOOST_CHECK_EQUAL(counters1.getNOutDatas() , 1); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 514 | BOOST_CHECK_EQUAL(counters1.getNInBytes(), nBytesSent2); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 515 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 516 | const FaceCounters& counters2 = face2->getCounters(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 517 | BOOST_CHECK_EQUAL(counters2.getNInInterests() , 3); |
| 518 | BOOST_CHECK_EQUAL(counters2.getNInDatas() , 1); |
| 519 | BOOST_CHECK_EQUAL(counters2.getNOutInterests(), 2); |
| 520 | BOOST_CHECK_EQUAL(counters2.getNOutDatas() , 4); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 521 | BOOST_CHECK_EQUAL(counters2.getNOutBytes(), nBytesSent2); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 522 | } |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 523 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 524 | BOOST_FIXTURE_TEST_CASE(EndToEnd6, EndToEndFixture) |
| 525 | { |
| 526 | UdpFactory factory; |
| 527 | |
| 528 | factory.createChannel("::1", "20071"); |
| 529 | |
| 530 | factory.createFace(FaceUri("udp://[::1]:20070"), |
| 531 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 532 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
| 533 | |
| 534 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 535 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 536 | "UdpChannel error: cannot connect or cannot accept connection"); |
| 537 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 538 | BOOST_REQUIRE(static_cast<bool>(face2)); |
| 539 | BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "udp6://[::1]:20070"); |
| 540 | BOOST_CHECK_EQUAL(face2->getLocalUri().toString(), "udp6://[::1]:20071"); |
| 541 | BOOST_CHECK_EQUAL(face2->isLocal(), false); |
| 542 | // face1 is not created yet |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 543 | |
| 544 | shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 545 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 546 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 547 | |
| 548 | Interest interest1("ndn:/TpnzGvW9R"); |
| 549 | Data data1 ("ndn:/KfczhUqVix"); |
| 550 | data1.setContent(0, 0); |
| 551 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 552 | Data data2 ("ndn:/XNBV796f"); |
| 553 | data2.setContent(0, 0); |
| 554 | Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 555 | Data data3 ("ndn:/XNBV794f"); |
| 556 | data3.setContent(0, 0); |
| 557 | |
| 558 | |
| 559 | ndn::SignatureSha256WithRsa fakeSignature; |
| 560 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 561 | reinterpret_cast<const uint8_t*>(0), |
| 562 | 0)); |
| 563 | |
| 564 | // set fake signature on data1 and data2 |
| 565 | data1.setSignature(fakeSignature); |
| 566 | data2.setSignature(fakeSignature); |
| 567 | data3.setSignature(fakeSignature); |
| 568 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 569 | face2->sendInterest(interest2); |
| 570 | face2->sendData (data2 ); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 571 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 572 | BOOST_CHECK_MESSAGE(limitedIo.run(3,//2 send + 1 listen return |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 573 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 574 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 575 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 576 | BOOST_REQUIRE(static_cast<bool>(face1)); |
| 577 | BOOST_CHECK_EQUAL(face1->getRemoteUri().toString(), "udp6://[::1]:20071"); |
| 578 | BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "udp6://[::1]:20070"); |
| 579 | BOOST_CHECK_EQUAL(face1->isLocal(), false); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 580 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 581 | face1->sendInterest(interest1); |
| 582 | face1->sendData (data1 ); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 583 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 584 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 585 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 586 | |
| 587 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 588 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 589 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1); |
| 590 | BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1); |
| 591 | BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 592 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 593 | BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName()); |
| 594 | BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName()); |
| 595 | BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName()); |
| 596 | BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName()); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 597 | |
| 598 | |
| 599 | |
| 600 | //checking if the connection accepting mechanism works properly. |
| 601 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 602 | face2->sendData (data3 ); |
| 603 | face2->sendInterest(interest3); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 604 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 605 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 606 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 607 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 608 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 2); |
| 609 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 2); |
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_EQUAL(face1_receivedInterests[1].getName(), interest3.getName()); |
| 612 | BOOST_CHECK_EQUAL(face1_receivedDatas [1].getName(), data3.getName()); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) |
| 616 | { |
| 617 | Interest interest1("ndn:/TpnzGvW9R"); |
| 618 | Interest interest2("ndn:/QWiIMfj5sL"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 619 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 620 | UdpFactory factory; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 621 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 622 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 623 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 624 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 625 | channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 626 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 627 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 628 | channel2->connect("127.0.0.1", "20070", |
| 629 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 630 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 631 | |
| 632 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 633 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 634 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 635 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 636 | BOOST_CHECK_EQUAL(faces.size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 637 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 638 | shared_ptr<UdpChannel> channel3 = factory.createChannel("127.0.0.1", "20072"); |
| 639 | channel3->connect("127.0.0.1", "20070", |
| 640 | bind(&EndToEndFixture::channel3_onFaceCreated, this, _1), |
| 641 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 642 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 643 | shared_ptr<UdpChannel> channel4 = factory.createChannel("127.0.0.1", "20073"); |
| 644 | |
| 645 | BOOST_CHECK_NE(channel3, channel4); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 646 | |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 647 | scheduler::schedule(time::milliseconds(500), |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame] | 648 | bind(&EndToEndFixture::connect, this, channel4, "127.0.0.1", "20070")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 649 | |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 650 | scheduler::schedule(time::milliseconds(400), bind(&EndToEndFixture::checkFaceList, this, 2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 651 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 652 | BOOST_CHECK_MESSAGE(limitedIo.run(2,// 2 connects |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 653 | time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 654 | "UdpChannel error: cannot connect or cannot accept multiple connections"); |
| 655 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 656 | BOOST_CHECK_EQUAL(faces.size(), 3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 657 | |
| 658 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 659 | face2->sendInterest(interest1); |
| 660 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 661 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 662 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 663 | BOOST_CHECK_EQUAL(faces.size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 664 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 665 | face3->sendInterest(interest2); |
| 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 | //channel1 should have created 2 faces, one when face2 sent an interest, one when face3 sent an interest |
| 670 | BOOST_CHECK_EQUAL(faces.size(), 5); |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 671 | BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 672 | bind(&EndToEndFixture::channel_onConnectFailedOk, this, _1)), |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 673 | UdpChannel::Error); |
| 674 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 675 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 676 | //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 677 | //BOOST_FIXTURE_TEST_CASE(EndToEndIpv6, EndToEndFixture) |
| 678 | //{ |
| 679 | // UdpFactory factory = UdpFactory(); |
| 680 | // 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] | 681 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 682 | // EventId abortEvent = |
| 683 | // scheduler.scheduleEvent(time::seconds(1), |
| 684 | // bind(&EndToEndFixture::abortTestCase, this, |
| 685 | // "UdpChannel error: cannot connect or cannot accept connection")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 686 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 687 | // limitedIoRemaining = 1; |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 688 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 689 | // shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 690 | // shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 691 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 692 | // channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 693 | // bind(&EndToEndFixture::channel1_onConnectFailed, this, _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 | // channel2->connect("::1", "20070", |
| 696 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 697 | // bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
| 698 | // g_io.run(); |
| 699 | // g_io.reset(); |
| 700 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 701 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 702 | // BOOST_REQUIRE(static_cast<bool>(face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 703 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 704 | // abortEvent = |
| 705 | // scheduler.scheduleEvent(time::seconds(1), |
| 706 | // bind(&EndToEndFixture::abortTestCase, this, |
| 707 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
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 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 710 | // Data data1 ("ndn:/KfczhUqVix"); |
| 711 | // data1.setContent(0, 0); |
| 712 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 713 | // Data data2 ("ndn:/XNBV796f"); |
| 714 | // data2.setContent(0, 0); |
| 715 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 716 | // Data data3 ("ndn:/XNBV794f"); |
| 717 | // data3.setContent(0, 0); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 718 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 719 | // ndn::SignatureSha256WithRsa fakeSignature; |
| 720 | // 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] | 721 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 722 | // // set fake signature on data1 and data2 |
| 723 | // data1.setSignature(fakeSignature); |
| 724 | // data2.setSignature(fakeSignature); |
| 725 | // data3.setSignature(fakeSignature); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 726 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 727 | // face2->sendInterest(interest2); |
| 728 | // face2->sendData (data2 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 729 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 730 | // limitedIoRemaining = 3; //2 send + 1 listen return |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 731 | // g_io.run(); |
| 732 | // g_io.reset(); |
| 733 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 734 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 735 | // BOOST_REQUIRE(static_cast<bool>(face1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 736 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 737 | // face1->sendInterest(interest1); |
| 738 | // face1->sendData (data1 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 739 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 740 | // abortEvent = |
| 741 | // scheduler.scheduleEvent(time::seconds(1), |
| 742 | // bind(&EndToEndFixture::abortTestCase, this, |
| 743 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 744 | // limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 745 | // g_io.run(); |
| 746 | // g_io.reset(); |
| 747 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 748 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 749 | // BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 750 | // BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1); |
| 751 | // BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1); |
| 752 | // BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 753 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 754 | // BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName()); |
| 755 | // BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName()); |
| 756 | // BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName()); |
| 757 | // BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 758 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 759 | // //checking if the connection accepting mechanism works properly. |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 760 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 761 | // face2->sendData (data3 ); |
| 762 | // face2->sendInterest(interest3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 763 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 764 | // abortEvent = |
| 765 | // scheduler.scheduleEvent(time::seconds(1), |
| 766 | // bind(&EndToEndFixture::abortTestCase, this, |
| 767 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 768 | // limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 769 | // g_io.run(); |
| 770 | // g_io.reset(); |
| 771 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 772 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 773 | // BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 2); |
| 774 | // BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 2); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 775 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 776 | // BOOST_CHECK_EQUAL(face1_receivedInterests[1].getName(), interest3.getName()); |
| 777 | // BOOST_CHECK_EQUAL(face1_receivedDatas [1].getName(), data3.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 778 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 779 | //} |
| 780 | |
| 781 | |
| 782 | //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 783 | //BOOST_FIXTURE_TEST_CASE(MultipleAcceptsIpv6, EndToEndFixture) |
| 784 | //{ |
| 785 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 786 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 787 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 788 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 789 | // UdpFactory factory = UdpFactory(); |
| 790 | // 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] | 791 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 792 | // EventId abortEvent = |
| 793 | // scheduler.scheduleEvent(time::seconds(4), |
| 794 | // bind(&EndToEndFixture::abortTestCase, this, |
| 795 | // "UdpChannel error: cannot connect or cannot accept connection")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 796 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 797 | // shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 798 | // shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 799 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 800 | // channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 801 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
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 | // channel2->connect("::1", "20070", |
| 804 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 805 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 806 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 807 | // limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 808 | // g_io.run(); |
| 809 | // g_io.reset(); |
| 810 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 811 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 812 | // BOOST_CHECK_EQUAL(faces.size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 813 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 814 | // shared_ptr<UdpChannel> channel3 = factory.createChannel("::1", "20072"); |
| 815 | // channel3->connect("::1", "20070", |
| 816 | // bind(&EndToEndFixture::channel3_onFaceCreated, this, _1), |
| 817 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 818 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 819 | // shared_ptr<UdpChannel> channel4 = factory.createChannel("::1", "20073"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 820 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 821 | // BOOST_CHECK_NE(channel3, channel4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 822 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 823 | // scheduler |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 824 | // .scheduleEvent(time::milliseconds(500), |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 825 | // bind(&UdpChannel::connect, channel4, |
| 826 | // "::1", "20070", |
| 827 | // static_cast<UdpChannel::FaceCreatedCallback>(bind(&EndToEndFixture:: |
| 828 | // channel_onFaceCreated, this, _1)), |
| 829 | // static_cast<UdpChannel::ConnectFailedCallback>(bind(&EndToEndFixture:: |
| 830 | // channel_onConnectFailed, this, _1)))); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 831 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 832 | // limitedIoRemaining = 2; // 2 connects |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 833 | // abortEvent = |
| 834 | // scheduler.scheduleEvent(time::seconds(4), |
| 835 | // bind(&EndToEndFixture::abortTestCase, this, |
| 836 | // "UdpChannel error: cannot connect or cannot accept multiple connections")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 837 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 838 | // scheduler.scheduleEvent(time::seconds(0.4), |
| 839 | // bind(&EndToEndFixture::checkFaceList, this, 2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 840 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 841 | // g_io.run(); |
| 842 | // g_io.reset(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 843 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 844 | // BOOST_CHECK_EQUAL(faces.size(), 3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 845 | // |
| 846 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 847 | // face2->sendInterest(interest1); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 848 | // abortEvent = |
| 849 | // scheduler.scheduleEvent(time::seconds(1), |
| 850 | // bind(&EndToEndFixture::abortTestCase, this, |
| 851 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 852 | // limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 853 | // g_io.run(); |
| 854 | // g_io.reset(); |
| 855 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 856 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 857 | // BOOST_CHECK_EQUAL(faces.size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 858 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 859 | // face3->sendInterest(interest2); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 860 | // abortEvent = |
| 861 | // scheduler.scheduleEvent(time::seconds(1), |
| 862 | // bind(&EndToEndFixture::abortTestCase, this, |
| 863 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 864 | // limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 865 | // g_io.run(); |
| 866 | // g_io.reset(); |
| 867 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 868 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 869 | // //channel1 should have created 2 faces, one when face2 sent an interest, one when face3 sent an interest |
| 870 | // BOOST_CHECK_EQUAL(faces.size(), 5); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 871 | // BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, |
| 872 | // this, |
| 873 | // _1), |
| 874 | // bind(&EndToEndFixture::channel_onConnectFailedOk, |
| 875 | // this, |
| 876 | // _1)), |
| 877 | // UdpChannel::Error); |
| 878 | //} |
| 879 | |
| 880 | |
| 881 | BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture) |
| 882 | { |
| 883 | UdpFactory factory = UdpFactory(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 884 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 885 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 886 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 887 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 888 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 889 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 890 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 891 | channel2->connect("127.0.0.1", "20070", |
| 892 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 893 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 894 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 895 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 896 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 897 | |
| 898 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
| 899 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 900 | BOOST_CHECK(static_cast<bool>(face2)); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 901 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 902 | // 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] | 903 | scheduler::schedule(time::milliseconds(100), bind(&Face::close, face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 904 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 905 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 906 | "FaceClosing error: cannot properly close faces"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 907 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 908 | BOOST_CHECK(!static_cast<bool>(face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 909 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 910 | BOOST_CHECK_EQUAL(channel2->size(), 0); |
| 911 | } |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 912 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 913 | BOOST_FIXTURE_TEST_CASE(ClosingIdleFace, EndToEndFixture) |
| 914 | { |
| 915 | Interest interest1("ndn:/TpnzGvW9R"); |
| 916 | Interest interest2("ndn:/QWiIMfj5sL"); |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 917 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 918 | UdpFactory factory; |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 919 | |
| 920 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070", |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 921 | time::seconds(2)); |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 922 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071", |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 923 | time::seconds(2)); |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 924 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 925 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 926 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 927 | |
| 928 | channel2->connect("127.0.0.1", "20070", |
| 929 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 930 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 931 | |
| 932 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 933 | "UdpChannel error: cannot connect or cannot accept connection"); |
| 934 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 935 | face2->sendInterest(interest1); |
| 936 | BOOST_CHECK(!face2->isOnDemand()); |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 937 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 938 | BOOST_CHECK_MESSAGE(limitedIo.run(2,//1 send + 1 listen return |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 939 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 940 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 941 | |
| 942 | BOOST_CHECK_EQUAL(faces.size(), 2); |
| 943 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(2)) == LimitedIo::EXCEED_TIME, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 944 | "Idle face should be still open because has been used recently"); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 945 | BOOST_CHECK_EQUAL(faces.size(), 2); |
| 946 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 947 | "Closing idle face error: face should be closed by now"); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 948 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 949 | //the face on listen should be closed now |
| 950 | BOOST_CHECK_EQUAL(channel1->size(), 0); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 951 | //checking that face2 has not been closed |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 952 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 953 | BOOST_REQUIRE(static_cast<bool>(face2)); |
| 954 | |
| 955 | face2->sendInterest(interest2); |
| 956 | BOOST_CHECK_MESSAGE(limitedIo.run(2,//1 send + 1 listen return |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 957 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 958 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 959 | //channel1 should have created a new face by now |
| 960 | BOOST_CHECK_EQUAL(channel1->size(), 1); |
| 961 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 962 | BOOST_REQUIRE(static_cast<bool>(face1)); |
| 963 | BOOST_CHECK(face1->isOnDemand()); |
| 964 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 965 | channel1->connect("127.0.0.1", "20071", |
| 966 | bind(&EndToEndFixture::channel1_onFaceCreatedNoCheck, this, _1), |
| 967 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 968 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 969 | BOOST_CHECK_MESSAGE(limitedIo.run(1,//1 connect |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 970 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 971 | "UdpChannel error: cannot connect"); |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 972 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 973 | BOOST_CHECK(!face1->isOnDemand()); |
| 974 | |
| 975 | //the connect should have set face1 as permanent face, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 976 | //but it shouln't have created any additional faces |
| 977 | BOOST_CHECK_EQUAL(channel1->size(), 1); |
| 978 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 979 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_TIME, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 980 | "Idle face should be still open because it's permanent now"); |
| 981 | //both faces are permanent, nothing should have changed |
| 982 | BOOST_CHECK_EQUAL(channel1->size(), 1); |
| 983 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
| 984 | } |
| 985 | |
Alexander Afanasyev | 70aaf8a | 2014-12-13 00:44:22 -0800 | [diff] [blame] | 986 | class FakeNetworkInterfaceFixture : public BaseFixture |
| 987 | { |
| 988 | public: |
| 989 | FakeNetworkInterfaceFixture() |
| 990 | { |
| 991 | using namespace boost::asio::ip; |
| 992 | |
| 993 | auto fakeInterfaces = make_shared<std::vector<NetworkInterfaceInfo>>(); |
| 994 | |
| 995 | fakeInterfaces->push_back( |
| 996 | NetworkInterfaceInfo {0, "eth0", |
| 997 | ethernet::Address::fromString("3e:15:c2:8b:65:00"), |
| 998 | {address_v4::from_string("0.0.0.0")}, |
| 999 | {address_v6::from_string("::")}, |
| 1000 | address_v4(), |
| 1001 | IFF_UP}); |
| 1002 | fakeInterfaces->push_back( |
| 1003 | NetworkInterfaceInfo {1, "eth0", |
| 1004 | ethernet::Address::fromString("3e:15:c2:8b:65:00"), |
| 1005 | {address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.2")}, |
| 1006 | {}, |
| 1007 | address_v4::from_string("192.168.2.255"), |
| 1008 | 0}); |
| 1009 | fakeInterfaces->push_back( |
| 1010 | NetworkInterfaceInfo {2, "eth1", |
| 1011 | ethernet::Address::fromString("3e:15:c2:8b:65:00"), |
| 1012 | {address_v4::from_string("198.51.100.1")}, |
| 1013 | {address_v6::from_string("2001:db8::2"), address_v6::from_string("2001:db8::3")}, |
| 1014 | address_v4::from_string("198.51.100.255"), |
| 1015 | IFF_MULTICAST | IFF_BROADCAST | IFF_UP}); |
| 1016 | |
| 1017 | setDebugNetworkInterfaces(fakeInterfaces); |
| 1018 | } |
| 1019 | |
| 1020 | ~FakeNetworkInterfaceFixture() |
| 1021 | { |
| 1022 | setDebugNetworkInterfaces(nullptr); |
| 1023 | } |
| 1024 | }; |
| 1025 | |
| 1026 | BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture) |
| 1027 | { |
| 1028 | using namespace boost::asio::ip; |
| 1029 | |
| 1030 | UdpFactory factory; |
| 1031 | factory.prohibitEndpoint(udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024)); |
| 1032 | BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1); |
| 1033 | BOOST_CHECK((factory.m_prohibitedEndpoints == |
| 1034 | std::set<udp::Endpoint> { |
| 1035 | udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024), |
| 1036 | })); |
| 1037 | |
| 1038 | factory.m_prohibitedEndpoints.clear(); |
| 1039 | factory.prohibitEndpoint(udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048)); |
| 1040 | BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1); |
| 1041 | BOOST_CHECK((factory.m_prohibitedEndpoints == |
| 1042 | std::set<udp::Endpoint> { |
| 1043 | udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048), |
| 1044 | })); |
| 1045 | |
| 1046 | factory.m_prohibitedEndpoints.clear(); |
| 1047 | factory.prohibitEndpoint(udp::Endpoint(address_v4(), 1024)); |
| 1048 | BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 6); |
| 1049 | BOOST_CHECK((factory.m_prohibitedEndpoints == |
| 1050 | std::set<udp::Endpoint> { |
| 1051 | udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024), |
| 1052 | udp::Endpoint(address_v4::from_string("192.168.2.2"), 1024), |
| 1053 | udp::Endpoint(address_v4::from_string("198.51.100.1"), 1024), |
| 1054 | udp::Endpoint(address_v4::from_string("198.51.100.255"), 1024), |
| 1055 | udp::Endpoint(address_v4::from_string("255.255.255.255"), 1024), |
| 1056 | udp::Endpoint(address_v4::from_string("0.0.0.0"), 1024) |
| 1057 | })); |
| 1058 | |
| 1059 | factory.m_prohibitedEndpoints.clear(); |
| 1060 | factory.prohibitEndpoint(udp::Endpoint(address_v6(), 2048)); |
| 1061 | BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 3); |
| 1062 | BOOST_CHECK((factory.m_prohibitedEndpoints == |
| 1063 | std::set<udp::Endpoint> { |
| 1064 | udp::Endpoint(address_v6::from_string("2001:db8::2"), 2048), |
| 1065 | udp::Endpoint(address_v6::from_string("2001:db8::3"), 2048), |
| 1066 | udp::Endpoint(address_v6::from_string("::"), 2048), |
| 1067 | })); |
| 1068 | } |
| 1069 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 1070 | BOOST_AUTO_TEST_SUITE_END() |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 1071 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 1072 | } // namespace tests |
| 1073 | } // namespace nfd |