Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 6028619 | 2017-07-26 01:07:48 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2025, Regents of the University of California, |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -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 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 26 | #include "mgmt/face-manager.hpp" |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 27 | #include "face/generic-link-service.hpp" |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 28 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 29 | #include "face-manager-command-fixture.hpp" |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 30 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 31 | #include <boost/mp11/list.hpp> |
| 32 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 33 | namespace nfd::tests { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 34 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 35 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 36 | BOOST_AUTO_TEST_SUITE(TestFaceManager) |
| 37 | |
Davide Pesavento | cf7db2f | 2019-03-24 23:17:28 -0400 | [diff] [blame] | 38 | BOOST_FIXTURE_TEST_SUITE(CreateFace, GlobalIoFixture) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 39 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 40 | class TcpFaceOnDemand |
| 41 | { |
| 42 | public: |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 43 | static ControlParameters |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 44 | getParameters() |
| 45 | { |
| 46 | return ControlParameters() |
| 47 | .setUri("tcp4://127.0.0.1:26363") |
| 48 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | class TcpFacePersistent |
| 53 | { |
| 54 | public: |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 55 | static ControlParameters |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 56 | getParameters() |
| 57 | { |
| 58 | return ControlParameters() |
| 59 | .setUri("tcp4://127.0.0.1:26363") |
| 60 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | class TcpFacePermanent |
| 65 | { |
| 66 | public: |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 67 | static ControlParameters |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 68 | getParameters() |
| 69 | { |
| 70 | return ControlParameters() |
| 71 | .setUri("tcp4://127.0.0.1:26363") |
| 72 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT); |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | class UdpFaceOnDemand |
| 77 | { |
| 78 | public: |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 79 | static ControlParameters |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 80 | getParameters() |
| 81 | { |
| 82 | return ControlParameters() |
| 83 | .setUri("udp4://127.0.0.1:26363") |
| 84 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND); |
| 85 | } |
| 86 | }; |
| 87 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 88 | class UdpFacePersistent |
| 89 | { |
| 90 | public: |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 91 | static ControlParameters |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 92 | getParameters() |
| 93 | { |
| 94 | return ControlParameters() |
| 95 | .setUri("udp4://127.0.0.1:26363") |
| 96 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | class UdpFacePermanent |
| 101 | { |
| 102 | public: |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 103 | static ControlParameters |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 104 | getParameters() |
| 105 | { |
| 106 | return ControlParameters() |
| 107 | .setUri("udp4://127.0.0.1:26363") |
| 108 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT); |
| 109 | } |
| 110 | }; |
| 111 | |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 112 | class LocalTcpFaceLocalFieldsEnabled |
| 113 | { |
| 114 | public: |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 115 | static ControlParameters |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 116 | getParameters() |
| 117 | { |
| 118 | return ControlParameters() |
| 119 | .setUri("tcp4://127.0.0.1:26363") |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 120 | .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true); |
| 121 | } |
| 122 | }; |
| 123 | |
| 124 | class LocalTcpFaceLocalFieldsDisabled |
| 125 | { |
| 126 | public: |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 127 | static ControlParameters |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 128 | getParameters() |
| 129 | { |
| 130 | return ControlParameters() |
| 131 | .setUri("tcp4://127.0.0.1:26363") |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 132 | .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false); |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | class NonLocalUdpFaceLocalFieldsEnabled // won't work because non-local scope |
| 137 | { |
| 138 | public: |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 139 | static ControlParameters |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 140 | getParameters() |
| 141 | { |
| 142 | return ControlParameters() |
| 143 | .setUri("udp4://127.0.0.1:26363") |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 144 | .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true); |
| 145 | } |
| 146 | }; |
| 147 | |
| 148 | class NonLocalUdpFaceLocalFieldsDisabled |
| 149 | { |
| 150 | public: |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 151 | static ControlParameters |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 152 | getParameters() |
| 153 | { |
| 154 | return ControlParameters() |
| 155 | .setUri("udp4://127.0.0.1:26363") |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 156 | .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false); |
| 157 | } |
| 158 | }; |
| 159 | |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 160 | class TcpFaceLpReliabilityEnabled |
| 161 | { |
| 162 | public: |
| 163 | static ControlParameters |
| 164 | getParameters() |
| 165 | { |
| 166 | return ControlParameters() |
| 167 | .setUri("tcp4://127.0.0.1:26363") |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 168 | .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true); |
| 169 | } |
| 170 | }; |
| 171 | |
| 172 | class TcpFaceLpReliabilityDisabled |
| 173 | { |
| 174 | public: |
| 175 | static ControlParameters |
| 176 | getParameters() |
| 177 | { |
| 178 | return ControlParameters() |
| 179 | .setUri("tcp4://127.0.0.1:26363") |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 180 | .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false); |
| 181 | } |
| 182 | }; |
| 183 | |
| 184 | class UdpFaceLpReliabilityEnabled |
| 185 | { |
| 186 | public: |
| 187 | static ControlParameters |
| 188 | getParameters() |
| 189 | { |
| 190 | return ControlParameters() |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 191 | .setUri("udp4://127.0.0.1:26363") |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 192 | .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true); |
| 193 | } |
| 194 | }; |
| 195 | |
| 196 | class UdpFaceLpReliabilityDisabled |
| 197 | { |
| 198 | public: |
| 199 | static ControlParameters |
| 200 | getParameters() |
| 201 | { |
| 202 | return ControlParameters() |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 203 | .setUri("udp4://127.0.0.1:26363") |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 204 | .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false); |
| 205 | } |
| 206 | }; |
| 207 | |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 208 | class TcpFaceCongestionMarkingEnabled |
| 209 | { |
| 210 | public: |
| 211 | static ControlParameters |
| 212 | getParameters() |
| 213 | { |
| 214 | return ControlParameters() |
| 215 | .setUri("tcp4://127.0.0.1:26363") |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 216 | .setBaseCongestionMarkingInterval(50_ms) |
| 217 | .setDefaultCongestionThreshold(1000) |
| 218 | .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true); |
| 219 | } |
| 220 | }; |
| 221 | |
| 222 | class TcpFaceCongestionMarkingDisabled |
| 223 | { |
| 224 | public: |
| 225 | static ControlParameters |
| 226 | getParameters() |
| 227 | { |
| 228 | return ControlParameters() |
| 229 | .setUri("tcp4://127.0.0.1:26363") |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 230 | .setBaseCongestionMarkingInterval(50_ms) |
| 231 | .setDefaultCongestionThreshold(1000) |
| 232 | .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false); |
| 233 | } |
| 234 | }; |
| 235 | |
| 236 | class UdpFaceCongestionMarkingEnabled |
| 237 | { |
| 238 | public: |
| 239 | static ControlParameters |
| 240 | getParameters() |
| 241 | { |
| 242 | return ControlParameters() |
| 243 | .setUri("udp4://127.0.0.1:26363") |
| 244 | .setBaseCongestionMarkingInterval(50_ms) |
| 245 | .setDefaultCongestionThreshold(1000) |
| 246 | .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true); |
| 247 | } |
| 248 | }; |
| 249 | |
| 250 | class UdpFaceCongestionMarkingDisabled |
| 251 | { |
| 252 | public: |
| 253 | static ControlParameters |
| 254 | getParameters() |
| 255 | { |
| 256 | return ControlParameters() |
| 257 | .setUri("udp4://127.0.0.1:26363") |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 258 | .setBaseCongestionMarkingInterval(50_ms) |
| 259 | .setDefaultCongestionThreshold(1000) |
| 260 | .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false); |
| 261 | } |
| 262 | }; |
| 263 | |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 264 | class TcpFaceMtuOverride |
| 265 | { |
| 266 | public: |
| 267 | static ControlParameters |
| 268 | getParameters() |
| 269 | { |
| 270 | return ControlParameters() |
| 271 | .setUri("tcp4://127.0.0.1:26363") |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 272 | .setMtu(1000); |
| 273 | } |
| 274 | }; |
| 275 | |
| 276 | class UdpFaceMtuOverride |
| 277 | { |
| 278 | public: |
| 279 | static ControlParameters |
| 280 | getParameters() |
| 281 | { |
| 282 | return ControlParameters() |
| 283 | .setUri("udp4://127.0.0.1:26363") |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 284 | .setMtu(1000); |
| 285 | } |
| 286 | }; |
| 287 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 288 | class RemoteUriMalformed |
Junxiao Shi | 38c7d9e | 2017-04-13 14:22:50 +0000 | [diff] [blame] | 289 | { |
| 290 | public: |
| 291 | static ControlParameters |
| 292 | getParameters() |
| 293 | { |
| 294 | return ControlParameters() |
| 295 | .setUri("tcp4://127.0.0.1:not-a-port"); |
| 296 | } |
| 297 | }; |
| 298 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 299 | class RemoteUriNonCanonical |
Junxiao Shi | 38c7d9e | 2017-04-13 14:22:50 +0000 | [diff] [blame] | 300 | { |
| 301 | public: |
| 302 | static ControlParameters |
| 303 | getParameters() |
| 304 | { |
| 305 | return ControlParameters() |
| 306 | .setUri("udp://localhost"); |
| 307 | } |
| 308 | }; |
| 309 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 310 | class LocalUriMalformed |
| 311 | { |
| 312 | public: |
| 313 | static ControlParameters |
| 314 | getParameters() |
| 315 | { |
| 316 | return ControlParameters() |
| 317 | .setUri("udp4://127.0.0.1:26363") |
| 318 | .setLocalUri("udp4://127.0.0.1:not-a-port"); |
| 319 | } |
| 320 | }; |
| 321 | |
| 322 | class LocalUriNonCanonical |
| 323 | { |
| 324 | public: |
| 325 | static ControlParameters |
| 326 | getParameters() |
| 327 | { |
| 328 | return ControlParameters() |
| 329 | .setUri("udp4://127.0.0.1:26363") |
| 330 | .setLocalUri("udp://localhost"); |
| 331 | } |
| 332 | }; |
| 333 | |
| 334 | class LocalUriUnsupported |
| 335 | { |
| 336 | public: |
| 337 | static ControlParameters |
| 338 | getParameters() |
| 339 | { |
| 340 | return ControlParameters() |
| 341 | .setUri("udp4://127.0.0.1:26363") |
| 342 | .setLocalUri("udp4://127.0.0.1:36363"); |
| 343 | } |
| 344 | }; |
| 345 | |
| 346 | class UnsupportedProtocol |
Junxiao Shi | 38c7d9e | 2017-04-13 14:22:50 +0000 | [diff] [blame] | 347 | { |
| 348 | public: |
| 349 | static ControlParameters |
| 350 | getParameters() |
| 351 | { |
| 352 | return ControlParameters() |
| 353 | .setUri("dev://eth0"); |
| 354 | } |
| 355 | }; |
| 356 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 357 | // Pairs of FaceCreateCommand request and success/failure response |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 358 | using TestCases = boost::mp11::mp_list< |
| 359 | boost::mp11::mp_list<TcpFaceOnDemand, CommandFailure<406>>, |
| 360 | boost::mp11::mp_list<TcpFacePersistent, CommandSuccess>, |
| 361 | boost::mp11::mp_list<TcpFacePermanent, CommandSuccess>, |
| 362 | boost::mp11::mp_list<UdpFaceOnDemand, CommandFailure<406>>, |
| 363 | boost::mp11::mp_list<UdpFacePersistent, CommandSuccess>, |
| 364 | boost::mp11::mp_list<UdpFacePermanent, CommandSuccess>, |
| 365 | boost::mp11::mp_list<LocalTcpFaceLocalFieldsEnabled, CommandSuccess>, |
| 366 | boost::mp11::mp_list<LocalTcpFaceLocalFieldsDisabled, CommandSuccess>, |
| 367 | boost::mp11::mp_list<NonLocalUdpFaceLocalFieldsEnabled, CommandFailure<406>>, |
| 368 | boost::mp11::mp_list<NonLocalUdpFaceLocalFieldsDisabled, CommandSuccess>, |
| 369 | boost::mp11::mp_list<TcpFaceLpReliabilityEnabled, CommandSuccess>, |
| 370 | boost::mp11::mp_list<TcpFaceLpReliabilityDisabled, CommandSuccess>, |
| 371 | boost::mp11::mp_list<UdpFaceLpReliabilityEnabled, CommandSuccess>, |
| 372 | boost::mp11::mp_list<UdpFaceLpReliabilityDisabled, CommandSuccess>, |
| 373 | boost::mp11::mp_list<TcpFaceCongestionMarkingEnabled, CommandSuccess>, |
| 374 | boost::mp11::mp_list<TcpFaceCongestionMarkingDisabled, CommandSuccess>, |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 375 | boost::mp11::mp_list<UdpFaceCongestionMarkingEnabled, CommandSuccess>, |
| 376 | boost::mp11::mp_list<UdpFaceCongestionMarkingDisabled, CommandSuccess>, |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 377 | boost::mp11::mp_list<TcpFaceMtuOverride, CommandFailure<406>>, |
| 378 | boost::mp11::mp_list<UdpFaceMtuOverride, CommandSuccess>, |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 379 | boost::mp11::mp_list<RemoteUriMalformed, CommandFailure<400>>, |
| 380 | boost::mp11::mp_list<RemoteUriNonCanonical, CommandFailure<400>>, |
| 381 | boost::mp11::mp_list<LocalUriMalformed, CommandFailure<400>>, |
| 382 | boost::mp11::mp_list<LocalUriNonCanonical, CommandFailure<400>>, |
| 383 | boost::mp11::mp_list<LocalUriUnsupported, CommandFailure<406>>, |
| 384 | boost::mp11::mp_list<UnsupportedProtocol, CommandFailure<406>> |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 385 | >; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 386 | |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 387 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, TestCases, FaceManagerCommandFixture) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 388 | { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 389 | using CreateRequest = boost::mp11::mp_first<T>; |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 390 | using CreateResult = boost::mp11::mp_second<T>; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 391 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 392 | Interest req = makeControlCommandRequest(this->CREATE_REQUEST, CreateRequest::getParameters()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 393 | |
| 394 | bool hasCallbackFired = false; |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 395 | this->node1.face.onSendData.connect([this, req, &hasCallbackFired] (const Data& response) { |
| 396 | if (!req.getName().isPrefixOf(response.getName())) { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 397 | return; |
| 398 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 399 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 400 | ControlResponse actual(response.getContent().blockFromValue()); |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 401 | ControlResponse expected(CreateResult::getExpected()); |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 402 | BOOST_TEST(expected.getCode() == actual.getCode(), actual.getText()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 403 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 404 | if (actual.getBody().hasWire()) { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 405 | ControlParameters expectedParams(CreateRequest::getParameters()); |
| 406 | ndn::nfd::FaceCreateCommand::applyDefaultsToRequest(expectedParams); |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 407 | ControlParameters actualParams(actual.getBody()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 408 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 409 | BOOST_TEST(actualParams.hasFaceId()); |
| 410 | BOOST_TEST(expectedParams.getUri() == actualParams.getUri()); |
| 411 | BOOST_TEST(actualParams.hasLocalUri()); |
| 412 | BOOST_TEST(actualParams.hasFlags()); |
| 413 | BOOST_TEST(expectedParams.getFacePersistency() == actualParams.getFacePersistency()); |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 414 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 415 | if (actual.getCode() == 200) { |
| 416 | if (expectedParams.hasFlags()) { |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 417 | BOOST_CHECK_EQUAL(expectedParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED), |
| 418 | actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 419 | BOOST_CHECK_EQUAL(expectedParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED), |
| 420 | actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); |
Eric Newberry | 17d1849 | 2018-02-10 22:50:06 -0700 | [diff] [blame] | 421 | if (expectedParams.hasFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) { |
| 422 | BOOST_CHECK_EQUAL(expectedParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED), |
| 423 | actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); |
| 424 | } |
| 425 | else { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 426 | // congestion marking is enabled by default |
| 427 | BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); |
Eric Newberry | 17d1849 | 2018-02-10 22:50:06 -0700 | [diff] [blame] | 428 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 429 | } |
| 430 | else { |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 431 | // local fields and reliability are disabled by default |
| 432 | // congestion marking is enabled by default on TCP, UDP, and Unix stream |
| 433 | BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
| 434 | BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); |
| 435 | BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | if (expectedParams.hasBaseCongestionMarkingInterval()) { |
| 439 | BOOST_CHECK_EQUAL(expectedParams.getBaseCongestionMarkingInterval(), |
| 440 | actualParams.getBaseCongestionMarkingInterval()); |
| 441 | } |
| 442 | else { |
| 443 | BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 100_ms); |
| 444 | } |
| 445 | |
| 446 | if (expectedParams.hasDefaultCongestionThreshold()) { |
| 447 | BOOST_CHECK_EQUAL(expectedParams.getDefaultCongestionThreshold(), |
| 448 | actualParams.getDefaultCongestionThreshold()); |
| 449 | } |
| 450 | else { |
| 451 | BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 65536); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 452 | } |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 453 | |
| 454 | if (expectedParams.hasMtu()) { |
| 455 | BOOST_CHECK_EQUAL(expectedParams.getMtu(), actualParams.getMtu()); |
| 456 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 457 | } |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 458 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 459 | |
| 460 | if (actual.getCode() != 200) { |
Junxiao Shi | 38c7d9e | 2017-04-13 14:22:50 +0000 | [diff] [blame] | 461 | FaceUri uri; |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 462 | if (uri.parse(CreateRequest::getParameters().getUri())) { |
Junxiao Shi | 38c7d9e | 2017-04-13 14:22:50 +0000 | [diff] [blame] | 463 | // ensure face not created |
Davide Pesavento | b5eee20 | 2017-09-21 23:59:22 -0400 | [diff] [blame] | 464 | const auto& faceTable = this->node1.faceTable; |
Junxiao Shi | 38c7d9e | 2017-04-13 14:22:50 +0000 | [diff] [blame] | 465 | BOOST_CHECK(std::none_of(faceTable.begin(), faceTable.end(), [uri] (Face& face) { |
| 466 | return face.getRemoteUri() == uri; |
| 467 | })); |
| 468 | } |
| 469 | else { |
| 470 | // do not check malformed FaceUri |
| 471 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 474 | hasCallbackFired = true; |
| 475 | }); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 476 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 477 | this->node1.face.receive(req); |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 478 | this->advanceClocks(1_ms, 10); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 479 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 480 | BOOST_TEST(hasCallbackFired); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 483 | BOOST_FIXTURE_TEST_CASE(ExistingFace, FaceManagerCommandFixture) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 484 | { |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 485 | using FaceType = UdpFacePersistent; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 486 | |
| 487 | { |
| 488 | // create face |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 489 | Interest req = makeControlCommandRequest(CREATE_REQUEST, FaceType::getParameters()); |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 490 | this->node1.face.receive(req); |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 491 | this->advanceClocks(1_ms, 10); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 494 | // find the created face |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 495 | auto foundFace = this->node1.findFaceByUri(FaceType::getParameters().getUri()); |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 496 | BOOST_TEST_REQUIRE(foundFace != nullptr); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 497 | |
| 498 | { |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 499 | // re-create face |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 500 | Interest req = makeControlCommandRequest(CREATE_REQUEST, FaceType::getParameters()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 501 | |
| 502 | bool hasCallbackFired = false; |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 503 | this->node1.face.onSendData.connect( |
Davide Pesavento | ac238f2 | 2017-09-12 15:19:40 -0400 | [diff] [blame] | 504 | [req, foundFace, &hasCallbackFired] (const Data& response) { |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 505 | if (!req.getName().isPrefixOf(response.getName())) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 506 | return; |
| 507 | } |
| 508 | |
| 509 | ControlResponse actual(response.getContent().blockFromValue()); |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 510 | BOOST_REQUIRE_EQUAL(actual.getCode(), 409); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 511 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 512 | ControlParameters actualParams(actual.getBody()); |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 513 | BOOST_CHECK_EQUAL(foundFace->getId(), actualParams.getFaceId()); |
| 514 | BOOST_CHECK_EQUAL(foundFace->getRemoteUri().toString(), actualParams.getUri()); |
| 515 | BOOST_CHECK_EQUAL(foundFace->getPersistency(), actualParams.getFacePersistency()); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 516 | auto linkService = dynamic_cast<face::GenericLinkService*>(foundFace->getLinkService()); |
| 517 | BOOST_CHECK_EQUAL(linkService->getOptions().baseCongestionMarkingInterval, |
| 518 | actualParams.getBaseCongestionMarkingInterval()); |
| 519 | BOOST_CHECK_EQUAL(linkService->getOptions().defaultCongestionThreshold, |
| 520 | actualParams.getDefaultCongestionThreshold()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 521 | |
| 522 | hasCallbackFired = true; |
| 523 | }); |
| 524 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 525 | this->node1.face.receive(req); |
Davide Pesavento | 1d2d337 | 2025-01-14 12:04:12 -0500 | [diff] [blame] | 526 | this->advanceClocks(1_ms, 10); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 527 | |
Davide Pesavento | 4296fe3 | 2025-01-14 23:00:41 -0500 | [diff] [blame] | 528 | BOOST_TEST(hasCallbackFired); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
| 532 | BOOST_AUTO_TEST_SUITE_END() // CreateFace |
| 533 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 534 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 535 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 536 | } // namespace nfd::tests |