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