blob: 2c7c177a6e5a0252028944df6aa656947d90d950 [file] [log] [blame]
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
Alexander Afanasyev0eb70652014-02-27 18:35:07 -08007#include "face/unix-stream-factory.hpp"
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +01008
Junxiao Shid9ee45c2014-02-27 15:38:11 -07009#include "tests/test-common.hpp"
Junxiao Shi7e2413b2014-03-02 11:15:09 -070010#include "tests/core/limited-io.hpp"
Junxiao Shid9ee45c2014-02-27 15:38:11 -070011
12namespace nfd {
13namespace tests {
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010014
15using namespace boost::asio::local;
16
Junxiao Shi61e3cc52014-03-03 20:40:28 -070017#define CHANNEL_PATH1 "unix-stream-test.1.sock"
18#define CHANNEL_PATH2 "unix-stream-test.2.sock"
19
Junxiao Shid9ee45c2014-02-27 15:38:11 -070020BOOST_FIXTURE_TEST_SUITE(FaceUnixStream, BaseFixture)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010021
22BOOST_AUTO_TEST_CASE(ChannelMap)
23{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -080024 UnixStreamFactory factory;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010025
Junxiao Shi61e3cc52014-03-03 20:40:28 -070026 shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
27 shared_ptr<UnixStreamChannel> channel1a = factory.createChannel(CHANNEL_PATH1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010028 BOOST_CHECK_EQUAL(channel1, channel1a);
Junxiao Shi61e3cc52014-03-03 20:40:28 -070029 std::string channel1uri = channel1->getUri().toString();
30 BOOST_CHECK_EQUAL(channel1uri.find("unix:///"), 0); // third '/' is the path separator
31 BOOST_CHECK_EQUAL(channel1uri.rfind(CHANNEL_PATH1),
32 channel1uri.size() - std::string(CHANNEL_PATH1).size());
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010033
Junxiao Shi61e3cc52014-03-03 20:40:28 -070034 shared_ptr<UnixStreamChannel> channel2 = factory.createChannel(CHANNEL_PATH2);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010035 BOOST_CHECK_NE(channel1, channel2);
36}
37
Junxiao Shid9ee45c2014-02-27 15:38:11 -070038class EndToEndFixture : protected BaseFixture
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010039{
40public:
41 void
42 client_onConnect(const boost::system::error_code& error)
43 {
44 BOOST_CHECK_MESSAGE(!error, error.message());
45
Junxiao Shi79494162014-04-02 18:25:11 -070046 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010047 }
48
49 void
Junxiao Shi61e3cc52014-03-03 20:40:28 -070050 channel1_onFaceCreated(const shared_ptr<Face>& newFace)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010051 {
Junxiao Shi79494162014-04-02 18:25:11 -070052 BOOST_CHECK(!static_cast<bool>(face1));
53 face1 = static_pointer_cast<UnixStreamFace>(newFace);
54 face1->onReceiveInterest +=
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010055 bind(&EndToEndFixture::face1_onReceiveInterest, this, _1);
Junxiao Shi79494162014-04-02 18:25:11 -070056 face1->onReceiveData +=
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010057 bind(&EndToEndFixture::face1_onReceiveData, this, _1);
58
Junxiao Shi79494162014-04-02 18:25:11 -070059 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010060 }
61
62 void
63 channel1_onConnectFailed(const std::string& reason)
64 {
65 BOOST_CHECK_MESSAGE(false, reason);
66
Junxiao Shi79494162014-04-02 18:25:11 -070067 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010068 }
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080069
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010070 void
71 face1_onReceiveInterest(const Interest& interest)
72 {
Junxiao Shi79494162014-04-02 18:25:11 -070073 face1_receivedInterests.push_back(interest);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010074
Junxiao Shi79494162014-04-02 18:25:11 -070075 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010076 }
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080077
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010078 void
79 face1_onReceiveData(const Data& data)
80 {
Junxiao Shi79494162014-04-02 18:25:11 -070081 face1_receivedDatas.push_back(data);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010082
Junxiao Shi79494162014-04-02 18:25:11 -070083 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010084 }
85
86 void
87 face2_onReceiveInterest(const Interest& interest)
88 {
Junxiao Shi79494162014-04-02 18:25:11 -070089 face2_receivedInterests.push_back(interest);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010090
Junxiao Shi79494162014-04-02 18:25:11 -070091 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010092 }
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080093
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010094 void
95 face2_onReceiveData(const Data& data)
96 {
Junxiao Shi79494162014-04-02 18:25:11 -070097 face2_receivedDatas.push_back(data);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010098
Junxiao Shi79494162014-04-02 18:25:11 -070099 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100100 }
101
102 void
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700103 channel_onFaceCreated(const shared_ptr<Face>& newFace)
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100104 {
Junxiao Shi79494162014-04-02 18:25:11 -0700105 faces.push_back(static_pointer_cast<UnixStreamFace>(newFace));
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100106
Junxiao Shi79494162014-04-02 18:25:11 -0700107 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100108 }
109
110 void
111 channel_onConnectFailed(const std::string& reason)
112 {
113 BOOST_CHECK_MESSAGE(false, reason);
114
Junxiao Shi79494162014-04-02 18:25:11 -0700115 limitedIo.afterOp();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100116 }
117
118protected:
Junxiao Shi79494162014-04-02 18:25:11 -0700119 LimitedIo limitedIo;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100120
Junxiao Shi79494162014-04-02 18:25:11 -0700121 shared_ptr<UnixStreamFace> face1;
122 std::vector<Interest> face1_receivedInterests;
123 std::vector<Data> face1_receivedDatas;
124 shared_ptr<UnixStreamFace> face2;
125 std::vector<Interest> face2_receivedInterests;
126 std::vector<Data> face2_receivedDatas;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100127
Junxiao Shi79494162014-04-02 18:25:11 -0700128 std::list< shared_ptr<UnixStreamFace> > faces;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100129};
130
131
132BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture)
133{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -0800134 UnixStreamFactory factory;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100135
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700136 shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100137 channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
138 bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
139
140 shared_ptr<stream_protocol::socket> client =
Alexander Afanasyev7329e022014-02-27 14:47:22 -0800141 make_shared<stream_protocol::socket>(boost::ref(g_io));
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700142 client->async_connect(stream_protocol::endpoint(CHANNEL_PATH1),
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100143 bind(&EndToEndFixture::client_onConnect, this, _1));
144
Junxiao Shi79494162014-04-02 18:25:11 -0700145 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700146 "UnixStreamChannel error: cannot connect or cannot accept connection");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100147
Junxiao Shi79494162014-04-02 18:25:11 -0700148 BOOST_REQUIRE(static_cast<bool>(face1));
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100149
Junxiao Shi79494162014-04-02 18:25:11 -0700150 BOOST_CHECK_EQUAL(face1->getRemoteUri().getScheme(), "fd");
151 BOOST_CHECK_NO_THROW(boost::lexical_cast<int>(face1->getRemoteUri().getHost()));
152 std::string face1localUri = face1->getLocalUri().toString();
153 BOOST_CHECK_EQUAL(face1localUri.find("unix:///"), 0); // third '/' is the path separator
154 BOOST_CHECK_EQUAL(face1localUri.rfind(CHANNEL_PATH1),
155 face1localUri.size() - std::string(CHANNEL_PATH1).size());
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +0000156
Junxiao Shi79494162014-04-02 18:25:11 -0700157 face2 = make_shared<UnixStreamFace>(client);
158 face2->onReceiveInterest +=
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100159 bind(&EndToEndFixture::face2_onReceiveInterest, this, _1);
Junxiao Shi79494162014-04-02 18:25:11 -0700160 face2->onReceiveData +=
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100161 bind(&EndToEndFixture::face2_onReceiveData, this, _1);
162
163 Interest interest1("ndn:/TpnzGvW9R");
164 Data data1 ("ndn:/KfczhUqVix");
165 data1.setContent(0, 0);
166 Interest interest2("ndn:/QWiIMfj5sL");
167 Data data2 ("ndn:/XNBV796f");
168 data2.setContent(0, 0);
169
170 ndn::SignatureSha256WithRsa fakeSignature;
171 fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
172
173 // set fake signature on data1 and data2
174 data1.setSignature(fakeSignature);
175 data2.setSignature(fakeSignature);
176
Junxiao Shi79494162014-04-02 18:25:11 -0700177 face1->sendInterest(interest1);
178 face1->sendInterest(interest1);
179 face1->sendInterest(interest1);
180 face1->sendData (data1 );
181 face2->sendInterest(interest2);
182 face2->sendData (data2 );
183 face2->sendData (data2 );
184 face2->sendData (data2 );
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100185
Junxiao Shi79494162014-04-02 18:25:11 -0700186 BOOST_CHECK_MESSAGE(limitedIo.run(8, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700187 "UnixStreamChannel error: cannot send or receive Interest/Data packets");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100188
Junxiao Shi79494162014-04-02 18:25:11 -0700189 BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
190 BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3);
191 BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 3);
192 BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100193
Junxiao Shi79494162014-04-02 18:25:11 -0700194 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName());
195 BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName());
196 BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName());
197 BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName());
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000198
Junxiao Shi79494162014-04-02 18:25:11 -0700199 const FaceCounters& counters1 = face1->getCounters();
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000200 BOOST_CHECK_EQUAL(counters1.getInInterest() , 1);
201 BOOST_CHECK_EQUAL(counters1.getInData() , 3);
202 BOOST_CHECK_EQUAL(counters1.getOutInterest(), 3);
203 BOOST_CHECK_EQUAL(counters1.getOutData() , 1);
204
Junxiao Shi79494162014-04-02 18:25:11 -0700205 const FaceCounters& counters2 = face2->getCounters();
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000206 BOOST_CHECK_EQUAL(counters2.getInInterest() , 3);
207 BOOST_CHECK_EQUAL(counters2.getInData() , 1);
208 BOOST_CHECK_EQUAL(counters2.getOutInterest(), 1);
209 BOOST_CHECK_EQUAL(counters2.getOutData() , 3);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100210}
211
212BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture)
213{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -0800214 UnixStreamFactory factory;
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100215
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700216 shared_ptr<UnixStreamChannel> channel = factory.createChannel(CHANNEL_PATH1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100217 channel->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
218 bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
219
220 shared_ptr<stream_protocol::socket> client1 =
Alexander Afanasyev7329e022014-02-27 14:47:22 -0800221 make_shared<stream_protocol::socket>(boost::ref(g_io));
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700222 client1->async_connect(stream_protocol::endpoint(CHANNEL_PATH1),
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100223 bind(&EndToEndFixture::client_onConnect, this, _1));
224
Junxiao Shi79494162014-04-02 18:25:11 -0700225 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700226 "UnixStreamChannel error: cannot connect or cannot accept connection");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100227
Junxiao Shi79494162014-04-02 18:25:11 -0700228 BOOST_CHECK_EQUAL(faces.size(), 1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100229
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100230 shared_ptr<stream_protocol::socket> client2 =
Alexander Afanasyev7329e022014-02-27 14:47:22 -0800231 make_shared<stream_protocol::socket>(boost::ref(g_io));
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700232 client2->async_connect(stream_protocol::endpoint(CHANNEL_PATH1),
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100233 bind(&EndToEndFixture::client_onConnect, this, _1));
234
Junxiao Shi79494162014-04-02 18:25:11 -0700235 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700236 "UnixStreamChannel error: cannot accept multiple connections");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100237
Junxiao Shi79494162014-04-02 18:25:11 -0700238 BOOST_CHECK_EQUAL(faces.size(), 2);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100239
240 // now close one of the faces
Junxiao Shi79494162014-04-02 18:25:11 -0700241 faces.front()->close();
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100242
243 // we should still be able to send/receive with the other one
Junxiao Shi79494162014-04-02 18:25:11 -0700244 face1 = faces.back();
245 face1->onReceiveInterest += bind(&EndToEndFixture::face1_onReceiveInterest, this, _1);
246 face1->onReceiveData += bind(&EndToEndFixture::face1_onReceiveData, this, _1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100247
Junxiao Shi79494162014-04-02 18:25:11 -0700248 face2 = make_shared<UnixStreamFace>(client2);
249 face2->onReceiveInterest += bind(&EndToEndFixture::face2_onReceiveInterest, this, _1);
250 face2->onReceiveData += bind(&EndToEndFixture::face2_onReceiveData, this, _1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100251
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100252 Interest interest1("ndn:/TpnzGvW9R");
253 Data data1 ("ndn:/KfczhUqVix");
254 data1.setContent(0, 0);
255 Interest interest2("ndn:/QWiIMfj5sL");
256 Data data2 ("ndn:/XNBV796f");
257 data2.setContent(0, 0);
258
259 ndn::SignatureSha256WithRsa fakeSignature;
260 fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
261
262 // set fake signature on data1 and data2
263 data1.setSignature(fakeSignature);
264 data2.setSignature(fakeSignature);
265
Junxiao Shi79494162014-04-02 18:25:11 -0700266 face1->sendInterest(interest1);
267 face1->sendData (data1 );
268 face2->sendInterest(interest2);
269 face2->sendData (data2 );
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100270
Junxiao Shi79494162014-04-02 18:25:11 -0700271 BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700272 "UnixStreamChannel error: cannot send or receive Interest/Data packets");
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100273
Junxiao Shi79494162014-04-02 18:25:11 -0700274 BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
275 BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1);
276 BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1);
277 BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100278
Junxiao Shi79494162014-04-02 18:25:11 -0700279 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2.getName());
280 BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2.getName());
281 BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1.getName());
282 BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1.getName());
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100283}
284
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800285static inline void
286noOp()
287{
288}
289
290BOOST_FIXTURE_TEST_CASE(UnixStreamFaceLocalControlHeader, EndToEndFixture)
291{
Alexander Afanasyev0eb70652014-02-27 18:35:07 -0800292 UnixStreamFactory factory;
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800293
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700294 shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800295 channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
296 bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
297
298 shared_ptr<stream_protocol::socket> client =
Alexander Afanasyev7329e022014-02-27 14:47:22 -0800299 make_shared<stream_protocol::socket>(boost::ref(g_io));
Junxiao Shi61e3cc52014-03-03 20:40:28 -0700300 client->async_connect(stream_protocol::endpoint(CHANNEL_PATH1),
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800301 bind(&EndToEndFixture::client_onConnect, this, _1));
302
Junxiao Shi79494162014-04-02 18:25:11 -0700303 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700304 "UnixStreamChannel error: cannot connect or cannot accept connection");
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800305
Junxiao Shi79494162014-04-02 18:25:11 -0700306 BOOST_REQUIRE(static_cast<bool>(face1));
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800307
Junxiao Shi79494162014-04-02 18:25:11 -0700308 face2 = make_shared<UnixStreamFace>(client);
309 face2->onReceiveInterest +=
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800310 bind(&EndToEndFixture::face2_onReceiveInterest, this, _1);
Junxiao Shi79494162014-04-02 18:25:11 -0700311 face2->onReceiveData +=
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800312 bind(&EndToEndFixture::face2_onReceiveData, this, _1);
313
314 Interest interest1("ndn:/TpnzGvW9R");
315 Data data1 ("ndn:/KfczhUqVix");
316 data1.setContent(0, 0);
317 Interest interest2("ndn:/QWiIMfj5sL");
318 Data data2 ("ndn:/XNBV796f");
319 data2.setContent(0, 0);
320
321 ndn::SignatureSha256WithRsa fakeSignature;
322 fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0));
323
324 // set fake signature on data1 and data2
325 data1.setSignature(fakeSignature);
326 data2.setSignature(fakeSignature);
327
Junxiao Shi79494162014-04-02 18:25:11 -0700328 face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
329 face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800330
Junxiao Shi79494162014-04-02 18:25:11 -0700331 BOOST_CHECK(face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
332 BOOST_CHECK(face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800333
Junxiao Shi79494162014-04-02 18:25:11 -0700334 face2->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID);
335 face2->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800336
Junxiao Shi79494162014-04-02 18:25:11 -0700337 BOOST_CHECK(face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID));
338 BOOST_CHECK(face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800339
340 ////////////////////////////////////////////////////////
341
342 interest1.setIncomingFaceId(11);
343 interest1.setNextHopFaceId(111);
344
Junxiao Shi79494162014-04-02 18:25:11 -0700345 face1->sendInterest(interest1);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800346
347 data1.setIncomingFaceId(22);
348 data1.getLocalControlHeader().setNextHopFaceId(222);
349
Junxiao Shi79494162014-04-02 18:25:11 -0700350 face1->sendData (data1);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800351
352 //
353
Junxiao Shi79494162014-04-02 18:25:11 -0700354 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700355 "UnixStreamChannel error: cannot send or receive Interest/Data packets");
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800356
Junxiao Shi79494162014-04-02 18:25:11 -0700357 BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1);
358 BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800359
360 // sending allows only IncomingFaceId, receiving allows only NextHopFaceId
Junxiao Shi79494162014-04-02 18:25:11 -0700361 BOOST_CHECK_EQUAL(face2_receivedInterests[0].getLocalControlHeader().hasIncomingFaceId(), false);
362 BOOST_CHECK_EQUAL(face2_receivedInterests[0].getLocalControlHeader().hasNextHopFaceId(), false);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800363
Junxiao Shi79494162014-04-02 18:25:11 -0700364 BOOST_CHECK_EQUAL(face2_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false);
365 BOOST_CHECK_EQUAL(face2_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800366
367 ////////////////////////////////////////////////////////
368
369 using namespace boost::asio;
370
371 std::vector<const_buffer> interestWithHeader;
372 Block iHeader = interest1.getLocalControlHeader().wireEncode(interest1, true, true);
373 Block iPayload = interest1.wireEncode();
374 interestWithHeader.push_back(buffer(iHeader.wire(), iHeader.size()));
375 interestWithHeader.push_back(buffer(iPayload.wire(), iPayload.size()));
376
377 std::vector<const_buffer> dataWithHeader;
378 Block dHeader = data1.getLocalControlHeader().wireEncode(data1, true, true);
379 Block dPayload = data1.wireEncode();
380 dataWithHeader.push_back(buffer(dHeader.wire(), dHeader.size()));
381 dataWithHeader.push_back(buffer(dPayload.wire(), dPayload.size()));
382
383 //
384
385 client->async_send(interestWithHeader, bind(&noOp));
386 client->async_send(dataWithHeader, bind(&noOp));
387
Junxiao Shi79494162014-04-02 18:25:11 -0700388 BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS,
Junxiao Shi7e2413b2014-03-02 11:15:09 -0700389 "UnixStreamChannel error: cannot send or receive Interest/Data packets");
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800390
Junxiao Shi79494162014-04-02 18:25:11 -0700391 BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1);
392 BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800393
Junxiao Shi79494162014-04-02 18:25:11 -0700394 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getLocalControlHeader().hasIncomingFaceId(), false);
395 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getLocalControlHeader().hasNextHopFaceId(), true);
396 BOOST_CHECK_EQUAL(face1_receivedInterests[0].getNextHopFaceId(), 111);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800397
Junxiao Shi79494162014-04-02 18:25:11 -0700398 BOOST_CHECK_EQUAL(face1_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false);
399 BOOST_CHECK_EQUAL(face1_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -0800400}
401
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100402BOOST_AUTO_TEST_SUITE_END()
403
Junxiao Shid9ee45c2014-02-27 15:38:11 -0700404} // namespace tests
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +0100405} // namespace nfd