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 | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2021, 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(BadPort) |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 271 | { |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 272 | // not a number |
| 273 | const std::string CONFIG1 = R"CONFIG( |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 274 | face_system |
| 275 | { |
| 276 | tcp |
| 277 | { |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 278 | port hello |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | )CONFIG"; |
| 282 | |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 283 | BOOST_CHECK_THROW(parseConfig(CONFIG1, true), ConfigFile::Error); |
| 284 | BOOST_CHECK_THROW(parseConfig(CONFIG1, false), ConfigFile::Error); |
| 285 | |
| 286 | // negative number |
| 287 | const std::string CONFIG2 = R"CONFIG( |
| 288 | face_system |
| 289 | { |
| 290 | tcp |
| 291 | { |
| 292 | port -1 |
| 293 | } |
| 294 | } |
| 295 | )CONFIG"; |
| 296 | |
| 297 | BOOST_CHECK_THROW(parseConfig(CONFIG2, true), ConfigFile::Error); |
| 298 | BOOST_CHECK_THROW(parseConfig(CONFIG2, false), ConfigFile::Error); |
| 299 | |
| 300 | // out of range |
| 301 | const std::string CONFIG3 = R"CONFIG( |
| 302 | face_system |
| 303 | { |
| 304 | tcp |
| 305 | { |
| 306 | port 65536 |
| 307 | } |
| 308 | } |
| 309 | )CONFIG"; |
| 310 | |
| 311 | BOOST_CHECK_THROW(parseConfig(CONFIG3, true), ConfigFile::Error); |
| 312 | BOOST_CHECK_THROW(parseConfig(CONFIG3, false), ConfigFile::Error); |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | BOOST_AUTO_TEST_CASE(UnknownOption) |
| 316 | { |
| 317 | const std::string CONFIG = R"CONFIG( |
| 318 | face_system |
| 319 | { |
| 320 | tcp |
| 321 | { |
| 322 | hello |
| 323 | } |
| 324 | } |
| 325 | )CONFIG"; |
| 326 | |
| 327 | BOOST_CHECK_THROW(parseConfig(CONFIG, true), ConfigFile::Error); |
| 328 | BOOST_CHECK_THROW(parseConfig(CONFIG, false), ConfigFile::Error); |
| 329 | } |
| 330 | |
| 331 | BOOST_AUTO_TEST_SUITE_END() // ProcessConfig |
| 332 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 333 | BOOST_AUTO_TEST_CASE(GetChannels) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 334 | { |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 335 | BOOST_CHECK_EQUAL(factory.getChannels().empty(), true); |
| 336 | |
| 337 | std::set<std::string> expected; |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 338 | expected.insert(createChannel("127.0.0.1", "20070")->getUri().toString()); |
| 339 | expected.insert(createChannel("127.0.0.1", "20071")->getUri().toString()); |
| 340 | expected.insert(createChannel("::1", "20071")->getUri().toString()); |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 341 | checkChannelListEqual(factory, expected); |
| 342 | } |
| 343 | |
| 344 | BOOST_AUTO_TEST_CASE(CreateChannel) |
| 345 | { |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 346 | auto channel1 = createChannel("127.0.0.1", "20070"); |
| 347 | auto channel1a = createChannel("127.0.0.1", "20070"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 348 | BOOST_CHECK_EQUAL(channel1, channel1a); |
| 349 | BOOST_CHECK_EQUAL(channel1->getUri().toString(), "tcp4://127.0.0.1:20070"); |
| 350 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 351 | auto channel2 = createChannel("127.0.0.1", "20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 352 | BOOST_CHECK_NE(channel1, channel2); |
| 353 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 354 | auto channel3 = createChannel("::1", "20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 355 | BOOST_CHECK_NE(channel2, channel3); |
| 356 | BOOST_CHECK_EQUAL(channel3->getUri().toString(), "tcp6://[::1]:20071"); |
| 357 | } |
| 358 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 359 | BOOST_AUTO_TEST_CASE(CreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 360 | { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 361 | createFace(factory, |
| 362 | FaceUri("tcp4://127.0.0.1:6363"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 363 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 364 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 365 | {CreateFaceExpectedResult::FAILURE, 504, "No channels available to connect"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 366 | |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 367 | createChannel("127.0.0.1", "20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 368 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 369 | createFace(factory, |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 370 | FaceUri("tcp4://127.0.0.1:6363"), |
| 371 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 372 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 373 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 374 | |
| 375 | createFace(factory, |
| 376 | FaceUri("tcp4://127.0.0.1:6363"), |
| 377 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 378 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, false}, |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 379 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 380 | |
| 381 | createFace(factory, |
| 382 | FaceUri("tcp4://127.0.0.1:20072"), |
| 383 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 384 | {ndn::nfd::FACE_PERSISTENCY_PERMANENT, {}, {}, {}, false, false, false}, |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 385 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 386 | |
| 387 | createFace(factory, |
| 388 | FaceUri("tcp4://127.0.0.1:20073"), |
| 389 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 390 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, true, false}, |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 391 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
| 392 | |
| 393 | createFace(factory, |
| 394 | FaceUri("tcp4://127.0.0.1:20073"), |
| 395 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 396 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, true}, |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 397 | {CreateFaceExpectedResult::SUCCESS, 0, ""}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 400 | BOOST_AUTO_TEST_CASE(UnsupportedCreateFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 401 | { |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 402 | createChannel("127.0.0.1", "20071"); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 403 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 404 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 405 | FaceUri("tcp4://127.0.0.1:20072"), |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 406 | FaceUri("tcp4://127.0.0.1:20071"), |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 407 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, false, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 408 | {CreateFaceExpectedResult::FAILURE, 406, |
| 409 | "Unicast TCP faces cannot be created with a LocalUri"}); |
| 410 | |
| 411 | createFace(factory, |
| 412 | FaceUri("tcp4://127.0.0.1:20072"), |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 413 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 414 | {ndn::nfd::FACE_PERSISTENCY_ON_DEMAND, {}, {}, {}, false, false, false}, |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 415 | {CreateFaceExpectedResult::FAILURE, 406, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 416 | "Outgoing TCP faces do not support on-demand persistency"}); |
Eric Newberry | 78e32b0 | 2017-04-01 14:34:44 +0000 | [diff] [blame] | 417 | |
| 418 | createFace(factory, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 419 | FaceUri("tcp4://198.51.100.100:6363"), |
| 420 | {}, |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 421 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, {}, true, false, false}, |
Davide Pesavento | 46afec4 | 2017-05-28 14:28:47 -0400 | [diff] [blame] | 422 | {CreateFaceExpectedResult::FAILURE, 406, |
| 423 | "Local fields can only be enabled on faces with local scope"}); |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 424 | |
| 425 | createFace(factory, |
| 426 | FaceUri("tcp4://127.0.0.1:20072"), |
| 427 | {}, |
| 428 | {ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, 1000, false, false, false}, |
| 429 | {CreateFaceExpectedResult::FAILURE, 406, |
| 430 | "TCP faces do not support MTU overrides"}); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 433 | class CreateFaceTimeoutFixture : public TcpFactoryFixture |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 434 | { |
| 435 | public: |
| 436 | void |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 437 | onFaceCreated(const shared_ptr<nfd::Face>& newFace) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 438 | { |
| 439 | BOOST_CHECK_MESSAGE(false, "Timeout expected"); |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 440 | face = newFace; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 441 | |
| 442 | limitedIo.afterOp(); |
| 443 | } |
| 444 | |
| 445 | void |
| 446 | onConnectFailed(const std::string& reason) |
| 447 | { |
| 448 | BOOST_CHECK_MESSAGE(true, reason); |
| 449 | |
| 450 | limitedIo.afterOp(); |
| 451 | } |
| 452 | |
| 453 | public: |
Davide Pesavento | 494a955 | 2018-02-04 22:16:05 -0500 | [diff] [blame] | 454 | shared_ptr<nfd::Face> face; |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 455 | }; |
| 456 | |
Davide Pesavento | b15276f | 2017-07-15 16:27:13 -0400 | [diff] [blame] | 457 | BOOST_FIXTURE_TEST_CASE(CreateFaceTimeout, CreateFaceTimeoutFixture) |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 458 | { |
Davide Pesavento | 4b89a6e | 2017-10-07 15:29:50 -0400 | [diff] [blame] | 459 | createChannel("0.0.0.0", "20070"); |
Davide Pesavento | 15b5505 | 2018-01-27 19:09:28 -0500 | [diff] [blame] | 460 | factory.createFace({FaceUri("tcp4://192.0.2.1:20070"), {}, {}}, |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame^] | 461 | std::bind(&CreateFaceTimeoutFixture::onFaceCreated, this, _1), |
| 462 | std::bind(&CreateFaceTimeoutFixture::onConnectFailed, this, _2)); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 463 | |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame^] | 464 | BOOST_CHECK_EQUAL(limitedIo.run(1, 10_s), LimitedIo::EXCEED_OPS); |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 465 | BOOST_CHECK(face == nullptr); |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 468 | BOOST_AUTO_TEST_SUITE_END() // TestTcpFactory |
| 469 | BOOST_AUTO_TEST_SUITE_END() // Face |
| 470 | |
| 471 | } // namespace tests |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 472 | } // namespace face |
Junxiao Shi | cde37ad | 2015-12-24 01:02:05 -0700 | [diff] [blame] | 473 | } // namespace nfd |