Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 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. |
| 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/>. |
| 24 | */ |
| 25 | |
| 26 | #include "face/tcp-factory.hpp" |
| 27 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 28 | #include "face-system-fixture.hpp" |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 29 | #include "factory-test-common.hpp" |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 30 | #include "tests/daemon/limited-io.hpp" |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 33 | namespace face { |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 34 | namespace tests { |
| 35 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 36 | class TcpFactoryFixture : public FaceSystemFactoryFixture<TcpFactory> |
| 37 | { |
| 38 | protected: |
| 39 | shared_ptr<TcpChannel> |
| 40 | createChannel(const std::string& localIp, const std::string& localPort) |
| 41 | { |
Davide Pesavento | 9c33b90 | 2018-05-20 01:30:29 -0400 | [diff] [blame] | 42 | tcp::Endpoint endpoint(boost::asio::ip::address::from_string(localIp), |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 43 | boost::lexical_cast<uint16_t>(localPort)); |
| 44 | return factory.createChannel(endpoint); |
| 45 | } |
Alexander Afanasyev | ded1742 | 2018-04-03 19:00:23 -0400 | [diff] [blame] | 46 | |
| 47 | protected: |
| 48 | LimitedIo limitedIo; |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 49 | }; |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 50 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 51 | BOOST_AUTO_TEST_SUITE(Face) |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 52 | BOOST_FIXTURE_TEST_SUITE(TestTcpFactory, TcpFactoryFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 53 | |
Junxiao Shi | 0ba6d64 | 2017-07-17 00:53:22 +0000 | [diff] [blame] | 54 | BOOST_AUTO_TEST_SUITE(ProcessConfig) |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 55 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 56 | BOOST_AUTO_TEST_CASE(Defaults) |
| 57 | { |
| 58 | const std::string CONFIG = R"CONFIG( |
| 59 | face_system |
| 60 | { |
| 61 | tcp |
| 62 | } |
| 63 | )CONFIG"; |
| 64 | |
| 65 | parseConfig(CONFIG, true); |
| 66 | parseConfig(CONFIG, false); |
| 67 | |
| 68 | checkChannelListEqual(factory, {"tcp4://0.0.0.0:6363", "tcp6://[::]:6363"}); |
| 69 | auto channels = factory.getChannels(); |
| 70 | BOOST_CHECK(std::all_of(channels.begin(), channels.end(), |
Davide Pesavento | d27841b | 2018-11-13 00:22:24 -0500 | [diff] [blame] | 71 | [] (const auto& ch) { return ch->isListening(); })); |
Alexander Afanasyev | ded1742 | 2018-04-03 19:00:23 -0400 | [diff] [blame] | 72 | |
| 73 | BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.size(), 2); |
| 74 | BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.count("127.0.0.0/8"), 1); |
| 75 | BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.count("::1/128"), 1); |
| 76 | BOOST_CHECK_EQUAL(factory.m_local.m_blacklist.size(), 0); |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | BOOST_AUTO_TEST_CASE(DisableListen) |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 80 | { |
| 81 | const std::string CONFIG = R"CONFIG( |
| 82 | face_system |
| 83 | { |
| 84 | tcp |
| 85 | { |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 86 | listen no |
| 87 | port 7001 |
| 88 | } |
| 89 | } |
| 90 | )CONFIG"; |
| 91 | |
| 92 | parseConfig(CONFIG, true); |
| 93 | parseConfig(CONFIG, false); |
| 94 | |
| 95 | checkChannelListEqual(factory, {"tcp4://0.0.0.0:7001", "tcp6://[::]:7001"}); |
| 96 | auto channels = factory.getChannels(); |
| 97 | BOOST_CHECK(std::none_of(channels.begin(), channels.end(), |
Davide Pesavento | d27841b | 2018-11-13 00:22:24 -0500 | [diff] [blame] | 98 | [] (const auto& ch) { return ch->isListening(); })); |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | BOOST_AUTO_TEST_CASE(DisableV4) |
| 102 | { |
| 103 | const std::string CONFIG = R"CONFIG( |
| 104 | face_system |
| 105 | { |
| 106 | tcp |
| 107 | { |
| 108 | port 7001 |
| 109 | enable_v4 no |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 110 | enable_v6 yes |
| 111 | } |
| 112 | } |
| 113 | )CONFIG"; |
| 114 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 115 | parseConfig(CONFIG, true); |
| 116 | parseConfig(CONFIG, false); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 117 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 118 | checkChannelListEqual(factory, {"tcp6://[::]:7001"}); |
| 119 | } |
| 120 | |
| 121 | BOOST_AUTO_TEST_CASE(DisableV6) |
| 122 | { |
| 123 | const std::string CONFIG = R"CONFIG( |
| 124 | face_system |
| 125 | { |
| 126 | tcp |
| 127 | { |
| 128 | port 7001 |
| 129 | enable_v4 yes |
| 130 | enable_v6 no |
| 131 | } |
| 132 | } |
| 133 | )CONFIG"; |
| 134 | |
| 135 | parseConfig(CONFIG, true); |
| 136 | parseConfig(CONFIG, false); |
| 137 | |
| 138 | checkChannelListEqual(factory, {"tcp4://0.0.0.0:7001"}); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Alexander Afanasyev | ded1742 | 2018-04-03 19:00:23 -0400 | [diff] [blame] | 141 | BOOST_AUTO_TEST_CASE(ConfigureLocal) |
| 142 | { |
| 143 | const std::string CONFIG = R"CONFIG( |
| 144 | face_system |
| 145 | { |
| 146 | tcp |
| 147 | { |
| 148 | local { |
| 149 | whitelist { |
| 150 | subnet 127.0.0.0/8 |
| 151 | } |
| 152 | |
| 153 | blacklist { |
| 154 | subnet ::1/128 |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | )CONFIG"; |
| 160 | |
| 161 | parseConfig(CONFIG, true); |
| 162 | parseConfig(CONFIG, false); |
| 163 | |
| 164 | BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.size(), 1); |
| 165 | BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.count("127.0.0.0/8"), 1); |
| 166 | BOOST_CHECK_EQUAL(factory.m_local.m_blacklist.size(), 1); |
| 167 | BOOST_CHECK_EQUAL(factory.m_local.m_blacklist.count("::1/128"), 1); |
| 168 | |
| 169 | createFace(factory, |
| 170 | FaceUri("tcp4://127.0.0.1:6363"), |
| 171 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 172 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Alexander Afanasyev | ded1742 | 2018-04-03 19:00:23 -0400 | [diff] [blame] | 173 | {CreateFaceExpectedResult::SUCCESS, 0, ""}, |
| 174 | [] (const nfd::Face& face) { |
| 175 | BOOST_CHECK_EQUAL(face.getScope(), ndn::nfd::FACE_SCOPE_LOCAL); |
| 176 | }); |
| 177 | |
| 178 | limitedIo.run(1, 100_ms); |
| 179 | } |
| 180 | |
| 181 | BOOST_AUTO_TEST_CASE(ConfigureNonLocal) |
| 182 | { |
| 183 | const std::string CONFIG = R"CONFIG( |
| 184 | face_system |
| 185 | { |
| 186 | tcp |
| 187 | { |
| 188 | local { |
| 189 | whitelist { |
| 190 | * |
| 191 | } |
| 192 | |
| 193 | blacklist { |
| 194 | subnet 127.0.0.0/8 |
| 195 | subnet ::1/128 |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | )CONFIG"; |
| 201 | |
| 202 | parseConfig(CONFIG, true); |
| 203 | parseConfig(CONFIG, false); |
| 204 | |
| 205 | BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.size(), 1); |
| 206 | BOOST_CHECK_EQUAL(factory.m_local.m_whitelist.count("*"), 1); |
| 207 | BOOST_CHECK_EQUAL(factory.m_local.m_blacklist.size(), 2); |
| 208 | BOOST_CHECK_EQUAL(factory.m_local.m_blacklist.count("127.0.0.0/8"), 1); |
| 209 | BOOST_CHECK_EQUAL(factory.m_local.m_blacklist.count("::1/128"), 1); |
| 210 | |
| 211 | createFace(factory, |
| 212 | FaceUri("tcp4://127.0.0.1:6363"), |
| 213 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 214 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Alexander Afanasyev | ded1742 | 2018-04-03 19:00:23 -0400 | [diff] [blame] | 215 | {CreateFaceExpectedResult::SUCCESS, 0, ""}, |
| 216 | [] (const nfd::Face& face) { |
| 217 | BOOST_CHECK_EQUAL(face.getScope(), ndn::nfd::FACE_SCOPE_NON_LOCAL); |
| 218 | }); |
| 219 | |
| 220 | limitedIo.run(1, 100_ms); |
| 221 | } |
| 222 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 223 | BOOST_AUTO_TEST_CASE(Omitted) |
| 224 | { |
| 225 | const std::string CONFIG = R"CONFIG( |
| 226 | face_system |
| 227 | { |
| 228 | } |
| 229 | )CONFIG"; |
| 230 | |
Junxiao Shi | 1b65ca1 | 2017-01-21 23:04:41 +0000 | [diff] [blame] | 231 | parseConfig(CONFIG, true); |
| 232 | parseConfig(CONFIG, false); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 233 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 234 | BOOST_CHECK_EQUAL(factory.getChannels().size(), 0); |
| 235 | } |
| 236 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 237 | BOOST_AUTO_TEST_CASE(AllDisabled) |
| 238 | { |
| 239 | const std::string CONFIG = R"CONFIG( |
| 240 | face_system |
| 241 | { |
| 242 | tcp |
| 243 | { |
| 244 | enable_v4 no |
| 245 | enable_v6 no |
| 246 | } |
| 247 | } |
| 248 | )CONFIG"; |
| 249 | |
| 250 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 251 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 252 | } |
| 253 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 254 | BOOST_AUTO_TEST_CASE(BadListen) |
| 255 | { |
| 256 | const std::string CONFIG = R"CONFIG( |
| 257 | face_system |
| 258 | { |
| 259 | tcp |
| 260 | { |
| 261 | listen hello |
| 262 | } |
| 263 | } |
| 264 | )CONFIG"; |
| 265 | |
| 266 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 267 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 268 | } |
| 269 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 270 | BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(BadPort, 2) // Bug #4489 |
| 271 | BOOST_AUTO_TEST_CASE(BadPort) |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 272 | { |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 273 | // not a number |
| 274 | const std::string CONFIG1 = R"CONFIG( |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 275 | face_system |
| 276 | { |
| 277 | tcp |
| 278 | { |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 279 | port hello |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | )CONFIG"; |
| 283 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 284 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 285 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 286 | |
| 287 | // negative number |
| 288 | const std::string CONFIG2 = R"CONFIG( |
| 289 | face_system |
| 290 | { |
| 291 | tcp |
| 292 | { |
| 293 | port -1 |
| 294 | } |
| 295 | } |
| 296 | )CONFIG"; |
| 297 | |
| 298 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 299 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
| 300 | |
| 301 | // out of range |
| 302 | const std::string CONFIG3 = R"CONFIG( |
| 303 | face_system |
| 304 | { |
| 305 | tcp |
| 306 | { |
| 307 | port 65536 |
| 308 | } |
| 309 | } |
| 310 | )CONFIG"; |
| 311 | |
| 312 | BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error); |
| 313 | BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | BOOST_AUTO_TEST_CASE(UnknownOption) |
| 317 | { |
| 318 | const std::string CONFIG = R"CONFIG( |
| 319 | face_system |
| 320 | { |
| 321 | tcp |
| 322 | { |
| 323 | hello |
| 324 | } |
| 325 | } |
| 326 | )CONFIG"; |
| 327 | |
| 328 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 329 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 330 | } |
| 331 | |
| 332 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 333 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 334 | BOOST_AUTO_TEST_CASE(GetChannels) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 335 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 336 | BOOST_CHECK_EQUAL(factory.getChannels().empty(), true); |
| 337 | |
| 338 | std::set<std::string> expected; |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 339 | expected.insert(createChannel("127.0.0.1", "20070")->getUri().toString()); |
| 340 | expected.insert(createChannel("127.0.0.1", "20071")->getUri().toString()); |
| 341 | expected.insert(createChannel("::1", "20071")->getUri().toString()); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 342 | checkChannelListEqual(factory, expected); |
| 343 | } |
| 344 | |
| 345 | BOOST_AUTO_TEST_CASE(CreateChannel) |
| 346 | { |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 347 | auto channel1 = createChannel("127.0.0.1", "20070"); |
| 348 | auto channel1a = createChannel("127.0.0.1", "20070"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 349 | BOOST_CHECK_EQUAL(channel1, channel1a); |
| 350 | BOOST_CHECK_EQUAL(channel1->getUri().toString(), "tcp4://127.0.0.1:20070"); |
| 351 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 352 | auto channel2 = createChannel("127.0.0.1", "20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 353 | BOOST_CHECK_NE(channel1, channel2); |
| 354 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 355 | auto channel3 = createChannel("::1", "20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 356 | BOOST_CHECK_NE(channel2, channel3); |
| 357 | BOOST_CHECK_EQUAL(channel3->getUri().toString(), "tcp6://[::1]:20071"); |
| 358 | } |
| 359 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 360 | BOOST_AUTO_TEST_CASE(CreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 361 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 362 | createFace(factory, |
| 363 | FaceUri("tcp4://127.0.0.1:6363"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 364 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 365 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 366 | {CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 367 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 368 | createChannel("127.0.0.1", "20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 369 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 370 | createFace(factory, |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 371 | FaceUri("tcp4://127.0.0.1:6363"), |
| 372 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 373 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 374 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 375 | |
| 376 | createFace(factory, |
| 377 | FaceUri("tcp4://127.0.0.1:6363"), |
| 378 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 379 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, false}, |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 380 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 381 | |
| 382 | createFace(factory, |
| 383 | FaceUri("tcp4://127.0.0.1:20072"), |
| 384 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 385 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 386 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 387 | |
| 388 | createFace(factory, |
| 389 | FaceUri("tcp4://127.0.0.1:20073"), |
| 390 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 391 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, true, false}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 392 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 393 | |
| 394 | createFace(factory, |
| 395 | FaceUri("tcp4://127.0.0.1:20073"), |
| 396 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 397 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, true}, |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 398 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 401 | BOOST_AUTO_TEST_CASE(UnsupportedCreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 402 | { |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 403 | createChannel("127.0.0.1", "20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 404 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 405 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 406 | FaceUri("tcp4://127.0.0.1:20072"), |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 407 | FaceUri("tcp4://127.0.0.1:20071"), |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 408 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 409 | {CreateFaceExpectedResult::FAILURE, 406, |
| 410 | "Unicast TCP faces cannot be created with a LocalUri"}); |
| 411 | |
| 412 | createFace(factory, |
| 413 | FaceUri("tcp4://127.0.0.1:20072"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 414 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 415 | {ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 416 | {CreateFaceExpectedResult::FAILURE, 406, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 417 | "Outgoing TCP faces do not support on-demand persistency"}); |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 418 | |
| 419 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 420 | FaceUri("tcp4://198.51.100.100:6363"), |
| 421 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 422 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, true, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 423 | {CreateFaceExpectedResult::FAILURE, 406, |
| 424 | "Local fields can only be enabled on faces with local scope"}); |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 425 | |
| 426 | createFace(factory, |
| 427 | FaceUri("tcp4://127.0.0.1:20072"), |
| 428 | {}, |
| 429 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, 1000, false, false, false}, |
| 430 | {CreateFaceExpectedResult::FAILURE, 406, |
| 431 | "TCP faces do not support MTU overrides"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 434 | class CreateFaceTimeoutFixture : public TcpFactoryFixture |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 435 | { |
| 436 | public: |
| 437 | void |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 438 | onFaceCreated(const shared_ptr<nfd::Face>& newFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 439 | { |
| 440 | BOOST_CHECK_MESSAGE(false, "Timeout expected"); |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 441 | face = newFace; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 442 | |
| 443 | limitedIo.afterOp(); |
| 444 | } |
| 445 | |
| 446 | void |
| 447 | onConnectFailed(const std::string& reason) |
| 448 | { |
| 449 | BOOST_CHECK_MESSAGE(true, reason); |
| 450 | |
| 451 | limitedIo.afterOp(); |
| 452 | } |
| 453 | |
| 454 | public: |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 455 | shared_ptr<nfd::Face> face; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 456 | }; |
| 457 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 458 | BOOST_FIXTURE_TEST_CASE(CreateFaceTimeout, CreateFaceTimeoutFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 459 | { |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 460 | createChannel("0.0.0.0", "20070"); |
Davide Pesavento | 15b5505 | 2018-01-27 19:09:28 -0500 | [diff] [blame] | 461 | factory.createFace({FaceUri("tcp4://192.0.2.1:20070"), {}, {}}, |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 462 | bind(&CreateFaceTimeoutFixture::onFaceCreated, this, _1), |
| 463 | bind(&CreateFaceTimeoutFixture::onConnectFailed, this, _2)); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 464 | |
Davide Pesavento | 15b5505 | 2018-01-27 19:09:28 -0500 | [diff] [blame] | 465 | BOOST_REQUIRE_EQUAL(limitedIo.run(1, 10_s), LimitedIo::EXCEED_OPS); |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 466 | BOOST_CHECK(face == nullptr); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 469 | BOOST_AUTO_TEST_SUITE_END() // TestTcpFactory |
| 470 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 471 | |
| 472 | } // namespace tests |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 473 | } // namespace face |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 474 | } // namespace nfd |