blob: 7e08b78e54ebedffb8198f567a7a5974fbe64df0 [file] [log] [blame]
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * 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 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 **/
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010024
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080025#include "face/unix-stream-factory.hpp"
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010026
Junxiao Shid9ee45c2014-02-27 15:38:11 -070027#include "tests/test-common.hpp"
Junxiao Shi7e2413b2014-03-02 11:15:09 -070028#include "tests/core/limited-io.hpp"
Junxiao Shid9ee45c2014-02-27 15:38:11 -070029
30namespace nfd {
31namespace tests {
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010032
33using namespace boost::asio::local;
34
Junxiao Shi61e3cc52014-03-03 20:40:28 -070035#define CHANNEL_PATH1 "unix-stream-test.1.sock"
36#define CHANNEL_PATH2 "unix-stream-test.2.sock"
37
Junxiao Shid9ee45c2014-02-27 15:38:11 -070038BOOST_FIXTURE_TEST_SUITE(FaceUnixStream, BaseFixture)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010039
40BOOST_AUTO_TEST_CASE(ChannelMap)
41{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080042 UnixStreamFactory factory;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010043
Junxiao Shi61e3cc52014-03-03 20:40:28 -070044 shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
45 shared_ptr<UnixStreamChannel> channel1a = factory.createChannel(CHANNEL_PATH1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010046 BOOST_CHECK_EQUAL(channel1, channel1a);
Junxiao Shi61e3cc52014-03-03 20:40:28 -070047 std::string channel1uri = channel1->getUri().toString();
48 BOOST_CHECK_EQUAL(channel1uri.find("unix:///"), 0); // third '/' is the path separator
49 BOOST_CHECK_EQUAL(channel1uri.rfind(CHANNEL_PATH1),
50 channel1uri.size() - std::string(CHANNEL_PATH1).size());
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010051
Junxiao Shi61e3cc52014-03-03 20:40:28 -070052 shared_ptr<UnixStreamChannel> channel2 = factory.createChannel(CHANNEL_PATH2);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010053 BOOST_CHECK_NE(channel1, channel2);
54}
55
Junxiao Shid9ee45c2014-02-27 15:38:11 -070056class EndToEndFixture : protected BaseFixture
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010057{
58public:
59 void
60 client_onConnect(const boost::system::error_code& error)
61 {
62 BOOST_CHECK_MESSAGE(!error, error.message());
63
Junxiao Shi79494162014-04-02 18:25:11 -070064 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010065 }
66
67 void
Junxiao Shi61e3cc52014-03-03 20:40:28 -070068 channel1_onFaceCreated(const shared_ptr<Face>& newFace)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010069 {
Junxiao Shi79494162014-04-02 18:25:11 -070070 BOOST_CHECK(!static_cast<bool>(face1));
71 face1 = static_pointer_cast<UnixStreamFace>(newFace);
72 face1->onReceiveInterest +=
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010073 bind(&EndToEndFixture::face1_onReceiveInterest, this, _1);
Junxiao Shi79494162014-04-02 18:25:11 -070074 face1->onReceiveData +=
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010075 bind(&EndToEndFixture::face1_onReceiveData, this, _1);
76
Junxiao Shi79494162014-04-02 18:25:11 -070077 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010078 }
79
80 void
81 channel1_onConnectFailed(const std::string& reason)
82 {
83 BOOST_CHECK_MESSAGE(false, reason);
84
Junxiao Shi79494162014-04-02 18:25:11 -070085 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010086 }
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080087
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010088 void
89 face1_onReceiveInterest(const Interest& interest)
90 {
Junxiao Shi79494162014-04-02 18:25:11 -070091 face1_receivedInterests.push_back(interest);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010092
Junxiao Shi79494162014-04-02 18:25:11 -070093 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010094 }
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080095
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010096 void
97 face1_onReceiveData(const Data& data)
98 {
Junxiao Shi79494162014-04-02 18:25:11 -070099 face1_receivedDatas.push_back(data);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100100
Junxiao Shi79494162014-04-02 18:25:11 -0700101 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100102 }
103
104 void
105 face2_onReceiveInterest(const Interest& interest)
106 {
Junxiao Shi79494162014-04-02 18:25:11 -0700107 face2_receivedInterests.push_back(interest);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100108
Junxiao Shi79494162014-04-02 18:25:11 -0700109 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100110 }
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800111
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100112 void
113 face2_onReceiveData(const Data& data)
114 {
Junxiao Shi79494162014-04-02 18:25:11 -0700115 face2_receivedDatas.push_back(data);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100116
Junxiao Shi79494162014-04-02 18:25:11 -0700117 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100118 }
119
120 void
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700121 channel_onFaceCreated(const shared_ptr<Face>& newFace)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100122 {
Junxiao Shi79494162014-04-02 18:25:11 -0700123 faces.push_back(static_pointer_cast<UnixStreamFace>(newFace));
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100124
Junxiao Shi79494162014-04-02 18:25:11 -0700125 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100126 }
127
128 void
129 channel_onConnectFailed(const std::string& reason)
130 {
131 BOOST_CHECK_MESSAGE(false, reason);
132
Junxiao Shi79494162014-04-02 18:25:11 -0700133 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100134 }
135
136protected:
Junxiao Shi79494162014-04-02 18:25:11 -0700137 LimitedIo limitedIo;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100138
Junxiao Shi79494162014-04-02 18:25:11 -0700139 shared_ptr<UnixStreamFace> face1;
140 std::vector<Interest> face1_receivedInterests;
141 std::vector<Data> face1_receivedDatas;
142 shared_ptr<UnixStreamFace> face2;
143 std::vector<Interest> face2_receivedInterests;
144 std::vector<Data> face2_receivedDatas;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100145
Junxiao Shi79494162014-04-02 18:25:11 -0700146 std::list< shared_ptr<UnixStreamFace> > faces;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100147};
148
149
150BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture)
151{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -0800152 UnixStreamFactory factory;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100153
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700154 shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100155 channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
156 bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
157
158 shared_ptr<stream_protocol::socket> client =
Alexander Afanasyev7329e022014-02-27 14:47:22 -0800159 make_shared<stream_protocol::socket>(boost::ref(g_io));
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700160 client->async_connect(stream_protocol::endpoint(CHANNEL_PATH1),
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100161 bind(&EndToEndFixture::client_onConnect, this, _1));
162
Junxiao Shi79494162014-04-02 18:25:11 -0700163 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700164 "UnixStreamChannel error: cannot connect or cannot accept connection");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100165
Junxiao Shi79494162014-04-02 18:25:11 -0700166 BOOST_REQUIRE(static_cast<bool>(face1));
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100167
Junxiao Shi79494162014-04-02 18:25:11 -0700168 BOOST_CHECK_EQUAL(face1->getRemoteUri().getScheme(), "fd");
169 BOOST_CHECK_NO_THROW(boost::lexical_cast<int>(face1->getRemoteUri().getHost()));
170 std::string face1localUri = face1->getLocalUri().toString();
171 BOOST_CHECK_EQUAL(face1localUri.find("unix:///"), 0); // third '/' is the path separator
172 BOOST_CHECK_EQUAL(face1localUri.rfind(CHANNEL_PATH1),
173 face1localUri.size() - std::string(CHANNEL_PATH1).size());
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000174
Junxiao Shi79494162014-04-02 18:25:11 -0700175 face2 = make_shared<UnixStreamFace>(client);
176 face2->onReceiveInterest +=
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100177 bind(&EndToEndFixture::face2_onReceiveInterest, this, _1);
Junxiao Shi79494162014-04-02 18:25:11 -0700178 face2->onReceiveData +=
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100179 bind(&EndToEndFixture::face2_onReceiveData, this, _1);
180
181 Interest interest1("ndn:/TpnzGvW9R");
182 Data data1 ("ndn:/KfczhUqVix");
183 data1.setContent(0, 0);
184 Interest interest2("ndn:/QWiIMfj5sL");
185 Data data2 ("ndn:/XNBV796f");
186 data2.setContent(0, 0);
187
188 ndn::SignatureSha256WithRsa fakeSignature;
189 fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
190
191 // set fake signature on data1 and data2
192 data1.setSignature(fakeSignature);
193 data2.setSignature(fakeSignature);
194
Junxiao Shi79494162014-04-02 18:25:11 -0700195 face1->sendInterest(interest1);
196 face1->sendInterest(interest1);
197 face1->sendInterest(interest1);
198 face1->sendData (data1 );
199 face2->sendInterest(interest2);
200 face2->sendData (data2 );
201 face2->sendData (data2 );
202 face2->sendData (data2 );
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100203
Junxiao Shi79494162014-04-02 18:25:11 -0700204 BOOST_CHECK_MESSAGE(limitedIo.run(8, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700205 "UnixStreamChannel error: cannot send or receive Interest/Data packets");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100206
Junxiao Shi79494162014-04-02 18:25:11 -0700207 BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
208 BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3);
209 BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 3);
210 BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100211
Junxiao Shi79494162014-04-02 18:25:11 -0700212 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName());
213 BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName());
214 BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName());
215 BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName());
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000216
Junxiao Shi79494162014-04-02 18:25:11 -0700217 const FaceCounters& counters1 = face1->getCounters();
Junxiao Shi6e694322014-04-03 10:27:13 -0700218 BOOST_CHECK_EQUAL(counters1.getNInInterests() , 1);
219 BOOST_CHECK_EQUAL(counters1.getNInDatas() , 3);
220 BOOST_CHECK_EQUAL(counters1.getNOutInterests(), 3);
221 BOOST_CHECK_EQUAL(counters1.getNOutDatas() , 1);
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000222
Junxiao Shi79494162014-04-02 18:25:11 -0700223 const FaceCounters& counters2 = face2->getCounters();
Junxiao Shi6e694322014-04-03 10:27:13 -0700224 BOOST_CHECK_EQUAL(counters2.getNInInterests() , 3);
225 BOOST_CHECK_EQUAL(counters2.getNInDatas() , 1);
226 BOOST_CHECK_EQUAL(counters2.getNOutInterests(), 1);
227 BOOST_CHECK_EQUAL(counters2.getNOutDatas() , 3);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100228}
229
230BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
231{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -0800232 UnixStreamFactory factory;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100233
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700234 shared_ptr<UnixStreamChannel> channel = factory.createChannel(CHANNEL_PATH1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100235 channel->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
236 bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
237
238 shared_ptr<stream_protocol::socket> client1 =
Alexander Afanasyev7329e022014-02-27 14:47:22 -0800239 make_shared<stream_protocol::socket>(boost::ref(g_io));
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700240 client1->async_connect(stream_protocol::endpoint(CHANNEL_PATH1),
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100241 bind(&EndToEndFixture::client_onConnect, this, _1));
242
Junxiao Shi79494162014-04-02 18:25:11 -0700243 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700244 "UnixStreamChannel error: cannot connect or cannot accept connection");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100245
Junxiao Shi79494162014-04-02 18:25:11 -0700246 BOOST_CHECK_EQUAL(faces.size(), 1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100247
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100248 shared_ptr<stream_protocol::socket> client2 =
Alexander Afanasyev7329e022014-02-27 14:47:22 -0800249 make_shared<stream_protocol::socket>(boost::ref(g_io));
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700250 client2->async_connect(stream_protocol::endpoint(CHANNEL_PATH1),
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100251 bind(&EndToEndFixture::client_onConnect, this, _1));
252
Junxiao Shi79494162014-04-02 18:25:11 -0700253 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700254 "UnixStreamChannel error: cannot accept multiple connections");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100255
Junxiao Shi79494162014-04-02 18:25:11 -0700256 BOOST_CHECK_EQUAL(faces.size(), 2);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100257
258 // now close one of the faces
Junxiao Shi79494162014-04-02 18:25:11 -0700259 faces.front()->close();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100260
261 // we should still be able to send/receive with the other one
Junxiao Shi79494162014-04-02 18:25:11 -0700262 face1 = faces.back();
263 face1->onReceiveInterest += bind(&EndToEndFixture::face1_onReceiveInterest, this, _1);
264 face1->onReceiveData += bind(&EndToEndFixture::face1_onReceiveData, this, _1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100265
Junxiao Shi79494162014-04-02 18:25:11 -0700266 face2 = make_shared<UnixStreamFace>(client2);
267 face2->onReceiveInterest += bind(&EndToEndFixture::face2_onReceiveInterest, this, _1);
268 face2->onReceiveData += bind(&EndToEndFixture::face2_onReceiveData, this, _1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100269
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100270 Interest interest1("ndn:/TpnzGvW9R");
271 Data data1 ("ndn:/KfczhUqVix");
272 data1.setContent(0, 0);
273 Interest interest2("ndn:/QWiIMfj5sL");
274 Data data2 ("ndn:/XNBV796f");
275 data2.setContent(0, 0);
276
277 ndn::SignatureSha256WithRsa fakeSignature;
278 fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
279
280 // set fake signature on data1 and data2
281 data1.setSignature(fakeSignature);
282 data2.setSignature(fakeSignature);
283
Junxiao Shi79494162014-04-02 18:25:11 -0700284 face1->sendInterest(interest1);
285 face1->sendData (data1 );
286 face2->sendInterest(interest2);
287 face2->sendData (data2 );
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100288
Junxiao Shi79494162014-04-02 18:25:11 -0700289 BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700290 "UnixStreamChannel error: cannot send or receive Interest/Data packets");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100291
Junxiao Shi79494162014-04-02 18:25:11 -0700292 BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
293 BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1);
294 BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1);
295 BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100296
Junxiao Shi79494162014-04-02 18:25:11 -0700297 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName());
298 BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName());
299 BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName());
300 BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName());
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100301}
302
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800303static inline void
304noOp()
305{
306}
307
308BOOST_FIXTURE_TEST_CASE(UnixStreamFaceLocalControlHeader, EndToEndFixture)
309{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -0800310 UnixStreamFactory factory;
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800311
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700312 shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800313 channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
314 bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
315
316 shared_ptr<stream_protocol::socket> client =
Alexander Afanasyev7329e022014-02-27 14:47:22 -0800317 make_shared<stream_protocol::socket>(boost::ref(g_io));
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700318 client->async_connect(stream_protocol::endpoint(CHANNEL_PATH1),
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800319 bind(&EndToEndFixture::client_onConnect, this, _1));
320
Junxiao Shi79494162014-04-02 18:25:11 -0700321 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700322 "UnixStreamChannel error: cannot connect or cannot accept connection");
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800323
Junxiao Shi79494162014-04-02 18:25:11 -0700324 BOOST_REQUIRE(static_cast<bool>(face1));
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800325
Junxiao Shi79494162014-04-02 18:25:11 -0700326 face2 = make_shared<UnixStreamFace>(client);
327 face2->onReceiveInterest +=
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800328 bind(&EndToEndFixture::face2_onReceiveInterest, this, _1);
Junxiao Shi79494162014-04-02 18:25:11 -0700329 face2->onReceiveData +=
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800330 bind(&EndToEndFixture::face2_onReceiveData, this, _1);
331
332 Interest interest1("ndn:/TpnzGvW9R");
333 Data data1 ("ndn:/KfczhUqVix");
334 data1.setContent(0, 0);
335 Interest interest2("ndn:/QWiIMfj5sL");
336 Data data2 ("ndn:/XNBV796f");
337 data2.setContent(0, 0);
338
339 ndn::SignatureSha256WithRsa fakeSignature;
340 fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
341
342 // set fake signature on data1 and data2
343 data1.setSignature(fakeSignature);
344 data2.setSignature(fakeSignature);
345
Junxiao Shi79494162014-04-02 18:25:11 -0700346 face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
347 face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800348
Junxiao Shi79494162014-04-02 18:25:11 -0700349 BOOST_CHECK(face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
350 BOOST_CHECK(face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800351
Junxiao Shi79494162014-04-02 18:25:11 -0700352 face2->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
353 face2->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800354
Junxiao Shi79494162014-04-02 18:25:11 -0700355 BOOST_CHECK(face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
356 BOOST_CHECK(face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800357
358 ////////////////////////////////////////////////////////
359
360 interest1.setIncomingFaceId(11);
361 interest1.setNextHopFaceId(111);
362
Junxiao Shi79494162014-04-02 18:25:11 -0700363 face1->sendInterest(interest1);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800364
365 data1.setIncomingFaceId(22);
366 data1.getLocalControlHeader().setNextHopFaceId(222);
367
Junxiao Shi79494162014-04-02 18:25:11 -0700368 face1->sendData (data1);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800369
370 //
371
Junxiao Shi79494162014-04-02 18:25:11 -0700372 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700373 "UnixStreamChannel error: cannot send or receive Interest/Data packets");
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800374
Junxiao Shi79494162014-04-02 18:25:11 -0700375 BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1);
376 BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800377
378 // sending allows only IncomingFaceId, receiving allows only NextHopFaceId
Junxiao Shi79494162014-04-02 18:25:11 -0700379 BOOST_CHECK_EQUAL(face2_receivedInterests[0].getLocalControlHeader().hasIncomingFaceId(), false);
380 BOOST_CHECK_EQUAL(face2_receivedInterests[0].getLocalControlHeader().hasNextHopFaceId(), false);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800381
Junxiao Shi79494162014-04-02 18:25:11 -0700382 BOOST_CHECK_EQUAL(face2_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false);
383 BOOST_CHECK_EQUAL(face2_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800384
385 ////////////////////////////////////////////////////////
386
387 using namespace boost::asio;
388
389 std::vector<const_buffer> interestWithHeader;
390 Block iHeader = interest1.getLocalControlHeader().wireEncode(interest1, true, true);
391 Block iPayload = interest1.wireEncode();
392 interestWithHeader.push_back(buffer(iHeader.wire(), iHeader.size()));
393 interestWithHeader.push_back(buffer(iPayload.wire(), iPayload.size()));
394
395 std::vector<const_buffer> dataWithHeader;
396 Block dHeader = data1.getLocalControlHeader().wireEncode(data1, true, true);
397 Block dPayload = data1.wireEncode();
398 dataWithHeader.push_back(buffer(dHeader.wire(), dHeader.size()));
399 dataWithHeader.push_back(buffer(dPayload.wire(), dPayload.size()));
400
401 //
402
403 client->async_send(interestWithHeader, bind(&noOp));
404 client->async_send(dataWithHeader, bind(&noOp));
405
Junxiao Shi79494162014-04-02 18:25:11 -0700406 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700407 "UnixStreamChannel error: cannot send or receive Interest/Data packets");
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800408
Junxiao Shi79494162014-04-02 18:25:11 -0700409 BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
410 BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800411
Junxiao Shi79494162014-04-02 18:25:11 -0700412 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getLocalControlHeader().hasIncomingFaceId(), false);
413 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getLocalControlHeader().hasNextHopFaceId(), true);
414 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getNextHopFaceId(), 111);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800415
Junxiao Shi79494162014-04-02 18:25:11 -0700416 BOOST_CHECK_EQUAL(face1_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false);
417 BOOST_CHECK_EQUAL(face1_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800418}
419
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100420BOOST_AUTO_TEST_SUITE_END()
421
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700422} // namespace tests
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100423} // namespace nfd