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); |
| 382 | // face1 is not created yet |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 383 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 384 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 385 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 386 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 387 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 388 | Interest interest1("ndn:/TpnzGvW9R"); |
| 389 | Data data1 ("ndn:/KfczhUqVix"); |
| 390 | data1.setContent(0, 0); |
| 391 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 392 | Data data2 ("ndn:/XNBV796f"); |
| 393 | data2.setContent(0, 0); |
| 394 | Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 395 | Data data3 ("ndn:/XNBV794f"); |
| 396 | data3.setContent(0, 0); |
| 397 | |
| 398 | |
| 399 | ndn::SignatureSha256WithRsa fakeSignature; |
| 400 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 401 | reinterpret_cast<const uint8_t*>(0), |
| 402 | 0)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 403 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 404 | // set fake signature on data1 and data2 |
| 405 | data1.setSignature(fakeSignature); |
| 406 | data2.setSignature(fakeSignature); |
| 407 | data3.setSignature(fakeSignature); |
| 408 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 409 | face2->sendInterest(interest2); |
| 410 | face2->sendData (data2 ); |
| 411 | face2->sendData (data2 ); |
| 412 | face2->sendData (data2 ); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 413 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 414 | BOOST_CHECK_MESSAGE(limitedIo.run(5,//4 send + 1 listen return |
Alexander Afanasyev | 6f5ff63 | 2014-03-07 16:40:10 +0000 | [diff] [blame] | 415 | time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 416 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 417 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 418 | BOOST_REQUIRE(static_cast<bool>(face1)); |
| 419 | BOOST_CHECK_EQUAL(face1->getRemoteUri().toString(), "udp4://127.0.0.1:20071"); |
| 420 | BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "udp4://127.0.0.1:20070"); |
| 421 | BOOST_CHECK_EQUAL(face1->isLocal(), false); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 422 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 423 | face1->sendInterest(interest1); |
| 424 | face1->sendInterest(interest1); |
| 425 | face1->sendInterest(interest1); |
| 426 | face1->sendData (data1 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 427 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 428 | BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 429 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 430 | |
| 431 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 432 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 433 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3); |
| 434 | BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 3); |
| 435 | BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 436 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 437 | BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName()); |
| 438 | BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName()); |
| 439 | BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName()); |
| 440 | BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 441 | |
| 442 | |
| 443 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 444 | //checking if the connection accepting mechanism works properly. |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 445 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 446 | face2->sendData (data3 ); |
| 447 | face2->sendInterest(interest3); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 448 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 449 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 450 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 451 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 452 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 2); |
| 453 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 454 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 455 | BOOST_CHECK_EQUAL(face1_receivedInterests[1].getName(), interest3.getName()); |
| 456 | BOOST_CHECK_EQUAL(face1_receivedDatas [3].getName(), data3.getName()); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 457 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 458 | const FaceCounters& counters1 = face1->getCounters(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 459 | BOOST_CHECK_EQUAL(counters1.getNInInterests() , 2); |
| 460 | BOOST_CHECK_EQUAL(counters1.getNInDatas() , 4); |
| 461 | BOOST_CHECK_EQUAL(counters1.getNOutInterests(), 3); |
| 462 | BOOST_CHECK_EQUAL(counters1.getNOutDatas() , 1); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 463 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 464 | const FaceCounters& counters2 = face2->getCounters(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 465 | BOOST_CHECK_EQUAL(counters2.getNInInterests() , 3); |
| 466 | BOOST_CHECK_EQUAL(counters2.getNInDatas() , 1); |
| 467 | BOOST_CHECK_EQUAL(counters2.getNOutInterests(), 2); |
| 468 | BOOST_CHECK_EQUAL(counters2.getNOutDatas() , 4); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 469 | } |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 470 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 471 | BOOST_FIXTURE_TEST_CASE(EndToEnd6, EndToEndFixture) |
| 472 | { |
| 473 | UdpFactory factory; |
| 474 | |
| 475 | factory.createChannel("::1", "20071"); |
| 476 | |
| 477 | factory.createFace(FaceUri("udp://[::1]:20070"), |
| 478 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 479 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
| 480 | |
| 481 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 482 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 483 | "UdpChannel error: cannot connect or cannot accept connection"); |
| 484 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 485 | BOOST_REQUIRE(static_cast<bool>(face2)); |
| 486 | BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "udp6://[::1]:20070"); |
| 487 | BOOST_CHECK_EQUAL(face2->getLocalUri().toString(), "udp6://[::1]:20071"); |
| 488 | BOOST_CHECK_EQUAL(face2->isLocal(), false); |
| 489 | // face1 is not created yet |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 490 | |
| 491 | shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 492 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 493 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 494 | |
| 495 | Interest interest1("ndn:/TpnzGvW9R"); |
| 496 | Data data1 ("ndn:/KfczhUqVix"); |
| 497 | data1.setContent(0, 0); |
| 498 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 499 | Data data2 ("ndn:/XNBV796f"); |
| 500 | data2.setContent(0, 0); |
| 501 | Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 502 | Data data3 ("ndn:/XNBV794f"); |
| 503 | data3.setContent(0, 0); |
| 504 | |
| 505 | |
| 506 | ndn::SignatureSha256WithRsa fakeSignature; |
| 507 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 508 | reinterpret_cast<const uint8_t*>(0), |
| 509 | 0)); |
| 510 | |
| 511 | // set fake signature on data1 and data2 |
| 512 | data1.setSignature(fakeSignature); |
| 513 | data2.setSignature(fakeSignature); |
| 514 | data3.setSignature(fakeSignature); |
| 515 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 516 | face2->sendInterest(interest2); |
| 517 | face2->sendData (data2 ); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 518 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 519 | BOOST_CHECK_MESSAGE(limitedIo.run(3,//2 send + 1 listen return |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 520 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 521 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 522 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 523 | BOOST_REQUIRE(static_cast<bool>(face1)); |
| 524 | BOOST_CHECK_EQUAL(face1->getRemoteUri().toString(), "udp6://[::1]:20071"); |
| 525 | BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "udp6://[::1]:20070"); |
| 526 | BOOST_CHECK_EQUAL(face1->isLocal(), false); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 527 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 528 | face1->sendInterest(interest1); |
| 529 | face1->sendData (data1 ); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 530 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 531 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 532 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 533 | |
| 534 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 535 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 536 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1); |
| 537 | BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1); |
| 538 | BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 539 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 540 | BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName()); |
| 541 | BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName()); |
| 542 | BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName()); |
| 543 | BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName()); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 544 | |
| 545 | |
| 546 | |
| 547 | //checking if the connection accepting mechanism works properly. |
| 548 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 549 | face2->sendData (data3 ); |
| 550 | face2->sendInterest(interest3); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 551 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 552 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 553 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 554 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 555 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 2); |
| 556 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 2); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 557 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 558 | BOOST_CHECK_EQUAL(face1_receivedInterests[1].getName(), interest3.getName()); |
| 559 | BOOST_CHECK_EQUAL(face1_receivedDatas [1].getName(), data3.getName()); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) |
| 563 | { |
| 564 | Interest interest1("ndn:/TpnzGvW9R"); |
| 565 | Interest interest2("ndn:/QWiIMfj5sL"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 566 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 567 | UdpFactory factory; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 568 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 569 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 570 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 571 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 572 | channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 573 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 574 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 575 | channel2->connect("127.0.0.1", "20070", |
| 576 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 577 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 578 | |
| 579 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 580 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 581 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 582 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 583 | BOOST_CHECK_EQUAL(faces.size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 584 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 585 | shared_ptr<UdpChannel> channel3 = factory.createChannel("127.0.0.1", "20072"); |
| 586 | channel3->connect("127.0.0.1", "20070", |
| 587 | bind(&EndToEndFixture::channel3_onFaceCreated, this, _1), |
| 588 | bind(&EndToEndFixture::channel_onConnectFailed, this, _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> channel4 = factory.createChannel("127.0.0.1", "20073"); |
| 591 | |
| 592 | BOOST_CHECK_NE(channel3, channel4); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 593 | |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 594 | scheduler::schedule(time::milliseconds(500), |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 595 | bind(&UdpChannel::connect, channel4, "127.0.0.1", "20070", |
| 596 | // does not work without static_cast |
| 597 | static_cast<UdpChannel::FaceCreatedCallback>( |
| 598 | bind(&EndToEndFixture::channel_onFaceCreated, this, _1)), |
| 599 | static_cast<UdpChannel::ConnectFailedCallback>( |
| 600 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)))); |
| 601 | |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 602 | scheduler::schedule(time::milliseconds(400), bind(&EndToEndFixture::checkFaceList, this, 2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 603 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 604 | BOOST_CHECK_MESSAGE(limitedIo.run(2,// 2 connects |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 605 | time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 606 | "UdpChannel error: cannot connect or cannot accept multiple connections"); |
| 607 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 608 | BOOST_CHECK_EQUAL(faces.size(), 3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 609 | |
| 610 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 611 | face2->sendInterest(interest1); |
| 612 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 613 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 614 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 615 | BOOST_CHECK_EQUAL(faces.size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 616 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 617 | face3->sendInterest(interest2); |
| 618 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 619 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 620 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 621 | //channel1 should have created 2 faces, one when face2 sent an interest, one when face3 sent an interest |
| 622 | BOOST_CHECK_EQUAL(faces.size(), 5); |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 623 | BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 624 | bind(&EndToEndFixture::channel_onConnectFailedOk, this, _1)), |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 625 | UdpChannel::Error); |
| 626 | } |
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 | //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 629 | //BOOST_FIXTURE_TEST_CASE(EndToEndIpv6, EndToEndFixture) |
| 630 | //{ |
| 631 | // UdpFactory factory = UdpFactory(); |
| 632 | // 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] | 633 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 634 | // EventId abortEvent = |
| 635 | // scheduler.scheduleEvent(time::seconds(1), |
| 636 | // bind(&EndToEndFixture::abortTestCase, this, |
| 637 | // "UdpChannel error: cannot connect or cannot accept connection")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 638 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 639 | // limitedIoRemaining = 1; |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 640 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 641 | // shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 642 | // shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 643 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 644 | // channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 645 | // bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 646 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 647 | // channel2->connect("::1", "20070", |
| 648 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 649 | // bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
| 650 | // g_io.run(); |
| 651 | // g_io.reset(); |
| 652 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 653 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 654 | // BOOST_REQUIRE(static_cast<bool>(face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 655 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 656 | // abortEvent = |
| 657 | // scheduler.scheduleEvent(time::seconds(1), |
| 658 | // bind(&EndToEndFixture::abortTestCase, this, |
| 659 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
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 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 662 | // Data data1 ("ndn:/KfczhUqVix"); |
| 663 | // data1.setContent(0, 0); |
| 664 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 665 | // Data data2 ("ndn:/XNBV796f"); |
| 666 | // data2.setContent(0, 0); |
| 667 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 668 | // Data data3 ("ndn:/XNBV794f"); |
| 669 | // data3.setContent(0, 0); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 670 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 671 | // ndn::SignatureSha256WithRsa fakeSignature; |
| 672 | // 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] | 673 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 674 | // // set fake signature on data1 and data2 |
| 675 | // data1.setSignature(fakeSignature); |
| 676 | // data2.setSignature(fakeSignature); |
| 677 | // data3.setSignature(fakeSignature); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 678 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 679 | // face2->sendInterest(interest2); |
| 680 | // face2->sendData (data2 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 681 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 682 | // limitedIoRemaining = 3; //2 send + 1 listen return |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 683 | // g_io.run(); |
| 684 | // g_io.reset(); |
| 685 | // scheduler.cancelEvent(abortEvent); |
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 | // BOOST_REQUIRE(static_cast<bool>(face1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 688 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 689 | // face1->sendInterest(interest1); |
| 690 | // face1->sendData (data1 ); |
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 | // abortEvent = |
| 693 | // scheduler.scheduleEvent(time::seconds(1), |
| 694 | // bind(&EndToEndFixture::abortTestCase, this, |
| 695 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 696 | // limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 697 | // g_io.run(); |
| 698 | // g_io.reset(); |
| 699 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 700 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 701 | // BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 702 | // BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1); |
| 703 | // BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1); |
| 704 | // BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
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_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName()); |
| 707 | // BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName()); |
| 708 | // BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName()); |
| 709 | // BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 710 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 711 | // //checking if the connection accepting mechanism works properly. |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 712 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 713 | // face2->sendData (data3 ); |
| 714 | // face2->sendInterest(interest3); |
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 | // abortEvent = |
| 717 | // scheduler.scheduleEvent(time::seconds(1), |
| 718 | // bind(&EndToEndFixture::abortTestCase, this, |
| 719 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 720 | // limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 721 | // g_io.run(); |
| 722 | // g_io.reset(); |
| 723 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 724 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 725 | // BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 2); |
| 726 | // BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 2); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 727 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 728 | // BOOST_CHECK_EQUAL(face1_receivedInterests[1].getName(), interest3.getName()); |
| 729 | // BOOST_CHECK_EQUAL(face1_receivedDatas [1].getName(), data3.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 730 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 731 | //} |
| 732 | |
| 733 | |
| 734 | //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 735 | //BOOST_FIXTURE_TEST_CASE(MultipleAcceptsIpv6, EndToEndFixture) |
| 736 | //{ |
| 737 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 738 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 739 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 740 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 741 | // UdpFactory factory = UdpFactory(); |
| 742 | // 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] | 743 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 744 | // EventId abortEvent = |
| 745 | // scheduler.scheduleEvent(time::seconds(4), |
| 746 | // bind(&EndToEndFixture::abortTestCase, this, |
| 747 | // "UdpChannel error: cannot connect or cannot accept connection")); |
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 | // shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 750 | // shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 751 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 752 | // channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 753 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 754 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 755 | // channel2->connect("::1", "20070", |
| 756 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 757 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 758 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 759 | // limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 760 | // g_io.run(); |
| 761 | // g_io.reset(); |
| 762 | // scheduler.cancelEvent(abortEvent); |
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 | // BOOST_CHECK_EQUAL(faces.size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 765 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 766 | // shared_ptr<UdpChannel> channel3 = factory.createChannel("::1", "20072"); |
| 767 | // channel3->connect("::1", "20070", |
| 768 | // bind(&EndToEndFixture::channel3_onFaceCreated, this, _1), |
| 769 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _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> channel4 = factory.createChannel("::1", "20073"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 772 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 773 | // BOOST_CHECK_NE(channel3, channel4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 774 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 775 | // scheduler |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 776 | // .scheduleEvent(time::milliseconds(500), |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 777 | // bind(&UdpChannel::connect, channel4, |
| 778 | // "::1", "20070", |
| 779 | // static_cast<UdpChannel::FaceCreatedCallback>(bind(&EndToEndFixture:: |
| 780 | // channel_onFaceCreated, this, _1)), |
| 781 | // static_cast<UdpChannel::ConnectFailedCallback>(bind(&EndToEndFixture:: |
| 782 | // channel_onConnectFailed, this, _1)))); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 783 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 784 | // limitedIoRemaining = 2; // 2 connects |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 785 | // abortEvent = |
| 786 | // scheduler.scheduleEvent(time::seconds(4), |
| 787 | // bind(&EndToEndFixture::abortTestCase, this, |
| 788 | // "UdpChannel error: cannot connect or cannot accept multiple connections")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 789 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 790 | // scheduler.scheduleEvent(time::seconds(0.4), |
| 791 | // bind(&EndToEndFixture::checkFaceList, this, 2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 792 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 793 | // g_io.run(); |
| 794 | // g_io.reset(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 795 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 796 | // BOOST_CHECK_EQUAL(faces.size(), 3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 797 | // |
| 798 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 799 | // face2->sendInterest(interest1); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 800 | // abortEvent = |
| 801 | // scheduler.scheduleEvent(time::seconds(1), |
| 802 | // bind(&EndToEndFixture::abortTestCase, this, |
| 803 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 804 | // limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 805 | // g_io.run(); |
| 806 | // g_io.reset(); |
| 807 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 808 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 809 | // BOOST_CHECK_EQUAL(faces.size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 810 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 811 | // face3->sendInterest(interest2); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 812 | // abortEvent = |
| 813 | // scheduler.scheduleEvent(time::seconds(1), |
| 814 | // bind(&EndToEndFixture::abortTestCase, this, |
| 815 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 816 | // limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 817 | // g_io.run(); |
| 818 | // g_io.reset(); |
| 819 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 820 | // |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 821 | // //channel1 should have created 2 faces, one when face2 sent an interest, one when face3 sent an interest |
| 822 | // BOOST_CHECK_EQUAL(faces.size(), 5); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 823 | // BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, |
| 824 | // this, |
| 825 | // _1), |
| 826 | // bind(&EndToEndFixture::channel_onConnectFailedOk, |
| 827 | // this, |
| 828 | // _1)), |
| 829 | // UdpChannel::Error); |
| 830 | //} |
| 831 | |
| 832 | |
| 833 | BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture) |
| 834 | { |
| 835 | UdpFactory factory = UdpFactory(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 836 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 837 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 838 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 839 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 840 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 841 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 842 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 843 | channel2->connect("127.0.0.1", "20070", |
| 844 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 845 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 846 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 847 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 848 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 849 | |
| 850 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
| 851 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 852 | BOOST_CHECK(static_cast<bool>(face2)); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 853 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 854 | // 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] | 855 | scheduler::schedule(time::milliseconds(100), bind(&Face::close, face2)); |
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_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 858 | "FaceClosing error: cannot properly close faces"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 859 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 860 | BOOST_CHECK(!static_cast<bool>(face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 861 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 862 | BOOST_CHECK_EQUAL(channel2->size(), 0); |
| 863 | } |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 864 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 865 | BOOST_FIXTURE_TEST_CASE(ClosingIdleFace, EndToEndFixture) |
| 866 | { |
| 867 | Interest interest1("ndn:/TpnzGvW9R"); |
| 868 | Interest interest2("ndn:/QWiIMfj5sL"); |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 869 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 870 | UdpFactory factory; |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 871 | |
| 872 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070", |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 873 | time::seconds(2)); |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 874 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071", |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 875 | time::seconds(2)); |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 876 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 877 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
Davide Pesavento | 126249b | 2014-03-13 02:42:21 +0100 | [diff] [blame] | 878 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 879 | |
| 880 | channel2->connect("127.0.0.1", "20070", |
| 881 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 882 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 883 | |
| 884 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 885 | "UdpChannel error: cannot connect or cannot accept connection"); |
| 886 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 887 | face2->sendInterest(interest1); |
| 888 | BOOST_CHECK(!face2->isOnDemand()); |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 889 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 890 | BOOST_CHECK_MESSAGE(limitedIo.run(2,//1 send + 1 listen return |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 891 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 892 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 893 | |
| 894 | BOOST_CHECK_EQUAL(faces.size(), 2); |
| 895 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(2)) == LimitedIo::EXCEED_TIME, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 896 | "Idle face should be still open because has been used recently"); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 897 | BOOST_CHECK_EQUAL(faces.size(), 2); |
| 898 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 899 | "Closing idle face error: face should be closed by now"); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 900 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 901 | //the face on listen should be closed now |
| 902 | BOOST_CHECK_EQUAL(channel1->size(), 0); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 903 | //checking that face2 has not been closed |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 904 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 905 | BOOST_REQUIRE(static_cast<bool>(face2)); |
| 906 | |
| 907 | face2->sendInterest(interest2); |
| 908 | BOOST_CHECK_MESSAGE(limitedIo.run(2,//1 send + 1 listen return |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 909 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 910 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 911 | //channel1 should have created a new face by now |
| 912 | BOOST_CHECK_EQUAL(channel1->size(), 1); |
| 913 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 914 | BOOST_REQUIRE(static_cast<bool>(face1)); |
| 915 | BOOST_CHECK(face1->isOnDemand()); |
| 916 | |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 917 | channel1->connect("127.0.0.1", "20071", |
| 918 | bind(&EndToEndFixture::channel1_onFaceCreatedNoCheck, this, _1), |
| 919 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 920 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 921 | BOOST_CHECK_MESSAGE(limitedIo.run(1,//1 connect |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 922 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 923 | "UdpChannel error: cannot connect"); |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 924 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 925 | BOOST_CHECK(!face1->isOnDemand()); |
| 926 | |
| 927 | //the connect should have set face1 as permanent face, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 928 | //but it shouln't have created any additional faces |
| 929 | BOOST_CHECK_EQUAL(channel1->size(), 1); |
| 930 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 931 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_TIME, |
Giulio Grassi | 69871f0 | 2014-03-09 16:14:44 +0100 | [diff] [blame] | 932 | "Idle face should be still open because it's permanent now"); |
| 933 | //both faces are permanent, nothing should have changed |
| 934 | BOOST_CHECK_EQUAL(channel1->size(), 1); |
| 935 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
| 936 | } |
| 937 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 938 | BOOST_AUTO_TEST_SUITE_END() |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 939 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 940 | } // namespace tests |
| 941 | } // namespace nfd |