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 | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 60 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 61 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
| 62 | BOOST_CHECK_NE(channel1, channel2); |
| 63 | |
| 64 | shared_ptr<UdpChannel> channel3 = factory.createChannel(interfaceIp, "20070"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 65 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 66 | //same endpoint of a unicast channel |
| 67 | BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, |
| 68 | "224.0.0.1", |
| 69 | "20070"), |
| 70 | UdpFactory::Error, |
| 71 | isTheSameUnicastEndpoint); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 72 | |
| 73 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 74 | shared_ptr<MulticastUdpFace> multicastFace1 = factory.createMulticastFace(interfaceIp, |
| 75 | "224.0.0.1", |
| 76 | "20072"); |
| 77 | shared_ptr<MulticastUdpFace> multicastFace1a = factory.createMulticastFace(interfaceIp, |
| 78 | "224.0.0.1", |
| 79 | "20072"); |
| 80 | BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 81 | |
| 82 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 83 | //same endpoint of a multicast face |
| 84 | BOOST_CHECK_EXCEPTION(factory.createChannel(interfaceIp, "20072"), |
| 85 | UdpFactory::Error, |
| 86 | isTheSameMulticastEndpoint); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 87 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 88 | //same multicast endpoint, different group |
| 89 | BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, |
| 90 | "224.0.0.42", |
| 91 | "20072"), |
| 92 | UdpFactory::Error, |
| 93 | isLocalEndpointOnDifferentGroup); |
| 94 | |
| 95 | BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp, |
| 96 | "192.168.10.15", |
| 97 | "20025"), |
| 98 | UdpFactory::Error, |
| 99 | isNotMulticastAddress); |
| 100 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 101 | |
| 102 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 103 | // //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 104 | // shared_ptr<UdpChannel> channel1v6 = factory.createChannel(//"::1", |
| 105 | // "fe80::5e96:9dff:fe7d:9c8d%en1", |
| 106 | // //"fe80::aa54:b2ff:fe08:27b8%wlan0", |
| 107 | // "20070"); |
| 108 | // |
| 109 | // //the creation of multicastFace2 works properly. It has been disable because it needs an IP address of |
| 110 | // //an available network interface (different from the first one used) |
| 111 | // shared_ptr<MulticastUdpFace> multicastFace2 = factory.createMulticastFace("192.168.1.17", |
| 112 | // "224.0.0.1", |
| 113 | // "20073"); |
| 114 | // BOOST_CHECK_NE(multicastFace1, multicastFace2); |
| 115 | // |
| 116 | // |
| 117 | // //ipv6 - work in progress |
| 118 | // shared_ptr<MulticastUdpFace> multicastFace3 = factory.createMulticastFace("fe80::5e96:9dff:fe7d:9c8d%en1", |
| 119 | // "FF01:0:0:0:0:0:0:2", |
| 120 | // "20073"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 121 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 122 | // shared_ptr<MulticastUdpFace> multicastFace4 = factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0", |
| 123 | // "FF01:0:0:0:0:0:0:2", |
| 124 | // "20073"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 125 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 126 | // BOOST_CHECK_EQUAL(multicastFace3, multicastFace4); |
| 127 | // |
| 128 | // shared_ptr<MulticastUdpFace> multicastFace5 = factory.createMulticastFace("::1", |
| 129 | // "FF01:0:0:0:0:0:0:2", |
| 130 | // "20073"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 131 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 132 | // BOOST_CHECK_NE(multicastFace3, multicastFace5); |
| 133 | // |
| 134 | // //same local ipv6 endpoint for a different multicast group |
| 135 | // BOOST_CHECK_THROW(factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0", |
| 136 | // "FE01:0:0:0:0:0:0:2", |
| 137 | // "20073"), |
| 138 | // UdpFactory::Error); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 139 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 140 | // //same local ipv6 (expect for th port number) endpoint for a different multicast group |
| 141 | // BOOST_CHECK_THROW(factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0", |
| 142 | // "FE01:0:0:0:0:0:0:2", |
| 143 | // "20075"), |
| 144 | // UdpFactory::Error); |
| 145 | // |
| 146 | // BOOST_CHECK_THROW(factory.createMulticastFace("fa80::20a:9dff:fef6:12ff", |
| 147 | // "FE12:0:0:0:0:0:0:2", |
| 148 | // "20075"), |
| 149 | // UdpFactory::Error); |
| 150 | // |
| 151 | // //not a multicast ipv6 |
| 152 | // BOOST_CHECK_THROW(factory.createMulticastFace("fa80::20a:9dff:fef6:12ff", |
| 153 | // "A112:0:0:0:0:0:0:2", |
| 154 | // "20075"), |
| 155 | // UdpFactory::Error); |
| 156 | |
| 157 | |
| 158 | |
| 159 | } |
| 160 | |
| 161 | class EndToEndFixture : protected BaseFixture |
| 162 | { |
| 163 | public: |
| 164 | void |
| 165 | channel1_onFaceCreated(const shared_ptr<UdpFace>& newFace) |
| 166 | { |
| 167 | BOOST_CHECK(!static_cast<bool>(m_face1)); |
| 168 | m_face1 = newFace; |
| 169 | m_face1->onReceiveInterest += |
| 170 | bind(&EndToEndFixture::face1_onReceiveInterest, this, _1); |
| 171 | m_face1->onReceiveData += |
| 172 | bind(&EndToEndFixture::face1_onReceiveData, this, _1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 173 | m_face1->onFail += |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 174 | bind(&EndToEndFixture::face1_onFail, this); |
| 175 | BOOST_CHECK_MESSAGE(true, "channel 1 face created"); |
| 176 | |
| 177 | m_faces.push_back(m_face1); |
| 178 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 179 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | void |
| 183 | channel1_onConnectFailed(const std::string& reason) |
| 184 | { |
| 185 | BOOST_CHECK_MESSAGE(false, reason); |
| 186 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 187 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 188 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 189 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 190 | void |
| 191 | face1_onReceiveInterest(const Interest& interest) |
| 192 | { |
| 193 | m_face1_receivedInterests.push_back(interest); |
| 194 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 195 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 196 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 197 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 198 | void |
| 199 | face1_onReceiveData(const Data& data) |
| 200 | { |
| 201 | m_face1_receivedDatas.push_back(data); |
| 202 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 203 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void |
| 207 | face1_onFail() |
| 208 | { |
| 209 | m_face1.reset(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 210 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | void |
| 214 | channel2_onFaceCreated(const shared_ptr<Face>& newFace) |
| 215 | { |
| 216 | BOOST_CHECK(!static_cast<bool>(m_face2)); |
| 217 | m_face2 = newFace; |
| 218 | m_face2->onReceiveInterest += |
| 219 | bind(&EndToEndFixture::face2_onReceiveInterest, this, _1); |
| 220 | m_face2->onReceiveData += |
| 221 | bind(&EndToEndFixture::face2_onReceiveData, this, _1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 222 | m_face2->onFail += |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 223 | bind(&EndToEndFixture::face2_onFail, this); |
| 224 | |
| 225 | m_faces.push_back(m_face2); |
| 226 | |
| 227 | BOOST_CHECK_MESSAGE(true, "channel 2 face created"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 228 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 229 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 230 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 231 | void |
| 232 | channel2_onConnectFailed(const std::string& reason) |
| 233 | { |
| 234 | BOOST_CHECK_MESSAGE(false, reason); |
| 235 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 236 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 237 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 238 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 239 | void |
| 240 | face2_onReceiveInterest(const Interest& interest) |
| 241 | { |
| 242 | m_face2_receivedInterests.push_back(interest); |
| 243 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 244 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 245 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 246 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 247 | void |
| 248 | face2_onReceiveData(const Data& data) |
| 249 | { |
| 250 | m_face2_receivedDatas.push_back(data); |
| 251 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 252 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | void |
| 256 | face2_onFail() |
| 257 | { |
| 258 | m_face2.reset(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 259 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | void |
| 263 | channel3_onFaceCreated(const shared_ptr<Face>& newFace) |
| 264 | { |
| 265 | BOOST_CHECK(!static_cast<bool>(m_face1)); |
| 266 | m_face3 = newFace; |
| 267 | m_faces.push_back(newFace); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 268 | |
| 269 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 270 | } |
| 271 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 272 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 273 | void |
| 274 | channel_onFaceCreated(const shared_ptr<UdpFace>& newFace) |
| 275 | { |
| 276 | m_faces.push_back(newFace); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 277 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void |
| 281 | channel_onConnectFailed(const std::string& reason) |
| 282 | { |
| 283 | BOOST_CHECK_MESSAGE(false, reason); |
| 284 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 285 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | void |
| 289 | channel_onConnectFailedOk(const std::string& reason) |
| 290 | { |
| 291 | //it's ok, it was supposed to fail |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 292 | m_limitedIo.afterOp(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | void |
| 296 | checkFaceList(size_t shouldBe) |
| 297 | { |
| 298 | BOOST_CHECK_EQUAL(m_faces.size(), shouldBe); |
| 299 | } |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 300 | |
| 301 | public: |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 302 | LimitedIo m_limitedIo; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 303 | |
| 304 | shared_ptr<Face> m_face1; |
| 305 | std::vector<Interest> m_face1_receivedInterests; |
| 306 | std::vector<Data> m_face1_receivedDatas; |
| 307 | shared_ptr<Face> m_face2; |
| 308 | std::vector<Interest> m_face2_receivedInterests; |
| 309 | std::vector<Data> m_face2_receivedDatas; |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 310 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 311 | shared_ptr<Face> m_face3; |
| 312 | |
| 313 | |
| 314 | std::list< shared_ptr<Face> > m_faces; |
| 315 | }; |
| 316 | |
| 317 | |
| 318 | BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture) |
| 319 | { |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 320 | UdpFactory factory; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 321 | |
| 322 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 323 | |
| 324 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 325 | //channel2->connect("127.0.0.1", "20070", |
| 326 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 327 | // bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 328 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 329 | factory.createFace(FaceUri("udp4://127.0.0.1:20070"), |
| 330 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 331 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 332 | |
| 333 | |
| 334 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 335 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 336 | |
| 337 | BOOST_REQUIRE(static_cast<bool>(m_face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 338 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 339 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 340 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 341 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 342 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 343 | |
| 344 | Interest interest1("ndn:/TpnzGvW9R"); |
| 345 | Data data1 ("ndn:/KfczhUqVix"); |
| 346 | data1.setContent(0, 0); |
| 347 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 348 | Data data2 ("ndn:/XNBV796f"); |
| 349 | data2.setContent(0, 0); |
| 350 | Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 351 | Data data3 ("ndn:/XNBV794f"); |
| 352 | data3.setContent(0, 0); |
| 353 | |
| 354 | |
| 355 | ndn::SignatureSha256WithRsa fakeSignature; |
| 356 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 357 | reinterpret_cast<const uint8_t*>(0), |
| 358 | 0)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 359 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 360 | // set fake signature on data1 and data2 |
| 361 | data1.setSignature(fakeSignature); |
| 362 | data2.setSignature(fakeSignature); |
| 363 | data3.setSignature(fakeSignature); |
| 364 | |
| 365 | m_face2->sendInterest(interest2); |
| 366 | m_face2->sendData (data2 ); |
| 367 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 368 | BOOST_CHECK_MESSAGE(m_limitedIo.run(3,//2 send + 1 listen return |
| 369 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 370 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 371 | |
| 372 | BOOST_REQUIRE(static_cast<bool>(m_face1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 373 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 374 | m_face1->sendInterest(interest1); |
| 375 | m_face1->sendData (data1 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 376 | |
| 377 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 378 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 379 | |
| 380 | |
| 381 | BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 382 | BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
| 383 | BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1); |
| 384 | BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
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 | BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName()); |
| 387 | BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName()); |
| 388 | BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName()); |
| 389 | BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 390 | |
| 391 | |
| 392 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 393 | //checking if the connection accepting mechanism works properly. |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 394 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 395 | m_face2->sendData (data3 ); |
| 396 | m_face2->sendInterest(interest3); |
| 397 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 398 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 399 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 400 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 401 | BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 2); |
| 402 | BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 2); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 403 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 404 | BOOST_CHECK_EQUAL(m_face1_receivedInterests[1].getName(), interest3.getName()); |
| 405 | BOOST_CHECK_EQUAL(m_face1_receivedDatas [1].getName(), data3.getName()); |
| 406 | |
| 407 | } |
| 408 | |
| 409 | BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) |
| 410 | { |
| 411 | Interest interest1("ndn:/TpnzGvW9R"); |
| 412 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 413 | Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 414 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 415 | UdpFactory factory; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 416 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 417 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 418 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 419 | |
| 420 | |
| 421 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 422 | channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 423 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 424 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 425 | channel2->connect("127.0.0.1", "20070", |
| 426 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 427 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 428 | |
| 429 | |
| 430 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 431 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 432 | |
| 433 | BOOST_CHECK_EQUAL(m_faces.size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 434 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 435 | shared_ptr<UdpChannel> channel3 = factory.createChannel("127.0.0.1", "20072"); |
| 436 | channel3->connect("127.0.0.1", "20070", |
| 437 | bind(&EndToEndFixture::channel3_onFaceCreated, this, _1), |
| 438 | bind(&EndToEndFixture::channel_onConnectFailed, this, _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> channel4 = factory.createChannel("127.0.0.1", "20073"); |
| 441 | |
| 442 | BOOST_CHECK_NE(channel3, channel4); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 443 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 444 | scheduler::schedule(time::seconds(0.5), |
| 445 | bind(&UdpChannel::connect, channel4, "127.0.0.1", "20070", |
| 446 | // does not work without static_cast |
| 447 | static_cast<UdpChannel::FaceCreatedCallback>( |
| 448 | bind(&EndToEndFixture::channel_onFaceCreated, this, _1)), |
| 449 | static_cast<UdpChannel::ConnectFailedCallback>( |
| 450 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)))); |
| 451 | |
| 452 | scheduler::schedule(time::seconds(0.4), bind(&EndToEndFixture::checkFaceList, this, 2)); |
| 453 | |
| 454 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2,// 2 connects |
| 455 | time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 456 | "UdpChannel error: cannot connect or cannot accept multiple connections"); |
| 457 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 458 | BOOST_CHECK_EQUAL(m_faces.size(), 3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 459 | |
| 460 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 461 | m_face2->sendInterest(interest1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 462 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 463 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 464 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 465 | BOOST_CHECK_EQUAL(m_faces.size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 466 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 467 | m_face3->sendInterest(interest2); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 468 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 469 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 470 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 471 | //channel1 should have created 2 faces, one when m_face2 sent an interest, one when m_face3 sent an interest |
| 472 | BOOST_CHECK_EQUAL(m_faces.size(), 5); |
| 473 | BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, |
| 474 | this, |
| 475 | _1), |
| 476 | bind(&EndToEndFixture::channel_onConnectFailedOk, |
| 477 | this, |
| 478 | _1)), |
| 479 | UdpChannel::Error); |
| 480 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 481 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 482 | //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 483 | //BOOST_FIXTURE_TEST_CASE(EndToEndIpv6, EndToEndFixture) |
| 484 | //{ |
| 485 | // UdpFactory factory = UdpFactory(); |
| 486 | // 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^] | 487 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 488 | // EventId abortEvent = |
| 489 | // scheduler.scheduleEvent(time::seconds(1), |
| 490 | // bind(&EndToEndFixture::abortTestCase, this, |
| 491 | // "UdpChannel error: cannot connect or cannot accept connection")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 492 | // |
| 493 | // m_limitedIoRemaining = 1; |
| 494 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 495 | // shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 496 | // shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 497 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 498 | // channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 499 | // bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 500 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 501 | // channel2->connect("::1", "20070", |
| 502 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 503 | // bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
| 504 | // g_io.run(); |
| 505 | // g_io.reset(); |
| 506 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 507 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 508 | // BOOST_REQUIRE(static_cast<bool>(m_face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 509 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 510 | // abortEvent = |
| 511 | // scheduler.scheduleEvent(time::seconds(1), |
| 512 | // bind(&EndToEndFixture::abortTestCase, this, |
| 513 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
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 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 516 | // Data data1 ("ndn:/KfczhUqVix"); |
| 517 | // data1.setContent(0, 0); |
| 518 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 519 | // Data data2 ("ndn:/XNBV796f"); |
| 520 | // data2.setContent(0, 0); |
| 521 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 522 | // Data data3 ("ndn:/XNBV794f"); |
| 523 | // data3.setContent(0, 0); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 524 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 525 | // ndn::SignatureSha256WithRsa fakeSignature; |
| 526 | // 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^] | 527 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 528 | // // set fake signature on data1 and data2 |
| 529 | // data1.setSignature(fakeSignature); |
| 530 | // data2.setSignature(fakeSignature); |
| 531 | // data3.setSignature(fakeSignature); |
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 | // m_face2->sendInterest(interest2); |
| 534 | // m_face2->sendData (data2 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 535 | // |
| 536 | // m_limitedIoRemaining = 3; //2 send + 1 listen return |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 537 | // g_io.run(); |
| 538 | // g_io.reset(); |
| 539 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 540 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 541 | // BOOST_REQUIRE(static_cast<bool>(m_face1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 542 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 543 | // m_face1->sendInterest(interest1); |
| 544 | // m_face1->sendData (data1 ); |
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 | // abortEvent = |
| 547 | // scheduler.scheduleEvent(time::seconds(1), |
| 548 | // bind(&EndToEndFixture::abortTestCase, this, |
| 549 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 550 | // m_limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 551 | // g_io.run(); |
| 552 | // g_io.reset(); |
| 553 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 554 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 555 | // BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 556 | // BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
| 557 | // BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1); |
| 558 | // BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
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_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName()); |
| 561 | // BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName()); |
| 562 | // BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName()); |
| 563 | // BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName()); |
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 | // //checking if the connection accepting mechanism works properly. |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 566 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 567 | // m_face2->sendData (data3 ); |
| 568 | // m_face2->sendInterest(interest3); |
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 | // abortEvent = |
| 571 | // scheduler.scheduleEvent(time::seconds(1), |
| 572 | // bind(&EndToEndFixture::abortTestCase, this, |
| 573 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 574 | // m_limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 575 | // g_io.run(); |
| 576 | // g_io.reset(); |
| 577 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 578 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 579 | // BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 2); |
| 580 | // BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 2); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 581 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 582 | // BOOST_CHECK_EQUAL(m_face1_receivedInterests[1].getName(), interest3.getName()); |
| 583 | // BOOST_CHECK_EQUAL(m_face1_receivedDatas [1].getName(), data3.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 584 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 585 | //} |
| 586 | |
| 587 | |
| 588 | //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 589 | //BOOST_FIXTURE_TEST_CASE(MultipleAcceptsIpv6, EndToEndFixture) |
| 590 | //{ |
| 591 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 592 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 593 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 594 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 595 | // UdpFactory factory = UdpFactory(); |
| 596 | // 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^] | 597 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 598 | // EventId abortEvent = |
| 599 | // scheduler.scheduleEvent(time::seconds(4), |
| 600 | // bind(&EndToEndFixture::abortTestCase, this, |
| 601 | // "UdpChannel error: cannot connect or cannot accept connection")); |
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 | // shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 604 | // shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 605 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 606 | // channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 607 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 608 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 609 | // channel2->connect("::1", "20070", |
| 610 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 611 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 612 | // |
| 613 | // m_limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 614 | // g_io.run(); |
| 615 | // g_io.reset(); |
| 616 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 617 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 618 | // BOOST_CHECK_EQUAL(m_faces.size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 619 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 620 | // shared_ptr<UdpChannel> channel3 = factory.createChannel("::1", "20072"); |
| 621 | // channel3->connect("::1", "20070", |
| 622 | // bind(&EndToEndFixture::channel3_onFaceCreated, this, _1), |
| 623 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _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> channel4 = factory.createChannel("::1", "20073"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 626 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 627 | // BOOST_CHECK_NE(channel3, channel4); |
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 | // scheduler |
| 630 | // .scheduleEvent(time::seconds(0.5), |
| 631 | // bind(&UdpChannel::connect, channel4, |
| 632 | // "::1", "20070", |
| 633 | // static_cast<UdpChannel::FaceCreatedCallback>(bind(&EndToEndFixture:: |
| 634 | // channel_onFaceCreated, this, _1)), |
| 635 | // static_cast<UdpChannel::ConnectFailedCallback>(bind(&EndToEndFixture:: |
| 636 | // channel_onConnectFailed, this, _1)))); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 637 | // |
| 638 | // m_limitedIoRemaining = 2; // 2 connects |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 639 | // abortEvent = |
| 640 | // scheduler.scheduleEvent(time::seconds(4), |
| 641 | // bind(&EndToEndFixture::abortTestCase, this, |
| 642 | // "UdpChannel error: cannot connect or cannot accept multiple connections")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 643 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 644 | // scheduler.scheduleEvent(time::seconds(0.4), |
| 645 | // bind(&EndToEndFixture::checkFaceList, this, 2)); |
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 | // g_io.run(); |
| 648 | // g_io.reset(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 649 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 650 | // BOOST_CHECK_EQUAL(m_faces.size(), 3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 651 | // |
| 652 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 653 | // m_face2->sendInterest(interest1); |
| 654 | // abortEvent = |
| 655 | // scheduler.scheduleEvent(time::seconds(1), |
| 656 | // bind(&EndToEndFixture::abortTestCase, this, |
| 657 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 658 | // m_limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 659 | // g_io.run(); |
| 660 | // g_io.reset(); |
| 661 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 662 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 663 | // BOOST_CHECK_EQUAL(m_faces.size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 664 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 665 | // m_face3->sendInterest(interest2); |
| 666 | // abortEvent = |
| 667 | // scheduler.scheduleEvent(time::seconds(1), |
| 668 | // bind(&EndToEndFixture::abortTestCase, this, |
| 669 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 670 | // m_limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 671 | // g_io.run(); |
| 672 | // g_io.reset(); |
| 673 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 674 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 675 | // //channel1 should have created 2 faces, one when m_face2 sent an interest, one when m_face3 sent an interest |
| 676 | // BOOST_CHECK_EQUAL(m_faces.size(), 5); |
| 677 | // BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, |
| 678 | // this, |
| 679 | // _1), |
| 680 | // bind(&EndToEndFixture::channel_onConnectFailedOk, |
| 681 | // this, |
| 682 | // _1)), |
| 683 | // UdpChannel::Error); |
| 684 | //} |
| 685 | |
| 686 | |
| 687 | BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture) |
| 688 | { |
| 689 | UdpFactory factory = UdpFactory(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 690 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 691 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 692 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 693 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 694 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 695 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 696 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 697 | channel2->connect("127.0.0.1", "20070", |
| 698 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 699 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 700 | |
| 701 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 702 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 703 | |
| 704 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
| 705 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 706 | BOOST_CHECK(static_cast<bool>(m_face2)); |
| 707 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 708 | // Face::close must be invoked during io run to be counted as an op |
| 709 | scheduler::schedule(time::seconds(0.1), bind(&Face::close, m_face2)); |
| 710 | |
| 711 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 712 | "FaceClosing error: cannot properly close faces"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 713 | |
| 714 | BOOST_CHECK(!static_cast<bool>(m_face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 715 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 716 | BOOST_CHECK_EQUAL(channel2->size(), 0); |
| 717 | } |
| 718 | |
| 719 | //BOOST_FIXTURE_TEST_CASE(MulticastFace, EndToEndFixture) |
| 720 | //{ |
| 721 | // //to instantiate multicast face on a specific ip address, change interfaceIp |
| 722 | // std::string interfaceIp = "0.0.0.0"; |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 723 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 724 | // UdpFactory factory = UdpFactory(); |
| 725 | // 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^] | 726 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 727 | // shared_ptr<MulticastUdpFace> multicastFace1 = |
| 728 | // factory.createMulticastFace(interfaceIp, "224.0.0.1", "20072"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 729 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 730 | // BOOST_REQUIRE(static_cast<bool>(multicastFace1)); |
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 | // channel1_onFaceCreated(multicastFace1); |
| 733 | // |
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 | // EventId abortEvent = |
| 736 | // scheduler.scheduleEvent(time::seconds(10), |
| 737 | // bind(&EndToEndFixture::abortTestCase, this, |
| 738 | // "MulticastFace error: cannot send or receive Interest/Data packets")); |
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 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 741 | // Data data1 ("ndn:/KfczhUqVix"); |
| 742 | // data1.setContent(0, 0); |
| 743 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 744 | // Data data2 ("ndn:/XNBV796f"); |
| 745 | // data2.setContent(0, 0); |
| 746 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 747 | // Data data3 ("ndn:/XNBV794f"); |
| 748 | // data3.setContent(0, 0); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 749 | // |
| 750 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 751 | // ndn::SignatureSha256WithRsa fakeSignature; |
| 752 | // 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^] | 753 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 754 | // // set fake signature on data1 and data2 |
| 755 | // data1.setSignature(fakeSignature); |
| 756 | // data2.setSignature(fakeSignature); |
| 757 | // data3.setSignature(fakeSignature); |
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 | // multicastFace1->sendInterest(interest1); |
| 760 | // multicastFace1->sendData (data1 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 761 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 762 | // g_io.reset(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 763 | // m_limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 764 | // g_io.run(); |
| 765 | // g_io.reset(); |
| 766 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 767 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 768 | // BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 769 | // BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 770 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 771 | // BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest1.getName()); |
| 772 | // BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data1.getName()); |
| 773 | //} |
| 774 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame^] | 775 | |
| 776 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 777 | BOOST_AUTO_TEST_SUITE_END() |
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 | } // namespace tests |
| 780 | } // namespace nfd |