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