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