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