Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -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" |
| 27 | #include "face/generic-link-service.hpp" |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 28 | #include "face-manager-command-fixture.hpp" |
| 29 | #include "nfd-manager-common-fixture.hpp" |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 30 | |
Junxiao Shi | cbc8e94 | 2016-09-06 03:17:45 +0000 | [diff] [blame] | 31 | #include <ndn-cxx/lp/tags.hpp> |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 32 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 33 | #include <thread> |
| 34 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 35 | namespace nfd { |
| 36 | namespace tests { |
| 37 | |
| 38 | BOOST_AUTO_TEST_SUITE(Mgmt) |
| 39 | BOOST_AUTO_TEST_SUITE(TestFaceManager) |
| 40 | |
| 41 | class FaceManagerUpdateFixture : public FaceManagerCommandFixture |
| 42 | { |
| 43 | public: |
| 44 | FaceManagerUpdateFixture() |
| 45 | : faceId(0) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | ~FaceManagerUpdateFixture() |
| 50 | { |
| 51 | destroyFace(); |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | createFace(const std::string& uri = "tcp4://127.0.0.1:26363", |
| 56 | ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT, |
| 57 | bool enableLocalFields = false) |
| 58 | { |
| 59 | ControlParameters params; |
| 60 | params.setUri(uri); |
| 61 | params.setFacePersistency(persistency); |
| 62 | params.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, enableLocalFields); |
| 63 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 64 | createFace(params); |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | createFace(const ControlParameters& createParams, |
| 69 | bool isForOnDemandFace = false) |
| 70 | { |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 71 | Name commandName("/localhost/nfd/faces/create"); |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 72 | commandName.append(createParams.wireEncode()); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 73 | auto command = makeInterest(commandName); |
| 74 | m_keyChain.sign(*command); |
| 75 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 76 | // if this creation if for on-demand face then create it on node2 |
| 77 | FaceManagerCommandNode& target = isForOnDemandFace ? this->node2 : this->node1; |
| 78 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 79 | bool hasCallbackFired = false; |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 80 | signal::ScopedConnection connection = target.face.onSendData.connect( |
| 81 | [&, command, isForOnDemandFace, this] (const Data& response) { |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 82 | if (!command->getName().isPrefixOf(response.getName())) { |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | ControlResponse create(response.getContent().blockFromValue()); |
| 87 | BOOST_REQUIRE_EQUAL(create.getCode(), 200); |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 88 | BOOST_REQUIRE(create.getBody().hasWire()); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 89 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 90 | ControlParameters faceParams(create.getBody()); |
| 91 | BOOST_REQUIRE(faceParams.hasFaceId()); |
| 92 | this->faceId = faceParams.getFaceId(); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 93 | |
| 94 | hasCallbackFired = true; |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 95 | |
| 96 | if (isForOnDemandFace) { |
| 97 | auto face = target.faceTable.get(static_cast<FaceId>(this->faceId)); |
| 98 | |
| 99 | // to force creation of on-demand face |
| 100 | face->sendInterest(*make_shared<Interest>("/hello/world")); |
| 101 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 102 | }); |
| 103 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 104 | target.face.receive(*command); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 105 | this->advanceClocks(time::milliseconds(1), 5); |
| 106 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 107 | if (isForOnDemandFace) { |
| 108 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); // allow wallclock time for socket IO |
| 109 | this->advanceClocks(time::milliseconds(1), 5); // let node1 accept Interest and create on-demand face |
| 110 | } |
| 111 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 112 | BOOST_REQUIRE(hasCallbackFired); |
| 113 | } |
| 114 | |
| 115 | void |
| 116 | updateFace(const ControlParameters& requestParams, |
| 117 | bool isSelfUpdating, |
| 118 | const function<void(const ControlResponse& resp)>& checkResp) |
| 119 | { |
| 120 | Name commandName("/localhost/nfd/faces/update"); |
| 121 | commandName.append(requestParams.wireEncode()); |
| 122 | auto command = makeInterest(commandName); |
| 123 | if (isSelfUpdating) { |
| 124 | // Attach IncomingFaceIdTag to interest |
| 125 | command->setTag(make_shared<lp::IncomingFaceIdTag>(faceId)); |
| 126 | } |
| 127 | m_keyChain.sign(*command); |
| 128 | |
| 129 | bool hasCallbackFired = false; |
| 130 | signal::ScopedConnection connection = this->node1.face.onSendData.connect( |
| 131 | [this, command, &hasCallbackFired, &checkResp] (const Data& response) { |
| 132 | if (!command->getName().isPrefixOf(response.getName())) { |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | ControlResponse actual(response.getContent().blockFromValue()); |
| 137 | checkResp(actual); |
| 138 | |
| 139 | hasCallbackFired = true; |
| 140 | }); |
| 141 | |
| 142 | this->node1.face.receive(*command); |
| 143 | this->advanceClocks(time::milliseconds(1), 5); |
| 144 | |
| 145 | BOOST_CHECK(hasCallbackFired); |
| 146 | } |
| 147 | |
| 148 | private: |
| 149 | void |
| 150 | destroyFace() |
| 151 | { |
| 152 | if (faceId == 0) { |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | ControlParameters params; |
| 157 | params.setFaceId(faceId); |
| 158 | |
| 159 | Name commandName("/localhost/nfd/faces/destroy"); |
| 160 | commandName.append(params.wireEncode()); |
| 161 | auto command = makeInterest(commandName); |
| 162 | m_keyChain.sign(*command); |
| 163 | |
| 164 | bool hasCallbackFired = false; |
| 165 | signal::ScopedConnection connection = this->node1.face.onSendData.connect( |
| 166 | [this, command, &hasCallbackFired] (const Data& response) { |
| 167 | if (!command->getName().isPrefixOf(response.getName())) { |
| 168 | return; |
| 169 | } |
| 170 | |
| 171 | ControlResponse destroy(response.getContent().blockFromValue()); |
| 172 | BOOST_CHECK_EQUAL(destroy.getCode(), 200); |
| 173 | |
| 174 | faceId = 0; |
| 175 | hasCallbackFired = true; |
| 176 | }); |
| 177 | |
| 178 | this->node1.face.receive(*command); |
| 179 | this->advanceClocks(time::milliseconds(1), 5); |
| 180 | |
| 181 | BOOST_CHECK(hasCallbackFired); |
| 182 | } |
| 183 | |
| 184 | public: |
| 185 | FaceId faceId; |
| 186 | }; |
| 187 | |
| 188 | BOOST_FIXTURE_TEST_SUITE(UpdateFace, FaceManagerUpdateFixture) |
| 189 | |
| 190 | BOOST_AUTO_TEST_CASE(FaceDoesNotExist) |
| 191 | { |
| 192 | ControlParameters requestParams; |
| 193 | requestParams.setFaceId(65535); |
| 194 | |
| 195 | updateFace(requestParams, false, [] (const ControlResponse& actual) { |
| 196 | ControlResponse expected(404, "Specified face does not exist"); |
| 197 | BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); |
| 198 | BOOST_TEST_MESSAGE(actual.getText()); |
| 199 | }); |
| 200 | } |
| 201 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 202 | template<bool CAN_CHANGE_PERSISTENCY> |
| 203 | class UpdatePersistencyDummyTransport : public face::Transport |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 204 | { |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 205 | public: |
| 206 | UpdatePersistencyDummyTransport() |
| 207 | { |
| 208 | this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT); |
| 209 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 210 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 211 | protected: |
| 212 | bool |
| 213 | canChangePersistencyToImpl(ndn::nfd::FacePersistency newPersistency) const override |
| 214 | { |
| 215 | return CAN_CHANGE_PERSISTENCY; |
| 216 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 217 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 218 | void |
| 219 | doClose() override |
| 220 | { |
| 221 | } |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 222 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 223 | private: |
| 224 | void |
| 225 | doSend(face::Transport::Packet&& packet) override |
| 226 | { |
| 227 | } |
| 228 | }; |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 229 | |
Yanbiao Li | 58ba3f9 | 2017-02-15 14:27:18 +0000 | [diff] [blame^] | 230 | namespace mpl = boost::mpl; |
| 231 | |
| 232 | using UpdatePersistencyTests = |
| 233 | mpl::vector<mpl::pair<UpdatePersistencyDummyTransport<true>, CommandSuccess>, |
| 234 | mpl::pair<UpdatePersistencyDummyTransport<false>, CommandFailure<409>>>; |
| 235 | |
| 236 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePersistency, T, UpdatePersistencyTests, FaceManagerUpdateFixture) |
| 237 | { |
| 238 | using TransportType = typename T::first; |
| 239 | using ResultType = typename T::second; |
| 240 | |
| 241 | auto face = make_shared<face::Face>(make_unique<face::GenericLinkService>(), |
| 242 | make_unique<TransportType>()); |
| 243 | this->node1.faceTable.add(face); |
| 244 | |
| 245 | auto parameters = ControlParameters() |
| 246 | .setFaceId(face->getId()) |
| 247 | .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT); |
| 248 | |
| 249 | updateFace(parameters, false, [] (const ControlResponse& actual) { |
| 250 | BOOST_TEST_MESSAGE(actual.getText()); |
| 251 | BOOST_CHECK_EQUAL(actual.getCode(), ResultType::getExpected().getCode()); |
| 252 | |
| 253 | // the response for either 200 or 409 will have a content body |
| 254 | BOOST_REQUIRE(actual.getBody().hasWire()); |
| 255 | |
| 256 | ControlParameters resp; |
| 257 | resp.wireDecode(actual.getBody()); |
| 258 | BOOST_CHECK_EQUAL(resp.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT); |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 259 | }); |
| 260 | } |
| 261 | |
| 262 | class TcpLocalFieldsEnable |
| 263 | { |
| 264 | public: |
| 265 | std::string |
| 266 | getUri() |
| 267 | { |
| 268 | return "tcp4://127.0.0.1:26363"; |
| 269 | } |
| 270 | |
| 271 | boost::asio::ip::address_v4 |
| 272 | getIpAddress() |
| 273 | { |
| 274 | return boost::asio::ip::address_v4::from_string("127.0.0.1"); |
| 275 | } |
| 276 | |
| 277 | ndn::nfd::FacePersistency |
| 278 | getPersistency() |
| 279 | { |
| 280 | return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; |
| 281 | } |
| 282 | |
| 283 | bool |
| 284 | getInitLocalFieldsEnabled() |
| 285 | { |
| 286 | return false; |
| 287 | } |
| 288 | |
| 289 | bool |
| 290 | getLocalFieldsEnabled() |
| 291 | { |
| 292 | return true; |
| 293 | } |
| 294 | |
| 295 | bool |
| 296 | getLocalFieldsEnabledMask() |
| 297 | { |
| 298 | return true; |
| 299 | } |
| 300 | |
| 301 | bool |
| 302 | shouldHaveWire() |
| 303 | { |
| 304 | return false; |
| 305 | } |
| 306 | }; |
| 307 | |
| 308 | class TcpLocalFieldsDisable |
| 309 | { |
| 310 | public: |
| 311 | std::string |
| 312 | getUri() |
| 313 | { |
| 314 | return "tcp4://127.0.0.1:26363"; |
| 315 | } |
| 316 | |
| 317 | ndn::nfd::FacePersistency |
| 318 | getPersistency() |
| 319 | { |
| 320 | return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; |
| 321 | } |
| 322 | |
| 323 | bool |
| 324 | getInitLocalFieldsEnabled() |
| 325 | { |
| 326 | return true; |
| 327 | } |
| 328 | |
| 329 | bool |
| 330 | getLocalFieldsEnabled() |
| 331 | { |
| 332 | return false; |
| 333 | } |
| 334 | |
| 335 | bool |
| 336 | getLocalFieldsEnabledMask() |
| 337 | { |
| 338 | return true; |
| 339 | } |
| 340 | |
| 341 | bool |
| 342 | shouldHaveWire() |
| 343 | { |
| 344 | return false; |
| 345 | } |
| 346 | }; |
| 347 | |
| 348 | // UDP faces are non-local by definition |
| 349 | class UdpLocalFieldsEnable |
| 350 | { |
| 351 | public: |
| 352 | std::string |
| 353 | getUri() |
| 354 | { |
| 355 | return "udp4://127.0.0.1:26363"; |
| 356 | } |
| 357 | |
| 358 | ndn::nfd::FacePersistency |
| 359 | getPersistency() |
| 360 | { |
| 361 | return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; |
| 362 | } |
| 363 | |
| 364 | bool |
| 365 | getInitLocalFieldsEnabled() |
| 366 | { |
| 367 | return false; |
| 368 | } |
| 369 | |
| 370 | bool |
| 371 | getLocalFieldsEnabled() |
| 372 | { |
| 373 | return true; |
| 374 | } |
| 375 | |
| 376 | bool |
| 377 | getLocalFieldsEnabledMask() |
| 378 | { |
| 379 | return true; |
| 380 | } |
| 381 | |
| 382 | bool |
| 383 | shouldHaveWire() |
| 384 | { |
| 385 | return true; |
| 386 | } |
| 387 | }; |
| 388 | |
| 389 | // UDP faces are non-local by definition |
| 390 | // In this test case, attempt to disable local fields on face with local fields already disabled |
| 391 | class UdpLocalFieldsDisable |
| 392 | { |
| 393 | public: |
| 394 | std::string |
| 395 | getUri() |
| 396 | { |
| 397 | return "udp4://127.0.0.1:26363"; |
| 398 | } |
| 399 | |
| 400 | ndn::nfd::FacePersistency |
| 401 | getPersistency() |
| 402 | { |
| 403 | return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; |
| 404 | } |
| 405 | |
| 406 | bool |
| 407 | getInitLocalFieldsEnabled() |
| 408 | { |
| 409 | return false; |
| 410 | } |
| 411 | |
| 412 | bool |
| 413 | getLocalFieldsEnabled() |
| 414 | { |
| 415 | return false; |
| 416 | } |
| 417 | |
| 418 | bool |
| 419 | getLocalFieldsEnabledMask() |
| 420 | { |
| 421 | return true; |
| 422 | } |
| 423 | |
| 424 | bool |
| 425 | shouldHaveWire() |
| 426 | { |
| 427 | return false; |
| 428 | } |
| 429 | }; |
| 430 | |
| 431 | // In this test case, set Flags to enable local fields on non-local face, but exclude local fields |
| 432 | // from Mask. This test case will pass as no action is taken due to the missing Mask bit. |
| 433 | class UdpLocalFieldsEnableNoMaskBit |
| 434 | { |
| 435 | public: |
| 436 | std::string |
| 437 | getUri() |
| 438 | { |
| 439 | return "udp4://127.0.0.1:26363"; |
| 440 | } |
| 441 | |
| 442 | ndn::nfd::FacePersistency |
| 443 | getPersistency() |
| 444 | { |
| 445 | return ndn::nfd::FACE_PERSISTENCY_PERSISTENT; |
| 446 | } |
| 447 | |
| 448 | bool |
| 449 | getInitLocalFieldsEnabled() |
| 450 | { |
| 451 | return false; |
| 452 | } |
| 453 | |
| 454 | bool |
| 455 | getLocalFieldsEnabled() |
| 456 | { |
| 457 | return true; |
| 458 | } |
| 459 | |
| 460 | bool |
| 461 | getLocalFieldsEnabledMask() |
| 462 | { |
| 463 | return false; |
| 464 | } |
| 465 | |
| 466 | bool |
| 467 | shouldHaveWire() |
| 468 | { |
| 469 | return false; |
| 470 | } |
| 471 | }; |
| 472 | |
Eric Newberry | b5aa7f5 | 2016-09-03 20:36:12 -0700 | [diff] [blame] | 473 | typedef mpl::vector<mpl::pair<TcpLocalFieldsEnable, CommandSuccess>, |
| 474 | mpl::pair<TcpLocalFieldsDisable, CommandSuccess>, |
| 475 | mpl::pair<UdpLocalFieldsEnable, CommandFailure<409>>, |
| 476 | mpl::pair<UdpLocalFieldsDisable, CommandSuccess>, |
| 477 | mpl::pair<UdpLocalFieldsEnableNoMaskBit, CommandSuccess>> LocalFieldFaces; |
| 478 | |
| 479 | BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateLocalFields, T, LocalFieldFaces) |
| 480 | { |
| 481 | typedef typename T::first TestType; |
| 482 | typedef typename T::second ResultType; |
| 483 | |
| 484 | createFace(TestType().getUri(), TestType().getPersistency(), TestType().getInitLocalFieldsEnabled()); |
| 485 | |
| 486 | ControlParameters requestParams; |
| 487 | requestParams.setFaceId(faceId); |
| 488 | requestParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, TestType().getLocalFieldsEnabled()); |
| 489 | if (!TestType().getLocalFieldsEnabledMask()) { |
| 490 | requestParams.unsetFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED); |
| 491 | } |
| 492 | |
| 493 | updateFace(requestParams, false, [] (const ControlResponse& actual) { |
| 494 | ControlResponse expected(ResultType().getExpected().getCode(), ""); |
| 495 | BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); |
| 496 | BOOST_TEST_MESSAGE(actual.getText()); |
| 497 | |
| 498 | if (TestType().shouldHaveWire() && actual.getBody().hasWire()) { |
| 499 | ControlParameters actualParams(actual.getBody()); |
| 500 | |
| 501 | BOOST_CHECK(!actualParams.hasFacePersistency()); |
| 502 | BOOST_CHECK(actualParams.hasFlags()); |
| 503 | BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
| 504 | BOOST_CHECK(actualParams.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
| 505 | } |
| 506 | }); |
| 507 | } |
| 508 | |
| 509 | BOOST_AUTO_TEST_CASE(UpdateLocalFieldsEnableDisable) |
| 510 | { |
| 511 | createFace(); |
| 512 | |
| 513 | ControlParameters enableParams; |
| 514 | enableParams.setFaceId(faceId); |
| 515 | enableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true); |
| 516 | |
| 517 | ControlParameters disableParams; |
| 518 | disableParams.setFaceId(faceId); |
| 519 | disableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false); |
| 520 | |
| 521 | updateFace(enableParams, false, [] (const ControlResponse& actual) { |
| 522 | ControlResponse expected(200, "OK"); |
| 523 | BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); |
| 524 | BOOST_TEST_MESSAGE(actual.getText()); |
| 525 | |
| 526 | if (actual.getBody().hasWire()) { |
| 527 | ControlParameters actualParams(actual.getBody()); |
| 528 | |
| 529 | BOOST_CHECK(actualParams.hasFaceId()); |
| 530 | BOOST_CHECK(actualParams.hasFacePersistency()); |
| 531 | BOOST_REQUIRE(actualParams.hasFlags()); |
| 532 | // Check if flags indicate local fields enabled |
| 533 | BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
| 534 | } |
| 535 | else { |
| 536 | BOOST_ERROR("Enable: Response does not contain ControlParameters"); |
| 537 | } |
| 538 | }); |
| 539 | |
| 540 | updateFace(disableParams, false, [] (const ControlResponse& actual) { |
| 541 | ControlResponse expected(200, "OK"); |
| 542 | BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode()); |
| 543 | BOOST_TEST_MESSAGE(actual.getText()); |
| 544 | |
| 545 | if (actual.getBody().hasWire()) { |
| 546 | ControlParameters actualParams(actual.getBody()); |
| 547 | |
| 548 | BOOST_CHECK(actualParams.hasFaceId()); |
| 549 | BOOST_CHECK(actualParams.hasFacePersistency()); |
| 550 | BOOST_REQUIRE(actualParams.hasFlags()); |
| 551 | // Check if flags indicate local fields disabled |
| 552 | BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED)); |
| 553 | } |
| 554 | else { |
| 555 | BOOST_ERROR("Disable: Response does not contain ControlParameters"); |
| 556 | } |
| 557 | }); |
| 558 | } |
| 559 | |
| 560 | BOOST_AUTO_TEST_CASE(SelfUpdating) |
| 561 | { |
| 562 | createFace(); |
| 563 | |
| 564 | // Send a command that does nothing (will return 200) and does not contain a FaceId |
| 565 | ControlParameters sentParams; |
| 566 | |
| 567 | updateFace(sentParams, true, [] (const ControlResponse& actual) { |
| 568 | ControlResponse expected(200, "OK"); |
| 569 | BOOST_REQUIRE_EQUAL(actual.getCode(), expected.getCode()); |
| 570 | BOOST_TEST_MESSAGE(actual.getText()); |
| 571 | }); |
| 572 | } |
| 573 | |
| 574 | BOOST_AUTO_TEST_SUITE_END() // UpdateFace |
| 575 | BOOST_AUTO_TEST_SUITE_END() // TestFaceManager |
| 576 | BOOST_AUTO_TEST_SUITE_END() // Mgmt |
| 577 | |
| 578 | } // namespace tests |
| 579 | } // namespace nfd |