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