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 | #include <ndn-cpp-dev/security/key-chain.hpp> |
| 9 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 10 | #include "tests/test-common.hpp" |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 11 | #include "tests/core/limited-io.hpp" |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 12 | |
| 13 | namespace nfd { |
| 14 | namespace tests { |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 15 | |
| 16 | using namespace boost::asio::local; |
| 17 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 18 | #define CHANNEL_PATH1 "unix-stream-test.1.sock" |
| 19 | #define CHANNEL_PATH2 "unix-stream-test.2.sock" |
| 20 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 21 | BOOST_FIXTURE_TEST_SUITE(FaceUnixStream, BaseFixture) |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 22 | |
| 23 | BOOST_AUTO_TEST_CASE(ChannelMap) |
| 24 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 25 | UnixStreamFactory factory; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 26 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 27 | shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1); |
| 28 | shared_ptr<UnixStreamChannel> channel1a = factory.createChannel(CHANNEL_PATH1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 29 | BOOST_CHECK_EQUAL(channel1, channel1a); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 30 | std::string channel1uri = channel1->getUri().toString(); |
| 31 | BOOST_CHECK_EQUAL(channel1uri.find("unix:///"), 0); // third '/' is the path separator |
| 32 | BOOST_CHECK_EQUAL(channel1uri.rfind(CHANNEL_PATH1), |
| 33 | channel1uri.size() - std::string(CHANNEL_PATH1).size()); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 34 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 35 | shared_ptr<UnixStreamChannel> channel2 = factory.createChannel(CHANNEL_PATH2); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 36 | BOOST_CHECK_NE(channel1, channel2); |
| 37 | } |
| 38 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 39 | class EndToEndFixture : protected BaseFixture |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 40 | { |
| 41 | public: |
| 42 | void |
| 43 | client_onConnect(const boost::system::error_code& error) |
| 44 | { |
| 45 | BOOST_CHECK_MESSAGE(!error, error.message()); |
| 46 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 47 | m_limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 51 | channel1_onFaceCreated(const shared_ptr<Face>& newFace) |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 52 | { |
| 53 | BOOST_CHECK(!static_cast<bool>(m_face1)); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 54 | m_face1 = static_pointer_cast<UnixStreamFace>(newFace); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 55 | m_face1->onReceiveInterest += |
| 56 | bind(&EndToEndFixture::face1_onReceiveInterest, this, _1); |
| 57 | m_face1->onReceiveData += |
| 58 | bind(&EndToEndFixture::face1_onReceiveData, this, _1); |
| 59 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 60 | m_limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void |
| 64 | channel1_onConnectFailed(const std::string& reason) |
| 65 | { |
| 66 | BOOST_CHECK_MESSAGE(false, reason); |
| 67 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 68 | m_limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 69 | } |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 70 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 71 | void |
| 72 | face1_onReceiveInterest(const Interest& interest) |
| 73 | { |
| 74 | m_face1_receivedInterests.push_back(interest); |
| 75 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 76 | m_limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 77 | } |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 78 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 79 | void |
| 80 | face1_onReceiveData(const Data& data) |
| 81 | { |
| 82 | m_face1_receivedDatas.push_back(data); |
| 83 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 84 | m_limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void |
| 88 | face2_onReceiveInterest(const Interest& interest) |
| 89 | { |
| 90 | m_face2_receivedInterests.push_back(interest); |
| 91 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 92 | m_limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 93 | } |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 94 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 95 | void |
| 96 | face2_onReceiveData(const Data& data) |
| 97 | { |
| 98 | m_face2_receivedDatas.push_back(data); |
| 99 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 100 | m_limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 104 | channel_onFaceCreated(const shared_ptr<Face>& newFace) |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 105 | { |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 106 | m_faces.push_back(static_pointer_cast<UnixStreamFace>(newFace)); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 107 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 108 | m_limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void |
| 112 | channel_onConnectFailed(const std::string& reason) |
| 113 | { |
| 114 | BOOST_CHECK_MESSAGE(false, reason); |
| 115 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 116 | m_limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | protected: |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 120 | LimitedIo m_limitedIo; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 121 | |
| 122 | shared_ptr<UnixStreamFace> m_face1; |
| 123 | std::vector<Interest> m_face1_receivedInterests; |
| 124 | std::vector<Data> m_face1_receivedDatas; |
| 125 | shared_ptr<UnixStreamFace> m_face2; |
| 126 | std::vector<Interest> m_face2_receivedInterests; |
| 127 | std::vector<Data> m_face2_receivedDatas; |
| 128 | |
| 129 | std::list< shared_ptr<UnixStreamFace> > m_faces; |
| 130 | }; |
| 131 | |
| 132 | |
| 133 | BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture) |
| 134 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 135 | UnixStreamFactory factory; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 136 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 137 | shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 138 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 139 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 140 | |
| 141 | shared_ptr<stream_protocol::socket> client = |
Alexander Afanasyev | 7329e02 | 2014-02-27 14:47:22 -0800 | [diff] [blame] | 142 | make_shared<stream_protocol::socket>(boost::ref(g_io)); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 143 | client->async_connect(stream_protocol::endpoint(CHANNEL_PATH1), |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 144 | bind(&EndToEndFixture::client_onConnect, this, _1)); |
| 145 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 146 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 147 | "UnixStreamChannel error: cannot connect or cannot accept connection"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 148 | |
| 149 | BOOST_REQUIRE(static_cast<bool>(m_face1)); |
| 150 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 151 | std::string face1uri = m_face1->getUri().toString(); |
| 152 | BOOST_CHECK_EQUAL(face1uri.find("unix:///"), 0); // third '/' is the path separator |
| 153 | BOOST_CHECK_EQUAL(face1uri.rfind(CHANNEL_PATH1), |
| 154 | face1uri.size() - std::string(CHANNEL_PATH1).size()); |
| 155 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 156 | m_face2 = make_shared<UnixStreamFace>(client); |
| 157 | m_face2->onReceiveInterest += |
| 158 | bind(&EndToEndFixture::face2_onReceiveInterest, this, _1); |
| 159 | m_face2->onReceiveData += |
| 160 | bind(&EndToEndFixture::face2_onReceiveData, this, _1); |
| 161 | |
| 162 | Interest interest1("ndn:/TpnzGvW9R"); |
| 163 | Data data1 ("ndn:/KfczhUqVix"); |
| 164 | data1.setContent(0, 0); |
| 165 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 166 | Data data2 ("ndn:/XNBV796f"); |
| 167 | data2.setContent(0, 0); |
| 168 | |
| 169 | ndn::SignatureSha256WithRsa fakeSignature; |
| 170 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0)); |
| 171 | |
| 172 | // set fake signature on data1 and data2 |
| 173 | data1.setSignature(fakeSignature); |
| 174 | data2.setSignature(fakeSignature); |
| 175 | |
| 176 | m_face1->sendInterest(interest1); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 177 | m_face1->sendInterest(interest1); |
| 178 | m_face1->sendInterest(interest1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 179 | m_face1->sendData (data1 ); |
| 180 | m_face2->sendInterest(interest2); |
| 181 | m_face2->sendData (data2 ); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 182 | m_face2->sendData (data2 ); |
| 183 | m_face2->sendData (data2 ); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 184 | |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 185 | BOOST_CHECK_MESSAGE(m_limitedIo.run(8, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 186 | "UnixStreamChannel error: cannot send or receive Interest/Data packets"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 187 | |
| 188 | BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 189 | BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 3); |
| 190 | BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 3); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 191 | BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
| 192 | |
| 193 | BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName()); |
| 194 | BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName()); |
| 195 | BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName()); |
| 196 | BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName()); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 197 | |
| 198 | const FaceCounters& counters1 = m_face1->getCounters(); |
| 199 | BOOST_CHECK_EQUAL(counters1.getInInterest() , 1); |
| 200 | BOOST_CHECK_EQUAL(counters1.getInData() , 3); |
| 201 | BOOST_CHECK_EQUAL(counters1.getOutInterest(), 3); |
| 202 | BOOST_CHECK_EQUAL(counters1.getOutData() , 1); |
| 203 | |
| 204 | const FaceCounters& counters2 = m_face2->getCounters(); |
| 205 | BOOST_CHECK_EQUAL(counters2.getInInterest() , 3); |
| 206 | BOOST_CHECK_EQUAL(counters2.getInData() , 1); |
| 207 | BOOST_CHECK_EQUAL(counters2.getOutInterest(), 1); |
| 208 | BOOST_CHECK_EQUAL(counters2.getOutData() , 3); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) |
| 212 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 213 | UnixStreamFactory factory; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 214 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 215 | shared_ptr<UnixStreamChannel> channel = factory.createChannel(CHANNEL_PATH1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 216 | channel->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 217 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
| 218 | |
| 219 | shared_ptr<stream_protocol::socket> client1 = |
Alexander Afanasyev | 7329e02 | 2014-02-27 14:47:22 -0800 | [diff] [blame] | 220 | make_shared<stream_protocol::socket>(boost::ref(g_io)); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 221 | client1->async_connect(stream_protocol::endpoint(CHANNEL_PATH1), |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 222 | bind(&EndToEndFixture::client_onConnect, this, _1)); |
| 223 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 224 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 225 | "UnixStreamChannel error: cannot connect or cannot accept connection"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 226 | |
| 227 | BOOST_CHECK_EQUAL(m_faces.size(), 1); |
| 228 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 229 | shared_ptr<stream_protocol::socket> client2 = |
Alexander Afanasyev | 7329e02 | 2014-02-27 14:47:22 -0800 | [diff] [blame] | 230 | make_shared<stream_protocol::socket>(boost::ref(g_io)); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 231 | client2->async_connect(stream_protocol::endpoint(CHANNEL_PATH1), |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 232 | bind(&EndToEndFixture::client_onConnect, this, _1)); |
| 233 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 234 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 235 | "UnixStreamChannel error: cannot accept multiple connections"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 236 | |
| 237 | BOOST_CHECK_EQUAL(m_faces.size(), 2); |
| 238 | |
| 239 | // now close one of the faces |
| 240 | m_faces.front()->close(); |
| 241 | |
| 242 | // we should still be able to send/receive with the other one |
| 243 | m_face1 = m_faces.back(); |
| 244 | m_face1->onReceiveInterest += |
| 245 | bind(&EndToEndFixture::face1_onReceiveInterest, this, _1); |
| 246 | m_face1->onReceiveData += |
| 247 | bind(&EndToEndFixture::face1_onReceiveData, this, _1); |
| 248 | |
| 249 | m_face2 = make_shared<UnixStreamFace>(client2); |
| 250 | m_face2->onReceiveInterest += |
| 251 | bind(&EndToEndFixture::face2_onReceiveInterest, this, _1); |
| 252 | m_face2->onReceiveData += |
| 253 | bind(&EndToEndFixture::face2_onReceiveData, this, _1); |
| 254 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 255 | Interest interest1("ndn:/TpnzGvW9R"); |
| 256 | Data data1 ("ndn:/KfczhUqVix"); |
| 257 | data1.setContent(0, 0); |
| 258 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 259 | Data data2 ("ndn:/XNBV796f"); |
| 260 | data2.setContent(0, 0); |
| 261 | |
| 262 | ndn::SignatureSha256WithRsa fakeSignature; |
| 263 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0)); |
| 264 | |
| 265 | // set fake signature on data1 and data2 |
| 266 | data1.setSignature(fakeSignature); |
| 267 | data2.setSignature(fakeSignature); |
| 268 | |
| 269 | m_face1->sendInterest(interest1); |
| 270 | m_face1->sendData (data1 ); |
| 271 | m_face2->sendInterest(interest2); |
| 272 | m_face2->sendData (data2 ); |
| 273 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 274 | BOOST_CHECK_MESSAGE(m_limitedIo.run(4, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 275 | "UnixStreamChannel error: cannot send or receive Interest/Data packets"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 276 | |
| 277 | BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 278 | BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
| 279 | BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1); |
| 280 | BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
| 281 | |
| 282 | BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getName(), interest2.getName()); |
| 283 | BOOST_CHECK_EQUAL(m_face1_receivedDatas [0].getName(), data2.getName()); |
| 284 | BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getName(), interest1.getName()); |
| 285 | BOOST_CHECK_EQUAL(m_face2_receivedDatas [0].getName(), data1.getName()); |
| 286 | } |
| 287 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 288 | static inline void |
| 289 | noOp() |
| 290 | { |
| 291 | } |
| 292 | |
| 293 | BOOST_FIXTURE_TEST_CASE(UnixStreamFaceLocalControlHeader, EndToEndFixture) |
| 294 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 295 | UnixStreamFactory factory; |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 296 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 297 | shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 298 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 299 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 300 | |
| 301 | shared_ptr<stream_protocol::socket> client = |
Alexander Afanasyev | 7329e02 | 2014-02-27 14:47:22 -0800 | [diff] [blame] | 302 | make_shared<stream_protocol::socket>(boost::ref(g_io)); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 303 | client->async_connect(stream_protocol::endpoint(CHANNEL_PATH1), |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 304 | bind(&EndToEndFixture::client_onConnect, this, _1)); |
| 305 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 306 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 307 | "UnixStreamChannel error: cannot connect or cannot accept connection"); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 308 | |
| 309 | BOOST_REQUIRE(static_cast<bool>(m_face1)); |
| 310 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 311 | m_face2 = make_shared<UnixStreamFace>(client); |
| 312 | m_face2->onReceiveInterest += |
| 313 | bind(&EndToEndFixture::face2_onReceiveInterest, this, _1); |
| 314 | m_face2->onReceiveData += |
| 315 | bind(&EndToEndFixture::face2_onReceiveData, this, _1); |
| 316 | |
| 317 | Interest interest1("ndn:/TpnzGvW9R"); |
| 318 | Data data1 ("ndn:/KfczhUqVix"); |
| 319 | data1.setContent(0, 0); |
| 320 | Interest interest2("ndn:/QWiIMfj5sL"); |
| 321 | Data data2 ("ndn:/XNBV796f"); |
| 322 | data2.setContent(0, 0); |
| 323 | |
| 324 | ndn::SignatureSha256WithRsa fakeSignature; |
| 325 | fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue, reinterpret_cast<const uint8_t*>(0), 0)); |
| 326 | |
| 327 | // set fake signature on data1 and data2 |
| 328 | data1.setSignature(fakeSignature); |
| 329 | data2.setSignature(fakeSignature); |
| 330 | |
| 331 | m_face1->setLocalControlHeaderFeature(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID); |
| 332 | m_face1->setLocalControlHeaderFeature(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID); |
| 333 | |
| 334 | BOOST_CHECK(m_face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 335 | BOOST_CHECK(m_face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 336 | |
| 337 | m_face2->setLocalControlHeaderFeature(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID); |
| 338 | m_face2->setLocalControlHeaderFeature(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID); |
| 339 | |
| 340 | BOOST_CHECK(m_face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_IN_FACEID)); |
| 341 | BOOST_CHECK(m_face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_HEADER_FEATURE_NEXTHOP_FACEID)); |
| 342 | |
| 343 | //////////////////////////////////////////////////////// |
| 344 | |
| 345 | interest1.setIncomingFaceId(11); |
| 346 | interest1.setNextHopFaceId(111); |
| 347 | |
| 348 | m_face1->sendInterest(interest1); |
| 349 | |
| 350 | data1.setIncomingFaceId(22); |
| 351 | data1.getLocalControlHeader().setNextHopFaceId(222); |
| 352 | |
| 353 | m_face1->sendData (data1); |
| 354 | |
| 355 | // |
| 356 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 357 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 358 | "UnixStreamChannel error: cannot send or receive Interest/Data packets"); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 359 | |
| 360 | BOOST_REQUIRE_EQUAL(m_face2_receivedInterests.size(), 1); |
| 361 | BOOST_REQUIRE_EQUAL(m_face2_receivedDatas .size(), 1); |
| 362 | |
| 363 | // sending allows only IncomingFaceId, receiving allows only NextHopFaceId |
| 364 | BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getLocalControlHeader().hasIncomingFaceId(), false); |
| 365 | BOOST_CHECK_EQUAL(m_face2_receivedInterests[0].getLocalControlHeader().hasNextHopFaceId(), false); |
| 366 | |
| 367 | BOOST_CHECK_EQUAL(m_face2_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false); |
| 368 | BOOST_CHECK_EQUAL(m_face2_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false); |
| 369 | |
| 370 | //////////////////////////////////////////////////////// |
| 371 | |
| 372 | using namespace boost::asio; |
| 373 | |
| 374 | std::vector<const_buffer> interestWithHeader; |
| 375 | Block iHeader = interest1.getLocalControlHeader().wireEncode(interest1, true, true); |
| 376 | Block iPayload = interest1.wireEncode(); |
| 377 | interestWithHeader.push_back(buffer(iHeader.wire(), iHeader.size())); |
| 378 | interestWithHeader.push_back(buffer(iPayload.wire(), iPayload.size())); |
| 379 | |
| 380 | std::vector<const_buffer> dataWithHeader; |
| 381 | Block dHeader = data1.getLocalControlHeader().wireEncode(data1, true, true); |
| 382 | Block dPayload = data1.wireEncode(); |
| 383 | dataWithHeader.push_back(buffer(dHeader.wire(), dHeader.size())); |
| 384 | dataWithHeader.push_back(buffer(dPayload.wire(), dPayload.size())); |
| 385 | |
| 386 | // |
| 387 | |
| 388 | client->async_send(interestWithHeader, bind(&noOp)); |
| 389 | client->async_send(dataWithHeader, bind(&noOp)); |
| 390 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 391 | BOOST_CHECK_MESSAGE(m_limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 392 | "UnixStreamChannel error: cannot send or receive Interest/Data packets"); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 393 | |
| 394 | BOOST_REQUIRE_EQUAL(m_face1_receivedInterests.size(), 1); |
| 395 | BOOST_REQUIRE_EQUAL(m_face1_receivedDatas .size(), 1); |
| 396 | |
| 397 | BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getLocalControlHeader().hasIncomingFaceId(), false); |
| 398 | BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getLocalControlHeader().hasNextHopFaceId(), true); |
| 399 | BOOST_CHECK_EQUAL(m_face1_receivedInterests[0].getNextHopFaceId(), 111); |
| 400 | |
| 401 | BOOST_CHECK_EQUAL(m_face1_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false); |
| 402 | BOOST_CHECK_EQUAL(m_face1_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false); |
| 403 | } |
| 404 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 405 | BOOST_AUTO_TEST_SUITE_END() |
| 406 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 407 | } // namespace tests |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 408 | } // namespace nfd |