blob: 89031fded1ee60f838d0ecce595c4c9923c3ffb5 [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/*
Davide Pesaventob7bfcb92022-05-22 23:55:23 -04003 * Copyright (c) 2014-2022, 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"
Davide Pesavento16916ae2019-03-29 23:53:26 -040028
Eric Newberryb5aa7f52016-09-03 20:36:12 -070029#include "face-manager-command-fixture.hpp"
Davide Pesavento16916ae2019-03-29 23:53:26 -040030#include "tests/daemon/face/dummy-transport.hpp"
Yanbiao Li58ba3f92017-02-15 14:27:18 +000031
Junxiao Shicbc8e942016-09-06 03:17:45 +000032#include <ndn-cxx/lp/tags.hpp>
Eric Newberryb5aa7f52016-09-03 20:36:12 -070033
Yanbiao Li58ba3f92017-02-15 14:27:18 +000034#include <thread>
35
Eric Newberry0c3e57b2018-01-25 20:54:46 -070036#include <boost/logic/tribool.hpp>
37
Eric Newberryb5aa7f52016-09-03 20:36:12 -070038namespace nfd {
39namespace tests {
40
41BOOST_AUTO_TEST_SUITE(Mgmt)
42BOOST_AUTO_TEST_SUITE(TestFaceManager)
43
Davide Pesavento3cf75dc2018-03-17 00:38:03 -040044namespace mpl = boost::mpl;
45
Eric Newberryb5aa7f52016-09-03 20:36:12 -070046class FaceManagerUpdateFixture : public FaceManagerCommandFixture
47{
48public:
Davide Pesavento22085362021-03-18 22:08:03 -040049 ~FaceManagerUpdateFixture() override
Eric Newberryb5aa7f52016-09-03 20:36:12 -070050 {
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,
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040057 std::optional<time::nanoseconds> baseCongestionMarkingInterval = std::nullopt,
58 std::optional<uint64_t> defaultCongestionThreshold = std::nullopt,
Eric Newberry2642cd22017-07-13 21:34:53 -040059 bool enableLocalFields = false,
Eric Newberry0c3e57b2018-01-25 20:54:46 -070060 bool enableReliability = false,
61 boost::logic::tribool enableCongestionMarking = boost::logic::indeterminate)
Eric Newberryb5aa7f52016-09-03 20:36:12 -070062 {
63 ControlParameters params;
64 params.setUri(uri);
65 params.setFacePersistency(persistency);
Eric Newberry0c3e57b2018-01-25 20:54:46 -070066
67 if (baseCongestionMarkingInterval) {
68 params.setBaseCongestionMarkingInterval(*baseCongestionMarkingInterval);
69 }
70
71 if (defaultCongestionThreshold) {
72 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
73 }
74
Eric Newberryb5aa7f52016-09-03 20:36:12 -070075 params.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, enableLocalFields);
Eric Newberry2642cd22017-07-13 21:34:53 -040076 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, enableReliability);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070077
Eric Newberry0c3e57b2018-01-25 20:54:46 -070078 if (!boost::logic::indeterminate(enableCongestionMarking)) {
Davide Pesaventofa2aa502019-03-22 13:30:02 -040079 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, bool(enableCongestionMarking));
Eric Newberry0c3e57b2018-01-25 20:54:46 -070080 }
81
Yanbiao Li58ba3f92017-02-15 14:27:18 +000082 createFace(params);
83 }
84
85 void
Davide Pesavento3cf75dc2018-03-17 00:38:03 -040086 createFace(const ControlParameters& createParams, bool isForOnDemandFace = false)
Yanbiao Li58ba3f92017-02-15 14:27:18 +000087 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +000088 Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", createParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070089
Yanbiao Li58ba3f92017-02-15 14:27:18 +000090 // if this creation if for on-demand face then create it on node2
91 FaceManagerCommandNode& target = isForOnDemandFace ? this->node2 : this->node1;
92
Eric Newberryb5aa7f52016-09-03 20:36:12 -070093 bool hasCallbackFired = false;
Yanbiao Li58ba3f92017-02-15 14:27:18 +000094 signal::ScopedConnection connection = target.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +000095 [&, req, isForOnDemandFace, this] (const Data& response) {
96 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -070097 return;
98 }
99
100 ControlResponse create(response.getContent().blockFromValue());
101 BOOST_REQUIRE_EQUAL(create.getCode(), 200);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000102 BOOST_REQUIRE(create.getBody().hasWire());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700103
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000104 ControlParameters faceParams(create.getBody());
105 BOOST_REQUIRE(faceParams.hasFaceId());
106 this->faceId = faceParams.getFaceId();
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700107
108 hasCallbackFired = true;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000109
110 if (isForOnDemandFace) {
111 auto face = target.faceTable.get(static_cast<FaceId>(this->faceId));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000112 // to force creation of on-demand face
Davide Pesavento22085362021-03-18 22:08:03 -0400113 face->sendInterest(*makeInterest("/hello/world"));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000114 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700115 });
116
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000117 target.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400118 advanceClocks(1_ms, 5);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700119
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000120 if (isForOnDemandFace) {
121 std::this_thread::sleep_for(std::chrono::milliseconds(100)); // allow wallclock time for socket IO
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400122 advanceClocks(1_ms, 5); // let node1 accept Interest and create on-demand face
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000123 }
124
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700125 BOOST_REQUIRE(hasCallbackFired);
126 }
127
128 void
129 updateFace(const ControlParameters& requestParams,
130 bool isSelfUpdating,
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400131 const std::function<void(const ControlResponse& resp)>& checkResp)
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700132 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000133 Interest req = makeControlCommandRequest("/localhost/nfd/faces/update", requestParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700134 if (isSelfUpdating) {
135 // Attach IncomingFaceIdTag to interest
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000136 req.setTag(make_shared<lp::IncomingFaceIdTag>(faceId));
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700137 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700138
139 bool hasCallbackFired = false;
140 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Davide Pesaventoac238f22017-09-12 15:19:40 -0400141 [req, &hasCallbackFired, &checkResp] (const Data& response) {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000142 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700143 return;
144 }
145
146 ControlResponse actual(response.getContent().blockFromValue());
147 checkResp(actual);
148
149 hasCallbackFired = true;
150 });
151
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000152 this->node1.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400153 advanceClocks(1_ms, 5);
154 BOOST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700155 }
156
157private:
158 void
159 destroyFace()
160 {
161 if (faceId == 0) {
162 return;
163 }
164
165 ControlParameters params;
166 params.setFaceId(faceId);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000167 Interest req = makeControlCommandRequest("/localhost/nfd/faces/destroy", params);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700168
169 bool hasCallbackFired = false;
170 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000171 [this, req, &hasCallbackFired] (const Data& response) {
172 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700173 return;
174 }
175
176 ControlResponse destroy(response.getContent().blockFromValue());
177 BOOST_CHECK_EQUAL(destroy.getCode(), 200);
178
179 faceId = 0;
180 hasCallbackFired = true;
181 });
182
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000183 this->node1.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400184 advanceClocks(1_ms, 5);
185 BOOST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700186 }
187
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400188protected:
189 FaceId faceId = 0;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700190};
191
192BOOST_FIXTURE_TEST_SUITE(UpdateFace, FaceManagerUpdateFixture)
193
194BOOST_AUTO_TEST_CASE(FaceDoesNotExist)
195{
196 ControlParameters requestParams;
197 requestParams.setFaceId(65535);
198
199 updateFace(requestParams, false, [] (const ControlResponse& actual) {
200 ControlResponse expected(404, "Specified face does not exist");
201 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
202 BOOST_TEST_MESSAGE(actual.getText());
203 });
204}
205
Davide Pesavento16916ae2019-03-29 23:53:26 -0400206using nfd::face::tests::DummyTransportBase;
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400207using UpdatePersistencyTests = mpl::vector<
Davide Pesavento16916ae2019-03-29 23:53:26 -0400208 mpl::pair<DummyTransportBase<true>, CommandSuccess>,
209 mpl::pair<DummyTransportBase<false>, CommandFailure<409>>
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400210>;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000211
212BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePersistency, T, UpdatePersistencyTests, FaceManagerUpdateFixture)
213{
214 using TransportType = typename T::first;
215 using ResultType = typename T::second;
216
217 auto face = make_shared<face::Face>(make_unique<face::GenericLinkService>(),
218 make_unique<TransportType>());
219 this->node1.faceTable.add(face);
220
221 auto parameters = ControlParameters()
222 .setFaceId(face->getId())
223 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
224
225 updateFace(parameters, false, [] (const ControlResponse& actual) {
226 BOOST_TEST_MESSAGE(actual.getText());
227 BOOST_CHECK_EQUAL(actual.getCode(), ResultType::getExpected().getCode());
228
229 // the response for either 200 or 409 will have a content body
230 BOOST_REQUIRE(actual.getBody().hasWire());
231
232 ControlParameters resp;
233 resp.wireDecode(actual.getBody());
234 BOOST_CHECK_EQUAL(resp.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700235 });
236}
237
Eric Newberry13ff2592020-03-06 17:32:29 -0800238BOOST_AUTO_TEST_CASE(UpdateMtu)
239{
240 createFace("udp4://127.0.0.1:26363");
241
242 ControlParameters validParams;
243 validParams.setFaceId(faceId);
244 validParams.setMtu(4000);
245
246 ControlParameters mtuTooLow;
247 mtuTooLow.setFaceId(faceId);
248 mtuTooLow.setMtu(63);
249
250 updateFace(validParams, false, [] (const ControlResponse& actual) {
251 BOOST_CHECK_EQUAL(actual.getCode(), 200);
252 BOOST_TEST_MESSAGE(actual.getText());
253
254 if (actual.getBody().hasWire()) {
255 ControlParameters actualParams(actual.getBody());
256
257 BOOST_CHECK(actualParams.hasFaceId());
258 BOOST_REQUIRE(actualParams.hasMtu());
259 // Check for changed MTU
260 BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000);
261 }
262 else {
263 BOOST_ERROR("Valid: Response does not contain ControlParameters");
264 }
265 });
266
267 updateFace(mtuTooLow, false, [] (const ControlResponse& actual) {
268 BOOST_CHECK_EQUAL(actual.getCode(), 409);
269 BOOST_TEST_MESSAGE(actual.getText());
270
271 if (actual.getBody().hasWire()) {
272 ControlParameters actualParams(actual.getBody());
273
274 BOOST_CHECK(!actualParams.hasFaceId());
275 BOOST_REQUIRE(actualParams.hasMtu());
276 // Check for returned invalid parameter
277 BOOST_CHECK_EQUAL(actualParams.getMtu(), 63);
278 }
279 else {
280 BOOST_ERROR("Too low: Response does not contain ControlParameters");
281 }
282 });
283}
284
285BOOST_AUTO_TEST_CASE(UpdateMtuUnsupportedFace)
286{
287 createFace("tcp4://127.0.0.1:26363");
288
289 ControlParameters updateParams;
290 updateParams.setFaceId(faceId);
291 updateParams.setMtu(4000);
292
293 updateFace(updateParams, false, [] (const ControlResponse& actual) {
294 BOOST_CHECK_EQUAL(actual.getCode(), 409);
295 BOOST_TEST_MESSAGE(actual.getText());
296
297 if (actual.getBody().hasWire()) {
298 ControlParameters actualParams(actual.getBody());
299
300 BOOST_CHECK(!actualParams.hasFaceId());
301 BOOST_REQUIRE(actualParams.hasMtu());
302 // Check for returned invalid parameter
303 BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000);
304 }
305 else {
306 BOOST_ERROR("Response does not contain ControlParameters");
307 }
308 });
309}
310
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700311class TcpLocalFieldsEnable
312{
313public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400314 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700315 getUri()
316 {
317 return "tcp4://127.0.0.1:26363";
318 }
319
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400320 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700321 getPersistency()
322 {
323 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
324 }
325
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400326 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700327 getInitLocalFieldsEnabled()
328 {
329 return false;
330 }
331
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400332 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700333 getLocalFieldsEnabled()
334 {
335 return true;
336 }
337
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400338 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700339 getLocalFieldsEnabledMask()
340 {
341 return true;
342 }
343
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400344 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700345 shouldHaveWire()
346 {
347 return false;
348 }
349};
350
351class TcpLocalFieldsDisable
352{
353public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400354 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700355 getUri()
356 {
357 return "tcp4://127.0.0.1:26363";
358 }
359
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400360 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700361 getPersistency()
362 {
363 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
364 }
365
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400366 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700367 getInitLocalFieldsEnabled()
368 {
369 return true;
370 }
371
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400372 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700373 getLocalFieldsEnabled()
374 {
375 return false;
376 }
377
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400378 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700379 getLocalFieldsEnabledMask()
380 {
381 return true;
382 }
383
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400384 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700385 shouldHaveWire()
386 {
387 return false;
388 }
389};
390
391// UDP faces are non-local by definition
392class UdpLocalFieldsEnable
393{
394public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400395 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700396 getUri()
397 {
398 return "udp4://127.0.0.1:26363";
399 }
400
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400401 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700402 getPersistency()
403 {
404 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
405 }
406
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400407 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700408 getInitLocalFieldsEnabled()
409 {
410 return false;
411 }
412
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400413 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700414 getLocalFieldsEnabled()
415 {
416 return true;
417 }
418
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400419 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700420 getLocalFieldsEnabledMask()
421 {
422 return true;
423 }
424
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400425 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700426 shouldHaveWire()
427 {
428 return true;
429 }
430};
431
432// UDP faces are non-local by definition
433// In this test case, attempt to disable local fields on face with local fields already disabled
434class UdpLocalFieldsDisable
435{
436public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400437 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700438 getUri()
439 {
440 return "udp4://127.0.0.1:26363";
441 }
442
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400443 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700444 getPersistency()
445 {
446 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
447 }
448
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400449 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700450 getInitLocalFieldsEnabled()
451 {
452 return false;
453 }
454
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400455 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700456 getLocalFieldsEnabled()
457 {
458 return false;
459 }
460
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400461 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700462 getLocalFieldsEnabledMask()
463 {
464 return true;
465 }
466
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400467 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700468 shouldHaveWire()
469 {
470 return false;
471 }
472};
473
474// In this test case, set Flags to enable local fields on non-local face, but exclude local fields
475// from Mask. This test case will pass as no action is taken due to the missing Mask bit.
476class UdpLocalFieldsEnableNoMaskBit
477{
478public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400479 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700480 getUri()
481 {
482 return "udp4://127.0.0.1:26363";
483 }
484
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400485 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700486 getPersistency()
487 {
488 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
489 }
490
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400491 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700492 getInitLocalFieldsEnabled()
493 {
494 return false;
495 }
496
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400497 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700498 getLocalFieldsEnabled()
499 {
500 return true;
501 }
502
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400503 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700504 getLocalFieldsEnabledMask()
505 {
506 return false;
507 }
508
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400509 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700510 shouldHaveWire()
511 {
512 return false;
513 }
514};
515
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400516using LocalFieldFaces = mpl::vector<
517 mpl::pair<TcpLocalFieldsEnable, CommandSuccess>,
518 mpl::pair<TcpLocalFieldsDisable, CommandSuccess>,
519 mpl::pair<UdpLocalFieldsEnable, CommandFailure<409>>,
520 mpl::pair<UdpLocalFieldsDisable, CommandSuccess>,
521 mpl::pair<UdpLocalFieldsEnableNoMaskBit, CommandSuccess>
522>;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700523
524BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateLocalFields, T, LocalFieldFaces)
525{
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400526 using TestType = typename T::first;
527 using ResultType = typename T::second;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700528
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400529 createFace(TestType::getUri(), TestType::getPersistency(), {}, {},
530 TestType::getInitLocalFieldsEnabled());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700531
532 ControlParameters requestParams;
533 requestParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400534 requestParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, TestType::getLocalFieldsEnabled());
535 if (!TestType::getLocalFieldsEnabledMask()) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700536 requestParams.unsetFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED);
537 }
538
539 updateFace(requestParams, false, [] (const ControlResponse& actual) {
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400540 ControlResponse expected(ResultType::getExpected());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700541 BOOST_TEST_MESSAGE(actual.getText());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400542 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700543
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400544 if (TestType::shouldHaveWire() && actual.getBody().hasWire()) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700545 ControlParameters actualParams(actual.getBody());
546
547 BOOST_CHECK(!actualParams.hasFacePersistency());
548 BOOST_CHECK(actualParams.hasFlags());
549 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
550 BOOST_CHECK(actualParams.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
551 }
552 });
553}
554
555BOOST_AUTO_TEST_CASE(UpdateLocalFieldsEnableDisable)
556{
557 createFace();
558
559 ControlParameters enableParams;
560 enableParams.setFaceId(faceId);
561 enableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true);
562
563 ControlParameters disableParams;
564 disableParams.setFaceId(faceId);
565 disableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false);
566
567 updateFace(enableParams, false, [] (const ControlResponse& actual) {
568 ControlResponse expected(200, "OK");
569 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
570 BOOST_TEST_MESSAGE(actual.getText());
571
572 if (actual.getBody().hasWire()) {
573 ControlParameters actualParams(actual.getBody());
574
575 BOOST_CHECK(actualParams.hasFaceId());
576 BOOST_CHECK(actualParams.hasFacePersistency());
577 BOOST_REQUIRE(actualParams.hasFlags());
578 // Check if flags indicate local fields enabled
579 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
580 }
581 else {
582 BOOST_ERROR("Enable: Response does not contain ControlParameters");
583 }
584 });
585
586 updateFace(disableParams, false, [] (const ControlResponse& actual) {
587 ControlResponse expected(200, "OK");
588 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
589 BOOST_TEST_MESSAGE(actual.getText());
590
591 if (actual.getBody().hasWire()) {
592 ControlParameters actualParams(actual.getBody());
593
594 BOOST_CHECK(actualParams.hasFaceId());
595 BOOST_CHECK(actualParams.hasFacePersistency());
596 BOOST_REQUIRE(actualParams.hasFlags());
597 // Check if flags indicate local fields disabled
598 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
599 }
600 else {
601 BOOST_ERROR("Disable: Response does not contain ControlParameters");
602 }
603 });
604}
605
Eric Newberry2642cd22017-07-13 21:34:53 -0400606BOOST_AUTO_TEST_CASE(UpdateReliabilityEnableDisable)
607{
608 createFace("udp4://127.0.0.1:26363");
609
610 ControlParameters enableParams;
611 enableParams.setFaceId(faceId);
612 enableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true);
613
614 ControlParameters disableParams;
615 disableParams.setFaceId(faceId);
616 disableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false);
617
618 updateFace(enableParams, false, [] (const ControlResponse& actual) {
619 ControlResponse expected(200, "OK");
620 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
621 BOOST_TEST_MESSAGE(actual.getText());
622
623 if (actual.getBody().hasWire()) {
624 ControlParameters actualParams(actual.getBody());
625
626 BOOST_CHECK(actualParams.hasFaceId());
627 BOOST_CHECK(actualParams.hasFacePersistency());
628 BOOST_REQUIRE(actualParams.hasFlags());
629 // Check if flags indicate reliability enabled
630 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
631 }
632 else {
633 BOOST_ERROR("Enable: Response does not contain ControlParameters");
634 }
635 });
636
637 updateFace(disableParams, false, [] (const ControlResponse& actual) {
638 ControlResponse expected(200, "OK");
639 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
640 BOOST_TEST_MESSAGE(actual.getText());
641
642 if (actual.getBody().hasWire()) {
643 ControlParameters actualParams(actual.getBody());
644
645 BOOST_CHECK(actualParams.hasFaceId());
646 BOOST_CHECK(actualParams.hasFacePersistency());
647 BOOST_REQUIRE(actualParams.hasFlags());
648 // Check if flags indicate reliability disabled
649 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
650 }
651 else {
652 BOOST_ERROR("Disable: Response does not contain ControlParameters");
653 }
654 });
655}
656
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700657BOOST_AUTO_TEST_CASE(UpdateCongestionMarkingEnableDisable)
658{
659 createFace("udp4://127.0.0.1:26363");
660
661 ControlParameters enableParams;
662 enableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400663 enableParams.setBaseCongestionMarkingInterval(50_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700664 enableParams.setDefaultCongestionThreshold(10000);
665 enableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true);
666
667 ControlParameters disableParams;
668 disableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400669 disableParams.setBaseCongestionMarkingInterval(70_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700670 disableParams.setDefaultCongestionThreshold(5000);
671 disableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false);
672
673 updateFace(enableParams, false, [] (const ControlResponse& actual) {
674 ControlResponse expected(200, "OK");
675 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
676 BOOST_TEST_MESSAGE(actual.getText());
677
678 if (actual.getBody().hasWire()) {
679 ControlParameters actualParams(actual.getBody());
680
681 BOOST_CHECK(actualParams.hasFaceId());
682 BOOST_CHECK(actualParams.hasFacePersistency());
683 // Check that congestion marking parameters changed
684 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400685 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 50_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700686 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
687 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 10000);
688 BOOST_REQUIRE(actualParams.hasFlags());
689 // Check if flags indicate congestion marking enabled
690 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
691 }
692 else {
693 BOOST_ERROR("Enable: Response does not contain ControlParameters");
694 }
695 });
696
697 updateFace(disableParams, false, [] (const ControlResponse& actual) {
698 ControlResponse expected(200, "OK");
699 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
700 BOOST_TEST_MESSAGE(actual.getText());
701
702 if (actual.getBody().hasWire()) {
703 ControlParameters actualParams(actual.getBody());
704
705 BOOST_CHECK(actualParams.hasFaceId());
706 BOOST_CHECK(actualParams.hasFacePersistency());
707 // Check that congestion marking parameters changed, even though feature disabled
708 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400709 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 70_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700710 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
711 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 5000);
712 BOOST_REQUIRE(actualParams.hasFlags());
713 // Check if flags indicate marking disabled
714 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
715 }
716 else {
717 BOOST_ERROR("Disable: Response does not contain ControlParameters");
718 }
719 });
720}
721
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700722BOOST_AUTO_TEST_CASE(SelfUpdating)
723{
724 createFace();
725
726 // Send a command that does nothing (will return 200) and does not contain a FaceId
727 ControlParameters sentParams;
728
729 updateFace(sentParams, true, [] (const ControlResponse& actual) {
730 ControlResponse expected(200, "OK");
731 BOOST_REQUIRE_EQUAL(actual.getCode(), expected.getCode());
732 BOOST_TEST_MESSAGE(actual.getText());
733 });
734}
735
736BOOST_AUTO_TEST_SUITE_END() // UpdateFace
737BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
738BOOST_AUTO_TEST_SUITE_END() // Mgmt
739
740} // namespace tests
741} // namespace nfd