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