Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 7 | #include "face/unix-stream-factory.hpp" |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 8 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 9 | #include "tests/test-common.hpp" |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 10 | #include "tests/core/limited-io.hpp" |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 11 | |
| 12 | namespace nfd { |
| 13 | namespace tests { |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 14 | |
| 15 | using namespace boost::asio::local; |
| 16 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 17 | #define CHANNEL_PATH1 "unix-stream-test.1.sock" |
| 18 | #define CHANNEL_PATH2 "unix-stream-test.2.sock" |
| 19 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 20 | BOOST_FIXTURE_TEST_SUITE(FaceUnixStream, BaseFixture) |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 21 | |
| 22 | BOOST_AUTO_TEST_CASE(ChannelMap) |
| 23 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 24 | UnixStreamFactory factory; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 25 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 26 | shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1); |
| 27 | shared_ptr<UnixStreamChannel> channel1a = factory.createChannel(CHANNEL_PATH1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 28 | BOOST_CHECK_EQUAL(channel1, channel1a); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 29 | 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 Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 33 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 34 | shared_ptr<UnixStreamChannel> channel2 = factory.createChannel(CHANNEL_PATH2); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 35 | BOOST_CHECK_NE(channel1, channel2); |
| 36 | } |
| 37 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 38 | class EndToEndFixture : protected BaseFixture |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 39 | { |
| 40 | public: |
| 41 | void |
| 42 | client_onConnect(const boost::system::error_code& error) |
| 43 | { |
| 44 | BOOST_CHECK_MESSAGE(!error, error.message()); |
| 45 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 46 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 50 | channel1_onFaceCreated(const shared_ptr<Face>& newFace) |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 51 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 52 | BOOST_CHECK(!static_cast<bool>(face1)); |
| 53 | face1 = static_pointer_cast<UnixStreamFace>(newFace); |
| 54 | face1->onReceiveInterest += |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 55 | bind(&EndToEndFixture::face1_onReceiveInterest, this, _1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 56 | face1->onReceiveData += |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 57 | bind(&EndToEndFixture::face1_onReceiveData, this, _1); |
| 58 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 59 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void |
| 63 | channel1_onConnectFailed(const std::string& reason) |
| 64 | { |
| 65 | BOOST_CHECK_MESSAGE(false, reason); |
| 66 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 67 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 68 | } |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 69 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 70 | void |
| 71 | face1_onReceiveInterest(const Interest& interest) |
| 72 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 73 | face1_receivedInterests.push_back(interest); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 74 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 75 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 76 | } |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 77 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 78 | void |
| 79 | face1_onReceiveData(const Data& data) |
| 80 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 81 | face1_receivedDatas.push_back(data); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 82 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 83 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void |
| 87 | face2_onReceiveInterest(const Interest& interest) |
| 88 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 89 | face2_receivedInterests.push_back(interest); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 90 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 91 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 92 | } |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 93 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 94 | void |
| 95 | face2_onReceiveData(const Data& data) |
| 96 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 97 | face2_receivedDatas.push_back(data); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 98 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 99 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 103 | channel_onFaceCreated(const shared_ptr<Face>& newFace) |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 104 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 105 | faces.push_back(static_pointer_cast<UnixStreamFace>(newFace)); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 106 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 107 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void |
| 111 | channel_onConnectFailed(const std::string& reason) |
| 112 | { |
| 113 | BOOST_CHECK_MESSAGE(false, reason); |
| 114 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 115 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | protected: |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 119 | LimitedIo limitedIo; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 120 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 121 | 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 Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 127 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 128 | std::list< shared_ptr<UnixStreamFace> > faces; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | |
| 132 | BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture) |
| 133 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 134 | UnixStreamFactory factory; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 135 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 136 | shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 137 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 138 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 139 | |
| 140 | shared_ptr<stream_protocol::socket> client = |
Alexander Afanasyev | 7329e02 | 2014-02-27 14:47:22 -0800 | [diff] [blame] | 141 | make_shared<stream_protocol::socket>(boost::ref(g_io)); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 142 | client->async_connect(stream_protocol::endpoint(CHANNEL_PATH1), |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 143 | bind(&EndToEndFixture::client_onConnect, this, _1)); |
| 144 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 145 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 146 | "UnixStreamChannel error: cannot connect or cannot accept connection"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 147 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 148 | BOOST_REQUIRE(static_cast<bool>(face1)); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 149 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 150 | 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 Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 156 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 157 | face2 = make_shared<UnixStreamFace>(client); |
| 158 | face2->onReceiveInterest += |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 159 | bind(&EndToEndFixture::face2_onReceiveInterest, this, _1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 160 | face2->onReceiveData += |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 161 | 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 Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 177 | 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 Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 185 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 186 | BOOST_CHECK_MESSAGE(limitedIo.run(8, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 187 | "UnixStreamChannel error: cannot send or receive Interest/Data packets"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 188 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 189 | 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 Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 193 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 194 | 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 Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 198 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 199 | const FaceCounters& counters1 = face1->getCounters(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 200 | BOOST_CHECK_EQUAL(counters1.getNInInterests() , 1); |
| 201 | BOOST_CHECK_EQUAL(counters1.getNInDatas() , 3); |
| 202 | BOOST_CHECK_EQUAL(counters1.getNOutInterests(), 3); |
| 203 | BOOST_CHECK_EQUAL(counters1.getNOutDatas() , 1); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 204 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 205 | const FaceCounters& counters2 = face2->getCounters(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 206 | BOOST_CHECK_EQUAL(counters2.getNInInterests() , 3); |
| 207 | BOOST_CHECK_EQUAL(counters2.getNInDatas() , 1); |
| 208 | BOOST_CHECK_EQUAL(counters2.getNOutInterests(), 1); |
| 209 | BOOST_CHECK_EQUAL(counters2.getNOutDatas() , 3); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) |
| 213 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 214 | UnixStreamFactory factory; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 215 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 216 | shared_ptr<UnixStreamChannel> channel = factory.createChannel(CHANNEL_PATH1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 217 | channel->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 218 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
| 219 | |
| 220 | shared_ptr<stream_protocol::socket> client1 = |
Alexander Afanasyev | 7329e02 | 2014-02-27 14:47:22 -0800 | [diff] [blame] | 221 | make_shared<stream_protocol::socket>(boost::ref(g_io)); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 222 | client1->async_connect(stream_protocol::endpoint(CHANNEL_PATH1), |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 223 | bind(&EndToEndFixture::client_onConnect, this, _1)); |
| 224 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 225 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 226 | "UnixStreamChannel error: cannot connect or cannot accept connection"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 227 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 228 | BOOST_CHECK_EQUAL(faces.size(), 1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 229 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 230 | shared_ptr<stream_protocol::socket> client2 = |
Alexander Afanasyev | 7329e02 | 2014-02-27 14:47:22 -0800 | [diff] [blame] | 231 | make_shared<stream_protocol::socket>(boost::ref(g_io)); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 232 | client2->async_connect(stream_protocol::endpoint(CHANNEL_PATH1), |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 233 | bind(&EndToEndFixture::client_onConnect, this, _1)); |
| 234 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 235 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 236 | "UnixStreamChannel error: cannot accept multiple connections"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 237 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 238 | BOOST_CHECK_EQUAL(faces.size(), 2); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 239 | |
| 240 | // now close one of the faces |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 241 | faces.front()->close(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 242 | |
| 243 | // we should still be able to send/receive with the other one |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 244 | face1 = faces.back(); |
| 245 | face1->onReceiveInterest += bind(&EndToEndFixture::face1_onReceiveInterest, this, _1); |
| 246 | face1->onReceiveData += bind(&EndToEndFixture::face1_onReceiveData, this, _1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 247 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 248 | face2 = make_shared<UnixStreamFace>(client2); |
| 249 | face2->onReceiveInterest += bind(&EndToEndFixture::face2_onReceiveInterest, this, _1); |
| 250 | face2->onReceiveData += bind(&EndToEndFixture::face2_onReceiveData, this, _1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 251 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 252 | 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 Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 266 | face1->sendInterest(interest1); |
| 267 | face1->sendData (data1 ); |
| 268 | face2->sendInterest(interest2); |
| 269 | face2->sendData (data2 ); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 270 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 271 | BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 272 | "UnixStreamChannel error: cannot send or receive Interest/Data packets"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 273 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 274 | 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 Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 278 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 279 | 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 Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 283 | } |
| 284 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 285 | static inline void |
| 286 | noOp() |
| 287 | { |
| 288 | } |
| 289 | |
| 290 | BOOST_FIXTURE_TEST_CASE(UnixStreamFaceLocalControlHeader, EndToEndFixture) |
| 291 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 292 | UnixStreamFactory factory; |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 293 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 294 | shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 295 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 296 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 297 | |
| 298 | shared_ptr<stream_protocol::socket> client = |
Alexander Afanasyev | 7329e02 | 2014-02-27 14:47:22 -0800 | [diff] [blame] | 299 | make_shared<stream_protocol::socket>(boost::ref(g_io)); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 300 | client->async_connect(stream_protocol::endpoint(CHANNEL_PATH1), |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 301 | bind(&EndToEndFixture::client_onConnect, this, _1)); |
| 302 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 303 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 304 | "UnixStreamChannel error: cannot connect or cannot accept connection"); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 305 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 306 | BOOST_REQUIRE(static_cast<bool>(face1)); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 307 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 308 | face2 = make_shared<UnixStreamFace>(client); |
| 309 | face2->onReceiveInterest += |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 310 | bind(&EndToEndFixture::face2_onReceiveInterest, this, _1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 311 | face2->onReceiveData += |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 312 | 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 Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 328 | face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 329 | face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 330 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 331 | BOOST_CHECK(face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 332 | BOOST_CHECK(face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 333 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 334 | face2->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 335 | face2->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 336 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 337 | BOOST_CHECK(face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 338 | BOOST_CHECK(face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 339 | |
| 340 | //////////////////////////////////////////////////////// |
| 341 | |
| 342 | interest1.setIncomingFaceId(11); |
| 343 | interest1.setNextHopFaceId(111); |
| 344 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 345 | face1->sendInterest(interest1); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 346 | |
| 347 | data1.setIncomingFaceId(22); |
| 348 | data1.getLocalControlHeader().setNextHopFaceId(222); |
| 349 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 350 | face1->sendData (data1); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 351 | |
| 352 | // |
| 353 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 354 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 355 | "UnixStreamChannel error: cannot send or receive Interest/Data packets"); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 356 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 357 | BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1); |
| 358 | BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 359 | |
| 360 | // sending allows only IncomingFaceId, receiving allows only NextHopFaceId |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 361 | BOOST_CHECK_EQUAL(face2_receivedInterests[0].getLocalControlHeader().hasIncomingFaceId(), false); |
| 362 | BOOST_CHECK_EQUAL(face2_receivedInterests[0].getLocalControlHeader().hasNextHopFaceId(), false); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 363 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 364 | BOOST_CHECK_EQUAL(face2_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false); |
| 365 | BOOST_CHECK_EQUAL(face2_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 366 | |
| 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 Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 388 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 389 | "UnixStreamChannel error: cannot send or receive Interest/Data packets"); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 390 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 391 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 392 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 393 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 394 | 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 Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 397 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 398 | BOOST_CHECK_EQUAL(face1_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false); |
| 399 | BOOST_CHECK_EQUAL(face1_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 400 | } |
| 401 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 402 | BOOST_AUTO_TEST_SUITE_END() |
| 403 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 404 | } // namespace tests |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 405 | } // namespace nfd |