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