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 | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 269 | const face::FaceCounters& counters1 = face1->getCounters(); |
| 270 | BOOST_CHECK_EQUAL(counters1.nInInterests, 1); |
| 271 | BOOST_CHECK_EQUAL(counters1.nInData, 3); |
| 272 | BOOST_CHECK_EQUAL(counters1.nOutInterests, 3); |
| 273 | BOOST_CHECK_EQUAL(counters1.nOutData, 1); |
| 274 | BOOST_CHECK_EQUAL(counters1.nInBytes, nBytesSent2); |
| 275 | BOOST_CHECK_EQUAL(counters1.nOutBytes, nBytesSent1); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 276 | |
Junxiao Shi | da93f1f | 2015-11-11 06:13:16 -0700 | [diff] [blame] | 277 | const face::FaceCounters& counters2 = face2->getCounters(); |
| 278 | BOOST_CHECK_EQUAL(counters2.nInInterests, 3); |
| 279 | BOOST_CHECK_EQUAL(counters2.nInData, 1); |
| 280 | BOOST_CHECK_EQUAL(counters2.nOutInterests, 1); |
| 281 | BOOST_CHECK_EQUAL(counters2.nOutData, 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_AUTO_TEST_SUITE_END() // TestUnixStream |
| 344 | BOOST_AUTO_TEST_SUITE_END() // Face |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 345 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 346 | } // namespace tests |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 347 | } // namespace nfd |