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)); |
| 173 | m_face1 = newFace; |
| 174 | m_face1->onReceiveInterest += |
| 175 | bind(&EndToEndFixture::face1_onReceiveInterest, this, _1); |
| 176 | m_face1->onReceiveData += |
| 177 | bind(&EndToEndFixture::face1_onReceiveData, this, _1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 178 | m_face1->onFail += |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 179 | bind(&EndToEndFixture::face1_onFail, this); |
| 180 | BOOST_CHECK_MESSAGE(true, "channel 1 face created"); |
| 181 | |
| 182 | m_faces.push_back(m_face1); |
| 183 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 184 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | void |
| 188 | channel1_onConnectFailed(const std::string& reason) |
| 189 | { |
| 190 | BOOST_CHECK_MESSAGE(false, reason); |
| 191 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 192 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 193 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 194 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 195 | void |
| 196 | face1_onReceiveInterest(const Interest& interest) |
| 197 | { |
| 198 | m_face1_receivedInterests.push_back(interest); |
| 199 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 200 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 201 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 202 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 203 | void |
| 204 | face1_onReceiveData(const Data& data) |
| 205 | { |
| 206 | m_face1_receivedDatas.push_back(data); |
| 207 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 208 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void |
| 212 | face1_onFail() |
| 213 | { |
| 214 | m_face1.reset(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 215 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | void |
| 219 | channel2_onFaceCreated(const shared_ptr<Face>& newFace) |
| 220 | { |
| 221 | BOOST_CHECK(!static_cast<bool>(m_face2)); |
| 222 | m_face2 = newFace; |
| 223 | m_face2->onReceiveInterest += |
| 224 | bind(&EndToEndFixture::face2_onReceiveInterest, this, _1); |
| 225 | m_face2->onReceiveData += |
| 226 | bind(&EndToEndFixture::face2_onReceiveData, this, _1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 227 | m_face2->onFail += |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 228 | bind(&EndToEndFixture::face2_onFail, this); |
| 229 | |
| 230 | m_faces.push_back(m_face2); |
| 231 | |
| 232 | BOOST_CHECK_MESSAGE(true, "channel 2 face created"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 233 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 234 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 235 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 236 | void |
| 237 | channel2_onConnectFailed(const std::string& reason) |
| 238 | { |
| 239 | BOOST_CHECK_MESSAGE(false, reason); |
| 240 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 241 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 242 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 243 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 244 | void |
| 245 | face2_onReceiveInterest(const Interest& interest) |
| 246 | { |
| 247 | m_face2_receivedInterests.push_back(interest); |
| 248 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 249 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 250 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 251 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 252 | void |
| 253 | face2_onReceiveData(const Data& data) |
| 254 | { |
| 255 | m_face2_receivedDatas.push_back(data); |
| 256 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 257 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | void |
| 261 | face2_onFail() |
| 262 | { |
| 263 | m_face2.reset(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 264 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | void |
| 268 | channel3_onFaceCreated(const shared_ptr<Face>& newFace) |
| 269 | { |
| 270 | BOOST_CHECK(!static_cast<bool>(m_face1)); |
| 271 | m_face3 = newFace; |
| 272 | m_faces.push_back(newFace); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 273 | |
| 274 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 275 | } |
| 276 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 277 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 278 | void |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame^] | 279 | channel_onFaceCreated(const shared_ptr<Face>& newFace) |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 280 | { |
| 281 | m_faces.push_back(newFace); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 282 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void |
| 286 | channel_onConnectFailed(const std::string& reason) |
| 287 | { |
| 288 | BOOST_CHECK_MESSAGE(false, reason); |
| 289 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 290 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | void |
| 294 | channel_onConnectFailedOk(const std::string& reason) |
| 295 | { |
| 296 | //it's ok, it was supposed to fail |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 297 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | void |
| 301 | checkFaceList(size_t shouldBe) |
| 302 | { |
| 303 | BOOST_CHECK_EQUAL(m_faces.size(), shouldBe); |
| 304 | } |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 305 | |
| 306 | public: |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 307 | LimitedIo m_limitedIo; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 308 | |
| 309 | shared_ptr<Face> m_face1; |
| 310 | std::vector<Interest> m_face1_receivedInterests; |
| 311 | std::vector<Data> m_face1_receivedDatas; |
| 312 | shared_ptr<Face> m_face2; |
| 313 | std::vector<Interest> m_face2_receivedInterests; |
| 314 | std::vector<Data> m_face2_receivedDatas; |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 315 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 316 | shared_ptr<Face> m_face3; |
| 317 | |
| 318 | |
| 319 | std::list< shared_ptr<Face> > m_faces; |
| 320 | }; |
| 321 | |
| 322 | |
| 323 | BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture) |
| 324 | { |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 325 | UdpFactory factory; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 326 | |
| 327 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 328 | |
| 329 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 330 | //channel2->connect("127.0.0.1", "20070", |
| 331 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 332 | // bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 333 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 334 | factory.createFace(FaceUri("udp4://127.0.0.1:20070"), |
| 335 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 336 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 337 | |
| 338 | |
| 339 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 340 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 341 | |
| 342 | BOOST_REQUIRE(static_cast<bool>(m_face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 343 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 344 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 345 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 346 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
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 | |
| 349 | Interest interest1("ndn:/TpnzGvW9R"); |
| 350 | Data data1 ("ndn:/KfczhUqVix"); |
| 351 | data1.setContent(0, 0); |
| 352 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 353 | Data data2 ("ndn:/XNBV796f"); |
| 354 | data2.setContent(0, 0); |
| 355 | Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 356 | Data data3 ("ndn:/XNBV794f"); |
| 357 | data3.setContent(0, 0); |
| 358 | |
| 359 | |
| 360 | ndn::SignatureSha256WithRsa fakeSignature; |
| 361 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 362 | reinterpret_cast<const uint8_t*>(0), |
| 363 | 0)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 364 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 365 | // set fake signature on data1 and data2 |
| 366 | data1.setSignature(fakeSignature); |
| 367 | data2.setSignature(fakeSignature); |
| 368 | data3.setSignature(fakeSignature); |
| 369 | |
| 370 | m_face2->sendInterest(interest2); |
| 371 | m_face2->sendData (data2 ); |
| 372 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 373 | BOOST_CHECK_MESSAGE(m_limitedIo.run(3,//2 send + 1 listen return |
| 374 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 375 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 376 | |
| 377 | BOOST_REQUIRE(static_cast<bool>(m_face1)); |
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); |
| 380 | m_face1->sendData (data1 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 381 | |
| 382 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 383 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 384 | |
| 385 | |
| 386 | BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 387 | BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
| 388 | BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1); |
| 389 | BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 390 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 391 | BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName()); |
| 392 | BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName()); |
| 393 | BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName()); |
| 394 | BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 395 | |
| 396 | |
| 397 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 398 | //checking if the connection accepting mechanism works properly. |
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 | m_face2->sendData (data3 ); |
| 401 | m_face2->sendInterest(interest3); |
| 402 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 403 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 404 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 405 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 406 | BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 2); |
| 407 | BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 2); |
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 | BOOST_CHECK_EQUAL(m_face1_receivedInterests[1].getName(), interest3.getName()); |
| 410 | BOOST_CHECK_EQUAL(m_face1_receivedDatas [1].getName(), data3.getName()); |
| 411 | |
| 412 | } |
| 413 | |
| 414 | BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) |
| 415 | { |
| 416 | Interest interest1("ndn:/TpnzGvW9R"); |
| 417 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 418 | Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 419 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 420 | UdpFactory factory; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 421 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 422 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 423 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 424 | |
| 425 | |
| 426 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 427 | channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 428 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 429 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 430 | channel2->connect("127.0.0.1", "20070", |
| 431 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 432 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 433 | |
| 434 | |
| 435 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 436 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 437 | |
| 438 | BOOST_CHECK_EQUAL(m_faces.size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 439 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 440 | shared_ptr<UdpChannel> channel3 = factory.createChannel("127.0.0.1", "20072"); |
| 441 | channel3->connect("127.0.0.1", "20070", |
| 442 | bind(&EndToEndFixture::channel3_onFaceCreated, this, _1), |
| 443 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 444 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 445 | shared_ptr<UdpChannel> channel4 = factory.createChannel("127.0.0.1", "20073"); |
| 446 | |
| 447 | BOOST_CHECK_NE(channel3, channel4); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 448 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 449 | scheduler::schedule(time::seconds(0.5), |
| 450 | bind(&UdpChannel::connect, channel4, "127.0.0.1", "20070", |
| 451 | // does not work without static_cast |
| 452 | static_cast<UdpChannel::FaceCreatedCallback>( |
| 453 | bind(&EndToEndFixture::channel_onFaceCreated, this, _1)), |
| 454 | static_cast<UdpChannel::ConnectFailedCallback>( |
| 455 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)))); |
| 456 | |
| 457 | scheduler::schedule(time::seconds(0.4), bind(&EndToEndFixture::checkFaceList, this, 2)); |
| 458 | |
| 459 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2,// 2 connects |
| 460 | time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 461 | "UdpChannel error: cannot connect or cannot accept multiple connections"); |
| 462 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 463 | BOOST_CHECK_EQUAL(m_faces.size(), 3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 464 | |
| 465 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 466 | m_face2->sendInterest(interest1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 467 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 468 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 469 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 470 | BOOST_CHECK_EQUAL(m_faces.size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 471 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 472 | m_face3->sendInterest(interest2); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 473 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 474 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 475 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 476 | //channel1 should have created 2 faces, one when m_face2 sent an interest, one when m_face3 sent an interest |
| 477 | BOOST_CHECK_EQUAL(m_faces.size(), 5); |
| 478 | BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, |
| 479 | this, |
| 480 | _1), |
| 481 | bind(&EndToEndFixture::channel_onConnectFailedOk, |
| 482 | this, |
| 483 | _1)), |
| 484 | UdpChannel::Error); |
| 485 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 486 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 487 | //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 488 | //BOOST_FIXTURE_TEST_CASE(EndToEndIpv6, EndToEndFixture) |
| 489 | //{ |
| 490 | // UdpFactory factory = UdpFactory(); |
| 491 | // 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] | 492 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 493 | // EventId abortEvent = |
| 494 | // scheduler.scheduleEvent(time::seconds(1), |
| 495 | // bind(&EndToEndFixture::abortTestCase, this, |
| 496 | // "UdpChannel error: cannot connect or cannot accept connection")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 497 | // |
| 498 | // m_limitedIoRemaining = 1; |
| 499 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 500 | // shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 501 | // shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 502 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 503 | // channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 504 | // bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 505 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 506 | // channel2->connect("::1", "20070", |
| 507 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 508 | // bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
| 509 | // g_io.run(); |
| 510 | // g_io.reset(); |
| 511 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 512 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 513 | // BOOST_REQUIRE(static_cast<bool>(m_face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 514 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 515 | // abortEvent = |
| 516 | // scheduler.scheduleEvent(time::seconds(1), |
| 517 | // bind(&EndToEndFixture::abortTestCase, this, |
| 518 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 519 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 520 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 521 | // Data data1 ("ndn:/KfczhUqVix"); |
| 522 | // data1.setContent(0, 0); |
| 523 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 524 | // Data data2 ("ndn:/XNBV796f"); |
| 525 | // data2.setContent(0, 0); |
| 526 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 527 | // Data data3 ("ndn:/XNBV794f"); |
| 528 | // data3.setContent(0, 0); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 529 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 530 | // ndn::SignatureSha256WithRsa fakeSignature; |
| 531 | // 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] | 532 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 533 | // // set fake signature on data1 and data2 |
| 534 | // data1.setSignature(fakeSignature); |
| 535 | // data2.setSignature(fakeSignature); |
| 536 | // data3.setSignature(fakeSignature); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 537 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 538 | // m_face2->sendInterest(interest2); |
| 539 | // m_face2->sendData (data2 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 540 | // |
| 541 | // m_limitedIoRemaining = 3; //2 send + 1 listen return |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 542 | // g_io.run(); |
| 543 | // g_io.reset(); |
| 544 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 545 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 546 | // BOOST_REQUIRE(static_cast<bool>(m_face1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 547 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 548 | // m_face1->sendInterest(interest1); |
| 549 | // m_face1->sendData (data1 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 550 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 551 | // abortEvent = |
| 552 | // scheduler.scheduleEvent(time::seconds(1), |
| 553 | // bind(&EndToEndFixture::abortTestCase, this, |
| 554 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 555 | // m_limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 556 | // g_io.run(); |
| 557 | // g_io.reset(); |
| 558 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 559 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 560 | // BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 561 | // BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
| 562 | // BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1); |
| 563 | // BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 564 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 565 | // BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName()); |
| 566 | // BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName()); |
| 567 | // BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName()); |
| 568 | // BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 569 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 570 | // //checking if the connection accepting mechanism works properly. |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 571 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 572 | // m_face2->sendData (data3 ); |
| 573 | // m_face2->sendInterest(interest3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 574 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 575 | // abortEvent = |
| 576 | // scheduler.scheduleEvent(time::seconds(1), |
| 577 | // bind(&EndToEndFixture::abortTestCase, this, |
| 578 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 579 | // m_limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 580 | // g_io.run(); |
| 581 | // g_io.reset(); |
| 582 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 583 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 584 | // BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 2); |
| 585 | // BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 2); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 586 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 587 | // BOOST_CHECK_EQUAL(m_face1_receivedInterests[1].getName(), interest3.getName()); |
| 588 | // BOOST_CHECK_EQUAL(m_face1_receivedDatas [1].getName(), data3.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 589 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 590 | //} |
| 591 | |
| 592 | |
| 593 | //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 594 | //BOOST_FIXTURE_TEST_CASE(MultipleAcceptsIpv6, EndToEndFixture) |
| 595 | //{ |
| 596 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 597 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 598 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 599 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 600 | // UdpFactory factory = UdpFactory(); |
| 601 | // 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] | 602 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 603 | // EventId abortEvent = |
| 604 | // scheduler.scheduleEvent(time::seconds(4), |
| 605 | // bind(&EndToEndFixture::abortTestCase, this, |
| 606 | // "UdpChannel error: cannot connect or cannot accept connection")); |
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 | // shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 609 | // shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 610 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 611 | // channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 612 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 613 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 614 | // channel2->connect("::1", "20070", |
| 615 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 616 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 617 | // |
| 618 | // m_limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 619 | // g_io.run(); |
| 620 | // g_io.reset(); |
| 621 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 622 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 623 | // BOOST_CHECK_EQUAL(m_faces.size(), 1); |
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 | // shared_ptr<UdpChannel> channel3 = factory.createChannel("::1", "20072"); |
| 626 | // channel3->connect("::1", "20070", |
| 627 | // bind(&EndToEndFixture::channel3_onFaceCreated, this, _1), |
| 628 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 629 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 630 | // shared_ptr<UdpChannel> channel4 = factory.createChannel("::1", "20073"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 631 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 632 | // BOOST_CHECK_NE(channel3, channel4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 633 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 634 | // scheduler |
| 635 | // .scheduleEvent(time::seconds(0.5), |
| 636 | // bind(&UdpChannel::connect, channel4, |
| 637 | // "::1", "20070", |
| 638 | // static_cast<UdpChannel::FaceCreatedCallback>(bind(&EndToEndFixture:: |
| 639 | // channel_onFaceCreated, this, _1)), |
| 640 | // static_cast<UdpChannel::ConnectFailedCallback>(bind(&EndToEndFixture:: |
| 641 | // channel_onConnectFailed, this, _1)))); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 642 | // |
| 643 | // m_limitedIoRemaining = 2; // 2 connects |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 644 | // abortEvent = |
| 645 | // scheduler.scheduleEvent(time::seconds(4), |
| 646 | // bind(&EndToEndFixture::abortTestCase, this, |
| 647 | // "UdpChannel error: cannot connect or cannot accept multiple connections")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 648 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 649 | // scheduler.scheduleEvent(time::seconds(0.4), |
| 650 | // bind(&EndToEndFixture::checkFaceList, this, 2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 651 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 652 | // g_io.run(); |
| 653 | // g_io.reset(); |
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_CHECK_EQUAL(m_faces.size(), 3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 656 | // |
| 657 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 658 | // m_face2->sendInterest(interest1); |
| 659 | // abortEvent = |
| 660 | // scheduler.scheduleEvent(time::seconds(1), |
| 661 | // bind(&EndToEndFixture::abortTestCase, this, |
| 662 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 663 | // m_limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 664 | // g_io.run(); |
| 665 | // g_io.reset(); |
| 666 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 667 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 668 | // BOOST_CHECK_EQUAL(m_faces.size(), 4); |
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 | // m_face3->sendInterest(interest2); |
| 671 | // abortEvent = |
| 672 | // scheduler.scheduleEvent(time::seconds(1), |
| 673 | // bind(&EndToEndFixture::abortTestCase, this, |
| 674 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 675 | // m_limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 676 | // g_io.run(); |
| 677 | // g_io.reset(); |
| 678 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 679 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 680 | // //channel1 should have created 2 faces, one when m_face2 sent an interest, one when m_face3 sent an interest |
| 681 | // BOOST_CHECK_EQUAL(m_faces.size(), 5); |
| 682 | // BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, |
| 683 | // this, |
| 684 | // _1), |
| 685 | // bind(&EndToEndFixture::channel_onConnectFailedOk, |
| 686 | // this, |
| 687 | // _1)), |
| 688 | // UdpChannel::Error); |
| 689 | //} |
| 690 | |
| 691 | |
| 692 | BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture) |
| 693 | { |
| 694 | UdpFactory factory = UdpFactory(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 695 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 696 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 697 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
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 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 700 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 701 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 702 | channel2->connect("127.0.0.1", "20070", |
| 703 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 704 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 705 | |
| 706 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 707 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 708 | |
| 709 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
| 710 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 711 | BOOST_CHECK(static_cast<bool>(m_face2)); |
| 712 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 713 | // Face::close must be invoked during io run to be counted as an op |
| 714 | scheduler::schedule(time::seconds(0.1), bind(&Face::close, m_face2)); |
| 715 | |
| 716 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 717 | "FaceClosing error: cannot properly close faces"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 718 | |
| 719 | BOOST_CHECK(!static_cast<bool>(m_face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 720 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 721 | BOOST_CHECK_EQUAL(channel2->size(), 0); |
| 722 | } |
| 723 | |
| 724 | //BOOST_FIXTURE_TEST_CASE(MulticastFace, EndToEndFixture) |
| 725 | //{ |
| 726 | // //to instantiate multicast face on a specific ip address, change interfaceIp |
| 727 | // std::string interfaceIp = "0.0.0.0"; |
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 | // UdpFactory factory = UdpFactory(); |
| 730 | // 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] | 731 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 732 | // shared_ptr<MulticastUdpFace> multicastFace1 = |
| 733 | // factory.createMulticastFace(interfaceIp, "224.0.0.1", "20072"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 734 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 735 | // BOOST_REQUIRE(static_cast<bool>(multicastFace1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 736 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 737 | // channel1_onFaceCreated(multicastFace1); |
| 738 | // |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 739 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 740 | // EventId abortEvent = |
| 741 | // scheduler.scheduleEvent(time::seconds(10), |
| 742 | // bind(&EndToEndFixture::abortTestCase, this, |
| 743 | // "MulticastFace error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 744 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 745 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 746 | // Data data1 ("ndn:/KfczhUqVix"); |
| 747 | // data1.setContent(0, 0); |
| 748 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 749 | // Data data2 ("ndn:/XNBV796f"); |
| 750 | // data2.setContent(0, 0); |
| 751 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 752 | // Data data3 ("ndn:/XNBV794f"); |
| 753 | // data3.setContent(0, 0); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 754 | // |
| 755 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 756 | // ndn::SignatureSha256WithRsa fakeSignature; |
| 757 | // 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] | 758 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 759 | // // set fake signature on data1 and data2 |
| 760 | // data1.setSignature(fakeSignature); |
| 761 | // data2.setSignature(fakeSignature); |
| 762 | // data3.setSignature(fakeSignature); |
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 | // multicastFace1->sendInterest(interest1); |
| 765 | // multicastFace1->sendData (data1 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 766 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 767 | // g_io.reset(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 768 | // m_limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 769 | // g_io.run(); |
| 770 | // g_io.reset(); |
| 771 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 772 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 773 | // BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 774 | // BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 775 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 776 | // BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest1.getName()); |
| 777 | // BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data1.getName()); |
| 778 | //} |
| 779 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 780 | |
| 781 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 782 | BOOST_AUTO_TEST_SUITE_END() |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 783 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 784 | } // namespace tests |
| 785 | } // namespace nfd |