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 | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, 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") |
| 120 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 121 | .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true); |
| 122 | } |
| 123 | }; |
| 124 | |
| 125 | class LocalTcpFaceLocalFieldsDisabled |
| 126 | { |
| 127 | public: |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 128 | static ControlParameters |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 129 | getParameters() |
| 130 | { |
| 131 | return ControlParameters() |
| 132 | .setUri("tcp4://127.0.0.1:26363") |
| 133 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 134 | .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false); |
| 135 | } |
| 136 | }; |
| 137 | |
| 138 | class NonLocalUdpFaceLocalFieldsEnabled // won't work because non-local scope |
| 139 | { |
| 140 | public: |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 141 | static ControlParameters |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 142 | getParameters() |
| 143 | { |
| 144 | return ControlParameters() |
| 145 | .setUri("udp4://127.0.0.1:26363") |
| 146 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 147 | .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true); |
| 148 | } |
| 149 | }; |
| 150 | |
| 151 | class NonLocalUdpFaceLocalFieldsDisabled |
| 152 | { |
| 153 | public: |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 154 | static ControlParameters |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 155 | getParameters() |
| 156 | { |
| 157 | return ControlParameters() |
| 158 | .setUri("udp4://127.0.0.1:26363") |
| 159 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 160 | .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false); |
| 161 | } |
| 162 | }; |
| 163 | |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 164 | class TcpFaceLpReliabilityEnabled |
| 165 | { |
| 166 | public: |
| 167 | static ControlParameters |
| 168 | getParameters() |
| 169 | { |
| 170 | return ControlParameters() |
| 171 | .setUri("tcp4://127.0.0.1:26363") |
| 172 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 173 | .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true); |
| 174 | } |
| 175 | }; |
| 176 | |
| 177 | class TcpFaceLpReliabilityDisabled |
| 178 | { |
| 179 | public: |
| 180 | static ControlParameters |
| 181 | getParameters() |
| 182 | { |
| 183 | return ControlParameters() |
| 184 | .setUri("tcp4://127.0.0.1:26363") |
| 185 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 186 | .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false); |
| 187 | } |
| 188 | }; |
| 189 | |
| 190 | class UdpFaceLpReliabilityEnabled |
| 191 | { |
| 192 | public: |
| 193 | static ControlParameters |
| 194 | getParameters() |
| 195 | { |
| 196 | return ControlParameters() |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 197 | .setUri("udp4://127.0.0.1:26363") |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 198 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 199 | .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true); |
| 200 | } |
| 201 | }; |
| 202 | |
| 203 | class UdpFaceLpReliabilityDisabled |
| 204 | { |
| 205 | public: |
| 206 | static ControlParameters |
| 207 | getParameters() |
| 208 | { |
| 209 | return ControlParameters() |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 210 | .setUri("udp4://127.0.0.1:26363") |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 211 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 212 | .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false); |
| 213 | } |
| 214 | }; |
| 215 | |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 216 | class TcpFaceCongestionMarkingEnabled |
| 217 | { |
| 218 | public: |
| 219 | static ControlParameters |
| 220 | getParameters() |
| 221 | { |
| 222 | return ControlParameters() |
| 223 | .setUri("tcp4://127.0.0.1:26363") |
| 224 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 225 | .setBaseCongestionMarkingInterval(50_ms) |
| 226 | .setDefaultCongestionThreshold(1000) |
| 227 | .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true); |
| 228 | } |
| 229 | }; |
| 230 | |
| 231 | class TcpFaceCongestionMarkingDisabled |
| 232 | { |
| 233 | public: |
| 234 | static ControlParameters |
| 235 | getParameters() |
| 236 | { |
| 237 | return ControlParameters() |
| 238 | .setUri("tcp4://127.0.0.1:26363") |
| 239 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 240 | .setBaseCongestionMarkingInterval(50_ms) |
| 241 | .setDefaultCongestionThreshold(1000) |
| 242 | .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false); |
| 243 | } |
| 244 | }; |
| 245 | |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 246 | class TcpFaceMtuOverride |
| 247 | { |
| 248 | public: |
| 249 | static ControlParameters |
| 250 | getParameters() |
| 251 | { |
| 252 | return ControlParameters() |
| 253 | .setUri("tcp4://127.0.0.1:26363") |
| 254 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 255 | .setMtu(1000); |
| 256 | } |
| 257 | }; |
| 258 | |
| 259 | class UdpFaceMtuOverride |
| 260 | { |
| 261 | public: |
| 262 | static ControlParameters |
| 263 | getParameters() |
| 264 | { |
| 265 | return ControlParameters() |
| 266 | .setUri("udp4://127.0.0.1:26363") |
| 267 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT) |
| 268 | .setMtu(1000); |
| 269 | } |
| 270 | }; |
| 271 | |
Junxiao Shi | 38c7d9e | 2017-04-13 14:22:50 +0000 | [diff] [blame] | 272 | class FaceUriMalformed |
| 273 | { |
| 274 | public: |
| 275 | static ControlParameters |
| 276 | getParameters() |
| 277 | { |
| 278 | return ControlParameters() |
| 279 | .setUri("tcp4://127.0.0.1:not-a-port"); |
| 280 | } |
| 281 | }; |
| 282 | |
| 283 | class FaceUriNonCanonical |
| 284 | { |
| 285 | public: |
| 286 | static ControlParameters |
| 287 | getParameters() |
| 288 | { |
| 289 | return ControlParameters() |
| 290 | .setUri("udp://localhost"); |
| 291 | } |
| 292 | }; |
| 293 | |
| 294 | class FaceUriUnsupportedScheme |
| 295 | { |
| 296 | public: |
| 297 | static ControlParameters |
| 298 | getParameters() |
| 299 | { |
| 300 | return ControlParameters() |
| 301 | .setUri("dev://eth0"); |
| 302 | } |
| 303 | }; |
| 304 | |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 305 | // Pairs of CreateCommand and success/failure status |
| 306 | using TestCases = boost::mp11::mp_list< |
| 307 | boost::mp11::mp_list<TcpFaceOnDemand, CommandFailure<406>>, |
| 308 | boost::mp11::mp_list<TcpFacePersistent, CommandSuccess>, |
| 309 | boost::mp11::mp_list<TcpFacePermanent, CommandSuccess>, |
| 310 | boost::mp11::mp_list<UdpFaceOnDemand, CommandFailure<406>>, |
| 311 | boost::mp11::mp_list<UdpFacePersistent, CommandSuccess>, |
| 312 | boost::mp11::mp_list<UdpFacePermanent, CommandSuccess>, |
| 313 | boost::mp11::mp_list<LocalTcpFaceLocalFieldsEnabled, CommandSuccess>, |
| 314 | boost::mp11::mp_list<LocalTcpFaceLocalFieldsDisabled, CommandSuccess>, |
| 315 | boost::mp11::mp_list<NonLocalUdpFaceLocalFieldsEnabled, CommandFailure<406>>, |
| 316 | boost::mp11::mp_list<NonLocalUdpFaceLocalFieldsDisabled, CommandSuccess>, |
| 317 | boost::mp11::mp_list<TcpFaceLpReliabilityEnabled, CommandSuccess>, |
| 318 | boost::mp11::mp_list<TcpFaceLpReliabilityDisabled, CommandSuccess>, |
| 319 | boost::mp11::mp_list<UdpFaceLpReliabilityEnabled, CommandSuccess>, |
| 320 | boost::mp11::mp_list<UdpFaceLpReliabilityDisabled, CommandSuccess>, |
| 321 | boost::mp11::mp_list<TcpFaceCongestionMarkingEnabled, CommandSuccess>, |
| 322 | boost::mp11::mp_list<TcpFaceCongestionMarkingDisabled, CommandSuccess>, |
| 323 | boost::mp11::mp_list<TcpFaceMtuOverride, CommandFailure<406>>, |
| 324 | boost::mp11::mp_list<UdpFaceMtuOverride, CommandSuccess>, |
| 325 | boost::mp11::mp_list<FaceUriMalformed, CommandFailure<400>>, |
| 326 | boost::mp11::mp_list<FaceUriNonCanonical, CommandFailure<400>>, |
| 327 | boost::mp11::mp_list<FaceUriUnsupportedScheme, CommandFailure<406>> |
| 328 | >; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 329 | |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 330 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, TestCases, FaceManagerCommandFixture) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 331 | { |
Davide Pesavento | f56cf63 | 2024-01-27 22:22:06 -0500 | [diff] [blame] | 332 | using FaceType = boost::mp11::mp_first<T>; |
| 333 | using CreateResult = boost::mp11::mp_second<T>; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 334 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 335 | Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", FaceType::getParameters()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 336 | |
| 337 | bool hasCallbackFired = false; |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 338 | this->node1.face.onSendData.connect([this, req, &hasCallbackFired] (const Data& response) { |
| 339 | if (!req.getName().isPrefixOf(response.getName())) { |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 340 | return; |
| 341 | } |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 342 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 343 | ControlResponse actual(response.getContent().blockFromValue()); |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 344 | ControlResponse expected(CreateResult::getExpected()); |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 345 | BOOST_TEST_MESSAGE(actual.getText()); |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 346 | BOOST_CHECK_EQUAL(expected.getCode(), actual.getCode()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 347 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 348 | if (actual.getBody().hasWire()) { |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 349 | ControlParameters expectedParams(FaceType::getParameters()); |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 350 | ControlParameters actualParams(actual.getBody()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 351 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 352 | BOOST_CHECK(actualParams.hasFaceId()); |
| 353 | BOOST_CHECK_EQUAL(expectedParams.getFacePersistency(), actualParams.getFacePersistency()); |
| 354 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 355 | if (actual.getCode() == 200) { |
| 356 | if (expectedParams.hasFlags()) { |
Eric Newberry | f40551a | 2016-09-05 15:41:16 -0700 | [diff] [blame] | 357 | BOOST_CHECK_EQUAL(expectedParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED), |
| 358 | actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
Eric Newberry | 2642cd2 | 2017-07-13 21:34:53 -0400 | [diff] [blame] | 359 | BOOST_CHECK_EQUAL(expectedParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED), |
| 360 | actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); |
Eric Newberry | 17d1849 | 2018-02-10 22:50:06 -0700 | [diff] [blame] | 361 | if (expectedParams.hasFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) { |
| 362 | BOOST_CHECK_EQUAL(expectedParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED), |
| 363 | actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); |
| 364 | } |
| 365 | else { |
| 366 | BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); |
| 367 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 368 | } |
| 369 | else { |
Eric Newberry | 17d1849 | 2018-02-10 22:50:06 -0700 | [diff] [blame] | 370 | // local fields and LpReliability are disabled by default, congestion marking is enabled |
| 371 | // by default on TCP, UDP, and Unix stream |
| 372 | BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
| 373 | BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)); |
| 374 | BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | if (expectedParams.hasBaseCongestionMarkingInterval()) { |
| 378 | BOOST_CHECK_EQUAL(expectedParams.getBaseCongestionMarkingInterval(), |
| 379 | actualParams.getBaseCongestionMarkingInterval()); |
| 380 | } |
| 381 | else { |
| 382 | BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 100_ms); |
| 383 | } |
| 384 | |
| 385 | if (expectedParams.hasDefaultCongestionThreshold()) { |
| 386 | BOOST_CHECK_EQUAL(expectedParams.getDefaultCongestionThreshold(), |
| 387 | actualParams.getDefaultCongestionThreshold()); |
| 388 | } |
| 389 | else { |
| 390 | BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 65536); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 391 | } |
Eric Newberry | 812d615 | 2018-06-06 15:06:01 -0700 | [diff] [blame] | 392 | |
| 393 | if (expectedParams.hasMtu()) { |
| 394 | BOOST_CHECK_EQUAL(expectedParams.getMtu(), actualParams.getMtu()); |
| 395 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 396 | } |
| 397 | else { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 398 | BOOST_CHECK_EQUAL(expectedParams.getUri(), actualParams.getUri()); |
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 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 401 | |
| 402 | if (actual.getCode() != 200) { |
Junxiao Shi | 38c7d9e | 2017-04-13 14:22:50 +0000 | [diff] [blame] | 403 | FaceUri uri; |
| 404 | if (uri.parse(FaceType::getParameters().getUri())) { |
| 405 | // ensure face not created |
Davide Pesavento | b5eee20 | 2017-09-21 23:59:22 -0400 | [diff] [blame] | 406 | const auto& faceTable = this->node1.faceTable; |
Junxiao Shi | 38c7d9e | 2017-04-13 14:22:50 +0000 | [diff] [blame] | 407 | BOOST_CHECK(std::none_of(faceTable.begin(), faceTable.end(), [uri] (Face& face) { |
| 408 | return face.getRemoteUri() == uri; |
| 409 | })); |
| 410 | } |
| 411 | else { |
| 412 | // do not check malformed FaceUri |
| 413 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Eric Newberry | 4260241 | 2016-08-27 09:33:18 -0700 | [diff] [blame] | 416 | hasCallbackFired = true; |
| 417 | }); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 418 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 419 | this->node1.face.receive(req); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 420 | this->advanceClocks(1_ms, 5); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 421 | |
| 422 | BOOST_CHECK(hasCallbackFired); |
| 423 | } |
| 424 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 425 | BOOST_FIXTURE_TEST_CASE(ExistingFace, FaceManagerCommandFixture) |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 426 | { |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 427 | using FaceType = UdpFacePersistent; |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 428 | |
| 429 | { |
| 430 | // create face |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 431 | Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", FaceType::getParameters()); |
| 432 | this->node1.face.receive(req); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 433 | this->advanceClocks(1_ms, 5); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 436 | // find the created face |
Davide Pesavento | a3c9ddb | 2017-04-10 22:15:24 -0400 | [diff] [blame] | 437 | auto foundFace = this->node1.findFaceByUri(FaceType::getParameters().getUri()); |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 438 | BOOST_REQUIRE(foundFace != nullptr); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 439 | |
| 440 | { |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 441 | // re-create face |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 442 | Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", FaceType::getParameters()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 443 | |
| 444 | bool hasCallbackFired = false; |
Junxiao Shi | b84e674 | 2016-07-19 13:16:22 +0000 | [diff] [blame] | 445 | this->node1.face.onSendData.connect( |
Davide Pesavento | ac238f2 | 2017-09-12 15:19:40 -0400 | [diff] [blame] | 446 | [req, foundFace, &hasCallbackFired] (const Data& response) { |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 447 | if (!req.getName().isPrefixOf(response.getName())) { |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 448 | return; |
| 449 | } |
| 450 | |
| 451 | ControlResponse actual(response.getContent().blockFromValue()); |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 452 | BOOST_REQUIRE_EQUAL(actual.getCode(), 409); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 453 | |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 454 | ControlParameters actualParams(actual.getBody()); |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame] | 455 | BOOST_CHECK_EQUAL(foundFace->getId(), actualParams.getFaceId()); |
| 456 | BOOST_CHECK_EQUAL(foundFace->getRemoteUri().toString(), actualParams.getUri()); |
| 457 | BOOST_CHECK_EQUAL(foundFace->getPersistency(), actualParams.getFacePersistency()); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 458 | auto linkService = dynamic_cast<face::GenericLinkService*>(foundFace->getLinkService()); |
| 459 | BOOST_CHECK_EQUAL(linkService->getOptions().baseCongestionMarkingInterval, |
| 460 | actualParams.getBaseCongestionMarkingInterval()); |
| 461 | BOOST_CHECK_EQUAL(linkService->getOptions().defaultCongestionThreshold, |
| 462 | actualParams.getDefaultCongestionThreshold()); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 463 | |
| 464 | hasCallbackFired = true; |
| 465 | }); |
| 466 | |
Junxiao Shi | 8a1f170 | 2017-07-03 00:05:08 +0000 | [diff] [blame] | 467 | this->node1.face.receive(req); |
Eric Newberry | 0c3e57b | 2018-01-25 20:54:46 -0700 | [diff] [blame] | 468 | this->advanceClocks(1_ms, 5); |
Yanbiao Li | 73860e3 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 469 | |
| 470 | BOOST_CHECK(hasCallbackFired); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | BOOST_AUTO_TEST_SUITE_END() // CreateFace |
| 475 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 476 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 477 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 478 | } // namespace nfd::tests |