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