blob: dd34fd84b080f98eb5dc9fae55ee3386ce0ef3a5 [file] [log] [blame]
Eric Newberryb5aa7f52016-09-03 20:36:12 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Eric Newberry2642cd22017-07-13 21:34:53 -04002/*
Eric Newberry0c3e57b2018-01-25 20:54:46 -07003 * Copyright (c) 2014-2018, Regents of the University of California,
Eric Newberryb5aa7f52016-09-03 20:36:12 -07004 * 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 Li58ba3f92017-02-15 14:27:18 +000026#include "mgmt/face-manager.hpp"
27#include "face/generic-link-service.hpp"
Eric Newberryb5aa7f52016-09-03 20:36:12 -070028#include "face-manager-command-fixture.hpp"
29#include "nfd-manager-common-fixture.hpp"
Yanbiao Li58ba3f92017-02-15 14:27:18 +000030
Junxiao Shicbc8e942016-09-06 03:17:45 +000031#include <ndn-cxx/lp/tags.hpp>
Eric Newberryb5aa7f52016-09-03 20:36:12 -070032
Yanbiao Li58ba3f92017-02-15 14:27:18 +000033#include <thread>
34
Eric Newberry0c3e57b2018-01-25 20:54:46 -070035#include <boost/logic/tribool.hpp>
36
Eric Newberryb5aa7f52016-09-03 20:36:12 -070037namespace nfd {
38namespace tests {
39
40BOOST_AUTO_TEST_SUITE(Mgmt)
41BOOST_AUTO_TEST_SUITE(TestFaceManager)
42
43class FaceManagerUpdateFixture : public FaceManagerCommandFixture
44{
45public:
46 FaceManagerUpdateFixture()
47 : faceId(0)
48 {
49 }
50
51 ~FaceManagerUpdateFixture()
52 {
53 destroyFace();
54 }
55
56 void
57 createFace(const std::string& uri = "tcp4://127.0.0.1:26363",
58 ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Eric Newberry0c3e57b2018-01-25 20:54:46 -070059 ndn::optional<time::nanoseconds> baseCongestionMarkingInterval = {},
60 ndn::optional<uint64_t> defaultCongestionThreshold = {},
Eric Newberry2642cd22017-07-13 21:34:53 -040061 bool enableLocalFields = false,
Eric Newberry0c3e57b2018-01-25 20:54:46 -070062 bool enableReliability = false,
63 boost::logic::tribool enableCongestionMarking = boost::logic::indeterminate)
Eric Newberryb5aa7f52016-09-03 20:36:12 -070064 {
65 ControlParameters params;
66 params.setUri(uri);
67 params.setFacePersistency(persistency);
Eric Newberry0c3e57b2018-01-25 20:54:46 -070068
69 if (baseCongestionMarkingInterval) {
70 params.setBaseCongestionMarkingInterval(*baseCongestionMarkingInterval);
71 }
72
73 if (defaultCongestionThreshold) {
74 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
75 }
76
Eric Newberryb5aa7f52016-09-03 20:36:12 -070077 params.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, enableLocalFields);
Eric Newberry2642cd22017-07-13 21:34:53 -040078 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, enableReliability);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070079
Eric Newberry0c3e57b2018-01-25 20:54:46 -070080 if (!boost::logic::indeterminate(enableCongestionMarking)) {
81 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, enableCongestionMarking);
82 }
83
Yanbiao Li58ba3f92017-02-15 14:27:18 +000084 createFace(params);
85 }
86
87 void
88 createFace(const ControlParameters& createParams,
89 bool isForOnDemandFace = false)
90 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +000091 Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", createParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070092
Yanbiao Li58ba3f92017-02-15 14:27:18 +000093 // if this creation if for on-demand face then create it on node2
94 FaceManagerCommandNode& target = isForOnDemandFace ? this->node2 : this->node1;
95
Eric Newberryb5aa7f52016-09-03 20:36:12 -070096 bool hasCallbackFired = false;
Yanbiao Li58ba3f92017-02-15 14:27:18 +000097 signal::ScopedConnection connection = target.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +000098 [&, req, isForOnDemandFace, this] (const Data& response) {
99 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700100 return;
101 }
102
103 ControlResponse create(response.getContent().blockFromValue());
104 BOOST_REQUIRE_EQUAL(create.getCode(), 200);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000105 BOOST_REQUIRE(create.getBody().hasWire());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700106
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000107 ControlParameters faceParams(create.getBody());
108 BOOST_REQUIRE(faceParams.hasFaceId());
109 this->faceId = faceParams.getFaceId();
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700110
111 hasCallbackFired = true;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000112
113 if (isForOnDemandFace) {
114 auto face = target.faceTable.get(static_cast<FaceId>(this->faceId));
115
116 // to force creation of on-demand face
117 face->sendInterest(*make_shared<Interest>("/hello/world"));
118 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700119 });
120
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000121 target.face.receive(req);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700122 this->advanceClocks(time::milliseconds(1), 5);
123
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000124 if (isForOnDemandFace) {
125 std::this_thread::sleep_for(std::chrono::milliseconds(100)); // allow wallclock time for socket IO
126 this->advanceClocks(time::milliseconds(1), 5); // let node1 accept Interest and create on-demand face
127 }
128
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700129 BOOST_REQUIRE(hasCallbackFired);
130 }
131
132 void
133 updateFace(const ControlParameters& requestParams,
134 bool isSelfUpdating,
135 const function<void(const ControlResponse& resp)>& checkResp)
136 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000137 Interest req = makeControlCommandRequest("/localhost/nfd/faces/update", requestParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700138 if (isSelfUpdating) {
139 // Attach IncomingFaceIdTag to interest
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000140 req.setTag(make_shared<lp::IncomingFaceIdTag>(faceId));
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700141 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700142
143 bool hasCallbackFired = false;
144 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Davide Pesaventoac238f22017-09-12 15:19:40 -0400145 [req, &hasCallbackFired, &checkResp] (const Data& response) {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000146 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700147 return;
148 }
149
150 ControlResponse actual(response.getContent().blockFromValue());
151 checkResp(actual);
152
153 hasCallbackFired = true;
154 });
155
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000156 this->node1.face.receive(req);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700157 this->advanceClocks(time::milliseconds(1), 5);
158
159 BOOST_CHECK(hasCallbackFired);
160 }
161
162private:
163 void
164 destroyFace()
165 {
166 if (faceId == 0) {
167 return;
168 }
169
170 ControlParameters params;
171 params.setFaceId(faceId);
172
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000173 Interest req = makeControlCommandRequest("/localhost/nfd/faces/destroy", params);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700174
175 bool hasCallbackFired = false;
176 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000177 [this, req, &hasCallbackFired] (const Data& response) {
178 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700179 return;
180 }
181
182 ControlResponse destroy(response.getContent().blockFromValue());
183 BOOST_CHECK_EQUAL(destroy.getCode(), 200);
184
185 faceId = 0;
186 hasCallbackFired = true;
187 });
188
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000189 this->node1.face.receive(req);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700190 this->advanceClocks(time::milliseconds(1), 5);
191
192 BOOST_CHECK(hasCallbackFired);
193 }
194
195public:
196 FaceId faceId;
197};
198
199BOOST_FIXTURE_TEST_SUITE(UpdateFace, FaceManagerUpdateFixture)
200
201BOOST_AUTO_TEST_CASE(FaceDoesNotExist)
202{
203 ControlParameters requestParams;
204 requestParams.setFaceId(65535);
205
206 updateFace(requestParams, false, [] (const ControlResponse& actual) {
207 ControlResponse expected(404, "Specified face does not exist");
208 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
209 BOOST_TEST_MESSAGE(actual.getText());
210 });
211}
212
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000213template<bool CAN_CHANGE_PERSISTENCY>
214class UpdatePersistencyDummyTransport : public face::Transport
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700215{
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000216public:
217 UpdatePersistencyDummyTransport()
218 {
219 this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
220 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700221
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000222protected:
223 bool
224 canChangePersistencyToImpl(ndn::nfd::FacePersistency newPersistency) const override
225 {
226 return CAN_CHANGE_PERSISTENCY;
227 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700228
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000229 void
230 doClose() override
231 {
232 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700233
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000234private:
235 void
236 doSend(face::Transport::Packet&& packet) override
237 {
238 }
239};
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700240
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000241namespace mpl = boost::mpl;
242
243using UpdatePersistencyTests =
244 mpl::vector<mpl::pair<UpdatePersistencyDummyTransport<true>, CommandSuccess>,
245 mpl::pair<UpdatePersistencyDummyTransport<false>, CommandFailure<409>>>;
246
247BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePersistency, T, UpdatePersistencyTests, FaceManagerUpdateFixture)
248{
249 using TransportType = typename T::first;
250 using ResultType = typename T::second;
251
252 auto face = make_shared<face::Face>(make_unique<face::GenericLinkService>(),
253 make_unique<TransportType>());
254 this->node1.faceTable.add(face);
255
256 auto parameters = ControlParameters()
257 .setFaceId(face->getId())
258 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
259
260 updateFace(parameters, false, [] (const ControlResponse& actual) {
261 BOOST_TEST_MESSAGE(actual.getText());
262 BOOST_CHECK_EQUAL(actual.getCode(), ResultType::getExpected().getCode());
263
264 // the response for either 200 or 409 will have a content body
265 BOOST_REQUIRE(actual.getBody().hasWire());
266
267 ControlParameters resp;
268 resp.wireDecode(actual.getBody());
269 BOOST_CHECK_EQUAL(resp.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700270 });
271}
272
273class TcpLocalFieldsEnable
274{
275public:
276 std::string
277 getUri()
278 {
279 return "tcp4://127.0.0.1:26363";
280 }
281
282 boost::asio::ip::address_v4
283 getIpAddress()
284 {
285 return boost::asio::ip::address_v4::from_string("127.0.0.1");
286 }
287
288 ndn::nfd::FacePersistency
289 getPersistency()
290 {
291 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
292 }
293
294 bool
295 getInitLocalFieldsEnabled()
296 {
297 return false;
298 }
299
300 bool
301 getLocalFieldsEnabled()
302 {
303 return true;
304 }
305
306 bool
307 getLocalFieldsEnabledMask()
308 {
309 return true;
310 }
311
312 bool
313 shouldHaveWire()
314 {
315 return false;
316 }
317};
318
319class TcpLocalFieldsDisable
320{
321public:
322 std::string
323 getUri()
324 {
325 return "tcp4://127.0.0.1:26363";
326 }
327
328 ndn::nfd::FacePersistency
329 getPersistency()
330 {
331 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
332 }
333
334 bool
335 getInitLocalFieldsEnabled()
336 {
337 return true;
338 }
339
340 bool
341 getLocalFieldsEnabled()
342 {
343 return false;
344 }
345
346 bool
347 getLocalFieldsEnabledMask()
348 {
349 return true;
350 }
351
352 bool
353 shouldHaveWire()
354 {
355 return false;
356 }
357};
358
359// UDP faces are non-local by definition
360class UdpLocalFieldsEnable
361{
362public:
363 std::string
364 getUri()
365 {
366 return "udp4://127.0.0.1:26363";
367 }
368
369 ndn::nfd::FacePersistency
370 getPersistency()
371 {
372 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
373 }
374
375 bool
376 getInitLocalFieldsEnabled()
377 {
378 return false;
379 }
380
381 bool
382 getLocalFieldsEnabled()
383 {
384 return true;
385 }
386
387 bool
388 getLocalFieldsEnabledMask()
389 {
390 return true;
391 }
392
393 bool
394 shouldHaveWire()
395 {
396 return true;
397 }
398};
399
400// UDP faces are non-local by definition
401// In this test case, attempt to disable local fields on face with local fields already disabled
402class UdpLocalFieldsDisable
403{
404public:
405 std::string
406 getUri()
407 {
408 return "udp4://127.0.0.1:26363";
409 }
410
411 ndn::nfd::FacePersistency
412 getPersistency()
413 {
414 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
415 }
416
417 bool
418 getInitLocalFieldsEnabled()
419 {
420 return false;
421 }
422
423 bool
424 getLocalFieldsEnabled()
425 {
426 return false;
427 }
428
429 bool
430 getLocalFieldsEnabledMask()
431 {
432 return true;
433 }
434
435 bool
436 shouldHaveWire()
437 {
438 return false;
439 }
440};
441
442// In this test case, set Flags to enable local fields on non-local face, but exclude local fields
443// from Mask. This test case will pass as no action is taken due to the missing Mask bit.
444class UdpLocalFieldsEnableNoMaskBit
445{
446public:
447 std::string
448 getUri()
449 {
450 return "udp4://127.0.0.1:26363";
451 }
452
453 ndn::nfd::FacePersistency
454 getPersistency()
455 {
456 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
457 }
458
459 bool
460 getInitLocalFieldsEnabled()
461 {
462 return false;
463 }
464
465 bool
466 getLocalFieldsEnabled()
467 {
468 return true;
469 }
470
471 bool
472 getLocalFieldsEnabledMask()
473 {
474 return false;
475 }
476
477 bool
478 shouldHaveWire()
479 {
480 return false;
481 }
482};
483
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700484typedef mpl::vector<mpl::pair<TcpLocalFieldsEnable, CommandSuccess>,
485 mpl::pair<TcpLocalFieldsDisable, CommandSuccess>,
486 mpl::pair<UdpLocalFieldsEnable, CommandFailure<409>>,
487 mpl::pair<UdpLocalFieldsDisable, CommandSuccess>,
488 mpl::pair<UdpLocalFieldsEnableNoMaskBit, CommandSuccess>> LocalFieldFaces;
489
490BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateLocalFields, T, LocalFieldFaces)
491{
492 typedef typename T::first TestType;
493 typedef typename T::second ResultType;
494
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700495 createFace(TestType().getUri(), TestType().getPersistency(), {}, {},
496 TestType().getInitLocalFieldsEnabled());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700497
498 ControlParameters requestParams;
499 requestParams.setFaceId(faceId);
500 requestParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, TestType().getLocalFieldsEnabled());
501 if (!TestType().getLocalFieldsEnabledMask()) {
502 requestParams.unsetFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED);
503 }
504
505 updateFace(requestParams, false, [] (const ControlResponse& actual) {
506 ControlResponse expected(ResultType().getExpected().getCode(), "");
507 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
508 BOOST_TEST_MESSAGE(actual.getText());
509
510 if (TestType().shouldHaveWire() && actual.getBody().hasWire()) {
511 ControlParameters actualParams(actual.getBody());
512
513 BOOST_CHECK(!actualParams.hasFacePersistency());
514 BOOST_CHECK(actualParams.hasFlags());
515 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
516 BOOST_CHECK(actualParams.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
517 }
518 });
519}
520
521BOOST_AUTO_TEST_CASE(UpdateLocalFieldsEnableDisable)
522{
523 createFace();
524
525 ControlParameters enableParams;
526 enableParams.setFaceId(faceId);
527 enableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true);
528
529 ControlParameters disableParams;
530 disableParams.setFaceId(faceId);
531 disableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false);
532
533 updateFace(enableParams, false, [] (const ControlResponse& actual) {
534 ControlResponse expected(200, "OK");
535 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
536 BOOST_TEST_MESSAGE(actual.getText());
537
538 if (actual.getBody().hasWire()) {
539 ControlParameters actualParams(actual.getBody());
540
541 BOOST_CHECK(actualParams.hasFaceId());
542 BOOST_CHECK(actualParams.hasFacePersistency());
543 BOOST_REQUIRE(actualParams.hasFlags());
544 // Check if flags indicate local fields enabled
545 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
546 }
547 else {
548 BOOST_ERROR("Enable: Response does not contain ControlParameters");
549 }
550 });
551
552 updateFace(disableParams, false, [] (const ControlResponse& actual) {
553 ControlResponse expected(200, "OK");
554 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
555 BOOST_TEST_MESSAGE(actual.getText());
556
557 if (actual.getBody().hasWire()) {
558 ControlParameters actualParams(actual.getBody());
559
560 BOOST_CHECK(actualParams.hasFaceId());
561 BOOST_CHECK(actualParams.hasFacePersistency());
562 BOOST_REQUIRE(actualParams.hasFlags());
563 // Check if flags indicate local fields disabled
564 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
565 }
566 else {
567 BOOST_ERROR("Disable: Response does not contain ControlParameters");
568 }
569 });
570}
571
Eric Newberry2642cd22017-07-13 21:34:53 -0400572BOOST_AUTO_TEST_CASE(UpdateReliabilityEnableDisable)
573{
574 createFace("udp4://127.0.0.1:26363");
575
576 ControlParameters enableParams;
577 enableParams.setFaceId(faceId);
578 enableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true);
579
580 ControlParameters disableParams;
581 disableParams.setFaceId(faceId);
582 disableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false);
583
584 updateFace(enableParams, false, [] (const ControlResponse& actual) {
585 ControlResponse expected(200, "OK");
586 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
587 BOOST_TEST_MESSAGE(actual.getText());
588
589 if (actual.getBody().hasWire()) {
590 ControlParameters actualParams(actual.getBody());
591
592 BOOST_CHECK(actualParams.hasFaceId());
593 BOOST_CHECK(actualParams.hasFacePersistency());
594 BOOST_REQUIRE(actualParams.hasFlags());
595 // Check if flags indicate reliability enabled
596 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
597 }
598 else {
599 BOOST_ERROR("Enable: Response does not contain ControlParameters");
600 }
601 });
602
603 updateFace(disableParams, false, [] (const ControlResponse& actual) {
604 ControlResponse expected(200, "OK");
605 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
606 BOOST_TEST_MESSAGE(actual.getText());
607
608 if (actual.getBody().hasWire()) {
609 ControlParameters actualParams(actual.getBody());
610
611 BOOST_CHECK(actualParams.hasFaceId());
612 BOOST_CHECK(actualParams.hasFacePersistency());
613 BOOST_REQUIRE(actualParams.hasFlags());
614 // Check if flags indicate reliability disabled
615 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
616 }
617 else {
618 BOOST_ERROR("Disable: Response does not contain ControlParameters");
619 }
620 });
621}
622
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700623BOOST_AUTO_TEST_CASE(UpdateCongestionMarkingEnableDisable)
624{
625 createFace("udp4://127.0.0.1:26363");
626
627 ControlParameters enableParams;
628 enableParams.setFaceId(faceId);
629 enableParams.setBaseCongestionMarkingInterval(time::milliseconds(50));
630 enableParams.setDefaultCongestionThreshold(10000);
631 enableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true);
632
633 ControlParameters disableParams;
634 disableParams.setFaceId(faceId);
635 disableParams.setBaseCongestionMarkingInterval(time::milliseconds(70));
636 disableParams.setDefaultCongestionThreshold(5000);
637 disableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false);
638
639 updateFace(enableParams, false, [] (const ControlResponse& actual) {
640 ControlResponse expected(200, "OK");
641 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
642 BOOST_TEST_MESSAGE(actual.getText());
643
644 if (actual.getBody().hasWire()) {
645 ControlParameters actualParams(actual.getBody());
646
647 BOOST_CHECK(actualParams.hasFaceId());
648 BOOST_CHECK(actualParams.hasFacePersistency());
649 // Check that congestion marking parameters changed
650 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
651 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), time::milliseconds(50));
652 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
653 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 10000);
654 BOOST_REQUIRE(actualParams.hasFlags());
655 // Check if flags indicate congestion marking enabled
656 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
657 }
658 else {
659 BOOST_ERROR("Enable: Response does not contain ControlParameters");
660 }
661 });
662
663 updateFace(disableParams, false, [] (const ControlResponse& actual) {
664 ControlResponse expected(200, "OK");
665 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
666 BOOST_TEST_MESSAGE(actual.getText());
667
668 if (actual.getBody().hasWire()) {
669 ControlParameters actualParams(actual.getBody());
670
671 BOOST_CHECK(actualParams.hasFaceId());
672 BOOST_CHECK(actualParams.hasFacePersistency());
673 // Check that congestion marking parameters changed, even though feature disabled
674 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
675 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), time::milliseconds(70));
676 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
677 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 5000);
678 BOOST_REQUIRE(actualParams.hasFlags());
679 // Check if flags indicate marking disabled
680 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
681 }
682 else {
683 BOOST_ERROR("Disable: Response does not contain ControlParameters");
684 }
685 });
686}
687
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700688BOOST_AUTO_TEST_CASE(SelfUpdating)
689{
690 createFace();
691
692 // Send a command that does nothing (will return 200) and does not contain a FaceId
693 ControlParameters sentParams;
694
695 updateFace(sentParams, true, [] (const ControlResponse& actual) {
696 ControlResponse expected(200, "OK");
697 BOOST_REQUIRE_EQUAL(actual.getCode(), expected.getCode());
698 BOOST_TEST_MESSAGE(actual.getText());
699 });
700}
701
702BOOST_AUTO_TEST_SUITE_END() // UpdateFace
703BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
704BOOST_AUTO_TEST_SUITE_END() // Mgmt
705
706} // namespace tests
707} // namespace nfd