blob: fc528c2bd9cf2d4b0d8050de9684c8f204988d66 [file] [log] [blame]
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev319f2c82015-01-07 14:56:53 -08003 * Copyright (c) 2014-2015, 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 */
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010025
Davide Pesavento6ad890a2015-03-09 03:43:17 +010026#include "face/unix-stream-channel.hpp"
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080027#include "face/unix-stream-factory.hpp"
Yukai Tu74c895d2015-09-21 01:11:51 -070028#include "face/unix-stream-transport.hpp"
29
30#include "face/generic-link-service.hpp"
31#include "face/lp-face-wrapper.hpp"
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010032
Junxiao Shid9ee45c2014-02-27 15:38:11 -070033#include "tests/test-common.hpp"
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070034#include "tests/limited-io.hpp"
Alexander Afanasyev650028d2014-04-25 18:39:10 -070035#include "dummy-stream-sender.hpp"
36#include "packet-datasets.hpp"
Junxiao Shid9ee45c2014-02-27 15:38:11 -070037
38namespace nfd {
39namespace tests {
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010040
Junxiao Shi61e3cc52014-03-03 20:40:28 -070041#define CHANNEL_PATH1 "unix-stream-test.1.sock"
42#define CHANNEL_PATH2 "unix-stream-test.2.sock"
43
Yukai Tu74c895d2015-09-21 01:11:51 -070044BOOST_AUTO_TEST_SUITE(Face)
45BOOST_FIXTURE_TEST_SUITE(TestUnixStream, BaseFixture)
46
47using nfd::Face;
48using face::LpFaceWrapper;
49using face::UnixStreamTransport;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010050
51BOOST_AUTO_TEST_CASE(ChannelMap)
52{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080053 UnixStreamFactory factory;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010054
Junxiao Shi61e3cc52014-03-03 20:40:28 -070055 shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
56 shared_ptr<UnixStreamChannel> channel1a = factory.createChannel(CHANNEL_PATH1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010057 BOOST_CHECK_EQUAL(channel1, channel1a);
Junxiao Shi61e3cc52014-03-03 20:40:28 -070058 std::string channel1uri = channel1->getUri().toString();
59 BOOST_CHECK_EQUAL(channel1uri.find("unix:///"), 0); // third '/' is the path separator
60 BOOST_CHECK_EQUAL(channel1uri.rfind(CHANNEL_PATH1),
61 channel1uri.size() - std::string(CHANNEL_PATH1).size());
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010062
Junxiao Shi61e3cc52014-03-03 20:40:28 -070063 shared_ptr<UnixStreamChannel> channel2 = factory.createChannel(CHANNEL_PATH2);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010064 BOOST_CHECK_NE(channel1, channel2);
65}
66
Steve DiBenedettoef04f272014-06-04 14:28:31 -060067BOOST_AUTO_TEST_CASE(GetChannels)
68{
69 UnixStreamFactory factory;
Davide Pesavento292e5e12015-03-13 02:08:33 +010070 BOOST_CHECK(factory.getChannels().empty());
Steve DiBenedettoef04f272014-06-04 14:28:31 -060071
Davide Pesavento292e5e12015-03-13 02:08:33 +010072 std::vector<shared_ptr<const Channel>> expectedChannels;
Steve DiBenedettoef04f272014-06-04 14:28:31 -060073 expectedChannels.push_back(factory.createChannel(CHANNEL_PATH1));
74 expectedChannels.push_back(factory.createChannel(CHANNEL_PATH2));
75
Davide Pesavento292e5e12015-03-13 02:08:33 +010076 for (const auto& channel : factory.getChannels()) {
77 auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), channel);
78 BOOST_REQUIRE(pos != expectedChannels.end());
79 expectedChannels.erase(pos);
80 }
Steve DiBenedettoef04f272014-06-04 14:28:31 -060081
82 BOOST_CHECK_EQUAL(expectedChannels.size(), 0);
83}
84
Yukai Tu7c90e6d2015-07-11 12:21:46 +080085BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate)
86{
87 UnixStreamFactory factory;
88
89 BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"),
90 ndn::nfd::FACE_PERSISTENCY_PERMANENT,
91 bind([]{}),
92 bind([]{})),
93 ProtocolFactory::Error);
94
95 BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"),
96 ndn::nfd::FACE_PERSISTENCY_ON_DEMAND,
97 bind([]{}),
98 bind([]{})),
99 ProtocolFactory::Error);
100
101 BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"),
102 ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
103 bind([]{}),
104 bind([]{})),
105 ProtocolFactory::Error);
106}
107
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700108class EndToEndFixture : protected BaseFixture
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100109{
110public:
111 void
112 client_onConnect(const boost::system::error_code& error)
113 {
114 BOOST_CHECK_MESSAGE(!error, error.message());
115
Junxiao Shi79494162014-04-02 18:25:11 -0700116 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100117 }
118
119 void
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700120 channel1_onFaceCreated(const shared_ptr<Face>& newFace)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100121 {
Junxiao Shi79494162014-04-02 18:25:11 -0700122 BOOST_CHECK(!static_cast<bool>(face1));
Yukai Tu74c895d2015-09-21 01:11:51 -0700123 face1 = static_pointer_cast<LpFaceWrapper>(newFace);
Junxiao Shic099ddb2014-12-25 20:53:20 -0700124 face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1));
125 face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1));
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100126
Junxiao Shi79494162014-04-02 18:25:11 -0700127 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100128 }
129
130 void
131 channel1_onConnectFailed(const std::string& reason)
132 {
133 BOOST_CHECK_MESSAGE(false, reason);
134
Junxiao Shi79494162014-04-02 18:25:11 -0700135 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100136 }
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800137
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100138 void
139 face1_onReceiveInterest(const Interest& interest)
140 {
Junxiao Shi79494162014-04-02 18:25:11 -0700141 face1_receivedInterests.push_back(interest);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100142
Junxiao Shi79494162014-04-02 18:25:11 -0700143 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100144 }
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800145
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100146 void
147 face1_onReceiveData(const Data& data)
148 {
Junxiao Shi79494162014-04-02 18:25:11 -0700149 face1_receivedDatas.push_back(data);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100150
Junxiao Shi79494162014-04-02 18:25:11 -0700151 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100152 }
153
154 void
155 face2_onReceiveInterest(const Interest& interest)
156 {
Junxiao Shi79494162014-04-02 18:25:11 -0700157 face2_receivedInterests.push_back(interest);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100158
Junxiao Shi79494162014-04-02 18:25:11 -0700159 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100160 }
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800161
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100162 void
163 face2_onReceiveData(const Data& data)
164 {
Junxiao Shi79494162014-04-02 18:25:11 -0700165 face2_receivedDatas.push_back(data);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100166
Junxiao Shi79494162014-04-02 18:25:11 -0700167 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100168 }
169
170 void
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700171 channel_onFaceCreated(const shared_ptr<Face>& newFace)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100172 {
Yukai Tu74c895d2015-09-21 01:11:51 -0700173 faces.push_back(static_pointer_cast<LpFaceWrapper>(newFace));
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100174
Junxiao Shi79494162014-04-02 18:25:11 -0700175 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100176 }
177
178 void
179 channel_onConnectFailed(const std::string& reason)
180 {
181 BOOST_CHECK_MESSAGE(false, reason);
182
Junxiao Shi79494162014-04-02 18:25:11 -0700183 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100184 }
185
Yukai Tu74c895d2015-09-21 01:11:51 -0700186 shared_ptr<LpFaceWrapper>
187 makeFace(UnixStreamTransport::protocol::socket&& socket)
Davide Pesavento292e5e12015-03-13 02:08:33 +0100188 {
Yukai Tu74c895d2015-09-21 01:11:51 -0700189 auto linkService = make_unique<face::GenericLinkService>();
190 auto transport = make_unique<UnixStreamTransport>(std::move(socket));
191 auto lpFace = make_unique<LpFace>(std::move(linkService), std::move(transport));
192 return make_shared<LpFaceWrapper>(std::move(lpFace));
Davide Pesavento292e5e12015-03-13 02:08:33 +0100193 }
194
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100195protected:
Junxiao Shi79494162014-04-02 18:25:11 -0700196 LimitedIo limitedIo;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100197
Yukai Tu74c895d2015-09-21 01:11:51 -0700198 shared_ptr<LpFaceWrapper> face1;
Junxiao Shi79494162014-04-02 18:25:11 -0700199 std::vector<Interest> face1_receivedInterests;
200 std::vector<Data> face1_receivedDatas;
Yukai Tu74c895d2015-09-21 01:11:51 -0700201 shared_ptr<LpFaceWrapper> face2;
Junxiao Shi79494162014-04-02 18:25:11 -0700202 std::vector<Interest> face2_receivedInterests;
203 std::vector<Data> face2_receivedDatas;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100204
Yukai Tu74c895d2015-09-21 01:11:51 -0700205 std::list<shared_ptr<LpFaceWrapper>> faces;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100206};
207
208
209BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture)
210{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -0800211 UnixStreamFactory factory;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100212
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700213 shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100214 channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
215 bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
216
Yukai Tu74c895d2015-09-21 01:11:51 -0700217 UnixStreamTransport::protocol::socket client(g_io);
218 client.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1),
Davide Pesavento292e5e12015-03-13 02:08:33 +0100219 bind(&EndToEndFixture::client_onConnect, this, _1));
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100220
Davide Pesavento292e5e12015-03-13 02:08:33 +0100221 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Connect");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100222
Junxiao Shi79494162014-04-02 18:25:11 -0700223 BOOST_REQUIRE(static_cast<bool>(face1));
Davide Pesavento94279412015-02-27 01:29:32 +0100224 BOOST_CHECK_EQUAL(face1->isLocal(), true);
Yukai Tu731f0d72015-07-04 11:14:44 +0800225 BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
Davide Pesavento94279412015-02-27 01:29:32 +0100226 BOOST_CHECK_EQUAL(face1->isMultiAccess(), false);
Junxiao Shi79494162014-04-02 18:25:11 -0700227 BOOST_CHECK_EQUAL(face1->getRemoteUri().getScheme(), "fd");
Davide Pesavento292e5e12015-03-13 02:08:33 +0100228 BOOST_CHECK_NO_THROW(std::stoi(face1->getRemoteUri().getHost()));
Junxiao Shi79494162014-04-02 18:25:11 -0700229 std::string face1localUri = face1->getLocalUri().toString();
230 BOOST_CHECK_EQUAL(face1localUri.find("unix:///"), 0); // third '/' is the path separator
231 BOOST_CHECK_EQUAL(face1localUri.rfind(CHANNEL_PATH1),
232 face1localUri.size() - std::string(CHANNEL_PATH1).size());
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000233
Davide Pesavento292e5e12015-03-13 02:08:33 +0100234 face2 = makeFace(std::move(client));
Junxiao Shic099ddb2014-12-25 20:53:20 -0700235 face2->onReceiveInterest.connect(bind(&EndToEndFixture::face2_onReceiveInterest, this, _1));
236 face2->onReceiveData.connect(bind(&EndToEndFixture::face2_onReceiveData, this, _1));
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100237
Alexander Afanasyev650028d2014-04-25 18:39:10 -0700238 shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
239 shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
240 shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL");
241 shared_ptr<Data> data2 = makeData("ndn:/XNBV796f");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100242
Alexander Afanasyev650028d2014-04-25 18:39:10 -0700243 face1->sendInterest(*interest1);
244 face1->sendInterest(*interest1);
245 face1->sendInterest(*interest1);
246 face1->sendData (*data1 );
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700247 size_t nBytesSent1 = interest1->wireEncode().size() * 3 + data1->wireEncode().size();
Alexander Afanasyev650028d2014-04-25 18:39:10 -0700248 face2->sendInterest(*interest2);
249 face2->sendData (*data2 );
250 face2->sendData (*data2 );
251 face2->sendData (*data2 );
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700252 size_t nBytesSent2 = interest2->wireEncode().size() + data2->wireEncode().size() * 3;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100253
Davide Pesavento292e5e12015-03-13 02:08:33 +0100254 BOOST_CHECK_MESSAGE(limitedIo.run(8, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Send/receive");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100255
Junxiao Shi79494162014-04-02 18:25:11 -0700256 BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
257 BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3);
258 BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 3);
259 BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100260
Alexander Afanasyev650028d2014-04-25 18:39:10 -0700261 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName());
262 BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName());
263 BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName());
264 BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName());
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000265
Junxiao Shi5dd26c32014-07-20 23:15:14 -0700266 // needed to ensure NOutBytes counters are accurate
267 limitedIo.run(LimitedIo::UNLIMITED_OPS, time::seconds(1));
268
Junxiao Shida93f1f2015-11-11 06:13:16 -0700269 const face::FaceCounters& counters1 = face1->getCounters();
270 BOOST_CHECK_EQUAL(counters1.nInInterests, 1);
271 BOOST_CHECK_EQUAL(counters1.nInData, 3);
272 BOOST_CHECK_EQUAL(counters1.nOutInterests, 3);
273 BOOST_CHECK_EQUAL(counters1.nOutData, 1);
274 BOOST_CHECK_EQUAL(counters1.nInBytes, nBytesSent2);
275 BOOST_CHECK_EQUAL(counters1.nOutBytes, nBytesSent1);
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000276
Junxiao Shida93f1f2015-11-11 06:13:16 -0700277 const face::FaceCounters& counters2 = face2->getCounters();
278 BOOST_CHECK_EQUAL(counters2.nInInterests, 3);
279 BOOST_CHECK_EQUAL(counters2.nInData, 1);
280 BOOST_CHECK_EQUAL(counters2.nOutInterests, 1);
281 BOOST_CHECK_EQUAL(counters2.nOutData, 3);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100282}
283
284BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
285{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -0800286 UnixStreamFactory factory;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100287
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700288 shared_ptr<UnixStreamChannel> channel = factory.createChannel(CHANNEL_PATH1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100289 channel->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
290 bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
291
Yukai Tu74c895d2015-09-21 01:11:51 -0700292 UnixStreamTransport::protocol::socket client1(g_io);
293 client1.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1),
Davide Pesavento292e5e12015-03-13 02:08:33 +0100294 bind(&EndToEndFixture::client_onConnect, this, _1));
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100295
Davide Pesavento292e5e12015-03-13 02:08:33 +0100296 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "First connect");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100297
Junxiao Shi79494162014-04-02 18:25:11 -0700298 BOOST_CHECK_EQUAL(faces.size(), 1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100299
Yukai Tu74c895d2015-09-21 01:11:51 -0700300 UnixStreamTransport::protocol::socket client2(g_io);
301 client2.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1),
Davide Pesavento292e5e12015-03-13 02:08:33 +0100302 bind(&EndToEndFixture::client_onConnect, this, _1));
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100303
Davide Pesavento292e5e12015-03-13 02:08:33 +0100304 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Second connect");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100305
Junxiao Shi79494162014-04-02 18:25:11 -0700306 BOOST_CHECK_EQUAL(faces.size(), 2);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100307
308 // now close one of the faces
Junxiao Shi79494162014-04-02 18:25:11 -0700309 faces.front()->close();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100310
311 // we should still be able to send/receive with the other one
Junxiao Shi79494162014-04-02 18:25:11 -0700312 face1 = faces.back();
Junxiao Shic099ddb2014-12-25 20:53:20 -0700313 face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1));
314 face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1));
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100315
Davide Pesavento292e5e12015-03-13 02:08:33 +0100316 face2 = makeFace(std::move(client2));
Junxiao Shic099ddb2014-12-25 20:53:20 -0700317 face2->onReceiveInterest.connect(bind(&EndToEndFixture::face2_onReceiveInterest, this, _1));
318 face2->onReceiveData.connect(bind(&EndToEndFixture::face2_onReceiveData, this, _1));
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100319
Alexander Afanasyev650028d2014-04-25 18:39:10 -0700320 shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R");
321 shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix");
322 shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL");
323 shared_ptr<Data> data2 = makeData("ndn:/XNBV796f");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100324
Alexander Afanasyev650028d2014-04-25 18:39:10 -0700325 face1->sendInterest(*interest1);
326 face1->sendData (*data1 );
327 face2->sendInterest(*interest2);
328 face2->sendData (*data2 );
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100329
Davide Pesavento292e5e12015-03-13 02:08:33 +0100330 BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Send/receive");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100331
Junxiao Shi79494162014-04-02 18:25:11 -0700332 BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
333 BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1);
334 BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1);
335 BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100336
Alexander Afanasyev650028d2014-04-25 18:39:10 -0700337 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName());
338 BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName());
339 BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName());
340 BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName());
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100341}
342
Yukai Tu74c895d2015-09-21 01:11:51 -0700343BOOST_AUTO_TEST_SUITE_END() // TestUnixStream
344BOOST_AUTO_TEST_SUITE_END() // Face
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100345
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700346} // namespace tests
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100347} // namespace nfd