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