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