blob: abab32021ae04a3cb43ed33ced01380cbd5f59d2 [file] [log] [blame]
Giulio Grassi624f6c62014-02-18 19:42:14 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Steve DiBenedettoef04f272014-06-04 14:28:31 -06003 * Copyright (c) 2014, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Steve DiBenedettoef04f272014-06-04 14:28:31 -060024 */
Giulio Grassi624f6c62014-02-18 19:42:14 +010025
26#include "face/udp-factory.hpp"
Alexander Afanasyev70aaf8a2014-12-13 00:44:22 -080027#include "core/network-interface.hpp"
Junxiao Shi7e2413b2014-03-02 11:15:09 -070028
29#include "tests/test-common.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070030#include "tests/limited-io.hpp"
Giulio Grassi624f6c62014-02-18 19:42:14 +010031
32namespace nfd {
33namespace tests {
34
35BOOST_FIXTURE_TEST_SUITE(FaceUdp, BaseFixture)
36
Steve DiBenedettoef04f272014-06-04 14:28:31 -060037BOOST_AUTO_TEST_CASE(GetChannels)
38{
39 UdpFactory factory;
40 BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true);
41
42 std::vector<shared_ptr<const Channel> > expectedChannels;
43
44 expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070"));
45 expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071"));
46 expectedChannels.push_back(factory.createChannel("::1", "20071"));
47
48 std::list<shared_ptr<const Channel> > channels = factory.getChannels();
49 for (std::list<shared_ptr<const Channel> >::const_iterator i = channels.begin();
50 i != channels.end(); ++i)
51 {
52 std::vector<shared_ptr<const Channel> >::iterator pos =
53 std::find(expectedChannels.begin(), expectedChannels.end(), *i);
54
55 BOOST_REQUIRE(pos != expectedChannels.end());
56 expectedChannels.erase(pos);
57 }
58
59 BOOST_CHECK_EQUAL(expectedChannels.size(), 0);
60}
61
Giulio Grassi624f6c62014-02-18 19:42:14 +010062class FactoryErrorCheck : protected BaseFixture
63{
64public:
Alexander Afanasyev86bc91a2014-08-28 22:29:16 -070065 bool
66 isTheSameMulticastEndpoint(const UdpFactory::Error& e) {
Giulio Grassi624f6c62014-02-18 19:42:14 +010067 return strcmp(e.what(),
68 "Cannot create the requested UDP unicast channel, local "
69 "endpoint is already allocated for a UDP multicast face") == 0;
70 }
Junxiao Shi7e2413b2014-03-02 11:15:09 -070071
Alexander Afanasyev86bc91a2014-08-28 22:29:16 -070072 bool
73 isNotMulticastAddress(const UdpFactory::Error& e) {
Giulio Grassi624f6c62014-02-18 19:42:14 +010074 return strcmp(e.what(),
75 "Cannot create the requested UDP multicast face, "
76 "the multicast group given as input is not a multicast address") == 0;
77 }
Junxiao Shi7e2413b2014-03-02 11:15:09 -070078
Alexander Afanasyev86bc91a2014-08-28 22:29:16 -070079 bool
80 isTheSameUnicastEndpoint(const UdpFactory::Error& e) {
Giulio Grassi624f6c62014-02-18 19:42:14 +010081 return strcmp(e.what(),
82 "Cannot create the requested UDP multicast face, local "
83 "endpoint is already allocated for a UDP unicast channel") == 0;
84 }
Junxiao Shi7e2413b2014-03-02 11:15:09 -070085
Alexander Afanasyev86bc91a2014-08-28 22:29:16 -070086 bool
87 isLocalEndpointOnDifferentGroup(const UdpFactory::Error& e) {
Giulio Grassi624f6c62014-02-18 19:42:14 +010088 return strcmp(e.what(),
89 "Cannot create the requested UDP multicast face, local "
90 "endpoint is already allocated for a UDP multicast face "
91 "on a different multicast group") == 0;
92 }
93};
Junxiao Shi7e2413b2014-03-02 11:15:09 -070094
Giulio Grassi624f6c62014-02-18 19:42:14 +010095BOOST_FIXTURE_TEST_CASE(ChannelMapUdp, FactoryErrorCheck)
96{
97 using boost::asio::ip::udp;
Junxiao Shi7e2413b2014-03-02 11:15:09 -070098
Giulio Grassi624f6c62014-02-18 19:42:14 +010099 UdpFactory factory = UdpFactory();
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700100
Giulio Grassi624f6c62014-02-18 19:42:14 +0100101 //to instantiate multicast face on a specific ip address, change interfaceIp
102 std::string interfaceIp = "0.0.0.0";
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700103
Giulio Grassi624f6c62014-02-18 19:42:14 +0100104 shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
105 shared_ptr<UdpChannel> channel1a = factory.createChannel("127.0.0.1", "20070");
106 BOOST_CHECK_EQUAL(channel1, channel1a);
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700107 BOOST_CHECK_EQUAL(channel1->getUri().toString(), "udp4://127.0.0.1:20070");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700108
Giulio Grassi624f6c62014-02-18 19:42:14 +0100109 shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
110 BOOST_CHECK_NE(channel1, channel2);
111
112 shared_ptr<UdpChannel> channel3 = factory.createChannel(interfaceIp, "20070");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700113
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700114 shared_ptr<UdpChannel> channel4 = factory.createChannel("::1", "20071");
115 BOOST_CHECK_NE(channel2, channel4);
116 BOOST_CHECK_EQUAL(channel4->getUri().toString(), "udp6://[::1]:20071");
117
Giulio Grassi624f6c62014-02-18 19:42:14 +0100118 //same endpoint of a unicast channel
119 BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp,
120 "224.0.0.1",
121 "20070"),
122 UdpFactory::Error,
123 isTheSameUnicastEndpoint);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700124
125
Giulio Grassi624f6c62014-02-18 19:42:14 +0100126 shared_ptr<MulticastUdpFace> multicastFace1 = factory.createMulticastFace(interfaceIp,
127 "224.0.0.1",
128 "20072");
129 shared_ptr<MulticastUdpFace> multicastFace1a = factory.createMulticastFace(interfaceIp,
130 "224.0.0.1",
131 "20072");
132 BOOST_CHECK_EQUAL(multicastFace1, multicastFace1a);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700133
134
Giulio Grassi624f6c62014-02-18 19:42:14 +0100135 //same endpoint of a multicast face
136 BOOST_CHECK_EXCEPTION(factory.createChannel(interfaceIp, "20072"),
137 UdpFactory::Error,
138 isTheSameMulticastEndpoint);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700139
Giulio Grassi624f6c62014-02-18 19:42:14 +0100140 //same multicast endpoint, different group
141 BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp,
142 "224.0.0.42",
143 "20072"),
144 UdpFactory::Error,
145 isLocalEndpointOnDifferentGroup);
146
147 BOOST_CHECK_EXCEPTION(factory.createMulticastFace(interfaceIp,
148 "192.168.10.15",
149 "20025"),
150 UdpFactory::Error,
151 isNotMulticastAddress);
152
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700153
Giulio Grassi624f6c62014-02-18 19:42:14 +0100154// //Test commented because it required to be run in a machine that can resolve ipv6 query
155// shared_ptr<UdpChannel> channel1v6 = factory.createChannel(//"::1",
156// "fe80::5e96:9dff:fe7d:9c8d%en1",
157// //"fe80::aa54:b2ff:fe08:27b8%wlan0",
158// "20070");
159//
160// //the creation of multicastFace2 works properly. It has been disable because it needs an IP address of
161// //an available network interface (different from the first one used)
162// shared_ptr<MulticastUdpFace> multicastFace2 = factory.createMulticastFace("192.168.1.17",
163// "224.0.0.1",
164// "20073");
165// BOOST_CHECK_NE(multicastFace1, multicastFace2);
166//
167//
168// //ipv6 - work in progress
169// shared_ptr<MulticastUdpFace> multicastFace3 = factory.createMulticastFace("fe80::5e96:9dff:fe7d:9c8d%en1",
170// "FF01:0:0:0:0:0:0:2",
171// "20073");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700172//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100173// shared_ptr<MulticastUdpFace> multicastFace4 = factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0",
174// "FF01:0:0:0:0:0:0:2",
175// "20073");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700176//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100177// BOOST_CHECK_EQUAL(multicastFace3, multicastFace4);
178//
179// shared_ptr<MulticastUdpFace> multicastFace5 = factory.createMulticastFace("::1",
180// "FF01:0:0:0:0:0:0:2",
181// "20073");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700182//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100183// BOOST_CHECK_NE(multicastFace3, multicastFace5);
184//
185// //same local ipv6 endpoint for a different multicast group
186// BOOST_CHECK_THROW(factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0",
187// "FE01:0:0:0:0:0:0:2",
188// "20073"),
189// UdpFactory::Error);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700190//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100191// //same local ipv6 (expect for th port number) endpoint for a different multicast group
192// BOOST_CHECK_THROW(factory.createMulticastFace("fe80::aa54:b2ff:fe08:27b8%wlan0",
193// "FE01:0:0:0:0:0:0:2",
194// "20075"),
195// UdpFactory::Error);
196//
197// BOOST_CHECK_THROW(factory.createMulticastFace("fa80::20a:9dff:fef6:12ff",
198// "FE12:0:0:0:0:0:0:2",
199// "20075"),
200// UdpFactory::Error);
201//
202// //not a multicast ipv6
203// BOOST_CHECK_THROW(factory.createMulticastFace("fa80::20a:9dff:fef6:12ff",
204// "A112:0:0:0:0:0:0:2",
205// "20075"),
206// UdpFactory::Error);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100207}
208
Alexander Afanasyev86bc91a2014-08-28 22:29:16 -0700209class FaceCreateFixture : protected BaseFixture
210{
211public:
212 void
213 ignore()
214 {
215 }
216
217 void
218 checkError(const std::string& errorActual, const std::string& errorExpected)
219 {
220 BOOST_CHECK_EQUAL(errorActual, errorExpected);
221 }
222
223 void
224 failIfError(const std::string& errorActual)
225 {
226 BOOST_FAIL("No error expected, but got: [" << errorActual << "]");
227 }
228};
229
230BOOST_FIXTURE_TEST_CASE(FaceCreate, FaceCreateFixture)
231{
232 UdpFactory factory = UdpFactory();
233
234 factory.createFace(FaceUri("udp4://127.0.0.1"),
235 bind(&FaceCreateFixture::ignore, this),
236 bind(&FaceCreateFixture::failIfError, this, _1));
237
238 factory.createFace(FaceUri("udp4://127.0.0.1/"),
239 bind(&FaceCreateFixture::ignore, this),
240 bind(&FaceCreateFixture::failIfError, this, _1));
241
242 factory.createFace(FaceUri("udp4://127.0.0.1/path"),
243 bind(&FaceCreateFixture::ignore, this),
244 bind(&FaceCreateFixture::checkError, this, _1, "Invalid URI"));
245
246}
247
Giulio Grassi624f6c62014-02-18 19:42:14 +0100248class EndToEndFixture : protected BaseFixture
249{
250public:
251 void
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700252 channel1_onFaceCreated(const shared_ptr<Face>& newFace)
Giulio Grassi624f6c62014-02-18 19:42:14 +0100253 {
Junxiao Shi79494162014-04-02 18:25:11 -0700254 BOOST_CHECK(!static_cast<bool>(face1));
Giulio Grassi69871f02014-03-09 16:14:44 +0100255 channel1_onFaceCreatedNoCheck(newFace);
256 }
Junxiao Shi79494162014-04-02 18:25:11 -0700257
Giulio Grassi69871f02014-03-09 16:14:44 +0100258 void
259 channel1_onFaceCreatedNoCheck(const shared_ptr<Face>& newFace)
260 {
Junxiao Shi79494162014-04-02 18:25:11 -0700261 face1 = newFace;
262 face1->onReceiveInterest +=
Giulio Grassi624f6c62014-02-18 19:42:14 +0100263 bind(&EndToEndFixture::face1_onReceiveInterest, this, _1);
Junxiao Shi79494162014-04-02 18:25:11 -0700264 face1->onReceiveData +=
Giulio Grassi624f6c62014-02-18 19:42:14 +0100265 bind(&EndToEndFixture::face1_onReceiveData, this, _1);
Junxiao Shi79494162014-04-02 18:25:11 -0700266 face1->onFail +=
Giulio Grassi624f6c62014-02-18 19:42:14 +0100267 bind(&EndToEndFixture::face1_onFail, this);
268 BOOST_CHECK_MESSAGE(true, "channel 1 face created");
269
Junxiao Shi79494162014-04-02 18:25:11 -0700270 faces.push_back(face1);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100271
Junxiao Shi79494162014-04-02 18:25:11 -0700272 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100273 }
274
275 void
276 channel1_onConnectFailed(const std::string& reason)
277 {
278 BOOST_CHECK_MESSAGE(false, reason);
279
Junxiao Shi79494162014-04-02 18:25:11 -0700280 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100281 }
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700282
Giulio Grassi624f6c62014-02-18 19:42:14 +0100283 void
284 face1_onReceiveInterest(const Interest& interest)
285 {
Junxiao Shi79494162014-04-02 18:25:11 -0700286 face1_receivedInterests.push_back(interest);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100287
Junxiao Shi79494162014-04-02 18:25:11 -0700288 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100289 }
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700290
Giulio Grassi624f6c62014-02-18 19:42:14 +0100291 void
292 face1_onReceiveData(const Data& data)
293 {
Junxiao Shi79494162014-04-02 18:25:11 -0700294 face1_receivedDatas.push_back(data);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100295
Junxiao Shi79494162014-04-02 18:25:11 -0700296 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100297 }
298
299 void
300 face1_onFail()
301 {
Junxiao Shi79494162014-04-02 18:25:11 -0700302 face1.reset();
303 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100304 }
305
306 void
307 channel2_onFaceCreated(const shared_ptr<Face>& newFace)
308 {
Junxiao Shi79494162014-04-02 18:25:11 -0700309 BOOST_CHECK(!static_cast<bool>(face2));
310 face2 = newFace;
311 face2->onReceiveInterest +=
Giulio Grassi624f6c62014-02-18 19:42:14 +0100312 bind(&EndToEndFixture::face2_onReceiveInterest, this, _1);
Junxiao Shi79494162014-04-02 18:25:11 -0700313 face2->onReceiveData +=
Giulio Grassi624f6c62014-02-18 19:42:14 +0100314 bind(&EndToEndFixture::face2_onReceiveData, this, _1);
Junxiao Shi79494162014-04-02 18:25:11 -0700315 face2->onFail +=
Giulio Grassi624f6c62014-02-18 19:42:14 +0100316 bind(&EndToEndFixture::face2_onFail, this);
317
Junxiao Shi79494162014-04-02 18:25:11 -0700318 faces.push_back(face2);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100319
320 BOOST_CHECK_MESSAGE(true, "channel 2 face created");
Junxiao Shi79494162014-04-02 18:25:11 -0700321 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100322 }
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700323
Giulio Grassi624f6c62014-02-18 19:42:14 +0100324 void
325 channel2_onConnectFailed(const std::string& reason)
326 {
327 BOOST_CHECK_MESSAGE(false, reason);
328
Junxiao Shi79494162014-04-02 18:25:11 -0700329 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100330 }
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700331
Giulio Grassi624f6c62014-02-18 19:42:14 +0100332 void
333 face2_onReceiveInterest(const Interest& interest)
334 {
Junxiao Shi79494162014-04-02 18:25:11 -0700335 face2_receivedInterests.push_back(interest);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100336
Junxiao Shi79494162014-04-02 18:25:11 -0700337 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100338 }
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700339
Giulio Grassi624f6c62014-02-18 19:42:14 +0100340 void
341 face2_onReceiveData(const Data& data)
342 {
Junxiao Shi79494162014-04-02 18:25:11 -0700343 face2_receivedDatas.push_back(data);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100344
Junxiao Shi79494162014-04-02 18:25:11 -0700345 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100346 }
347
348 void
349 face2_onFail()
350 {
Junxiao Shi79494162014-04-02 18:25:11 -0700351 face2.reset();
352 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100353 }
354
355 void
356 channel3_onFaceCreated(const shared_ptr<Face>& newFace)
357 {
Junxiao Shi79494162014-04-02 18:25:11 -0700358 BOOST_CHECK(!static_cast<bool>(face1));
359 face3 = newFace;
360 faces.push_back(newFace);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700361
Junxiao Shi79494162014-04-02 18:25:11 -0700362 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100363 }
364
Giulio Grassi624f6c62014-02-18 19:42:14 +0100365 void
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700366 channel_onFaceCreated(const shared_ptr<Face>& newFace)
Giulio Grassi624f6c62014-02-18 19:42:14 +0100367 {
Junxiao Shi79494162014-04-02 18:25:11 -0700368 faces.push_back(newFace);
369 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100370 }
371
372 void
373 channel_onConnectFailed(const std::string& reason)
374 {
375 BOOST_CHECK_MESSAGE(false, reason);
376
Junxiao Shi79494162014-04-02 18:25:11 -0700377 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100378 }
379
380 void
381 channel_onConnectFailedOk(const std::string& reason)
382 {
Davide Pesaventoab1e8f22014-10-21 22:45:33 +0200383 // it's ok, it was supposed to fail
Junxiao Shi79494162014-04-02 18:25:11 -0700384 limitedIo.afterOp();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100385 }
386
387 void
388 checkFaceList(size_t shouldBe)
389 {
Junxiao Shi79494162014-04-02 18:25:11 -0700390 BOOST_CHECK_EQUAL(faces.size(), shouldBe);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100391 }
Giulio Grassi624f6c62014-02-18 19:42:14 +0100392
Davide Pesaventoab1e8f22014-10-21 22:45:33 +0200393 void
394 connect(const shared_ptr<UdpChannel>& channel,
395 const std::string& remoteHost,
396 const std::string& remotePort)
397 {
398 channel->connect(remoteHost, remotePort,
399 bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
400 bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
401 }
402
Giulio Grassi624f6c62014-02-18 19:42:14 +0100403public:
Junxiao Shi79494162014-04-02 18:25:11 -0700404 LimitedIo limitedIo;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100405
Junxiao Shi79494162014-04-02 18:25:11 -0700406 shared_ptr<Face> face1;
407 std::vector<Interest> face1_receivedInterests;
408 std::vector<Data> face1_receivedDatas;
409 shared_ptr<Face> face2;
410 std::vector<Interest> face2_receivedInterests;
411 std::vector<Data> face2_receivedDatas;
412 shared_ptr<Face> face3;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100413
Junxiao Shi79494162014-04-02 18:25:11 -0700414 std::list< shared_ptr<Face> > faces;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100415};
416
417
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000418BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture)
Giulio Grassi624f6c62014-02-18 19:42:14 +0100419{
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700420 UdpFactory factory;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100421
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000422 factory.createChannel("127.0.0.1", "20071");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700423
Giulio Grassi624f6c62014-02-18 19:42:14 +0100424 factory.createFace(FaceUri("udp4://127.0.0.1:20070"),
425 bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
426 bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700427
428
Junxiao Shi79494162014-04-02 18:25:11 -0700429 BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700430 "UdpChannel error: cannot connect or cannot accept connection");
Giulio Grassi624f6c62014-02-18 19:42:14 +0100431
Junxiao Shi79494162014-04-02 18:25:11 -0700432 BOOST_REQUIRE(static_cast<bool>(face2));
433 BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "udp4://127.0.0.1:20070");
434 BOOST_CHECK_EQUAL(face2->getLocalUri().toString(), "udp4://127.0.0.1:20071");
435 BOOST_CHECK_EQUAL(face2->isLocal(), false);
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700436 BOOST_CHECK_EQUAL(face2->getCounters().getNOutBytes(), 0);
437 BOOST_CHECK_EQUAL(face2->getCounters().getNInBytes(), 0);
Junxiao Shi79494162014-04-02 18:25:11 -0700438 // face1 is not created yet
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700439
Giulio Grassi624f6c62014-02-18 19:42:14 +0100440 shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
441 channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
442 bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700443
Giulio Grassi624f6c62014-02-18 19:42:14 +0100444 Interest interest1("ndn:/TpnzGvW9R");
445 Data data1 ("ndn:/KfczhUqVix");
446 data1.setContent(0, 0);
447 Interest interest2("ndn:/QWiIMfj5sL");
448 Data data2 ("ndn:/XNBV796f");
449 data2.setContent(0, 0);
450 Interest interest3("ndn:/QWiIhjgkj5sL");
451 Data data3 ("ndn:/XNBV794f");
452 data3.setContent(0, 0);
453
454
455 ndn::SignatureSha256WithRsa fakeSignature;
456 fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue,
457 reinterpret_cast<const uint8_t*>(0),
458 0));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700459
Giulio Grassi624f6c62014-02-18 19:42:14 +0100460 // set fake signature on data1 and data2
461 data1.setSignature(fakeSignature);
462 data2.setSignature(fakeSignature);
463 data3.setSignature(fakeSignature);
464
Junxiao Shi79494162014-04-02 18:25:11 -0700465 face2->sendInterest(interest2);
466 face2->sendData (data2 );
467 face2->sendData (data2 );
468 face2->sendData (data2 );
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700469 size_t nBytesSent2 = interest2.wireEncode().size() + data2.wireEncode().size() * 3;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100470
Junxiao Shi79494162014-04-02 18:25:11 -0700471 BOOST_CHECK_MESSAGE(limitedIo.run(5,//4 send + 1 listen return
Alexander Afanasyev6f5ff632014-03-07 16:40:10 +0000472 time::seconds(4)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700473 "UdpChannel error: cannot send or receive Interest/Data packets");
Giulio Grassi624f6c62014-02-18 19:42:14 +0100474
Junxiao Shi79494162014-04-02 18:25:11 -0700475 BOOST_REQUIRE(static_cast<bool>(face1));
476 BOOST_CHECK_EQUAL(face1->getRemoteUri().toString(), "udp4://127.0.0.1:20071");
477 BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "udp4://127.0.0.1:20070");
478 BOOST_CHECK_EQUAL(face1->isLocal(), false);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700479
Junxiao Shi79494162014-04-02 18:25:11 -0700480 face1->sendInterest(interest1);
481 face1->sendInterest(interest1);
482 face1->sendInterest(interest1);
483 face1->sendData (data1 );
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700484
Junxiao Shi79494162014-04-02 18:25:11 -0700485 BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(4)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700486 "UdpChannel error: cannot send or receive Interest/Data packets");
Giulio Grassi624f6c62014-02-18 19:42:14 +0100487
Junxiao Shi79494162014-04-02 18:25:11 -0700488 BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
489 BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3);
490 BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 3);
491 BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700492
Junxiao Shi79494162014-04-02 18:25:11 -0700493 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName());
494 BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName());
495 BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName());
496 BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName());
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700497
498
499
Giulio Grassi624f6c62014-02-18 19:42:14 +0100500 //checking if the connection accepting mechanism works properly.
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700501
Junxiao Shi79494162014-04-02 18:25:11 -0700502 face2->sendData (data3 );
503 face2->sendInterest(interest3);
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700504 nBytesSent2 += data3.wireEncode().size() + interest3.wireEncode().size();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100505
Junxiao Shi79494162014-04-02 18:25:11 -0700506 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700507 "UdpChannel error: cannot send or receive Interest/Data packets");
508
Junxiao Shi79494162014-04-02 18:25:11 -0700509 BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 2);
510 BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 4);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700511
Junxiao Shi79494162014-04-02 18:25:11 -0700512 BOOST_CHECK_EQUAL(face1_receivedInterests[1].getName(), interest3.getName());
513 BOOST_CHECK_EQUAL(face1_receivedDatas [3].getName(), data3.getName());
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000514
Junxiao Shi79494162014-04-02 18:25:11 -0700515 const FaceCounters& counters1 = face1->getCounters();
Junxiao Shi6e694322014-04-03 10:27:13 -0700516 BOOST_CHECK_EQUAL(counters1.getNInInterests() , 2);
517 BOOST_CHECK_EQUAL(counters1.getNInDatas() , 4);
518 BOOST_CHECK_EQUAL(counters1.getNOutInterests(), 3);
519 BOOST_CHECK_EQUAL(counters1.getNOutDatas() , 1);
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700520 BOOST_CHECK_EQUAL(counters1.getNInBytes(), nBytesSent2);
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000521
Junxiao Shi79494162014-04-02 18:25:11 -0700522 const FaceCounters& counters2 = face2->getCounters();
Junxiao Shi6e694322014-04-03 10:27:13 -0700523 BOOST_CHECK_EQUAL(counters2.getNInInterests() , 3);
524 BOOST_CHECK_EQUAL(counters2.getNInDatas() , 1);
525 BOOST_CHECK_EQUAL(counters2.getNOutInterests(), 2);
526 BOOST_CHECK_EQUAL(counters2.getNOutDatas() , 4);
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700527 BOOST_CHECK_EQUAL(counters2.getNOutBytes(), nBytesSent2);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000528}
Giulio Grassi624f6c62014-02-18 19:42:14 +0100529
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000530BOOST_FIXTURE_TEST_CASE(EndToEnd6, EndToEndFixture)
531{
532 UdpFactory factory;
533
534 factory.createChannel("::1", "20071");
535
536 factory.createFace(FaceUri("udp://[::1]:20070"),
537 bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
538 bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
539
540
Junxiao Shi79494162014-04-02 18:25:11 -0700541 BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000542 "UdpChannel error: cannot connect or cannot accept connection");
543
Junxiao Shi79494162014-04-02 18:25:11 -0700544 BOOST_REQUIRE(static_cast<bool>(face2));
545 BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "udp6://[::1]:20070");
546 BOOST_CHECK_EQUAL(face2->getLocalUri().toString(), "udp6://[::1]:20071");
547 BOOST_CHECK_EQUAL(face2->isLocal(), false);
548 // face1 is not created yet
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000549
550 shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070");
551 channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
552 bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
553
554 Interest interest1("ndn:/TpnzGvW9R");
555 Data data1 ("ndn:/KfczhUqVix");
556 data1.setContent(0, 0);
557 Interest interest2("ndn:/QWiIMfj5sL");
558 Data data2 ("ndn:/XNBV796f");
559 data2.setContent(0, 0);
560 Interest interest3("ndn:/QWiIhjgkj5sL");
561 Data data3 ("ndn:/XNBV794f");
562 data3.setContent(0, 0);
563
564
565 ndn::SignatureSha256WithRsa fakeSignature;
566 fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue,
567 reinterpret_cast<const uint8_t*>(0),
568 0));
569
570 // set fake signature on data1 and data2
571 data1.setSignature(fakeSignature);
572 data2.setSignature(fakeSignature);
573 data3.setSignature(fakeSignature);
574
Junxiao Shi79494162014-04-02 18:25:11 -0700575 face2->sendInterest(interest2);
576 face2->sendData (data2 );
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000577
Junxiao Shi79494162014-04-02 18:25:11 -0700578 BOOST_CHECK_MESSAGE(limitedIo.run(3,//2 send + 1 listen return
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000579 time::seconds(1)) == LimitedIo::EXCEED_OPS,
580 "UdpChannel error: cannot send or receive Interest/Data packets");
581
Junxiao Shi79494162014-04-02 18:25:11 -0700582 BOOST_REQUIRE(static_cast<bool>(face1));
583 BOOST_CHECK_EQUAL(face1->getRemoteUri().toString(), "udp6://[::1]:20071");
584 BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "udp6://[::1]:20070");
585 BOOST_CHECK_EQUAL(face1->isLocal(), false);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000586
Junxiao Shi79494162014-04-02 18:25:11 -0700587 face1->sendInterest(interest1);
588 face1->sendData (data1 );
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000589
Junxiao Shi79494162014-04-02 18:25:11 -0700590 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000591 "UdpChannel error: cannot send or receive Interest/Data packets");
592
593
Junxiao Shi79494162014-04-02 18:25:11 -0700594 BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
595 BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1);
596 BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1);
597 BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000598
Junxiao Shi79494162014-04-02 18:25:11 -0700599 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName());
600 BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName());
601 BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName());
602 BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName());
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000603
604
605
606 //checking if the connection accepting mechanism works properly.
607
Junxiao Shi79494162014-04-02 18:25:11 -0700608 face2->sendData (data3 );
609 face2->sendInterest(interest3);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000610
Junxiao Shi79494162014-04-02 18:25:11 -0700611 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000612 "UdpChannel error: cannot send or receive Interest/Data packets");
613
Junxiao Shi79494162014-04-02 18:25:11 -0700614 BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 2);
615 BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 2);
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000616
Junxiao Shi79494162014-04-02 18:25:11 -0700617 BOOST_CHECK_EQUAL(face1_receivedInterests[1].getName(), interest3.getName());
618 BOOST_CHECK_EQUAL(face1_receivedDatas [1].getName(), data3.getName());
Giulio Grassi624f6c62014-02-18 19:42:14 +0100619}
620
621BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
622{
623 Interest interest1("ndn:/TpnzGvW9R");
624 Interest interest2("ndn:/QWiIMfj5sL");
Giulio Grassi624f6c62014-02-18 19:42:14 +0100625
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700626 UdpFactory factory;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100627
Giulio Grassi624f6c62014-02-18 19:42:14 +0100628 shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
629 shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700630
Giulio Grassi624f6c62014-02-18 19:42:14 +0100631 channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
632 bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700633
Giulio Grassi624f6c62014-02-18 19:42:14 +0100634 channel2->connect("127.0.0.1", "20070",
635 bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
636 bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700637
638
Junxiao Shi79494162014-04-02 18:25:11 -0700639 BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700640 "UdpChannel error: cannot connect or cannot accept connection");
Giulio Grassi624f6c62014-02-18 19:42:14 +0100641
Junxiao Shi79494162014-04-02 18:25:11 -0700642 BOOST_CHECK_EQUAL(faces.size(), 1);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700643
Giulio Grassi624f6c62014-02-18 19:42:14 +0100644 shared_ptr<UdpChannel> channel3 = factory.createChannel("127.0.0.1", "20072");
645 channel3->connect("127.0.0.1", "20070",
646 bind(&EndToEndFixture::channel3_onFaceCreated, this, _1),
647 bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700648
Giulio Grassi624f6c62014-02-18 19:42:14 +0100649 shared_ptr<UdpChannel> channel4 = factory.createChannel("127.0.0.1", "20073");
650
651 BOOST_CHECK_NE(channel3, channel4);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100652
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700653 scheduler::schedule(time::milliseconds(500),
Davide Pesaventoab1e8f22014-10-21 22:45:33 +0200654 bind(&EndToEndFixture::connect, this, channel4, "127.0.0.1", "20070"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700655
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700656 scheduler::schedule(time::milliseconds(400), bind(&EndToEndFixture::checkFaceList, this, 2));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700657
Junxiao Shi79494162014-04-02 18:25:11 -0700658 BOOST_CHECK_MESSAGE(limitedIo.run(2,// 2 connects
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700659 time::seconds(4)) == LimitedIo::EXCEED_OPS,
660 "UdpChannel error: cannot connect or cannot accept multiple connections");
661
Junxiao Shi79494162014-04-02 18:25:11 -0700662 BOOST_CHECK_EQUAL(faces.size(), 3);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700663
664
Junxiao Shi79494162014-04-02 18:25:11 -0700665 face2->sendInterest(interest1);
666 BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700667 "UdpChannel error: cannot send or receive Interest/Data packets");
668
Junxiao Shi79494162014-04-02 18:25:11 -0700669 BOOST_CHECK_EQUAL(faces.size(), 4);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700670
Junxiao Shi79494162014-04-02 18:25:11 -0700671 face3->sendInterest(interest2);
672 BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700673 "UdpChannel error: cannot send or receive Interest/Data packets");
674
Junxiao Shi79494162014-04-02 18:25:11 -0700675 //channel1 should have created 2 faces, one when face2 sent an interest, one when face3 sent an interest
676 BOOST_CHECK_EQUAL(faces.size(), 5);
Davide Pesavento126249b2014-03-13 02:42:21 +0100677 BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
678 bind(&EndToEndFixture::channel_onConnectFailedOk, this, _1)),
Giulio Grassi624f6c62014-02-18 19:42:14 +0100679 UdpChannel::Error);
680}
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700681
Giulio Grassi624f6c62014-02-18 19:42:14 +0100682//Test commented because it required to be run in a machine that can resolve ipv6 query
683//BOOST_FIXTURE_TEST_CASE(EndToEndIpv6, EndToEndFixture)
684//{
685// UdpFactory factory = UdpFactory();
686// Scheduler scheduler(g_io); // to limit the amount of time the test may take
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700687//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100688// EventId abortEvent =
689// scheduler.scheduleEvent(time::seconds(1),
690// bind(&EndToEndFixture::abortTestCase, this,
691// "UdpChannel error: cannot connect or cannot accept connection"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700692//
Junxiao Shi79494162014-04-02 18:25:11 -0700693// limitedIoRemaining = 1;
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700694//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100695// shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070");
696// shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700697//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100698// channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
699// bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700700//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100701// channel2->connect("::1", "20070",
702// bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
703// bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
704// g_io.run();
705// g_io.reset();
706// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700707//
Junxiao Shi79494162014-04-02 18:25:11 -0700708// BOOST_REQUIRE(static_cast<bool>(face2));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700709//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100710// abortEvent =
711// scheduler.scheduleEvent(time::seconds(1),
712// bind(&EndToEndFixture::abortTestCase, this,
713// "UdpChannel error: cannot send or receive Interest/Data packets"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700714//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100715// Interest interest1("ndn:/TpnzGvW9R");
716// Data data1 ("ndn:/KfczhUqVix");
717// data1.setContent(0, 0);
718// Interest interest2("ndn:/QWiIMfj5sL");
719// Data data2 ("ndn:/XNBV796f");
720// data2.setContent(0, 0);
721// Interest interest3("ndn:/QWiIhjgkj5sL");
722// Data data3 ("ndn:/XNBV794f");
723// data3.setContent(0, 0);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700724//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100725// ndn::SignatureSha256WithRsa fakeSignature;
726// fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700727//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100728// // set fake signature on data1 and data2
729// data1.setSignature(fakeSignature);
730// data2.setSignature(fakeSignature);
731// data3.setSignature(fakeSignature);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700732//
Junxiao Shi79494162014-04-02 18:25:11 -0700733// face2->sendInterest(interest2);
734// face2->sendData (data2 );
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700735//
Junxiao Shi79494162014-04-02 18:25:11 -0700736// limitedIoRemaining = 3; //2 send + 1 listen return
Giulio Grassi624f6c62014-02-18 19:42:14 +0100737// g_io.run();
738// g_io.reset();
739// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700740//
Junxiao Shi79494162014-04-02 18:25:11 -0700741// BOOST_REQUIRE(static_cast<bool>(face1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700742//
Junxiao Shi79494162014-04-02 18:25:11 -0700743// face1->sendInterest(interest1);
744// face1->sendData (data1 );
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700745//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100746// abortEvent =
747// scheduler.scheduleEvent(time::seconds(1),
748// bind(&EndToEndFixture::abortTestCase, this,
749// "UdpChannel error: cannot send or receive Interest/Data packets"));
Junxiao Shi79494162014-04-02 18:25:11 -0700750// limitedIoRemaining = 2;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100751// g_io.run();
752// g_io.reset();
753// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700754//
Junxiao Shi79494162014-04-02 18:25:11 -0700755// BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
756// BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1);
757// BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1);
758// BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700759//
Junxiao Shi79494162014-04-02 18:25:11 -0700760// BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName());
761// BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName());
762// BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName());
763// BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName());
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700764//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100765// //checking if the connection accepting mechanism works properly.
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700766//
Junxiao Shi79494162014-04-02 18:25:11 -0700767// face2->sendData (data3 );
768// face2->sendInterest(interest3);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700769//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100770// abortEvent =
771// scheduler.scheduleEvent(time::seconds(1),
772// bind(&EndToEndFixture::abortTestCase, this,
773// "UdpChannel error: cannot send or receive Interest/Data packets"));
Junxiao Shi79494162014-04-02 18:25:11 -0700774// limitedIoRemaining = 2;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100775// g_io.run();
776// g_io.reset();
777// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700778//
Junxiao Shi79494162014-04-02 18:25:11 -0700779// BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 2);
780// BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 2);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700781//
Junxiao Shi79494162014-04-02 18:25:11 -0700782// BOOST_CHECK_EQUAL(face1_receivedInterests[1].getName(), interest3.getName());
783// BOOST_CHECK_EQUAL(face1_receivedDatas [1].getName(), data3.getName());
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700784//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100785//}
786
787
788//Test commented because it required to be run in a machine that can resolve ipv6 query
789//BOOST_FIXTURE_TEST_CASE(MultipleAcceptsIpv6, EndToEndFixture)
790//{
791// Interest interest1("ndn:/TpnzGvW9R");
792// Interest interest2("ndn:/QWiIMfj5sL");
793// Interest interest3("ndn:/QWiIhjgkj5sL");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700794//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100795// UdpFactory factory = UdpFactory();
796// Scheduler scheduler(g_io); // to limit the amount of time the test may take
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700797//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100798// EventId abortEvent =
799// scheduler.scheduleEvent(time::seconds(4),
800// bind(&EndToEndFixture::abortTestCase, this,
801// "UdpChannel error: cannot connect or cannot accept connection"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700802//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100803// shared_ptr<UdpChannel> channel1 = factory.createChannel("::1", "20070");
804// shared_ptr<UdpChannel> channel2 = factory.createChannel("::1", "20071");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700805//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100806// channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
807// bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700808//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100809// channel2->connect("::1", "20070",
810// bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
811// bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700812//
Junxiao Shi79494162014-04-02 18:25:11 -0700813// limitedIoRemaining = 1;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100814// g_io.run();
815// g_io.reset();
816// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700817//
Junxiao Shi79494162014-04-02 18:25:11 -0700818// BOOST_CHECK_EQUAL(faces.size(), 1);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700819//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100820// shared_ptr<UdpChannel> channel3 = factory.createChannel("::1", "20072");
821// channel3->connect("::1", "20070",
822// bind(&EndToEndFixture::channel3_onFaceCreated, this, _1),
823// bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700824//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100825// shared_ptr<UdpChannel> channel4 = factory.createChannel("::1", "20073");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700826//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100827// BOOST_CHECK_NE(channel3, channel4);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700828//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100829// scheduler
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700830// .scheduleEvent(time::milliseconds(500),
Giulio Grassi624f6c62014-02-18 19:42:14 +0100831// bind(&UdpChannel::connect, channel4,
832// "::1", "20070",
833// static_cast<UdpChannel::FaceCreatedCallback>(bind(&EndToEndFixture::
834// channel_onFaceCreated, this, _1)),
835// static_cast<UdpChannel::ConnectFailedCallback>(bind(&EndToEndFixture::
836// channel_onConnectFailed, this, _1))));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700837//
Junxiao Shi79494162014-04-02 18:25:11 -0700838// limitedIoRemaining = 2; // 2 connects
Giulio Grassi624f6c62014-02-18 19:42:14 +0100839// abortEvent =
840// scheduler.scheduleEvent(time::seconds(4),
841// bind(&EndToEndFixture::abortTestCase, this,
842// "UdpChannel error: cannot connect or cannot accept multiple connections"));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700843//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100844// scheduler.scheduleEvent(time::seconds(0.4),
845// bind(&EndToEndFixture::checkFaceList, this, 2));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700846//
Giulio Grassi624f6c62014-02-18 19:42:14 +0100847// g_io.run();
848// g_io.reset();
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700849//
Junxiao Shi79494162014-04-02 18:25:11 -0700850// BOOST_CHECK_EQUAL(faces.size(), 3);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700851//
852//
Junxiao Shi79494162014-04-02 18:25:11 -0700853// face2->sendInterest(interest1);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100854// abortEvent =
855// scheduler.scheduleEvent(time::seconds(1),
856// bind(&EndToEndFixture::abortTestCase, this,
857// "UdpChannel error: cannot send or receive Interest/Data packets"));
Junxiao Shi79494162014-04-02 18:25:11 -0700858// limitedIoRemaining = 1;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100859// g_io.run();
860// g_io.reset();
861// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700862//
Junxiao Shi79494162014-04-02 18:25:11 -0700863// BOOST_CHECK_EQUAL(faces.size(), 4);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700864//
Junxiao Shi79494162014-04-02 18:25:11 -0700865// face3->sendInterest(interest2);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100866// abortEvent =
867// scheduler.scheduleEvent(time::seconds(1),
868// bind(&EndToEndFixture::abortTestCase, this,
869// "UdpChannel error: cannot send or receive Interest/Data packets"));
Junxiao Shi79494162014-04-02 18:25:11 -0700870// limitedIoRemaining = 1;
Giulio Grassi624f6c62014-02-18 19:42:14 +0100871// g_io.run();
872// g_io.reset();
873// scheduler.cancelEvent(abortEvent);
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700874//
Junxiao Shi79494162014-04-02 18:25:11 -0700875// //channel1 should have created 2 faces, one when face2 sent an interest, one when face3 sent an interest
876// BOOST_CHECK_EQUAL(faces.size(), 5);
Giulio Grassi624f6c62014-02-18 19:42:14 +0100877// BOOST_CHECK_THROW(channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated,
878// this,
879// _1),
880// bind(&EndToEndFixture::channel_onConnectFailedOk,
881// this,
882// _1)),
883// UdpChannel::Error);
884//}
885
886
887BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture)
888{
889 UdpFactory factory = UdpFactory();
Giulio Grassi624f6c62014-02-18 19:42:14 +0100890
Giulio Grassi624f6c62014-02-18 19:42:14 +0100891 shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070");
892 shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071");
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700893
Giulio Grassi624f6c62014-02-18 19:42:14 +0100894 channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
895 bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700896
Giulio Grassi624f6c62014-02-18 19:42:14 +0100897 channel2->connect("127.0.0.1", "20070",
898 bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
899 bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700900
Junxiao Shi79494162014-04-02 18:25:11 -0700901 BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700902 "UdpChannel error: cannot connect or cannot accept connection");
Giulio Grassi624f6c62014-02-18 19:42:14 +0100903
904 BOOST_CHECK_EQUAL(channel2->size(), 1);
905
Junxiao Shi79494162014-04-02 18:25:11 -0700906 BOOST_CHECK(static_cast<bool>(face2));
Giulio Grassi624f6c62014-02-18 19:42:14 +0100907
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700908 // Face::close must be invoked during io run to be counted as an op
Junxiao Shi79494162014-04-02 18:25:11 -0700909 scheduler::schedule(time::milliseconds(100), bind(&Face::close, face2));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700910
Junxiao Shi79494162014-04-02 18:25:11 -0700911 BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700912 "FaceClosing error: cannot properly close faces");
Giulio Grassi624f6c62014-02-18 19:42:14 +0100913
Junxiao Shi79494162014-04-02 18:25:11 -0700914 BOOST_CHECK(!static_cast<bool>(face2));
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700915
Giulio Grassi624f6c62014-02-18 19:42:14 +0100916 BOOST_CHECK_EQUAL(channel2->size(), 0);
917}
Junxiao Shi79494162014-04-02 18:25:11 -0700918
Giulio Grassi69871f02014-03-09 16:14:44 +0100919BOOST_FIXTURE_TEST_CASE(ClosingIdleFace, EndToEndFixture)
920{
921 Interest interest1("ndn:/TpnzGvW9R");
922 Interest interest2("ndn:/QWiIMfj5sL");
Davide Pesavento126249b2014-03-13 02:42:21 +0100923
Giulio Grassi69871f02014-03-09 16:14:44 +0100924 UdpFactory factory;
Davide Pesavento126249b2014-03-13 02:42:21 +0100925
926 shared_ptr<UdpChannel> channel1 = factory.createChannel("127.0.0.1", "20070",
Giulio Grassi69871f02014-03-09 16:14:44 +0100927 time::seconds(2));
Davide Pesavento126249b2014-03-13 02:42:21 +0100928 shared_ptr<UdpChannel> channel2 = factory.createChannel("127.0.0.1", "20071",
Giulio Grassi69871f02014-03-09 16:14:44 +0100929 time::seconds(2));
Davide Pesavento126249b2014-03-13 02:42:21 +0100930
Giulio Grassi69871f02014-03-09 16:14:44 +0100931 channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
Davide Pesavento126249b2014-03-13 02:42:21 +0100932 bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
Giulio Grassi69871f02014-03-09 16:14:44 +0100933
934 channel2->connect("127.0.0.1", "20070",
935 bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
936 bind(&EndToEndFixture::channel2_onConnectFailed, this, _1));
Junxiao Shi79494162014-04-02 18:25:11 -0700937
938 BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS,
Giulio Grassi69871f02014-03-09 16:14:44 +0100939 "UdpChannel error: cannot connect or cannot accept connection");
940
Junxiao Shi79494162014-04-02 18:25:11 -0700941 face2->sendInterest(interest1);
942 BOOST_CHECK(!face2->isOnDemand());
Giulio Grassi69871f02014-03-09 16:14:44 +0100943
Junxiao Shi79494162014-04-02 18:25:11 -0700944 BOOST_CHECK_MESSAGE(limitedIo.run(2,//1 send + 1 listen return
Giulio Grassi69871f02014-03-09 16:14:44 +0100945 time::seconds(1)) == LimitedIo::EXCEED_OPS,
946 "UdpChannel error: cannot send or receive Interest/Data packets");
Junxiao Shi79494162014-04-02 18:25:11 -0700947
948 BOOST_CHECK_EQUAL(faces.size(), 2);
949 BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(2)) == LimitedIo::EXCEED_TIME,
Giulio Grassi69871f02014-03-09 16:14:44 +0100950 "Idle face should be still open because has been used recently");
Junxiao Shi79494162014-04-02 18:25:11 -0700951 BOOST_CHECK_EQUAL(faces.size(), 2);
952 BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_OPS,
Giulio Grassi69871f02014-03-09 16:14:44 +0100953 "Closing idle face error: face should be closed by now");
Junxiao Shi79494162014-04-02 18:25:11 -0700954
Giulio Grassi69871f02014-03-09 16:14:44 +0100955 //the face on listen should be closed now
956 BOOST_CHECK_EQUAL(channel1->size(), 0);
Junxiao Shi79494162014-04-02 18:25:11 -0700957 //checking that face2 has not been closed
Giulio Grassi69871f02014-03-09 16:14:44 +0100958 BOOST_CHECK_EQUAL(channel2->size(), 1);
Junxiao Shi79494162014-04-02 18:25:11 -0700959 BOOST_REQUIRE(static_cast<bool>(face2));
960
961 face2->sendInterest(interest2);
962 BOOST_CHECK_MESSAGE(limitedIo.run(2,//1 send + 1 listen return
Giulio Grassi69871f02014-03-09 16:14:44 +0100963 time::seconds(1)) == LimitedIo::EXCEED_OPS,
964 "UdpChannel error: cannot send or receive Interest/Data packets");
965 //channel1 should have created a new face by now
966 BOOST_CHECK_EQUAL(channel1->size(), 1);
967 BOOST_CHECK_EQUAL(channel2->size(), 1);
Junxiao Shi79494162014-04-02 18:25:11 -0700968 BOOST_REQUIRE(static_cast<bool>(face1));
969 BOOST_CHECK(face1->isOnDemand());
970
Giulio Grassi69871f02014-03-09 16:14:44 +0100971 channel1->connect("127.0.0.1", "20071",
972 bind(&EndToEndFixture::channel1_onFaceCreatedNoCheck, this, _1),
973 bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
974
Junxiao Shi79494162014-04-02 18:25:11 -0700975 BOOST_CHECK_MESSAGE(limitedIo.run(1,//1 connect
Giulio Grassi69871f02014-03-09 16:14:44 +0100976 time::seconds(1)) == LimitedIo::EXCEED_OPS,
977 "UdpChannel error: cannot connect");
Alexander Afanasyev355c0662014-03-20 18:08:17 -0700978
Junxiao Shi79494162014-04-02 18:25:11 -0700979 BOOST_CHECK(!face1->isOnDemand());
980
981 //the connect should have set face1 as permanent face,
Giulio Grassi69871f02014-03-09 16:14:44 +0100982 //but it shouln't have created any additional faces
983 BOOST_CHECK_EQUAL(channel1->size(), 1);
984 BOOST_CHECK_EQUAL(channel2->size(), 1);
Junxiao Shi79494162014-04-02 18:25:11 -0700985 BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(4)) == LimitedIo::EXCEED_TIME,
Giulio Grassi69871f02014-03-09 16:14:44 +0100986 "Idle face should be still open because it's permanent now");
987 //both faces are permanent, nothing should have changed
988 BOOST_CHECK_EQUAL(channel1->size(), 1);
989 BOOST_CHECK_EQUAL(channel2->size(), 1);
990}
991
Alexander Afanasyev70aaf8a2014-12-13 00:44:22 -0800992class FakeNetworkInterfaceFixture : public BaseFixture
993{
994public:
995 FakeNetworkInterfaceFixture()
996 {
997 using namespace boost::asio::ip;
998
999 auto fakeInterfaces = make_shared<std::vector<NetworkInterfaceInfo>>();
1000
1001 fakeInterfaces->push_back(
1002 NetworkInterfaceInfo {0, "eth0",
1003 ethernet::Address::fromString("3e:15:c2:8b:65:00"),
1004 {address_v4::from_string("0.0.0.0")},
1005 {address_v6::from_string("::")},
1006 address_v4(),
1007 IFF_UP});
1008 fakeInterfaces->push_back(
1009 NetworkInterfaceInfo {1, "eth0",
1010 ethernet::Address::fromString("3e:15:c2:8b:65:00"),
1011 {address_v4::from_string("192.168.2.1"), address_v4::from_string("192.168.2.2")},
1012 {},
1013 address_v4::from_string("192.168.2.255"),
1014 0});
1015 fakeInterfaces->push_back(
1016 NetworkInterfaceInfo {2, "eth1",
1017 ethernet::Address::fromString("3e:15:c2:8b:65:00"),
1018 {address_v4::from_string("198.51.100.1")},
1019 {address_v6::from_string("2001:db8::2"), address_v6::from_string("2001:db8::3")},
1020 address_v4::from_string("198.51.100.255"),
1021 IFF_MULTICAST | IFF_BROADCAST | IFF_UP});
1022
1023 setDebugNetworkInterfaces(fakeInterfaces);
1024 }
1025
1026 ~FakeNetworkInterfaceFixture()
1027 {
1028 setDebugNetworkInterfaces(nullptr);
1029 }
1030};
1031
1032BOOST_FIXTURE_TEST_CASE(Bug2292, FakeNetworkInterfaceFixture)
1033{
1034 using namespace boost::asio::ip;
1035
1036 UdpFactory factory;
1037 factory.prohibitEndpoint(udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024));
1038 BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
1039 BOOST_CHECK((factory.m_prohibitedEndpoints ==
1040 std::set<udp::Endpoint> {
1041 udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
1042 }));
1043
1044 factory.m_prohibitedEndpoints.clear();
1045 factory.prohibitEndpoint(udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048));
1046 BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 1);
1047 BOOST_CHECK((factory.m_prohibitedEndpoints ==
1048 std::set<udp::Endpoint> {
1049 udp::Endpoint(address_v6::from_string("2001:db8::1"), 2048),
1050 }));
1051
1052 factory.m_prohibitedEndpoints.clear();
1053 factory.prohibitEndpoint(udp::Endpoint(address_v4(), 1024));
1054 BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 6);
1055 BOOST_CHECK((factory.m_prohibitedEndpoints ==
1056 std::set<udp::Endpoint> {
1057 udp::Endpoint(address_v4::from_string("192.168.2.1"), 1024),
1058 udp::Endpoint(address_v4::from_string("192.168.2.2"), 1024),
1059 udp::Endpoint(address_v4::from_string("198.51.100.1"), 1024),
1060 udp::Endpoint(address_v4::from_string("198.51.100.255"), 1024),
1061 udp::Endpoint(address_v4::from_string("255.255.255.255"), 1024),
1062 udp::Endpoint(address_v4::from_string("0.0.0.0"), 1024)
1063 }));
1064
1065 factory.m_prohibitedEndpoints.clear();
1066 factory.prohibitEndpoint(udp::Endpoint(address_v6(), 2048));
1067 BOOST_REQUIRE_EQUAL(factory.m_prohibitedEndpoints.size(), 3);
1068 BOOST_CHECK((factory.m_prohibitedEndpoints ==
1069 std::set<udp::Endpoint> {
1070 udp::Endpoint(address_v6::from_string("2001:db8::2"), 2048),
1071 udp::Endpoint(address_v6::from_string("2001:db8::3"), 2048),
1072 udp::Endpoint(address_v6::from_string("::"), 2048),
1073 }));
1074}
1075
Giulio Grassi624f6c62014-02-18 19:42:14 +01001076BOOST_AUTO_TEST_SUITE_END()
Junxiao Shi7e2413b2014-03-02 11:15:09 -07001077
Giulio Grassi624f6c62014-02-18 19:42:14 +01001078} // namespace tests
1079} // namespace nfd