Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014, 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 | */ |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 26 | #include "face/tcp-factory.hpp" |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 27 | #include "core/resolver.hpp" |
| 28 | #include "core/network-interface.hpp" |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 29 | #include <ndn-cxx/security/key-chain.hpp> |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 30 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 31 | #include "tests/test-common.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 32 | #include "tests/limited-io.hpp" |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 33 | #include "dummy-stream-sender.hpp" |
| 34 | #include "packet-datasets.hpp" |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 35 | |
| 36 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 37 | namespace tests { |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 38 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 39 | BOOST_FIXTURE_TEST_SUITE(FaceTcp, BaseFixture) |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 40 | |
| 41 | BOOST_AUTO_TEST_CASE(ChannelMap) |
| 42 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 43 | TcpFactory factory; |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 44 | |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 45 | shared_ptr<TcpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 46 | shared_ptr<TcpChannel> channel1a = factory.createChannel("127.0.0.1", "20070"); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 47 | BOOST_CHECK_EQUAL(channel1, channel1a); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 48 | BOOST_CHECK_EQUAL(channel1->getUri().toString(), "tcp4://127.0.0.1:20070"); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 49 | |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 50 | shared_ptr<TcpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 51 | BOOST_CHECK_NE(channel1, channel2); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 52 | |
| 53 | shared_ptr<TcpChannel> channel3 = factory.createChannel("::1", "20071"); |
| 54 | BOOST_CHECK_NE(channel2, channel3); |
| 55 | BOOST_CHECK_EQUAL(channel3->getUri().toString(), "tcp6://[::1]:20071"); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 58 | BOOST_AUTO_TEST_CASE(GetChannels) |
| 59 | { |
| 60 | TcpFactory factory; |
| 61 | BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true); |
| 62 | |
| 63 | std::vector<shared_ptr<const Channel> > expectedChannels; |
| 64 | expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070")); |
| 65 | expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071")); |
| 66 | expectedChannels.push_back(factory.createChannel("::1", "20071")); |
| 67 | |
| 68 | std::list<shared_ptr<const Channel> > channels = factory.getChannels(); |
| 69 | for (std::list<shared_ptr<const Channel> >::const_iterator i = channels.begin(); |
| 70 | i != channels.end(); ++i) |
| 71 | { |
| 72 | std::vector<shared_ptr<const Channel> >::iterator pos = |
| 73 | std::find(expectedChannels.begin(), expectedChannels.end(), *i); |
| 74 | |
| 75 | BOOST_REQUIRE(pos != expectedChannels.end()); |
| 76 | expectedChannels.erase(pos); |
| 77 | } |
| 78 | |
| 79 | BOOST_CHECK_EQUAL(expectedChannels.size(), 0); |
| 80 | } |
| 81 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 82 | class EndToEndFixture : protected BaseFixture |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 83 | { |
| 84 | public: |
| 85 | void |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 86 | channel1_onFaceCreated(const shared_ptr<Face>& newFace) |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 87 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 88 | BOOST_CHECK(!static_cast<bool>(face1)); |
| 89 | face1 = newFace; |
| 90 | face1->onReceiveInterest += |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 91 | bind(&EndToEndFixture::face1_onReceiveInterest, this, _1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 92 | face1->onReceiveData += |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 93 | bind(&EndToEndFixture::face1_onReceiveData, this, _1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 94 | face1->onFail += |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 95 | bind(&EndToEndFixture::face1_onFail, this); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 96 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 97 | limitedIo.afterOp(); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | void |
| 101 | channel1_onConnectFailed(const std::string& reason) |
| 102 | { |
| 103 | BOOST_CHECK_MESSAGE(false, reason); |
| 104 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 105 | limitedIo.afterOp(); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 106 | } |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 107 | |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 108 | void |
| 109 | face1_onReceiveInterest(const Interest& interest) |
| 110 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 111 | face1_receivedInterests.push_back(interest); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 112 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 113 | limitedIo.afterOp(); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 114 | } |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 115 | |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 116 | void |
| 117 | face1_onReceiveData(const Data& data) |
| 118 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 119 | face1_receivedDatas.push_back(data); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 120 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 121 | limitedIo.afterOp(); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | void |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 125 | face1_onFail() |
| 126 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 127 | face1.reset(); |
| 128 | limitedIo.afterOp(); |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | void |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 132 | channel2_onFaceCreated(const shared_ptr<Face>& newFace) |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 133 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 134 | BOOST_CHECK(!static_cast<bool>(face2)); |
| 135 | face2 = newFace; |
| 136 | face2->onReceiveInterest += |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 137 | bind(&EndToEndFixture::face2_onReceiveInterest, this, _1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 138 | face2->onReceiveData += |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 139 | bind(&EndToEndFixture::face2_onReceiveData, this, _1); |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 140 | face2->onFail += |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 141 | bind(&EndToEndFixture::face2_onFail, this); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 142 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 143 | limitedIo.afterOp(); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void |
| 147 | channel2_onConnectFailed(const std::string& reason) |
| 148 | { |
| 149 | BOOST_CHECK_MESSAGE(false, reason); |
| 150 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 151 | limitedIo.afterOp(); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 152 | } |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 153 | |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 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); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 158 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 159 | limitedIo.afterOp(); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 160 | } |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 161 | |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [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); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 166 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 167 | limitedIo.afterOp(); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | void |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 171 | face2_onFail() |
| 172 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 173 | face2.reset(); |
| 174 | limitedIo.afterOp(); |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | void |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 178 | channel_onFaceCreated(const shared_ptr<Face>& newFace) |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 179 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 180 | faces.push_back(newFace); |
| 181 | limitedIo.afterOp(); |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | void |
| 185 | channel_onConnectFailed(const std::string& reason) |
| 186 | { |
| 187 | BOOST_CHECK_MESSAGE(false, reason); |
| 188 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 189 | limitedIo.afterOp(); |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void |
| 193 | checkFaceList(size_t shouldBe) |
| 194 | { |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 195 | BOOST_CHECK_EQUAL(faces.size(), shouldBe); |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 196 | } |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 197 | |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 198 | public: |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 199 | LimitedIo limitedIo; |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 200 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 201 | shared_ptr<Face> face1; |
| 202 | std::vector<Interest> face1_receivedInterests; |
| 203 | std::vector<Data> face1_receivedDatas; |
| 204 | shared_ptr<Face> face2; |
| 205 | std::vector<Interest> face2_receivedInterests; |
| 206 | std::vector<Data> face2_receivedDatas; |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 207 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 208 | std::list< shared_ptr<Face> > faces; |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 209 | }; |
| 210 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 211 | BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture) |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 212 | { |
Steve DiBenedetto | ca53ac6 | 2014-03-27 19:58:40 -0600 | [diff] [blame] | 213 | TcpFactory factory1; |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 214 | |
Steve DiBenedetto | ca53ac6 | 2014-03-27 19:58:40 -0600 | [diff] [blame] | 215 | shared_ptr<TcpChannel> channel1 = factory1.createChannel("127.0.0.1", "20070"); |
| 216 | factory1.createChannel("127.0.0.1", "20071"); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 217 | |
Alexander Afanasyev | 53a6fd3 | 2014-03-23 00:00:04 -0700 | [diff] [blame] | 218 | BOOST_CHECK_EQUAL(channel1->isListening(), false); |
| 219 | |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 220 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 221 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 222 | |
Alexander Afanasyev | 53a6fd3 | 2014-03-23 00:00:04 -0700 | [diff] [blame] | 223 | BOOST_CHECK_EQUAL(channel1->isListening(), true); |
| 224 | |
Steve DiBenedetto | ca53ac6 | 2014-03-27 19:58:40 -0600 | [diff] [blame] | 225 | TcpFactory factory2; |
| 226 | |
| 227 | shared_ptr<TcpChannel> channel2 = factory2.createChannel("127.0.0.2", "20070"); |
| 228 | factory2.createChannel("127.0.0.2", "20071"); |
| 229 | |
| 230 | factory2.createFace(FaceUri("tcp://127.0.0.1:20070"), |
| 231 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 232 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 233 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 234 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 235 | "TcpChannel error: cannot connect or cannot accept connection"); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 236 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 237 | BOOST_REQUIRE(static_cast<bool>(face1)); |
| 238 | BOOST_REQUIRE(static_cast<bool>(face2)); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 239 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 240 | BOOST_CHECK(face1->isOnDemand()); |
| 241 | BOOST_CHECK(!face2->isOnDemand()); |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 242 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 243 | BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "tcp4://127.0.0.1:20070"); |
| 244 | BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "tcp4://127.0.0.1:20070"); |
| 245 | // face1 has an unknown remoteUri, since the source port is automatically chosen by OS |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 246 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 247 | BOOST_CHECK_EQUAL(face1->isLocal(), true); |
| 248 | BOOST_CHECK_EQUAL(face2->isLocal(), true); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 249 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 250 | BOOST_CHECK_EQUAL(static_cast<bool>(dynamic_pointer_cast<LocalFace>(face1)), true); |
| 251 | BOOST_CHECK_EQUAL(static_cast<bool>(dynamic_pointer_cast<LocalFace>(face2)), true); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 252 | |
| 253 | // integrated tests needs to check that TcpFace for non-loopback fails these tests... |
| 254 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 255 | shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R"); |
| 256 | shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix"); |
| 257 | shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL"); |
| 258 | shared_ptr<Data> data2 = makeData("ndn:/XNBV796f"); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 259 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 260 | face1->sendInterest(*interest1); |
| 261 | face1->sendInterest(*interest1); |
| 262 | face1->sendInterest(*interest1); |
| 263 | face1->sendData (*data1 ); |
| 264 | face2->sendInterest(*interest2); |
| 265 | face2->sendData (*data2 ); |
| 266 | face2->sendData (*data2 ); |
| 267 | face2->sendData (*data2 ); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 268 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 269 | BOOST_CHECK_MESSAGE(limitedIo.run(8, time::seconds(10)) == LimitedIo::EXCEED_OPS, |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 270 | "TcpChannel error: cannot send or receive Interest/Data packets"); |
| 271 | |
| 272 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 273 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 274 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 3); |
| 275 | BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 3); |
| 276 | BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 277 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 278 | BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName()); |
| 279 | BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName()); |
| 280 | BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName()); |
| 281 | BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName()); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 282 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 283 | const FaceCounters& counters1 = face1->getCounters(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 284 | BOOST_CHECK_EQUAL(counters1.getNInInterests() , 1); |
| 285 | BOOST_CHECK_EQUAL(counters1.getNInDatas() , 3); |
| 286 | BOOST_CHECK_EQUAL(counters1.getNOutInterests(), 3); |
| 287 | BOOST_CHECK_EQUAL(counters1.getNOutDatas() , 1); |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 288 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 289 | const FaceCounters& counters2 = face2->getCounters(); |
Junxiao Shi | 6e69432 | 2014-04-03 10:27:13 -0700 | [diff] [blame] | 290 | BOOST_CHECK_EQUAL(counters2.getNInInterests() , 3); |
| 291 | BOOST_CHECK_EQUAL(counters2.getNInDatas() , 1); |
| 292 | BOOST_CHECK_EQUAL(counters2.getNOutInterests(), 1); |
| 293 | BOOST_CHECK_EQUAL(counters2.getNOutDatas() , 3); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | BOOST_FIXTURE_TEST_CASE(EndToEnd6, EndToEndFixture) |
| 297 | { |
Steve DiBenedetto | ca53ac6 | 2014-03-27 19:58:40 -0600 | [diff] [blame] | 298 | TcpFactory factory1; |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 299 | |
Steve DiBenedetto | ca53ac6 | 2014-03-27 19:58:40 -0600 | [diff] [blame] | 300 | shared_ptr<TcpChannel> channel1 = factory1.createChannel("::1", "20070"); |
| 301 | shared_ptr<TcpChannel> channel2 = factory1.createChannel("::1", "20071"); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 302 | |
| 303 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 304 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
| 305 | |
Steve DiBenedetto | ca53ac6 | 2014-03-27 19:58:40 -0600 | [diff] [blame] | 306 | TcpFactory factory2; |
| 307 | |
| 308 | factory2.createChannel("::2", "20070"); |
| 309 | |
| 310 | factory2.createFace(FaceUri("tcp://[::1]:20070"), |
| 311 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 312 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 313 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 314 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 315 | "TcpChannel error: cannot connect or cannot accept connection"); |
| 316 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 317 | BOOST_REQUIRE(static_cast<bool>(face1)); |
| 318 | BOOST_REQUIRE(static_cast<bool>(face2)); |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 319 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 320 | BOOST_CHECK_EQUAL(face2->getRemoteUri().toString(), "tcp6://[::1]:20070"); |
| 321 | BOOST_CHECK_EQUAL(face1->getLocalUri().toString(), "tcp6://[::1]:20070"); |
| 322 | // face1 has an unknown remoteUri, since the source port is automatically chosen by OS |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 323 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 324 | BOOST_CHECK_EQUAL(face1->isLocal(), true); |
| 325 | BOOST_CHECK_EQUAL(face2->isLocal(), true); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 326 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 327 | BOOST_CHECK_EQUAL(static_cast<bool>(dynamic_pointer_cast<LocalFace>(face1)), true); |
| 328 | BOOST_CHECK_EQUAL(static_cast<bool>(dynamic_pointer_cast<LocalFace>(face2)), true); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 329 | |
| 330 | // integrated tests needs to check that TcpFace for non-loopback fails these tests... |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 331 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 332 | shared_ptr<Interest> interest1 = makeInterest("ndn:/TpnzGvW9R"); |
| 333 | shared_ptr<Data> data1 = makeData("ndn:/KfczhUqVix"); |
| 334 | shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL"); |
| 335 | shared_ptr<Data> data2 = makeData("ndn:/XNBV796f"); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 336 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 337 | face1->sendInterest(*interest1); |
| 338 | face1->sendData (*data1 ); |
| 339 | face2->sendInterest(*interest2); |
| 340 | face2->sendData (*data2 ); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 341 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 342 | BOOST_CHECK_MESSAGE(limitedIo.run(4, time::seconds(10)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 343 | "TcpChannel error: cannot send or receive Interest/Data packets"); |
| 344 | |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 345 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 346 | BOOST_REQUIRE_EQUAL(face1_receivedInterests.size(), 1); |
| 347 | BOOST_REQUIRE_EQUAL(face1_receivedDatas .size(), 1); |
| 348 | BOOST_REQUIRE_EQUAL(face2_receivedInterests.size(), 1); |
| 349 | BOOST_REQUIRE_EQUAL(face2_receivedDatas .size(), 1); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 350 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 351 | BOOST_CHECK_EQUAL(face1_receivedInterests[0].getName(), interest2->getName()); |
| 352 | BOOST_CHECK_EQUAL(face1_receivedDatas [0].getName(), data2->getName()); |
| 353 | BOOST_CHECK_EQUAL(face2_receivedInterests[0].getName(), interest1->getName()); |
| 354 | BOOST_CHECK_EQUAL(face2_receivedDatas [0].getName(), data1->getName()); |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 357 | BOOST_FIXTURE_TEST_CASE(MultipleAccepts, EndToEndFixture) |
| 358 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 359 | TcpFactory factory; |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 360 | |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 361 | shared_ptr<TcpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 362 | shared_ptr<TcpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 363 | |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 364 | channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 365 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 366 | |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 367 | channel2->connect("127.0.0.1", "20070", |
| 368 | bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 369 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1), |
Alexander Afanasyev | c1e2ee0 | 2014-02-25 17:02:07 -0800 | [diff] [blame] | 370 | time::seconds(4)); // very short timeout |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 371 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 372 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 373 | "TcpChannel error: cannot connect or cannot accept connection"); |
| 374 | |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 375 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 376 | BOOST_CHECK_EQUAL(faces.size(), 2); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 377 | |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 378 | shared_ptr<TcpChannel> channel3 = factory.createChannel("127.0.0.1", "20072"); |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 379 | channel3->connect("127.0.0.1", "20070", |
| 380 | bind(&EndToEndFixture::channel_onFaceCreated, this, _1), |
| 381 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1), |
Alexander Afanasyev | c1e2ee0 | 2014-02-25 17:02:07 -0800 | [diff] [blame] | 382 | time::seconds(4)); // very short timeout |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 383 | |
| 384 | |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 385 | shared_ptr<TcpChannel> channel4 = factory.createChannel("127.0.0.1", "20073"); |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 386 | |
| 387 | BOOST_CHECK_NE(channel3, channel4); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 388 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 389 | scheduler::schedule(time::seconds(1), |
| 390 | bind(&TcpChannel::connect, channel4, "127.0.0.1", "20070", |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 391 | // does not work without static_cast |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 392 | static_cast<TcpChannel::FaceCreatedCallback>( |
| 393 | bind(&EndToEndFixture::channel_onFaceCreated, this, _1)), |
| 394 | static_cast<TcpChannel::ConnectFailedCallback>( |
| 395 | bind(&EndToEndFixture::channel_onConnectFailed, this, _1)), |
| 396 | time::seconds(4))); |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 397 | |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 398 | scheduler::schedule(time::milliseconds(500), |
Alexander Afanasyev | 7329e02 | 2014-02-27 14:47:22 -0800 | [diff] [blame] | 399 | bind(&EndToEndFixture::checkFaceList, this, 4)); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 400 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 401 | BOOST_CHECK_MESSAGE(limitedIo.run(4,// 2 connects and 2 accepts |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 402 | time::seconds(10)) == LimitedIo::EXCEED_OPS, |
| 403 | "TcpChannel error: cannot connect or cannot accept multiple connections"); |
Alexander Afanasyev | 7329e02 | 2014-02-27 14:47:22 -0800 | [diff] [blame] | 404 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 405 | BOOST_CHECK_EQUAL(faces.size(), 6); |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 408 | |
| 409 | BOOST_FIXTURE_TEST_CASE(FaceClosing, EndToEndFixture) |
| 410 | { |
Alexander Afanasyev | 0eb7065 | 2014-02-27 18:35:07 -0800 | [diff] [blame] | 411 | TcpFactory factory; |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 412 | |
Alexander Afanasyev | d665530 | 2014-02-28 08:41:28 -0800 | [diff] [blame] | 413 | shared_ptr<TcpChannel> channel1 = factory.createChannel("127.0.0.1", "20070"); |
| 414 | shared_ptr<TcpChannel> channel2 = factory.createChannel("127.0.0.1", "20071"); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 415 | |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 416 | channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), |
| 417 | bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 418 | |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 419 | channel2->connect("127.0.0.1", "20070", |
| 420 | bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), |
| 421 | bind(&EndToEndFixture::channel2_onConnectFailed, this, _1), |
Alexander Afanasyev | c1e2ee0 | 2014-02-25 17:02:07 -0800 | [diff] [blame] | 422 | time::seconds(4)); // very short timeout |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 423 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 424 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 425 | "TcpChannel error: cannot connect or cannot accept connection"); |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 426 | |
| 427 | BOOST_CHECK_EQUAL(channel1->size(), 1); |
| 428 | BOOST_CHECK_EQUAL(channel2->size(), 1); |
| 429 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 430 | BOOST_REQUIRE(static_cast<bool>(face1)); |
| 431 | BOOST_CHECK(static_cast<bool>(face2)); |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 432 | |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 433 | // Face::close must be invoked during io run to be counted as an op |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 434 | scheduler::schedule(time::milliseconds(100), bind(&Face::close, face1)); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 435 | |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 436 | BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, |
Junxiao Shi | 7e2413b | 2014-03-02 11:15:09 -0700 | [diff] [blame] | 437 | "FaceClosing error: cannot properly close faces"); |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 438 | |
| 439 | // both faces should get closed |
Junxiao Shi | 7949416 | 2014-04-02 18:25:11 -0700 | [diff] [blame] | 440 | BOOST_CHECK(!static_cast<bool>(face1)); |
| 441 | BOOST_CHECK(!static_cast<bool>(face2)); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 442 | |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 443 | BOOST_CHECK_EQUAL(channel1->size(), 0); |
| 444 | BOOST_CHECK_EQUAL(channel2->size(), 0); |
| 445 | } |
| 446 | |
| 447 | |
Alexander Afanasyev | 650028d | 2014-04-25 18:39:10 -0700 | [diff] [blame] | 448 | |
| 449 | |
| 450 | class SimpleEndToEndFixture : protected BaseFixture |
| 451 | { |
| 452 | public: |
| 453 | void |
| 454 | onFaceCreated(const shared_ptr<Face>& face) |
| 455 | { |
| 456 | face->onReceiveInterest += |
| 457 | bind(&SimpleEndToEndFixture::onReceiveInterest, this, _1); |
| 458 | face->onReceiveData += |
| 459 | bind(&SimpleEndToEndFixture::onReceiveData, this, _1); |
| 460 | face->onFail += |
| 461 | bind(&SimpleEndToEndFixture::onFail, this, face); |
| 462 | |
| 463 | if (static_cast<bool>(dynamic_pointer_cast<LocalFace>(face))) { |
| 464 | static_pointer_cast<LocalFace>(face)->setLocalControlHeaderFeature( |
| 465 | LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID); |
| 466 | |
| 467 | static_pointer_cast<LocalFace>(face)->setLocalControlHeaderFeature( |
| 468 | LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID); |
| 469 | } |
| 470 | |
| 471 | limitedIo.afterOp(); |
| 472 | } |
| 473 | |
| 474 | void |
| 475 | onConnectFailed(const std::string& reason) |
| 476 | { |
| 477 | BOOST_CHECK_MESSAGE(false, reason); |
| 478 | |
| 479 | limitedIo.afterOp(); |
| 480 | } |
| 481 | |
| 482 | void |
| 483 | onReceiveInterest(const Interest& interest) |
| 484 | { |
| 485 | receivedInterests.push_back(interest); |
| 486 | |
| 487 | limitedIo.afterOp(); |
| 488 | } |
| 489 | |
| 490 | void |
| 491 | onReceiveData(const Data& data) |
| 492 | { |
| 493 | receivedDatas.push_back(data); |
| 494 | |
| 495 | limitedIo.afterOp(); |
| 496 | } |
| 497 | |
| 498 | void |
| 499 | onFail(const shared_ptr<Face>& face) |
| 500 | { |
| 501 | limitedIo.afterOp(); |
| 502 | } |
| 503 | |
| 504 | public: |
| 505 | LimitedIo limitedIo; |
| 506 | |
| 507 | std::vector<Interest> receivedInterests; |
| 508 | std::vector<Data> receivedDatas; |
| 509 | }; |
| 510 | |
| 511 | |
| 512 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(LocalFaceCorruptedInput, Dataset, |
| 513 | CorruptedPackets, SimpleEndToEndFixture) |
| 514 | { |
| 515 | TcpFactory factory; |
| 516 | |
| 517 | shared_ptr<TcpChannel> channel = factory.createChannel("127.0.0.1", "20070"); |
| 518 | channel->listen(bind(&SimpleEndToEndFixture::onFaceCreated, this, _1), |
| 519 | bind(&SimpleEndToEndFixture::onConnectFailed, this, _1)); |
| 520 | BOOST_REQUIRE_EQUAL(channel->isListening(), true); |
| 521 | |
| 522 | DummyStreamSender<boost::asio::ip::tcp, Dataset> sender; |
| 523 | sender.start(Resolver<boost::asio::ip::tcp>::syncResolve("127.0.0.1", "20070")); |
| 524 | |
| 525 | BOOST_CHECK_MESSAGE(limitedIo.run(LimitedIo::UNLIMITED_OPS, |
| 526 | time::seconds(1)) == LimitedIo::EXCEED_TIME, |
| 527 | "Exception thrown for " + Dataset::getName()); |
| 528 | } |
| 529 | |
| 530 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(FaceCorruptedInput, Dataset, |
| 531 | CorruptedPackets, SimpleEndToEndFixture) |
| 532 | { |
| 533 | // tests with non-local Face |
| 534 | std::string someIpv4Address; |
| 535 | std::list< shared_ptr<NetworkInterfaceInfo> > ifs = listNetworkInterfaces(); |
| 536 | for (std::list< shared_ptr<NetworkInterfaceInfo> >::const_iterator i = ifs.begin(); |
| 537 | i != ifs.end(); |
| 538 | ++i) |
| 539 | { |
| 540 | if (!(*i)->isLoopback() && (*i)->isUp() && !(*i)->ipv4Addresses.empty()) |
| 541 | { |
| 542 | someIpv4Address = (*i)->ipv4Addresses[0].to_string(); |
| 543 | break; |
| 544 | } |
| 545 | } |
| 546 | if (someIpv4Address.empty()) |
| 547 | { |
| 548 | BOOST_TEST_MESSAGE("Test with non-local Face cannot be run " |
| 549 | "(no non-local interface with IPv4 address available)"); |
| 550 | return; |
| 551 | } |
| 552 | |
| 553 | TcpFactory factory; |
| 554 | |
| 555 | shared_ptr<TcpChannel> channel = factory.createChannel(someIpv4Address, "20070"); |
| 556 | channel->listen(bind(&SimpleEndToEndFixture::onFaceCreated, this, _1), |
| 557 | bind(&SimpleEndToEndFixture::onConnectFailed, this, _1)); |
| 558 | BOOST_REQUIRE_EQUAL(channel->isListening(), true); |
| 559 | |
| 560 | |
| 561 | DummyStreamSender<boost::asio::ip::tcp, Dataset> sender; |
| 562 | sender.start(Resolver<boost::asio::ip::tcp>::syncResolve(someIpv4Address, "20070")); |
| 563 | |
| 564 | BOOST_CHECK_MESSAGE(limitedIo.run(LimitedIo::UNLIMITED_OPS, |
| 565 | time::seconds(1)) == LimitedIo::EXCEED_TIME, |
| 566 | "Exception thrown for " + Dataset::getName()); |
| 567 | } |
| 568 | |
Alexander Afanasyev | 1886180 | 2014-06-13 17:49:03 -0700 | [diff] [blame^] | 569 | class FaceCreateTimeoutFixture : protected BaseFixture |
| 570 | { |
| 571 | public: |
| 572 | void |
| 573 | onFaceCreated(const shared_ptr<Face>& newFace) |
| 574 | { |
| 575 | BOOST_CHECK_MESSAGE(false, "Timeout expected"); |
| 576 | BOOST_CHECK(!static_cast<bool>(face1)); |
| 577 | face1 = newFace; |
| 578 | |
| 579 | limitedIo.afterOp(); |
| 580 | } |
| 581 | |
| 582 | void |
| 583 | onConnectFailed(const std::string& reason) |
| 584 | { |
| 585 | BOOST_CHECK_MESSAGE(true, reason); |
| 586 | |
| 587 | limitedIo.afterOp(); |
| 588 | } |
| 589 | |
| 590 | public: |
| 591 | LimitedIo limitedIo; |
| 592 | |
| 593 | shared_ptr<Face> face1; |
| 594 | }; |
| 595 | |
| 596 | |
| 597 | BOOST_FIXTURE_TEST_CASE(FaceCreateTimeout, FaceCreateTimeoutFixture) |
| 598 | { |
| 599 | TcpFactory factory; |
| 600 | shared_ptr<TcpChannel> channel = factory.createChannel("0.0.0.0", "20070"); |
| 601 | |
| 602 | factory.createFace(FaceUri("tcp://192.0.2.1:20070"), |
| 603 | bind(&FaceCreateTimeoutFixture::onFaceCreated, this, _1), |
| 604 | bind(&FaceCreateTimeoutFixture::onConnectFailed, this, _1)); |
| 605 | |
| 606 | BOOST_CHECK_MESSAGE(limitedIo.run(1, time::seconds(10)) == LimitedIo::EXCEED_OPS, |
| 607 | "TcpChannel error: cannot connect or cannot accept connection"); |
| 608 | |
| 609 | BOOST_CHECK_EQUAL(static_cast<bool>(face1), false); |
| 610 | } |
| 611 | |
| 612 | |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 613 | BOOST_AUTO_TEST_SUITE_END() |
| 614 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 615 | } // namespace tests |
Junxiao Shi | 96dc0c4 | 2014-01-30 23:51:59 -0700 | [diff] [blame] | 616 | } // namespace nfd |