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