blob: bab2f2baaaf8c2e8bb09925a4fafde835110580f [file] [log] [blame]
Giulio Grassi624f6c62014-02-18 19:42:14 +01001/* -*- 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 Grassi624f6c62014-02-18 19:42:14 +01008#include "core/face-uri.hpp"
Giulio Grassi624f6c62014-02-18 19:42:14 +01009#include <ndn-cpp-dev/security/key-chain.hpp>
Junxiao Shi7e2413b2014-03-02 11:15:09 -070010
11#include "tests/test-common.hpp"
12#include "tests/core/limited-io.hpp"
Giulio Grassi624f6c62014-02-18 19:42:14 +010013
14namespace nfd {
15namespace tests {
16
17BOOST_FIXTURE_TEST_SUITE(FaceUdp, BaseFixture)
18
19class FactoryErrorCheck : protected BaseFixture
20{
21public:
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 Shi7e2413b2014-03-02 11:15:09 -070027
Giulio Grassi624f6c62014-02-18 19:42:14 +010028 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 Shi7e2413b2014-03-02 11:15:09 -070033
Giulio Grassi624f6c62014-02-18 19:42:14 +010034 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 Shi7e2413b2014-03-02 11:15:09 -070039
Giulio Grassi624f6c62014-02-18 19:42:14 +010040 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 Shi7e2413b2014-03-02 11:15:09 -070047
Giulio Grassi624f6c62014-02-18 19:42:14 +010048BOOST_FIXTURE_TEST_CASE(ChannelMapUdp, FactoryErrorCheck)
49{
50 using boost::asio::ip::udp;
Junxiao Shi7e2413b2014-03-02 11:15:09 -070051
Giulio Grassi624f6c62014-02-18 19:42:14 +010052 UdpFactory factory = UdpFactory();
Junxiao Shi7e2413b2014-03-02 11:15:09 -070053
Giulio Grassi624f6c62014-02-18 19:42:14 +010054 //to instantiate multicast face on a specific ip address, change interfaceIp
55 std::string interfaceIp = "0.0.0.0";
Junxiao Shi7e2413b2014-03-02 11:15:09 -070056
Giulio Grassi624f6c62014-02-18 19:42:14 +010057 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 Shi61e3cc52014-03-03 20:40:28 -070060 BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070");
Junxiao Shi7e2413b2014-03-02 11:15:09 -070061
Giulio Grassi624f6c62014-02-18 19:42:14 +010062 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 Shi7e2413b2014-03-02 11:15:09 -070066
Junxiao Shi61e3cc52014-03-03 20:40:28 -070067 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 Grassi624f6c62014-02-18 19:42:14 +010071 //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 Shi7e2413b2014-03-02 11:15:09 -070077
78
Giulio Grassi624f6c62014-02-18 19:42:14 +010079 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 Shi7e2413b2014-03-02 11:15:09 -070086
87
Giulio Grassi624f6c62014-02-18 19:42:14 +010088 //same endpoint of a multicast face
89 BOOST_CHECK_EXCEPTION(factory.createChannel(interfaceIp, "20072"),
90 UdpFactory::Error,
91 isTheSameMulticastEndpoint);
Junxiao Shi7e2413b2014-03-02 11:15:09 -070092
Giulio Grassi624f6c62014-02-18 19:42:14 +010093 //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 Shi7e2413b2014-03-02 11:15:09 -0700106
107
Giulio Grassi624f6c62014-02-18 19:42:14 +0100108// //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 Shi7e2413b2014-03-02 11:15:09 -0700126//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100127// shared_ptr<MulticastUdpFace> multicastFace4 = factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0",
128// "FF01:0:0:0:0:0:0:2",
129// "20073");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700130//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100131// 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 Shi7e2413b2014-03-02 11:15:09 -0700136//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100137// 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 Shi7e2413b2014-03-02 11:15:09 -0700144//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100145// //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
166class EndToEndFixture : protected BaseFixture
167{
168public:
169 void
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700170 channel1_onFaceCreated(const shared_ptr<Face>& newFace)
Giulio Grassi624f6c62014-02-18 19:42:14 +0100171 {
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 Shi7e2413b2014-03-02 11:15:09 -0700178 m_face1->onFail +=
Giulio Grassi624f6c62014-02-18 19:42:14 +0100179 bind(&EndToEndFixture::face1_onFail, this);
180 BOOST_CHECK_MESSAGE(true, "channel 1 face created");
181
182 m_faces.push_back(m_face1);
183
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700184 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100185 }
186
187 void
188 channel1_onConnectFailed(const std::string& reason)
189 {
190 BOOST_CHECK_MESSAGE(false, reason);
191
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700192 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100193 }
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700194
Giulio Grassi624f6c62014-02-18 19:42:14 +0100195 void
196 face1_onReceiveInterest(const Interest& interest)
197 {
198 m_face1_receivedInterests.push_back(interest);
199
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700200 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100201 }
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700202
Giulio Grassi624f6c62014-02-18 19:42:14 +0100203 void
204 face1_onReceiveData(const Data& data)
205 {
206 m_face1_receivedDatas.push_back(data);
207
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700208 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100209 }
210
211 void
212 face1_onFail()
213 {
214 m_face1.reset();
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700215 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100216 }
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 Shi7e2413b2014-03-02 11:15:09 -0700227 m_face2->onFail +=
Giulio Grassi624f6c62014-02-18 19:42:14 +0100228 bind(&EndToEndFixture::face2_onFail, this);
229
230 m_faces.push_back(m_face2);
231
232 BOOST_CHECK_MESSAGE(true, "channel 2 face created");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700233 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100234 }
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700235
Giulio Grassi624f6c62014-02-18 19:42:14 +0100236 void
237 channel2_onConnectFailed(const std::string& reason)
238 {
239 BOOST_CHECK_MESSAGE(false, reason);
240
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700241 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100242 }
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700243
Giulio Grassi624f6c62014-02-18 19:42:14 +0100244 void
245 face2_onReceiveInterest(const Interest& interest)
246 {
247 m_face2_receivedInterests.push_back(interest);
248
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700249 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100250 }
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700251
Giulio Grassi624f6c62014-02-18 19:42:14 +0100252 void
253 face2_onReceiveData(const Data& data)
254 {
255 m_face2_receivedDatas.push_back(data);
256
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700257 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100258 }
259
260 void
261 face2_onFail()
262 {
263 m_face2.reset();
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700264 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100265 }
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 Shi7e2413b2014-03-02 11:15:09 -0700273
274 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100275 }
276
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700277
Giulio Grassi624f6c62014-02-18 19:42:14 +0100278 void
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700279 channel_onFaceCreated(const shared_ptr<Face>& newFace)
Giulio Grassi624f6c62014-02-18 19:42:14 +0100280 {
281 m_faces.push_back(newFace);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700282 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100283 }
284
285 void
286 channel_onConnectFailed(const std::string& reason)
287 {
288 BOOST_CHECK_MESSAGE(false, reason);
289
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700290 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100291 }
292
293 void
294 channel_onConnectFailedOk(const std::string& reason)
295 {
296 //it's ok, it was supposed to fail
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700297 m_limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100298 }
299
300 void
301 checkFaceList(size_t shouldBe)
302 {
303 BOOST_CHECK_EQUAL(m_faces.size(), shouldBe);
304 }
Giulio Grassi624f6c62014-02-18 19:42:14 +0100305
306public:
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700307 LimitedIo m_limitedIo;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100308
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 Shi7e2413b2014-03-02 11:15:09 -0700315
Giulio Grassi624f6c62014-02-18 19:42:14 +0100316 shared_ptr<Face> m_face3;
317
318
319 std::list< shared_ptr<Face> > m_faces;
320};
321
322
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000323BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture)
Giulio Grassi624f6c62014-02-18 19:42:14 +0100324{
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700325 UdpFactory factory;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100326
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000327 factory.createChannel("127.0.0.1", "20071");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700328
Giulio Grassi624f6c62014-02-18 19:42:14 +0100329 factory.createFace(FaceUri("udp4://127.0.0.1:20070"),
330 bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
331 bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700332
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 Grassi624f6c62014-02-18 19:42:14 +0100336
337 BOOST_REQUIRE(static_cast<bool>(m_face2));
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000338 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 Shi7e2413b2014-03-02 11:15:09 -0700341
Giulio Grassi624f6c62014-02-18 19:42:14 +0100342 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 Shi7e2413b2014-03-02 11:15:09 -0700345
Giulio Grassi624f6c62014-02-18 19:42:14 +0100346 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 Shi7e2413b2014-03-02 11:15:09 -0700361
Giulio Grassi624f6c62014-02-18 19:42:14 +0100362 // 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 Afanasyev6f5ff632014-03-07 16:40:10 +0000369 m_face2->sendData (data2 );
370 m_face2->sendData (data2 );
Giulio Grassi624f6c62014-02-18 19:42:14 +0100371
Alexander Afanasyev6f5ff632014-03-07 16:40:10 +0000372 BOOST_CHECK_MESSAGE(m_limitedIo.run(5,//4 send + 1 listen return
373 time::seconds(4)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700374 "UdpChannel error: cannot send or receive Interest/Data packets");
Giulio Grassi624f6c62014-02-18 19:42:14 +0100375
376 BOOST_REQUIRE(static_cast<bool>(m_face1));
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000377 BOOST_CHECK_EQUAL(m_face1->getUri().toString(), "udp4://127.0.0.1:20071");
378 BOOST_CHECK_EQUAL(m_face1->isLocal(), false);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700379
Giulio Grassi624f6c62014-02-18 19:42:14 +0100380 m_face1->sendInterest(interest1);
Alexander Afanasyev6f5ff632014-03-07 16:40:10 +0000381 m_face1->sendInterest(interest1);
382 m_face1->sendInterest(interest1);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100383 m_face1->sendData (data1 );
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700384
Alexander Afanasyev6f5ff632014-03-07 16:40:10 +0000385 BOOST_CHECK_MESSAGE(m_limitedIo.run(4, time::seconds(4)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700386 "UdpChannel error: cannot send or receive Interest/Data packets");
Giulio Grassi624f6c62014-02-18 19:42:14 +0100387
388
389 BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
Alexander Afanasyev6f5ff632014-03-07 16:40:10 +0000390 BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 3);
391 BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 3);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100392 BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700393
Giulio Grassi624f6c62014-02-18 19:42:14 +0100394 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 Shi7e2413b2014-03-02 11:15:09 -0700398
399
400
Giulio Grassi624f6c62014-02-18 19:42:14 +0100401 //checking if the connection accepting mechanism works properly.
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700402
Giulio Grassi624f6c62014-02-18 19:42:14 +0100403 m_face2->sendData (data3 );
404 m_face2->sendInterest(interest3);
405
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700406 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 Grassi624f6c62014-02-18 19:42:14 +0100409 BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 2);
Alexander Afanasyev6f5ff632014-03-07 16:40:10 +0000410 BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 4);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700411
Giulio Grassi624f6c62014-02-18 19:42:14 +0100412 BOOST_CHECK_EQUAL(m_face1_receivedInterests[1].getName(), interest3.getName());
Alexander Afanasyev6f5ff632014-03-07 16:40:10 +0000413 BOOST_CHECK_EQUAL(m_face1_receivedDatas [3].getName(), data3.getName());
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000414
415 const FaceCounters& counters1 = m_face1->getCounters();
416 BOOST_CHECK_EQUAL(counters1.getInInterest() , 2);
417 BOOST_CHECK_EQUAL(counters1.getInData() , 4);
418 BOOST_CHECK_EQUAL(counters1.getOutInterest(), 3);
419 BOOST_CHECK_EQUAL(counters1.getOutData() , 1);
420
421 const FaceCounters& counters2 = m_face2->getCounters();
422 BOOST_CHECK_EQUAL(counters2.getInInterest() , 3);
423 BOOST_CHECK_EQUAL(counters2.getInData() , 1);
424 BOOST_CHECK_EQUAL(counters2.getOutInterest(), 2);
425 BOOST_CHECK_EQUAL(counters2.getOutData() , 4);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000426}
Giulio Grassi624f6c62014-02-18 19:42:14 +0100427
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000428BOOST_FIXTURE_TEST_CASE(EndToEnd6, EndToEndFixture)
429{
430 UdpFactory factory;
431
432 factory.createChannel("::1", "20071");
433
434 factory.createFace(FaceUri("udp://[::1]:20070"),
435 bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
436 bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
437
438
439 BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS,
440 "UdpChannel error: cannot connect or cannot accept connection");
441
442 BOOST_REQUIRE(static_cast<bool>(m_face2));
443 BOOST_CHECK_EQUAL(m_face2->getUri().toString(), "udp6://[::1]:20070");
444 BOOST_CHECK_EQUAL(m_face2->isLocal(), false);
445 // m_face1 is not created yet
446
447 shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070");
448 channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
449 bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
450
451 Interest interest1("ndn:/TpnzGvW9R");
452 Data data1 ("ndn:/KfczhUqVix");
453 data1.setContent(0, 0);
454 Interest interest2("ndn:/QWiIMfj5sL");
455 Data data2 ("ndn:/XNBV796f");
456 data2.setContent(0, 0);
457 Interest interest3("ndn:/QWiIhjgkj5sL");
458 Data data3 ("ndn:/XNBV794f");
459 data3.setContent(0, 0);
460
461
462 ndn::SignatureSha256WithRsa fakeSignature;
463 fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue,
464 reinterpret_cast<const uint8_t*>(0),
465 0));
466
467 // set fake signature on data1 and data2
468 data1.setSignature(fakeSignature);
469 data2.setSignature(fakeSignature);
470 data3.setSignature(fakeSignature);
471
472 m_face2->sendInterest(interest2);
473 m_face2->sendData (data2 );
474
475 BOOST_CHECK_MESSAGE(m_limitedIo.run(3,//2 send + 1 listen return
476 time::seconds(1)) == LimitedIo::EXCEED_OPS,
477 "UdpChannel error: cannot send or receive Interest/Data packets");
478
479 BOOST_REQUIRE(static_cast<bool>(m_face1));
480 BOOST_CHECK_EQUAL(m_face1->getUri().toString(), "udp6://[::1]:20071");
481 BOOST_CHECK_EQUAL(m_face1->isLocal(), false);
482
483 m_face1->sendInterest(interest1);
484 m_face1->sendData (data1 );
485
486 BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
487 "UdpChannel error: cannot send or receive Interest/Data packets");
488
489
490 BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
491 BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1);
492 BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1);
493 BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1);
494
495 BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName());
496 BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName());
497 BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName());
498 BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName());
499
500
501
502 //checking if the connection accepting mechanism works properly.
503
504 m_face2->sendData (data3 );
505 m_face2->sendInterest(interest3);
506
507 BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
508 "UdpChannel error: cannot send or receive Interest/Data packets");
509
510 BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 2);
511 BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 2);
512
513 BOOST_CHECK_EQUAL(m_face1_receivedInterests[1].getName(), interest3.getName());
514 BOOST_CHECK_EQUAL(m_face1_receivedDatas [1].getName(), data3.getName());
Giulio Grassi624f6c62014-02-18 19:42:14 +0100515}
516
517BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
518{
519 Interest interest1("ndn:/TpnzGvW9R");
520 Interest interest2("ndn:/QWiIMfj5sL");
521 Interest interest3("ndn:/QWiIhjgkj5sL");
522
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700523 UdpFactory factory;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100524
Giulio Grassi624f6c62014-02-18 19:42:14 +0100525 shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
526 shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700527
528
529
Giulio Grassi624f6c62014-02-18 19:42:14 +0100530 channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
531 bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700532
Giulio Grassi624f6c62014-02-18 19:42:14 +0100533 channel2->connect("127.0.0.1", "20070",
534 bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
535 bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700536
537
538 BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS,
539 "UdpChannel error: cannot connect or cannot accept connection");
Giulio Grassi624f6c62014-02-18 19:42:14 +0100540
541 BOOST_CHECK_EQUAL(m_faces.size(), 1);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700542
Giulio Grassi624f6c62014-02-18 19:42:14 +0100543 shared_ptr<UdpChannel> channel3 = factory.createChannel("127.0.0.1", "20072");
544 channel3->connect("127.0.0.1", "20070",
545 bind(&EndToEndFixture::channel3_onFaceCreated, this, _1),
546 bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700547
Giulio Grassi624f6c62014-02-18 19:42:14 +0100548 shared_ptr<UdpChannel> channel4 = factory.createChannel("127.0.0.1", "20073");
549
550 BOOST_CHECK_NE(channel3, channel4);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100551
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700552 scheduler::schedule(time::seconds(0.5),
553 bind(&UdpChannel::connect, channel4, "127.0.0.1", "20070",
554 // does not work without static_cast
555 static_cast<UdpChannel::FaceCreatedCallback>(
556 bind(&EndToEndFixture::channel_onFaceCreated, this, _1)),
557 static_cast<UdpChannel::ConnectFailedCallback>(
558 bind(&EndToEndFixture::channel_onConnectFailed, this, _1))));
559
560 scheduler::schedule(time::seconds(0.4), bind(&EndToEndFixture::checkFaceList, this, 2));
561
562 BOOST_CHECK_MESSAGE(m_limitedIo.run(2,// 2 connects
563 time::seconds(4)) == LimitedIo::EXCEED_OPS,
564 "UdpChannel error: cannot connect or cannot accept multiple connections");
565
Giulio Grassi624f6c62014-02-18 19:42:14 +0100566 BOOST_CHECK_EQUAL(m_faces.size(), 3);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700567
568
Giulio Grassi624f6c62014-02-18 19:42:14 +0100569 m_face2->sendInterest(interest1);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700570 BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS,
571 "UdpChannel error: cannot send or receive Interest/Data packets");
572
Giulio Grassi624f6c62014-02-18 19:42:14 +0100573 BOOST_CHECK_EQUAL(m_faces.size(), 4);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700574
Giulio Grassi624f6c62014-02-18 19:42:14 +0100575 m_face3->sendInterest(interest2);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700576 BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS,
577 "UdpChannel error: cannot send or receive Interest/Data packets");
578
Giulio Grassi624f6c62014-02-18 19:42:14 +0100579 //channel1 should have created 2 faces, one when m_face2 sent an interest, one when m_face3 sent an interest
580 BOOST_CHECK_EQUAL(m_faces.size(), 5);
581 BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated,
582 this,
583 _1),
584 bind(&EndToEndFixture::channel_onConnectFailedOk,
585 this,
586 _1)),
587 UdpChannel::Error);
588}
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700589
Giulio Grassi624f6c62014-02-18 19:42:14 +0100590//Test commented because it required to be run in a machine that can resolve ipv6 query
591//BOOST_FIXTURE_TEST_CASE(EndToEndIpv6, EndToEndFixture)
592//{
593// UdpFactory factory = UdpFactory();
594// Scheduler scheduler(g_io); // to limit the amount of time the test may take
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700595//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100596// EventId abortEvent =
597// scheduler.scheduleEvent(time::seconds(1),
598// bind(&EndToEndFixture::abortTestCase, this,
599// "UdpChannel error: cannot connect or cannot accept connection"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700600//
601// m_limitedIoRemaining = 1;
602//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100603// shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070");
604// shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700605//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100606// channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
607// bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700608//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100609// channel2->connect("::1", "20070",
610// bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
611// bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
612// g_io.run();
613// g_io.reset();
614// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700615//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100616// BOOST_REQUIRE(static_cast<bool>(m_face2));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700617//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100618// abortEvent =
619// scheduler.scheduleEvent(time::seconds(1),
620// bind(&EndToEndFixture::abortTestCase, this,
621// "UdpChannel error: cannot send or receive Interest/Data packets"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700622//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100623// Interest interest1("ndn:/TpnzGvW9R");
624// Data data1 ("ndn:/KfczhUqVix");
625// data1.setContent(0, 0);
626// Interest interest2("ndn:/QWiIMfj5sL");
627// Data data2 ("ndn:/XNBV796f");
628// data2.setContent(0, 0);
629// Interest interest3("ndn:/QWiIhjgkj5sL");
630// Data data3 ("ndn:/XNBV794f");
631// data3.setContent(0, 0);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700632//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100633// ndn::SignatureSha256WithRsa fakeSignature;
634// fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700635//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100636// // set fake signature on data1 and data2
637// data1.setSignature(fakeSignature);
638// data2.setSignature(fakeSignature);
639// data3.setSignature(fakeSignature);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700640//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100641// m_face2->sendInterest(interest2);
642// m_face2->sendData (data2 );
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700643//
644// m_limitedIoRemaining = 3; //2 send + 1 listen return
Giulio Grassi624f6c62014-02-18 19:42:14 +0100645// g_io.run();
646// g_io.reset();
647// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700648//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100649// BOOST_REQUIRE(static_cast<bool>(m_face1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700650//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100651// m_face1->sendInterest(interest1);
652// m_face1->sendData (data1 );
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700653//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100654// abortEvent =
655// scheduler.scheduleEvent(time::seconds(1),
656// bind(&EndToEndFixture::abortTestCase, this,
657// "UdpChannel error: cannot send or receive Interest/Data packets"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700658// m_limitedIoRemaining = 2;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100659// g_io.run();
660// g_io.reset();
661// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700662//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100663// BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
664// BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1);
665// BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1);
666// BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700667//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100668// BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName());
669// BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName());
670// BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName());
671// BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName());
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700672//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100673// //checking if the connection accepting mechanism works properly.
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700674//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100675// m_face2->sendData (data3 );
676// m_face2->sendInterest(interest3);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700677//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100678// abortEvent =
679// scheduler.scheduleEvent(time::seconds(1),
680// bind(&EndToEndFixture::abortTestCase, this,
681// "UdpChannel error: cannot send or receive Interest/Data packets"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700682// m_limitedIoRemaining = 2;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100683// g_io.run();
684// g_io.reset();
685// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700686//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100687// BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 2);
688// BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 2);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700689//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100690// BOOST_CHECK_EQUAL(m_face1_receivedInterests[1].getName(), interest3.getName());
691// BOOST_CHECK_EQUAL(m_face1_receivedDatas [1].getName(), data3.getName());
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700692//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100693//}
694
695
696//Test commented because it required to be run in a machine that can resolve ipv6 query
697//BOOST_FIXTURE_TEST_CASE(MultipleAcceptsIpv6, EndToEndFixture)
698//{
699// Interest interest1("ndn:/TpnzGvW9R");
700// Interest interest2("ndn:/QWiIMfj5sL");
701// Interest interest3("ndn:/QWiIhjgkj5sL");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700702//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100703// UdpFactory factory = UdpFactory();
704// Scheduler scheduler(g_io); // to limit the amount of time the test may take
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700705//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100706// EventId abortEvent =
707// scheduler.scheduleEvent(time::seconds(4),
708// bind(&EndToEndFixture::abortTestCase, this,
709// "UdpChannel error: cannot connect or cannot accept connection"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700710//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100711// shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070");
712// shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700713//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100714// channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
715// bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700716//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100717// channel2->connect("::1", "20070",
718// bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
719// bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700720//
721// m_limitedIoRemaining = 1;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100722// g_io.run();
723// g_io.reset();
724// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700725//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100726// BOOST_CHECK_EQUAL(m_faces.size(), 1);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700727//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100728// shared_ptr<UdpChannel> channel3 = factory.createChannel("::1", "20072");
729// channel3->connect("::1", "20070",
730// bind(&EndToEndFixture::channel3_onFaceCreated, this, _1),
731// bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700732//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100733// shared_ptr<UdpChannel> channel4 = factory.createChannel("::1", "20073");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700734//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100735// BOOST_CHECK_NE(channel3, channel4);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700736//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100737// scheduler
738// .scheduleEvent(time::seconds(0.5),
739// bind(&UdpChannel::connect, channel4,
740// "::1", "20070",
741// static_cast<UdpChannel::FaceCreatedCallback>(bind(&EndToEndFixture::
742// channel_onFaceCreated, this, _1)),
743// static_cast<UdpChannel::ConnectFailedCallback>(bind(&EndToEndFixture::
744// channel_onConnectFailed, this, _1))));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700745//
746// m_limitedIoRemaining = 2; // 2 connects
Giulio Grassi624f6c62014-02-18 19:42:14 +0100747// abortEvent =
748// scheduler.scheduleEvent(time::seconds(4),
749// bind(&EndToEndFixture::abortTestCase, this,
750// "UdpChannel error: cannot connect or cannot accept multiple connections"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700751//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100752// scheduler.scheduleEvent(time::seconds(0.4),
753// bind(&EndToEndFixture::checkFaceList, this, 2));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700754//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100755// g_io.run();
756// g_io.reset();
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700757//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100758// BOOST_CHECK_EQUAL(m_faces.size(), 3);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700759//
760//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100761// m_face2->sendInterest(interest1);
762// abortEvent =
763// scheduler.scheduleEvent(time::seconds(1),
764// bind(&EndToEndFixture::abortTestCase, this,
765// "UdpChannel error: cannot send or receive Interest/Data packets"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700766// m_limitedIoRemaining = 1;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100767// g_io.run();
768// g_io.reset();
769// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700770//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100771// BOOST_CHECK_EQUAL(m_faces.size(), 4);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700772//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100773// m_face3->sendInterest(interest2);
774// abortEvent =
775// scheduler.scheduleEvent(time::seconds(1),
776// bind(&EndToEndFixture::abortTestCase, this,
777// "UdpChannel error: cannot send or receive Interest/Data packets"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700778// m_limitedIoRemaining = 1;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100779// g_io.run();
780// g_io.reset();
781// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700782//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100783// //channel1 should have created 2 faces, one when m_face2 sent an interest, one when m_face3 sent an interest
784// BOOST_CHECK_EQUAL(m_faces.size(), 5);
785// BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated,
786// this,
787// _1),
788// bind(&EndToEndFixture::channel_onConnectFailedOk,
789// this,
790// _1)),
791// UdpChannel::Error);
792//}
793
794
795BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture)
796{
797 UdpFactory factory = UdpFactory();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100798
Giulio Grassi624f6c62014-02-18 19:42:14 +0100799 shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
800 shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700801
Giulio Grassi624f6c62014-02-18 19:42:14 +0100802 channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
803 bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700804
Giulio Grassi624f6c62014-02-18 19:42:14 +0100805 channel2->connect("127.0.0.1", "20070",
806 bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
807 bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700808
809 BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS,
810 "UdpChannel error: cannot connect or cannot accept connection");
Giulio Grassi624f6c62014-02-18 19:42:14 +0100811
812 BOOST_CHECK_EQUAL(channel2->size(), 1);
813
Giulio Grassi624f6c62014-02-18 19:42:14 +0100814 BOOST_CHECK(static_cast<bool>(m_face2));
815
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700816 // Face::close must be invoked during io run to be counted as an op
817 scheduler::schedule(time::seconds(0.1), bind(&Face::close, m_face2));
818
819 BOOST_CHECK_MESSAGE(m_limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS,
820 "FaceClosing error: cannot properly close faces");
Giulio Grassi624f6c62014-02-18 19:42:14 +0100821
822 BOOST_CHECK(!static_cast<bool>(m_face2));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700823
Giulio Grassi624f6c62014-02-18 19:42:14 +0100824 BOOST_CHECK_EQUAL(channel2->size(), 0);
825}
826
827//BOOST_FIXTURE_TEST_CASE(MulticastFace, EndToEndFixture)
828//{
829// //to instantiate multicast face on a specific ip address, change interfaceIp
830// std::string interfaceIp = "0.0.0.0";
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700831//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100832// UdpFactory factory = UdpFactory();
833// Scheduler scheduler(g_io); // to limit the amount of time the test may take
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700834//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100835// shared_ptr<MulticastUdpFace> multicastFace1 =
836// factory.createMulticastFace(interfaceIp, "224.0.0.1", "20072");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700837//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100838// BOOST_REQUIRE(static_cast<bool>(multicastFace1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700839//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100840// channel1_onFaceCreated(multicastFace1);
841//
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700842//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100843// EventId abortEvent =
844// scheduler.scheduleEvent(time::seconds(10),
845// bind(&EndToEndFixture::abortTestCase, this,
846// "MulticastFace error: cannot send or receive Interest/Data packets"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700847//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100848// Interest interest1("ndn:/TpnzGvW9R");
849// Data data1 ("ndn:/KfczhUqVix");
850// data1.setContent(0, 0);
851// Interest interest2("ndn:/QWiIMfj5sL");
852// Data data2 ("ndn:/XNBV796f");
853// data2.setContent(0, 0);
854// Interest interest3("ndn:/QWiIhjgkj5sL");
855// Data data3 ("ndn:/XNBV794f");
856// data3.setContent(0, 0);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700857//
858//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100859// ndn::SignatureSha256WithRsa fakeSignature;
860// fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700861//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100862// // set fake signature on data1 and data2
863// data1.setSignature(fakeSignature);
864// data2.setSignature(fakeSignature);
865// data3.setSignature(fakeSignature);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700866//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100867// multicastFace1->sendInterest(interest1);
868// multicastFace1->sendData (data1 );
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700869//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100870// g_io.reset();
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700871// m_limitedIoRemaining = 2;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100872// g_io.run();
873// g_io.reset();
874// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700875//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100876// BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1);
877// BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700878//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100879// BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest1.getName());
880// BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data1.getName());
881//}
882
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700883
884
Giulio Grassi624f6c62014-02-18 19:42:14 +0100885BOOST_AUTO_TEST_SUITE_END()
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700886
Giulio Grassi624f6c62014-02-18 19:42:14 +0100887} // namespace tests
888} // namespace nfd