Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 24 | */ |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 25 | |
Davide Pesavento | 6ad890a | 2015-03-09 03:43:17 +0100 | [diff] [blame] | 26 | #include "face/unix-stream-channel.hpp" |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 27 | #include "face/unix-stream-factory.hpp" |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 28 | #include "face/unix-stream-transport.hpp" |
| 29 | |
| 30 | #include "face/generic-link-service.hpp" |
| 31 | #include "face/lp-face-wrapper.hpp" |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 32 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 33 | #include "tests/test-common.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 34 | #include "tests/limited-io.hpp" |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 35 | #include "dummy-stream-sender.hpp" |
| 36 | #include "packet-datasets.hpp" |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 37 | |
| 38 | namespace nfd { |
| 39 | namespace tests { |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 40 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 41 | #define CHANNEL_PATH1 "unix-stream-test.1.sock" |
| 42 | #define CHANNEL_PATH2 "unix-stream-test.2.sock" |
| 43 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 44 | BOOST_AUTO_TEST_SUITE(Face) |
| 45 | BOOST_FIXTURE_TEST_SUITE(TestUnixStream, BaseFixture) |
| 46 | |
| 47 | using nfd::Face; |
| 48 | using face::LpFaceWrapper; |
| 49 | using face::UnixStreamTransport; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 50 | |
| 51 | BOOST_AUTO_TEST_CASE(ChannelMap) |
| 52 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 53 | UnixStreamFactory factory; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 54 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 55 | shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1); |
| 56 | shared_ptr<UnixStreamChannel> channel1a = factory.createChannel(CHANNEL_PATH1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 57 | BOOST_CHECK_EQUAL(channel1, channel1a); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 58 | std::string channel1uri = channel1->getUri().toString(); |
| 59 | BOOST_CHECK_EQUAL(channel1uri.find("unix:///"), 0); // third '/' is the path separator |
| 60 | BOOST_CHECK_EQUAL(channel1uri.rfind(CHANNEL_PATH1), |
| 61 | channel1uri.size() - std::string(CHANNEL_PATH1).size()); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 62 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 63 | shared_ptr<UnixStreamChannel> channel2 = factory.createChannel(CHANNEL_PATH2); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 64 | BOOST_CHECK_NE(channel1, channel2); |
| 65 | } |
| 66 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 67 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 68 | { |
| 69 | UnixStreamFactory factory; |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 70 | BOOST_CHECK(factory.getChannels().empty()); |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 71 | |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 72 | std::vector<shared_ptr<const Channel>> expectedChannels; |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 73 | expectedChannels.push_back(factory.createChannel(CHANNEL_PATH1)); |
| 74 | expectedChannels.push_back(factory.createChannel(CHANNEL_PATH2)); |
| 75 | |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 76 | for (const auto& channel : factory.getChannels()) { |
| 77 | auto pos = std::find(expectedChannels.begin(), expectedChannels.end(), channel); |
| 78 | BOOST_REQUIRE(pos != expectedChannels.end()); |
| 79 | expectedChannels.erase(pos); |
| 80 | } |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 81 | |
| 82 | BOOST_CHECK_EQUAL(expectedChannels.size(), 0); |
| 83 | } |
| 84 | |
Yukai Tu | 7c90e6d | 2015-07-11 12:21:46 +0800 | [diff] [blame] | 85 | BOOST_AUTO_TEST_CASE(UnsupportedFaceCreate) |
| 86 | { |
| 87 | UnixStreamFactory factory; |
| 88 | |
| 89 | BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"), |
| 90 | ndn::nfd::FACE_PERSISTENCY_PERMANENT, |
| 91 | bind([]{}), |
| 92 | bind([]{})), |
| 93 | ProtocolFactory::Error); |
| 94 | |
| 95 | BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"), |
| 96 | ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, |
| 97 | bind([]{}), |
| 98 | bind([]{})), |
| 99 | ProtocolFactory::Error); |
| 100 | |
| 101 | BOOST_CHECK_THROW(factory.createFace(FaceUri("unix:///var/run/nfd.sock"), |
| 102 | ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 103 | bind([]{}), |
| 104 | bind([]{})), |
| 105 | ProtocolFactory::Error); |
| 106 | } |
| 107 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 108 | class EndToEndFixture : protected BaseFixture |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 109 | { |
| 110 | public: |
| 111 | void |
| 112 | client_onConnect(const boost::system::error_code& error) |
| 113 | { |
| 114 | BOOST_CHECK_MESSAGE(!error, error.message()); |
| 115 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 116 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | void |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 120 | channel1_onFaceCreated(const shared_ptr<Face>& newFace) |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 121 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 122 | BOOST_CHECK(!static_cast<bool>(face1)); |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 123 | face1 = static_pointer_cast<LpFaceWrapper>(newFace); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 124 | face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1)); |
| 125 | face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1)); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 126 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 127 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | void |
| 131 | channel1_onConnectFailed(const std::string& reason) |
| 132 | { |
| 133 | BOOST_CHECK_MESSAGE(false, reason); |
| 134 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 135 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 136 | } |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 137 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 138 | void |
| 139 | face1_onReceiveInterest(const Interest& interest) |
| 140 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 141 | face1_receivedInterests.push_back(interest); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 142 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 143 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 144 | } |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 145 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 146 | void |
| 147 | face1_onReceiveData(const Data& data) |
| 148 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 149 | face1_receivedDatas.push_back(data); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 150 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 151 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | void |
| 155 | face2_onReceiveInterest(const Interest& interest) |
| 156 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 157 | face2_receivedInterests.push_back(interest); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 158 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 159 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 160 | } |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 161 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 162 | void |
| 163 | face2_onReceiveData(const Data& data) |
| 164 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 165 | face2_receivedDatas.push_back(data); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 166 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 167 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | void |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 171 | channel_onFaceCreated(const shared_ptr<Face>& newFace) |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 172 | { |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 173 | faces.push_back(static_pointer_cast<LpFaceWrapper>(newFace)); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 174 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 175 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | void |
| 179 | channel_onConnectFailed(const std::string& reason) |
| 180 | { |
| 181 | BOOST_CHECK_MESSAGE(false, reason); |
| 182 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 183 | limitedIo.afterOp(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 184 | } |
| 185 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 186 | shared_ptr<LpFaceWrapper> |
| 187 | makeFace(UnixStreamTransport::protocol::socket&& socket) |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 188 | { |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 189 | auto linkService = make_unique<face::GenericLinkService>(); |
| 190 | auto transport = make_unique<UnixStreamTransport>(std::move(socket)); |
| 191 | auto lpFace = make_unique<LpFace>(std::move(linkService), std::move(transport)); |
| 192 | return make_shared<LpFaceWrapper>(std::move(lpFace)); |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 193 | } |
| 194 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 195 | protected: |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 196 | LimitedIo limitedIo; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 197 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 198 | shared_ptr<LpFaceWrapper> face1; |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 199 | std::vector<Interest> face1_receivedInterests; |
| 200 | std::vector<Data> face1_receivedDatas; |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 201 | shared_ptr<LpFaceWrapper> face2; |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 202 | std::vector<Interest> face2_receivedInterests; |
| 203 | std::vector<Data> face2_receivedDatas; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 204 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 205 | std::list<shared_ptr<LpFaceWrapper>> faces; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | |
| 209 | BOOST_FIXTURE_TEST_CASE(EndToEnd, EndToEndFixture) |
| 210 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 211 | UnixStreamFactory factory; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 212 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 213 | shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 214 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 215 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 216 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 217 | UnixStreamTransport::protocol::socket client(g_io); |
| 218 | client.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1), |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 219 | bind(&EndToEndFixture::client_onConnect, this, _1)); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 220 | |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 221 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Connect"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 222 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 223 | BOOST_REQUIRE(static_cast<bool>(face1)); |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 224 | BOOST_CHECK_EQUAL(face1->isLocal(), true); |
Yukai Tu | 731f0d7 | 2015-07-04 11:14:44 +0800 | [diff] [blame] | 225 | BOOST_CHECK_EQUAL(face1->getPersistency(), ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
Davide Pesavento | 9427941 | 2015-02-27 01:29:32 +0100 | [diff] [blame] | 226 | BOOST_CHECK_EQUAL(face1->isMultiAccess(), false); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 227 | BOOST_CHECK_EQUAL(face1->getRemoteUri().getScheme(), "fd"); |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 228 | BOOST_CHECK_NO_THROW(std::stoi(face1->getRemoteUri().getHost())); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 229 | std::string face1localUri = face1->getLocalUri().toString(); |
| 230 | BOOST_CHECK_EQUAL(face1localUri.find("unix:///"), 0); // third '/' is the path separator |
| 231 | BOOST_CHECK_EQUAL(face1localUri.rfind(CHANNEL_PATH1), |
| 232 | face1localUri.size() - std::string(CHANNEL_PATH1).size()); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 233 | |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 234 | face2 = makeFace(std::move(client)); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 235 | face2->onReceiveInterest.connect(bind(&EndToEndFixture::face2_onReceiveInterest, this, _1)); |
| 236 | face2->onReceiveData.connect(bind(&EndToEndFixture::face2_onReceiveData, this, _1)); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 237 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 238 | shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R"); |
| 239 | shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix"); |
| 240 | shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL"); |
| 241 | shared_ptr<Data> data2 = makeData("ndn:/XNBV796f"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 242 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 243 | face1->sendInterest(*interest1); |
| 244 | face1->sendInterest(*interest1); |
| 245 | face1->sendInterest(*interest1); |
| 246 | face1->sendData (*data1 ); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 247 | size_t nBytesSent1 = interest1->wireEncode().size() * 3 + data1->wireEncode().size(); |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 248 | face2->sendInterest(*interest2); |
| 249 | face2->sendData (*data2 ); |
| 250 | face2->sendData (*data2 ); |
| 251 | face2->sendData (*data2 ); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 252 | size_t nBytesSent2 = interest2->wireEncode().size() + data2->wireEncode().size() * 3; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 253 | |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 254 | BOOST_CHECK_MESSAGE(limitedIo.run(8, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Send/receive"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 255 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 256 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 257 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3); |
| 258 | BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 3); |
| 259 | BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 260 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 261 | BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName()); |
| 262 | BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName()); |
| 263 | BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName()); |
| 264 | BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName()); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 265 | |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 266 | // needed to ensure NOutBytes counters are accurate |
| 267 | limitedIo.run(LimitedIo::UNLIMITED_OPS, time::seconds(1)); |
| 268 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 269 | const FaceCounters& counters1 = face1->getCounters(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 270 | BOOST_CHECK_EQUAL(counters1.getNInInterests() , 1); |
| 271 | BOOST_CHECK_EQUAL(counters1.getNInDatas() , 3); |
| 272 | BOOST_CHECK_EQUAL(counters1.getNOutInterests(), 3); |
| 273 | BOOST_CHECK_EQUAL(counters1.getNOutDatas() , 1); |
Junxiao Shi | 5dd26c3 | 2014-07-20 23:15:14 -0700 | [diff] [blame] | 274 | BOOST_CHECK_EQUAL(counters1.getNInBytes(), nBytesSent2); |
| 275 | BOOST_CHECK_EQUAL(counters1.getNOutBytes(), nBytesSent1); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 276 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 277 | const FaceCounters& counters2 = face2->getCounters(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 278 | BOOST_CHECK_EQUAL(counters2.getNInInterests() , 3); |
| 279 | BOOST_CHECK_EQUAL(counters2.getNInDatas() , 1); |
| 280 | BOOST_CHECK_EQUAL(counters2.getNOutInterests(), 1); |
| 281 | BOOST_CHECK_EQUAL(counters2.getNOutDatas() , 3); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) |
| 285 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 286 | UnixStreamFactory factory; |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 287 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 288 | shared_ptr<UnixStreamChannel> channel = factory.createChannel(CHANNEL_PATH1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 289 | channel->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 290 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
| 291 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 292 | UnixStreamTransport::protocol::socket client1(g_io); |
| 293 | client1.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1), |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 294 | bind(&EndToEndFixture::client_onConnect, this, _1)); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 295 | |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 296 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "First connect"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 297 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 298 | BOOST_CHECK_EQUAL(faces.size(), 1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 299 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 300 | UnixStreamTransport::protocol::socket client2(g_io); |
| 301 | client2.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1), |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 302 | bind(&EndToEndFixture::client_onConnect, this, _1)); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 303 | |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 304 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Second connect"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 305 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 306 | BOOST_CHECK_EQUAL(faces.size(), 2); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 307 | |
| 308 | // now close one of the faces |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 309 | faces.front()->close(); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 310 | |
| 311 | // we should still be able to send/receive with the other one |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 312 | face1 = faces.back(); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 313 | face1->onReceiveInterest.connect(bind(&EndToEndFixture::face1_onReceiveInterest, this, _1)); |
| 314 | face1->onReceiveData.connect(bind(&EndToEndFixture::face1_onReceiveData, this, _1)); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 315 | |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 316 | face2 = makeFace(std::move(client2)); |
Junxiao Shi | c099ddb | 2014-12-25 20:53:20 -0700 | [diff] [blame] | 317 | face2->onReceiveInterest.connect(bind(&EndToEndFixture::face2_onReceiveInterest, this, _1)); |
| 318 | face2->onReceiveData.connect(bind(&EndToEndFixture::face2_onReceiveData, this, _1)); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 319 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 320 | shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R"); |
| 321 | shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix"); |
| 322 | shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL"); |
| 323 | shared_ptr<Data> data2 = makeData("ndn:/XNBV796f"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 324 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 325 | face1->sendInterest(*interest1); |
| 326 | face1->sendData (*data1 ); |
| 327 | face2->sendInterest(*interest2); |
| 328 | face2->sendData (*data2 ); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 329 | |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 330 | BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Send/receive"); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 331 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 332 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 333 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1); |
| 334 | BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1); |
| 335 | BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 336 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 337 | BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName()); |
| 338 | BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName()); |
| 339 | BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName()); |
| 340 | BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName()); |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 341 | } |
| 342 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 343 | //BOOST_FIXTURE_TEST_CASE(UnixStreamTransportLocalControlHeader, EndToEndFixture) |
| 344 | //{ |
| 345 | // UnixStreamFactory factory; |
| 346 | // |
| 347 | // shared_ptr<UnixStreamChannel> channel1 = factory.createChannel(CHANNEL_PATH1); |
| 348 | // channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 349 | // bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 350 | // |
| 351 | // UnixStreamTransport::protocol::socket client(g_io); |
| 352 | // client.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1), |
| 353 | // bind(&EndToEndFixture::client_onConnect, this, _1)); |
| 354 | // |
| 355 | // BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Connect"); |
| 356 | // |
| 357 | // BOOST_REQUIRE(static_cast<bool>(face1)); |
| 358 | // |
| 359 | // face2 = makeFace(std::move(client)); |
| 360 | // face2->onReceiveInterest.connect(bind(&EndToEndFixture::face2_onReceiveInterest, this, _1)); |
| 361 | // face2->onReceiveData.connect(bind(&EndToEndFixture::face2_onReceiveData, this, _1)); |
| 362 | // |
| 363 | // shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R"); |
| 364 | // shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix"); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 365 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 366 | // face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 367 | // face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 368 | // |
| 369 | // BOOST_CHECK(face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 370 | // BOOST_CHECK(face1->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 371 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 372 | // face2->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 373 | // face2->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 374 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 375 | // BOOST_CHECK(face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID)); |
| 376 | // BOOST_CHECK(face2->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID)); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 377 | |
| 378 | //////////////////////////////////////////////////////// |
| 379 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 380 | // interest1->setIncomingFaceId(11); |
| 381 | // interest1->setNextHopFaceId(111); |
| 382 | // face1->sendInterest(*interest1); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 383 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 384 | // data1->setIncomingFaceId(22); |
| 385 | // data1->getLocalControlHeader().setNextHopFaceId(222); |
| 386 | // face1->sendData(*data1); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 387 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 388 | // BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 389 | // "Regular send/receive"); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 390 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 391 | // BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1); |
| 392 | // BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 393 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 394 | // sending allows only IncomingFaceId, receiving allows only NextHopFaceId |
| 395 | // BOOST_CHECK_EQUAL(face2_receivedInterests[0].getLocalControlHeader().hasIncomingFaceId(), false); |
| 396 | // BOOST_CHECK_EQUAL(face2_receivedInterests[0].getLocalControlHeader().hasNextHopFaceId(), false); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 397 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 398 | // BOOST_CHECK_EQUAL(face2_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false); |
| 399 | // BOOST_CHECK_EQUAL(face2_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 400 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 401 | // face1->close(); |
| 402 | // face1.reset(); |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 403 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 404 | //////////////////////////////////////////////////////// |
| 405 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 406 | // client.async_connect(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1), |
| 407 | // bind(&EndToEndFixture::client_onConnect, this, _1)); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 408 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 409 | // BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, "Connect"); |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 410 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 411 | // BOOST_REQUIRE(static_cast<bool>(face1)); |
| 412 | // face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 413 | // face1->setLocalControlHeaderFeature(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
Davide Pesavento | 292e5e1 | 2015-03-13 02:08:33 +0100 | [diff] [blame] | 414 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 415 | // Block iHeader = interest1->getLocalControlHeader() |
| 416 | // .wireEncode(*interest1, ndn::nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID | |
| 417 | // ndn::nfd::LocalControlHeader::ENCODE_NEXT_HOP); |
| 418 | // Block iPayload = interest1->wireEncode(); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 419 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 420 | // Block dHeader = data1->getLocalControlHeader() |
| 421 | // .wireEncode(*data1, ndn::nfd::LocalControlHeader::ENCODE_INCOMING_FACE_ID | |
| 422 | // ndn::nfd::LocalControlHeader::ENCODE_NEXT_HOP); |
| 423 | // Block dPayload = data1->wireEncode(); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 424 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 425 | // client.async_send(std::vector<boost::asio::const_buffer>{iHeader, iPayload}, |
| 426 | // [] (const boost::system::error_code& error, size_t nBytesSent) { |
| 427 | // BOOST_CHECK_MESSAGE(!error, error.message()); |
| 428 | // }); |
| 429 | // client.async_send(std::vector<boost::asio::const_buffer>{dHeader, dPayload}, |
| 430 | // [] (const boost::system::error_code& error, size_t nBytesSent) { |
| 431 | // BOOST_CHECK_MESSAGE(!error, error.message()); |
| 432 | // }); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 433 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 434 | // BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(1)) == LimitedIo::EXCEED_OPS, |
| 435 | // "Send/receive with LocalControlHeader"); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 436 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 437 | // BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 438 | // BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 439 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 440 | // BOOST_CHECK_EQUAL(face1_receivedInterests[0].getLocalControlHeader().hasIncomingFaceId(), false); |
| 441 | // BOOST_CHECK_EQUAL(face1_receivedInterests[0].getLocalControlHeader().hasNextHopFaceId(), true); |
| 442 | // BOOST_CHECK_EQUAL(face1_receivedInterests[0].getNextHopFaceId(), 111); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 443 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 444 | // BOOST_CHECK_EQUAL(face1_receivedDatas[0].getLocalControlHeader().hasIncomingFaceId(), false); |
| 445 | // BOOST_CHECK_EQUAL(face1_receivedDatas[0].getLocalControlHeader().hasNextHopFaceId(), false); |
| 446 | //} |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 447 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 448 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 449 | //class SimpleEndToEndFixture : protected BaseFixture |
| 450 | //{ |
| 451 | //public: |
| 452 | // void |
| 453 | // onFaceCreated(const shared_ptr<Face>& face) |
| 454 | // { |
| 455 | // face->onReceiveInterest.connect(bind(&SimpleEndToEndFixture::onReceiveInterest, this, _1)); |
| 456 | // face->onReceiveData.connect(bind(&SimpleEndToEndFixture::onReceiveData, this, _1)); |
| 457 | // face->onFail.connect(bind(&SimpleEndToEndFixture::onFail, this, face)); |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 458 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 459 | // if (static_cast<bool>(dynamic_pointer_cast<LocalFace>(face))) { |
| 460 | // static_pointer_cast<LocalFace>(face)->setLocalControlHeaderFeature( |
| 461 | // LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 462 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 463 | // static_pointer_cast<LocalFace>(face)->setLocalControlHeaderFeature( |
| 464 | // LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 465 | // } |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 466 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 467 | // limitedIo.afterOp(); |
| 468 | // } |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 469 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 470 | // void |
| 471 | // onConnectFailed(const std::string& reason) |
| 472 | // { |
| 473 | // BOOST_CHECK_MESSAGE(false, reason); |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 474 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 475 | // limitedIo.afterOp(); |
| 476 | // } |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 477 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 478 | // void |
| 479 | // onReceiveInterest(const Interest& interest) |
| 480 | // { |
| 481 | // receivedInterests.push_back(interest); |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 482 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 483 | // limitedIo.afterOp(); |
| 484 | // } |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 485 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 486 | // void |
| 487 | // onReceiveData(const Data& data) |
| 488 | // { |
| 489 | // receivedDatas.push_back(data); |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 490 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 491 | // limitedIo.afterOp(); |
| 492 | // } |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 493 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 494 | // void |
| 495 | // onFail(const shared_ptr<Face>& face) |
| 496 | // { |
| 497 | // limitedIo.afterOp(); |
| 498 | // } |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 499 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 500 | //public: |
| 501 | // LimitedIo limitedIo; |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 502 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 503 | // std::vector<Interest> receivedInterests; |
| 504 | // std::vector<Data> receivedDatas; |
| 505 | //}; |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 506 | |
| 507 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 508 | //BOOST_FIXTURE_TEST_CASE_TEMPLATE(CorruptedInput, Dataset, |
| 509 | // CorruptedPackets, SimpleEndToEndFixture) |
| 510 | //{ |
| 511 | // UnixStreamFactory factory; |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 512 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 513 | // shared_ptr<UnixStreamChannel> channel = factory.createChannel(CHANNEL_PATH1); |
| 514 | // channel->listen(bind(&SimpleEndToEndFixture::onFaceCreated, this, _1), |
| 515 | // bind(&SimpleEndToEndFixture::onConnectFailed, this, _1)); |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 516 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 517 | // DummyStreamSender<UnixStreamTransport::protocol, Dataset> sender; |
| 518 | // sender.start(UnixStreamTransport::protocol::endpoint(CHANNEL_PATH1)); |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 519 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 520 | // BOOST_CHECK_MESSAGE(limitedIo.run(LimitedIo::UNLIMITED_OPS, time::seconds(1)) == LimitedIo::EXCEED_TIME, |
| 521 | // "Exception thrown for " + Dataset::getName()); |
| 522 | //} |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 523 | |
Yukai Tu | 74c895d | 2015-09-21 01:11:51 -0700 | [diff] [blame] | 524 | BOOST_AUTO_TEST_SUITE_END() // TestUnixStream |
| 525 | BOOST_AUTO_TEST_SUITE_END() // Face |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 526 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 527 | } // namespace tests |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 528 | } // namespace nfd |