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 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 323 | BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture) |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 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 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 327 | factory.createChannel("127.0.0.1", "20071"); |
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)); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 338 | BOOST_CHECK_EQUAL(m_face2->getUri().toString(), "udp4://127.0.0.1:20070"); |
| 339 | BOOST_CHECK_EQUAL(m_face2->isLocal(), false); |
| 340 | // m_face1 is not created yet |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 341 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 342 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 343 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 344 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 345 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 346 | Interest interest1("ndn:/TpnzGvW9R"); |
| 347 | Data data1 ("ndn:/KfczhUqVix"); |
| 348 | data1.setContent(0, 0); |
| 349 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 350 | Data data2 ("ndn:/XNBV796f"); |
| 351 | data2.setContent(0, 0); |
| 352 | Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 353 | Data data3 ("ndn:/XNBV794f"); |
| 354 | data3.setContent(0, 0); |
| 355 | |
| 356 | |
| 357 | ndn::SignatureSha256WithRsa fakeSignature; |
| 358 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 359 | reinterpret_cast<const uint8_t*>(0), |
| 360 | 0)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 361 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 362 | // set fake signature on data1 and data2 |
| 363 | data1.setSignature(fakeSignature); |
| 364 | data2.setSignature(fakeSignature); |
| 365 | data3.setSignature(fakeSignature); |
| 366 | |
| 367 | m_face2->sendInterest(interest2); |
| 368 | m_face2->sendData (data2 ); |
Alexander Afanasyev | 6f5ff63 | 2014-03-07 16:40:10 +0000 | [diff] [blame^] | 369 | m_face2->sendData (data2 ); |
| 370 | m_face2->sendData (data2 ); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 371 | |
Alexander Afanasyev | 6f5ff63 | 2014-03-07 16:40:10 +0000 | [diff] [blame^] | 372 | BOOST_CHECK_MESSAGE(m_limitedIo.run(5,//4 send + 1 listen return |
| 373 | time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 374 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 375 | |
| 376 | BOOST_REQUIRE(static_cast<bool>(m_face1)); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 377 | BOOST_CHECK_EQUAL(m_face1->getUri().toString(), "udp4://127.0.0.1:20071"); |
| 378 | BOOST_CHECK_EQUAL(m_face1->isLocal(), false); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 379 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 380 | m_face1->sendInterest(interest1); |
Alexander Afanasyev | 6f5ff63 | 2014-03-07 16:40:10 +0000 | [diff] [blame^] | 381 | m_face1->sendInterest(interest1); |
| 382 | m_face1->sendInterest(interest1); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 383 | m_face1->sendData (data1 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 384 | |
Alexander Afanasyev | 6f5ff63 | 2014-03-07 16:40:10 +0000 | [diff] [blame^] | 385 | BOOST_CHECK_MESSAGE(m_limitedIo.run(4, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 386 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 387 | |
| 388 | |
| 389 | BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
Alexander Afanasyev | 6f5ff63 | 2014-03-07 16:40:10 +0000 | [diff] [blame^] | 390 | BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 3); |
| 391 | BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 3); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 392 | BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 393 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 394 | BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName()); |
| 395 | BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName()); |
| 396 | BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName()); |
| 397 | BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 398 | |
| 399 | |
| 400 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 401 | //checking if the connection accepting mechanism works properly. |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 402 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 403 | m_face2->sendData (data3 ); |
| 404 | m_face2->sendInterest(interest3); |
| 405 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 406 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 407 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 408 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 409 | BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 2); |
Alexander Afanasyev | 6f5ff63 | 2014-03-07 16:40:10 +0000 | [diff] [blame^] | 410 | BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 411 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 412 | BOOST_CHECK_EQUAL(m_face1_receivedInterests[1].getName(), interest3.getName()); |
Alexander Afanasyev | 6f5ff63 | 2014-03-07 16:40:10 +0000 | [diff] [blame^] | 413 | BOOST_CHECK_EQUAL(m_face1_receivedDatas [3].getName(), data3.getName()); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 414 | } |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 415 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 416 | BOOST_FIXTURE_TEST_CASE(EndToEnd6, EndToEndFixture) |
| 417 | { |
| 418 | UdpFactory factory; |
| 419 | |
| 420 | factory.createChannel("::1", "20071"); |
| 421 | |
| 422 | factory.createFace(FaceUri("udp://[::1]:20070"), |
| 423 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 424 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
| 425 | |
| 426 | |
| 427 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 428 | "UdpChannel error: cannot connect or cannot accept connection"); |
| 429 | |
| 430 | BOOST_REQUIRE(static_cast<bool>(m_face2)); |
| 431 | BOOST_CHECK_EQUAL(m_face2->getUri().toString(), "udp6://[::1]:20070"); |
| 432 | BOOST_CHECK_EQUAL(m_face2->isLocal(), false); |
| 433 | // m_face1 is not created yet |
| 434 | |
| 435 | shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 436 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 437 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 438 | |
| 439 | Interest interest1("ndn:/TpnzGvW9R"); |
| 440 | Data data1 ("ndn:/KfczhUqVix"); |
| 441 | data1.setContent(0, 0); |
| 442 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 443 | Data data2 ("ndn:/XNBV796f"); |
| 444 | data2.setContent(0, 0); |
| 445 | Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 446 | Data data3 ("ndn:/XNBV794f"); |
| 447 | data3.setContent(0, 0); |
| 448 | |
| 449 | |
| 450 | ndn::SignatureSha256WithRsa fakeSignature; |
| 451 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, |
| 452 | reinterpret_cast<const uint8_t*>(0), |
| 453 | 0)); |
| 454 | |
| 455 | // set fake signature on data1 and data2 |
| 456 | data1.setSignature(fakeSignature); |
| 457 | data2.setSignature(fakeSignature); |
| 458 | data3.setSignature(fakeSignature); |
| 459 | |
| 460 | m_face2->sendInterest(interest2); |
| 461 | m_face2->sendData (data2 ); |
| 462 | |
| 463 | BOOST_CHECK_MESSAGE(m_limitedIo.run(3,//2 send + 1 listen return |
| 464 | time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 465 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 466 | |
| 467 | BOOST_REQUIRE(static_cast<bool>(m_face1)); |
| 468 | BOOST_CHECK_EQUAL(m_face1->getUri().toString(), "udp6://[::1]:20071"); |
| 469 | BOOST_CHECK_EQUAL(m_face1->isLocal(), false); |
| 470 | |
| 471 | m_face1->sendInterest(interest1); |
| 472 | m_face1->sendData (data1 ); |
| 473 | |
| 474 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 475 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 476 | |
| 477 | |
| 478 | BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 479 | BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
| 480 | BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1); |
| 481 | BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
| 482 | |
| 483 | BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName()); |
| 484 | BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName()); |
| 485 | BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName()); |
| 486 | BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName()); |
| 487 | |
| 488 | |
| 489 | |
| 490 | //checking if the connection accepting mechanism works properly. |
| 491 | |
| 492 | m_face2->sendData (data3 ); |
| 493 | m_face2->sendInterest(interest3); |
| 494 | |
| 495 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 496 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 497 | |
| 498 | BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 2); |
| 499 | BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 2); |
| 500 | |
| 501 | BOOST_CHECK_EQUAL(m_face1_receivedInterests[1].getName(), interest3.getName()); |
| 502 | BOOST_CHECK_EQUAL(m_face1_receivedDatas [1].getName(), data3.getName()); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) |
| 506 | { |
| 507 | Interest interest1("ndn:/TpnzGvW9R"); |
| 508 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 509 | Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 510 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 511 | UdpFactory factory; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 512 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 513 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 514 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 515 | |
| 516 | |
| 517 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 518 | channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 519 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 520 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 521 | channel2->connect("127.0.0.1", "20070", |
| 522 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 523 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 524 | |
| 525 | |
| 526 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 527 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 528 | |
| 529 | BOOST_CHECK_EQUAL(m_faces.size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 530 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 531 | shared_ptr<UdpChannel> channel3 = factory.createChannel("127.0.0.1", "20072"); |
| 532 | channel3->connect("127.0.0.1", "20070", |
| 533 | bind(&EndToEndFixture::channel3_onFaceCreated, this, _1), |
| 534 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 535 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 536 | shared_ptr<UdpChannel> channel4 = factory.createChannel("127.0.0.1", "20073"); |
| 537 | |
| 538 | BOOST_CHECK_NE(channel3, channel4); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 539 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 540 | scheduler::schedule(time::seconds(0.5), |
| 541 | bind(&UdpChannel::connect, channel4, "127.0.0.1", "20070", |
| 542 | // does not work without static_cast |
| 543 | static_cast<UdpChannel::FaceCreatedCallback>( |
| 544 | bind(&EndToEndFixture::channel_onFaceCreated, this, _1)), |
| 545 | static_cast<UdpChannel::ConnectFailedCallback>( |
| 546 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)))); |
| 547 | |
| 548 | scheduler::schedule(time::seconds(0.4), bind(&EndToEndFixture::checkFaceList, this, 2)); |
| 549 | |
| 550 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2,// 2 connects |
| 551 | time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 552 | "UdpChannel error: cannot connect or cannot accept multiple connections"); |
| 553 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 554 | BOOST_CHECK_EQUAL(m_faces.size(), 3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 555 | |
| 556 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 557 | m_face2->sendInterest(interest1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 558 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 559 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 560 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 561 | BOOST_CHECK_EQUAL(m_faces.size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 562 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 563 | m_face3->sendInterest(interest2); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 564 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 565 | "UdpChannel error: cannot send or receive Interest/Data packets"); |
| 566 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 567 | //channel1 should have created 2 faces, one when m_face2 sent an interest, one when m_face3 sent an interest |
| 568 | BOOST_CHECK_EQUAL(m_faces.size(), 5); |
| 569 | BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, |
| 570 | this, |
| 571 | _1), |
| 572 | bind(&EndToEndFixture::channel_onConnectFailedOk, |
| 573 | this, |
| 574 | _1)), |
| 575 | UdpChannel::Error); |
| 576 | } |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 577 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 578 | //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 579 | //BOOST_FIXTURE_TEST_CASE(EndToEndIpv6, EndToEndFixture) |
| 580 | //{ |
| 581 | // UdpFactory factory = UdpFactory(); |
| 582 | // 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] | 583 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 584 | // EventId abortEvent = |
| 585 | // scheduler.scheduleEvent(time::seconds(1), |
| 586 | // bind(&EndToEndFixture::abortTestCase, this, |
| 587 | // "UdpChannel error: cannot connect or cannot accept connection")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 588 | // |
| 589 | // m_limitedIoRemaining = 1; |
| 590 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 591 | // shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 592 | // shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 593 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 594 | // channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 595 | // bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 596 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 597 | // channel2->connect("::1", "20070", |
| 598 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 599 | // bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
| 600 | // g_io.run(); |
| 601 | // g_io.reset(); |
| 602 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 603 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 604 | // BOOST_REQUIRE(static_cast<bool>(m_face2)); |
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 | // abortEvent = |
| 607 | // scheduler.scheduleEvent(time::seconds(1), |
| 608 | // bind(&EndToEndFixture::abortTestCase, this, |
| 609 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
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 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 612 | // Data data1 ("ndn:/KfczhUqVix"); |
| 613 | // data1.setContent(0, 0); |
| 614 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 615 | // Data data2 ("ndn:/XNBV796f"); |
| 616 | // data2.setContent(0, 0); |
| 617 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 618 | // Data data3 ("ndn:/XNBV794f"); |
| 619 | // data3.setContent(0, 0); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 620 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 621 | // ndn::SignatureSha256WithRsa fakeSignature; |
| 622 | // 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] | 623 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 624 | // // set fake signature on data1 and data2 |
| 625 | // data1.setSignature(fakeSignature); |
| 626 | // data2.setSignature(fakeSignature); |
| 627 | // data3.setSignature(fakeSignature); |
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 | // m_face2->sendInterest(interest2); |
| 630 | // m_face2->sendData (data2 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 631 | // |
| 632 | // m_limitedIoRemaining = 3; //2 send + 1 listen return |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 633 | // g_io.run(); |
| 634 | // g_io.reset(); |
| 635 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 636 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 637 | // BOOST_REQUIRE(static_cast<bool>(m_face1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 638 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 639 | // m_face1->sendInterest(interest1); |
| 640 | // m_face1->sendData (data1 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 641 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 642 | // abortEvent = |
| 643 | // scheduler.scheduleEvent(time::seconds(1), |
| 644 | // bind(&EndToEndFixture::abortTestCase, this, |
| 645 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 646 | // m_limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 647 | // g_io.run(); |
| 648 | // g_io.reset(); |
| 649 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 650 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 651 | // BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 652 | // BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
| 653 | // BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1); |
| 654 | // BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 655 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 656 | // BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName()); |
| 657 | // BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName()); |
| 658 | // BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName()); |
| 659 | // BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 660 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 661 | // //checking if the connection accepting mechanism works properly. |
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 | // m_face2->sendData (data3 ); |
| 664 | // m_face2->sendInterest(interest3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 665 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 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 = 2; |
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 | // BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 2); |
| 676 | // BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 2); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 677 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 678 | // BOOST_CHECK_EQUAL(m_face1_receivedInterests[1].getName(), interest3.getName()); |
| 679 | // BOOST_CHECK_EQUAL(m_face1_receivedDatas [1].getName(), data3.getName()); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 680 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 681 | //} |
| 682 | |
| 683 | |
| 684 | //Test commented because it required to be run in a machine that can resolve ipv6 query |
| 685 | //BOOST_FIXTURE_TEST_CASE(MultipleAcceptsIpv6, EndToEndFixture) |
| 686 | //{ |
| 687 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 688 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 689 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 690 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 691 | // UdpFactory factory = UdpFactory(); |
| 692 | // 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] | 693 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 694 | // EventId abortEvent = |
| 695 | // scheduler.scheduleEvent(time::seconds(4), |
| 696 | // bind(&EndToEndFixture::abortTestCase, this, |
| 697 | // "UdpChannel error: cannot connect or cannot accept connection")); |
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 | // shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070"); |
| 700 | // shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071"); |
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 | // channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 703 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 704 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 705 | // channel2->connect("::1", "20070", |
| 706 | // bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 707 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 708 | // |
| 709 | // m_limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 710 | // g_io.run(); |
| 711 | // g_io.reset(); |
| 712 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 713 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 714 | // BOOST_CHECK_EQUAL(m_faces.size(), 1); |
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 | // shared_ptr<UdpChannel> channel3 = factory.createChannel("::1", "20072"); |
| 717 | // channel3->connect("::1", "20070", |
| 718 | // bind(&EndToEndFixture::channel3_onFaceCreated, this, _1), |
| 719 | // bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
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 | // shared_ptr<UdpChannel> channel4 = factory.createChannel("::1", "20073"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 722 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 723 | // BOOST_CHECK_NE(channel3, channel4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 724 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 725 | // scheduler |
| 726 | // .scheduleEvent(time::seconds(0.5), |
| 727 | // bind(&UdpChannel::connect, channel4, |
| 728 | // "::1", "20070", |
| 729 | // static_cast<UdpChannel::FaceCreatedCallback>(bind(&EndToEndFixture:: |
| 730 | // channel_onFaceCreated, this, _1)), |
| 731 | // static_cast<UdpChannel::ConnectFailedCallback>(bind(&EndToEndFixture:: |
| 732 | // channel_onConnectFailed, this, _1)))); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 733 | // |
| 734 | // m_limitedIoRemaining = 2; // 2 connects |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 735 | // abortEvent = |
| 736 | // scheduler.scheduleEvent(time::seconds(4), |
| 737 | // bind(&EndToEndFixture::abortTestCase, this, |
| 738 | // "UdpChannel error: cannot connect or cannot accept multiple connections")); |
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 | // scheduler.scheduleEvent(time::seconds(0.4), |
| 741 | // bind(&EndToEndFixture::checkFaceList, this, 2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 742 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 743 | // g_io.run(); |
| 744 | // g_io.reset(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 745 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 746 | // BOOST_CHECK_EQUAL(m_faces.size(), 3); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 747 | // |
| 748 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 749 | // m_face2->sendInterest(interest1); |
| 750 | // abortEvent = |
| 751 | // scheduler.scheduleEvent(time::seconds(1), |
| 752 | // bind(&EndToEndFixture::abortTestCase, this, |
| 753 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 754 | // m_limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 755 | // g_io.run(); |
| 756 | // g_io.reset(); |
| 757 | // scheduler.cancelEvent(abortEvent); |
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 | // BOOST_CHECK_EQUAL(m_faces.size(), 4); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 760 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 761 | // m_face3->sendInterest(interest2); |
| 762 | // abortEvent = |
| 763 | // scheduler.scheduleEvent(time::seconds(1), |
| 764 | // bind(&EndToEndFixture::abortTestCase, this, |
| 765 | // "UdpChannel error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 766 | // m_limitedIoRemaining = 1; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 767 | // g_io.run(); |
| 768 | // g_io.reset(); |
| 769 | // scheduler.cancelEvent(abortEvent); |
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 | // //channel1 should have created 2 faces, one when m_face2 sent an interest, one when m_face3 sent an interest |
| 772 | // BOOST_CHECK_EQUAL(m_faces.size(), 5); |
| 773 | // BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, |
| 774 | // this, |
| 775 | // _1), |
| 776 | // bind(&EndToEndFixture::channel_onConnectFailedOk, |
| 777 | // this, |
| 778 | // _1)), |
| 779 | // UdpChannel::Error); |
| 780 | //} |
| 781 | |
| 782 | |
| 783 | BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture) |
| 784 | { |
| 785 | UdpFactory factory = UdpFactory(); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 786 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 787 | shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 788 | shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 789 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 790 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 791 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 792 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 793 | channel2->connect("127.0.0.1", "20070", |
| 794 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 795 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 796 | |
| 797 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 798 | "UdpChannel error: cannot connect or cannot accept connection"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 799 | |
| 800 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
| 801 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 802 | BOOST_CHECK(static_cast<bool>(m_face2)); |
| 803 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 804 | // Face::close must be invoked during io run to be counted as an op |
| 805 | scheduler::schedule(time::seconds(0.1), bind(&Face::close, m_face2)); |
| 806 | |
| 807 | BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS, |
| 808 | "FaceClosing error: cannot properly close faces"); |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 809 | |
| 810 | BOOST_CHECK(!static_cast<bool>(m_face2)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 811 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 812 | BOOST_CHECK_EQUAL(channel2->size(), 0); |
| 813 | } |
| 814 | |
| 815 | //BOOST_FIXTURE_TEST_CASE(MulticastFace, EndToEndFixture) |
| 816 | //{ |
| 817 | // //to instantiate multicast face on a specific ip address, change interfaceIp |
| 818 | // std::string interfaceIp = "0.0.0.0"; |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 819 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 820 | // UdpFactory factory = UdpFactory(); |
| 821 | // 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] | 822 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 823 | // shared_ptr<MulticastUdpFace> multicastFace1 = |
| 824 | // factory.createMulticastFace(interfaceIp, "224.0.0.1", "20072"); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 825 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 826 | // BOOST_REQUIRE(static_cast<bool>(multicastFace1)); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 827 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 828 | // channel1_onFaceCreated(multicastFace1); |
| 829 | // |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 830 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 831 | // EventId abortEvent = |
| 832 | // scheduler.scheduleEvent(time::seconds(10), |
| 833 | // bind(&EndToEndFixture::abortTestCase, this, |
| 834 | // "MulticastFace error: cannot send or receive Interest/Data packets")); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 835 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 836 | // Interest interest1("ndn:/TpnzGvW9R"); |
| 837 | // Data data1 ("ndn:/KfczhUqVix"); |
| 838 | // data1.setContent(0, 0); |
| 839 | // Interest interest2("ndn:/QWiIMfj5sL"); |
| 840 | // Data data2 ("ndn:/XNBV796f"); |
| 841 | // data2.setContent(0, 0); |
| 842 | // Interest interest3("ndn:/QWiIhjgkj5sL"); |
| 843 | // Data data3 ("ndn:/XNBV794f"); |
| 844 | // data3.setContent(0, 0); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 845 | // |
| 846 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 847 | // ndn::SignatureSha256WithRsa fakeSignature; |
| 848 | // 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] | 849 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 850 | // // set fake signature on data1 and data2 |
| 851 | // data1.setSignature(fakeSignature); |
| 852 | // data2.setSignature(fakeSignature); |
| 853 | // data3.setSignature(fakeSignature); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 854 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 855 | // multicastFace1->sendInterest(interest1); |
| 856 | // multicastFace1->sendData (data1 ); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 857 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 858 | // g_io.reset(); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 859 | // m_limitedIoRemaining = 2; |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 860 | // g_io.run(); |
| 861 | // g_io.reset(); |
| 862 | // scheduler.cancelEvent(abortEvent); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 863 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 864 | // BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 865 | // BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 866 | // |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 867 | // BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest1.getName()); |
| 868 | // BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data1.getName()); |
| 869 | //} |
| 870 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 871 | |
| 872 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 873 | BOOST_AUTO_TEST_SUITE_END() |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 874 | |
Giulio Grassi | 624f6c6 | 2014-02-18 19:42:14 +0100 | [diff] [blame] | 875 | } // namespace tests |
| 876 | } // namespace nfd |