blob: 600038051cf75e91175d87cd5e263f449f61c424 [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
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040038namespace nfd::tests {
Eric Newberryb5aa7f52016-09-03 20:36:12 -070039
40BOOST_AUTO_TEST_SUITE(Mgmt)
41BOOST_AUTO_TEST_SUITE(TestFaceManager)
42
Davide Pesavento3cf75dc2018-03-17 00:38:03 -040043namespace mpl = boost::mpl;
44
Eric Newberryb5aa7f52016-09-03 20:36:12 -070045class FaceManagerUpdateFixture : public FaceManagerCommandFixture
46{
47public:
Davide Pesavento22085362021-03-18 22:08:03 -040048 ~FaceManagerUpdateFixture() override
Eric Newberryb5aa7f52016-09-03 20:36:12 -070049 {
50 destroyFace();
51 }
52
53 void
54 createFace(const std::string& uri = "tcp4://127.0.0.1:26363",
55 ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040056 std::optional<time::nanoseconds> baseCongestionMarkingInterval = std::nullopt,
57 std::optional<uint64_t> defaultCongestionThreshold = std::nullopt,
Eric Newberry2642cd22017-07-13 21:34:53 -040058 bool enableLocalFields = false,
Eric Newberry0c3e57b2018-01-25 20:54:46 -070059 bool enableReliability = false,
60 boost::logic::tribool enableCongestionMarking = boost::logic::indeterminate)
Eric Newberryb5aa7f52016-09-03 20:36:12 -070061 {
62 ControlParameters params;
63 params.setUri(uri);
64 params.setFacePersistency(persistency);
Eric Newberry0c3e57b2018-01-25 20:54:46 -070065
66 if (baseCongestionMarkingInterval) {
67 params.setBaseCongestionMarkingInterval(*baseCongestionMarkingInterval);
68 }
69
70 if (defaultCongestionThreshold) {
71 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
72 }
73
Eric Newberryb5aa7f52016-09-03 20:36:12 -070074 params.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, enableLocalFields);
Eric Newberry2642cd22017-07-13 21:34:53 -040075 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, enableReliability);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070076
Eric Newberry0c3e57b2018-01-25 20:54:46 -070077 if (!boost::logic::indeterminate(enableCongestionMarking)) {
Davide Pesaventofa2aa502019-03-22 13:30:02 -040078 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, bool(enableCongestionMarking));
Eric Newberry0c3e57b2018-01-25 20:54:46 -070079 }
80
Yanbiao Li58ba3f92017-02-15 14:27:18 +000081 createFace(params);
82 }
83
84 void
Davide Pesavento3cf75dc2018-03-17 00:38:03 -040085 createFace(const ControlParameters& createParams, bool isForOnDemandFace = false)
Yanbiao Li58ba3f92017-02-15 14:27:18 +000086 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +000087 Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", createParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070088
Yanbiao Li58ba3f92017-02-15 14:27:18 +000089 // if this creation if for on-demand face then create it on node2
90 FaceManagerCommandNode& target = isForOnDemandFace ? this->node2 : this->node1;
91
Eric Newberryb5aa7f52016-09-03 20:36:12 -070092 bool hasCallbackFired = false;
Yanbiao Li58ba3f92017-02-15 14:27:18 +000093 signal::ScopedConnection connection = target.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +000094 [&, req, isForOnDemandFace, this] (const Data& response) {
95 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -070096 return;
97 }
98
99 ControlResponse create(response.getContent().blockFromValue());
100 BOOST_REQUIRE_EQUAL(create.getCode(), 200);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000101 BOOST_REQUIRE(create.getBody().hasWire());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700102
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000103 ControlParameters faceParams(create.getBody());
104 BOOST_REQUIRE(faceParams.hasFaceId());
105 this->faceId = faceParams.getFaceId();
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700106
107 hasCallbackFired = true;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000108
109 if (isForOnDemandFace) {
110 auto face = target.faceTable.get(static_cast<FaceId>(this->faceId));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000111 // to force creation of on-demand face
Davide Pesavento22085362021-03-18 22:08:03 -0400112 face->sendInterest(*makeInterest("/hello/world"));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000113 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700114 });
115
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000116 target.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400117 advanceClocks(1_ms, 5);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700118
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000119 if (isForOnDemandFace) {
120 std::this_thread::sleep_for(std::chrono::milliseconds(100)); // allow wallclock time for socket IO
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400121 advanceClocks(1_ms, 5); // let node1 accept Interest and create on-demand face
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000122 }
123
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700124 BOOST_REQUIRE(hasCallbackFired);
125 }
126
127 void
128 updateFace(const ControlParameters& requestParams,
129 bool isSelfUpdating,
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400130 const std::function<void(const ControlResponse& resp)>& checkResp)
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700131 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000132 Interest req = makeControlCommandRequest("/localhost/nfd/faces/update", requestParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700133 if (isSelfUpdating) {
134 // Attach IncomingFaceIdTag to interest
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000135 req.setTag(make_shared<lp::IncomingFaceIdTag>(faceId));
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700136 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700137
138 bool hasCallbackFired = false;
139 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Davide Pesaventoac238f22017-09-12 15:19:40 -0400140 [req, &hasCallbackFired, &checkResp] (const Data& response) {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000141 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700142 return;
143 }
144
145 ControlResponse actual(response.getContent().blockFromValue());
146 checkResp(actual);
147
148 hasCallbackFired = true;
149 });
150
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000151 this->node1.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400152 advanceClocks(1_ms, 5);
153 BOOST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700154 }
155
156private:
157 void
158 destroyFace()
159 {
160 if (faceId == 0) {
161 return;
162 }
163
164 ControlParameters params;
165 params.setFaceId(faceId);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000166 Interest req = makeControlCommandRequest("/localhost/nfd/faces/destroy", params);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700167
168 bool hasCallbackFired = false;
169 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000170 [this, req, &hasCallbackFired] (const Data& response) {
171 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700172 return;
173 }
174
175 ControlResponse destroy(response.getContent().blockFromValue());
176 BOOST_CHECK_EQUAL(destroy.getCode(), 200);
177
178 faceId = 0;
179 hasCallbackFired = true;
180 });
181
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000182 this->node1.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400183 advanceClocks(1_ms, 5);
184 BOOST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700185 }
186
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400187protected:
188 FaceId faceId = 0;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700189};
190
191BOOST_FIXTURE_TEST_SUITE(UpdateFace, FaceManagerUpdateFixture)
192
193BOOST_AUTO_TEST_CASE(FaceDoesNotExist)
194{
195 ControlParameters requestParams;
196 requestParams.setFaceId(65535);
197
198 updateFace(requestParams, false, [] (const ControlResponse& actual) {
199 ControlResponse expected(404, "Specified face does not exist");
200 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
201 BOOST_TEST_MESSAGE(actual.getText());
202 });
203}
204
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400205using UpdatePersistencyTests = mpl::vector<
Davide Pesavento16916ae2019-03-29 23:53:26 -0400206 mpl::pair<DummyTransportBase<true>, CommandSuccess>,
207 mpl::pair<DummyTransportBase<false>, CommandFailure<409>>
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400208>;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000209
210BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePersistency, T, UpdatePersistencyTests, FaceManagerUpdateFixture)
211{
212 using TransportType = typename T::first;
213 using ResultType = typename T::second;
214
215 auto face = make_shared<face::Face>(make_unique<face::GenericLinkService>(),
216 make_unique<TransportType>());
217 this->node1.faceTable.add(face);
218
219 auto parameters = ControlParameters()
220 .setFaceId(face->getId())
221 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
222
223 updateFace(parameters, false, [] (const ControlResponse& actual) {
224 BOOST_TEST_MESSAGE(actual.getText());
225 BOOST_CHECK_EQUAL(actual.getCode(), ResultType::getExpected().getCode());
226
227 // the response for either 200 or 409 will have a content body
228 BOOST_REQUIRE(actual.getBody().hasWire());
229
230 ControlParameters resp;
231 resp.wireDecode(actual.getBody());
232 BOOST_CHECK_EQUAL(resp.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700233 });
234}
235
Eric Newberry13ff2592020-03-06 17:32:29 -0800236BOOST_AUTO_TEST_CASE(UpdateMtu)
237{
238 createFace("udp4://127.0.0.1:26363");
239
240 ControlParameters validParams;
241 validParams.setFaceId(faceId);
242 validParams.setMtu(4000);
243
244 ControlParameters mtuTooLow;
245 mtuTooLow.setFaceId(faceId);
246 mtuTooLow.setMtu(63);
247
248 updateFace(validParams, false, [] (const ControlResponse& actual) {
249 BOOST_CHECK_EQUAL(actual.getCode(), 200);
250 BOOST_TEST_MESSAGE(actual.getText());
251
252 if (actual.getBody().hasWire()) {
253 ControlParameters actualParams(actual.getBody());
254
255 BOOST_CHECK(actualParams.hasFaceId());
256 BOOST_REQUIRE(actualParams.hasMtu());
257 // Check for changed MTU
258 BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000);
259 }
260 else {
261 BOOST_ERROR("Valid: Response does not contain ControlParameters");
262 }
263 });
264
265 updateFace(mtuTooLow, false, [] (const ControlResponse& actual) {
266 BOOST_CHECK_EQUAL(actual.getCode(), 409);
267 BOOST_TEST_MESSAGE(actual.getText());
268
269 if (actual.getBody().hasWire()) {
270 ControlParameters actualParams(actual.getBody());
271
272 BOOST_CHECK(!actualParams.hasFaceId());
273 BOOST_REQUIRE(actualParams.hasMtu());
274 // Check for returned invalid parameter
275 BOOST_CHECK_EQUAL(actualParams.getMtu(), 63);
276 }
277 else {
278 BOOST_ERROR("Too low: Response does not contain ControlParameters");
279 }
280 });
281}
282
283BOOST_AUTO_TEST_CASE(UpdateMtuUnsupportedFace)
284{
285 createFace("tcp4://127.0.0.1:26363");
286
287 ControlParameters updateParams;
288 updateParams.setFaceId(faceId);
289 updateParams.setMtu(4000);
290
291 updateFace(updateParams, false, [] (const ControlResponse& actual) {
292 BOOST_CHECK_EQUAL(actual.getCode(), 409);
293 BOOST_TEST_MESSAGE(actual.getText());
294
295 if (actual.getBody().hasWire()) {
296 ControlParameters actualParams(actual.getBody());
297
298 BOOST_CHECK(!actualParams.hasFaceId());
299 BOOST_REQUIRE(actualParams.hasMtu());
300 // Check for returned invalid parameter
301 BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000);
302 }
303 else {
304 BOOST_ERROR("Response does not contain ControlParameters");
305 }
306 });
307}
308
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700309class TcpLocalFieldsEnable
310{
311public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400312 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700313 getUri()
314 {
315 return "tcp4://127.0.0.1:26363";
316 }
317
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400318 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700319 getPersistency()
320 {
321 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
322 }
323
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400324 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700325 getInitLocalFieldsEnabled()
326 {
327 return false;
328 }
329
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400330 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700331 getLocalFieldsEnabled()
332 {
333 return true;
334 }
335
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400336 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700337 getLocalFieldsEnabledMask()
338 {
339 return true;
340 }
341
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400342 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700343 shouldHaveWire()
344 {
345 return false;
346 }
347};
348
349class TcpLocalFieldsDisable
350{
351public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400352 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700353 getUri()
354 {
355 return "tcp4://127.0.0.1:26363";
356 }
357
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400358 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700359 getPersistency()
360 {
361 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
362 }
363
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400364 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700365 getInitLocalFieldsEnabled()
366 {
367 return true;
368 }
369
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400370 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700371 getLocalFieldsEnabled()
372 {
373 return false;
374 }
375
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400376 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700377 getLocalFieldsEnabledMask()
378 {
379 return true;
380 }
381
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400382 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700383 shouldHaveWire()
384 {
385 return false;
386 }
387};
388
389// UDP faces are non-local by definition
390class UdpLocalFieldsEnable
391{
392public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400393 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700394 getUri()
395 {
396 return "udp4://127.0.0.1:26363";
397 }
398
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400399 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700400 getPersistency()
401 {
402 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
403 }
404
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400405 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700406 getInitLocalFieldsEnabled()
407 {
408 return false;
409 }
410
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400411 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700412 getLocalFieldsEnabled()
413 {
414 return true;
415 }
416
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400417 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700418 getLocalFieldsEnabledMask()
419 {
420 return true;
421 }
422
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400423 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700424 shouldHaveWire()
425 {
426 return true;
427 }
428};
429
430// UDP faces are non-local by definition
431// In this test case, attempt to disable local fields on face with local fields already disabled
432class UdpLocalFieldsDisable
433{
434public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400435 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700436 getUri()
437 {
438 return "udp4://127.0.0.1:26363";
439 }
440
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400441 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700442 getPersistency()
443 {
444 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
445 }
446
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400447 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700448 getInitLocalFieldsEnabled()
449 {
450 return false;
451 }
452
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400453 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700454 getLocalFieldsEnabled()
455 {
456 return false;
457 }
458
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400459 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700460 getLocalFieldsEnabledMask()
461 {
462 return true;
463 }
464
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400465 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700466 shouldHaveWire()
467 {
468 return false;
469 }
470};
471
472// In this test case, set Flags to enable local fields on non-local face, but exclude local fields
473// from Mask. This test case will pass as no action is taken due to the missing Mask bit.
474class UdpLocalFieldsEnableNoMaskBit
475{
476public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400477 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700478 getUri()
479 {
480 return "udp4://127.0.0.1:26363";
481 }
482
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400483 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700484 getPersistency()
485 {
486 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
487 }
488
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400489 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700490 getInitLocalFieldsEnabled()
491 {
492 return false;
493 }
494
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400495 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700496 getLocalFieldsEnabled()
497 {
498 return true;
499 }
500
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400501 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700502 getLocalFieldsEnabledMask()
503 {
504 return false;
505 }
506
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400507 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700508 shouldHaveWire()
509 {
510 return false;
511 }
512};
513
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400514using LocalFieldFaces = mpl::vector<
515 mpl::pair<TcpLocalFieldsEnable, CommandSuccess>,
516 mpl::pair<TcpLocalFieldsDisable, CommandSuccess>,
517 mpl::pair<UdpLocalFieldsEnable, CommandFailure<409>>,
518 mpl::pair<UdpLocalFieldsDisable, CommandSuccess>,
519 mpl::pair<UdpLocalFieldsEnableNoMaskBit, CommandSuccess>
520>;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700521
522BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateLocalFields, T, LocalFieldFaces)
523{
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400524 using TestType = typename T::first;
525 using ResultType = typename T::second;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700526
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400527 createFace(TestType::getUri(), TestType::getPersistency(), {}, {},
528 TestType::getInitLocalFieldsEnabled());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700529
530 ControlParameters requestParams;
531 requestParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400532 requestParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, TestType::getLocalFieldsEnabled());
533 if (!TestType::getLocalFieldsEnabledMask()) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700534 requestParams.unsetFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED);
535 }
536
537 updateFace(requestParams, false, [] (const ControlResponse& actual) {
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400538 ControlResponse expected(ResultType::getExpected());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700539 BOOST_TEST_MESSAGE(actual.getText());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400540 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700541
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400542 if (TestType::shouldHaveWire() && actual.getBody().hasWire()) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700543 ControlParameters actualParams(actual.getBody());
544
545 BOOST_CHECK(!actualParams.hasFacePersistency());
546 BOOST_CHECK(actualParams.hasFlags());
547 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
548 BOOST_CHECK(actualParams.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
549 }
550 });
551}
552
553BOOST_AUTO_TEST_CASE(UpdateLocalFieldsEnableDisable)
554{
555 createFace();
556
557 ControlParameters enableParams;
558 enableParams.setFaceId(faceId);
559 enableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true);
560
561 ControlParameters disableParams;
562 disableParams.setFaceId(faceId);
563 disableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false);
564
565 updateFace(enableParams, false, [] (const ControlResponse& actual) {
566 ControlResponse expected(200, "OK");
567 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
568 BOOST_TEST_MESSAGE(actual.getText());
569
570 if (actual.getBody().hasWire()) {
571 ControlParameters actualParams(actual.getBody());
572
573 BOOST_CHECK(actualParams.hasFaceId());
574 BOOST_CHECK(actualParams.hasFacePersistency());
575 BOOST_REQUIRE(actualParams.hasFlags());
576 // Check if flags indicate local fields enabled
577 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
578 }
579 else {
580 BOOST_ERROR("Enable: Response does not contain ControlParameters");
581 }
582 });
583
584 updateFace(disableParams, 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 local fields disabled
596 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
597 }
598 else {
599 BOOST_ERROR("Disable: Response does not contain ControlParameters");
600 }
601 });
602}
603
Eric Newberry2642cd22017-07-13 21:34:53 -0400604BOOST_AUTO_TEST_CASE(UpdateReliabilityEnableDisable)
605{
606 createFace("udp4://127.0.0.1:26363");
607
608 ControlParameters enableParams;
609 enableParams.setFaceId(faceId);
610 enableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true);
611
612 ControlParameters disableParams;
613 disableParams.setFaceId(faceId);
614 disableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false);
615
616 updateFace(enableParams, false, [] (const ControlResponse& actual) {
617 ControlResponse expected(200, "OK");
618 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
619 BOOST_TEST_MESSAGE(actual.getText());
620
621 if (actual.getBody().hasWire()) {
622 ControlParameters actualParams(actual.getBody());
623
624 BOOST_CHECK(actualParams.hasFaceId());
625 BOOST_CHECK(actualParams.hasFacePersistency());
626 BOOST_REQUIRE(actualParams.hasFlags());
627 // Check if flags indicate reliability enabled
628 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
629 }
630 else {
631 BOOST_ERROR("Enable: Response does not contain ControlParameters");
632 }
633 });
634
635 updateFace(disableParams, false, [] (const ControlResponse& actual) {
636 ControlResponse expected(200, "OK");
637 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
638 BOOST_TEST_MESSAGE(actual.getText());
639
640 if (actual.getBody().hasWire()) {
641 ControlParameters actualParams(actual.getBody());
642
643 BOOST_CHECK(actualParams.hasFaceId());
644 BOOST_CHECK(actualParams.hasFacePersistency());
645 BOOST_REQUIRE(actualParams.hasFlags());
646 // Check if flags indicate reliability disabled
647 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
648 }
649 else {
650 BOOST_ERROR("Disable: Response does not contain ControlParameters");
651 }
652 });
653}
654
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700655BOOST_AUTO_TEST_CASE(UpdateCongestionMarkingEnableDisable)
656{
657 createFace("udp4://127.0.0.1:26363");
658
659 ControlParameters enableParams;
660 enableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400661 enableParams.setBaseCongestionMarkingInterval(50_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700662 enableParams.setDefaultCongestionThreshold(10000);
663 enableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true);
664
665 ControlParameters disableParams;
666 disableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400667 disableParams.setBaseCongestionMarkingInterval(70_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700668 disableParams.setDefaultCongestionThreshold(5000);
669 disableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false);
670
671 updateFace(enableParams, false, [] (const ControlResponse& actual) {
672 ControlResponse expected(200, "OK");
673 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
674 BOOST_TEST_MESSAGE(actual.getText());
675
676 if (actual.getBody().hasWire()) {
677 ControlParameters actualParams(actual.getBody());
678
679 BOOST_CHECK(actualParams.hasFaceId());
680 BOOST_CHECK(actualParams.hasFacePersistency());
681 // Check that congestion marking parameters changed
682 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400683 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 50_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700684 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
685 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 10000);
686 BOOST_REQUIRE(actualParams.hasFlags());
687 // Check if flags indicate congestion marking enabled
688 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
689 }
690 else {
691 BOOST_ERROR("Enable: Response does not contain ControlParameters");
692 }
693 });
694
695 updateFace(disableParams, false, [] (const ControlResponse& actual) {
696 ControlResponse expected(200, "OK");
697 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
698 BOOST_TEST_MESSAGE(actual.getText());
699
700 if (actual.getBody().hasWire()) {
701 ControlParameters actualParams(actual.getBody());
702
703 BOOST_CHECK(actualParams.hasFaceId());
704 BOOST_CHECK(actualParams.hasFacePersistency());
705 // Check that congestion marking parameters changed, even though feature disabled
706 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400707 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 70_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700708 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
709 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 5000);
710 BOOST_REQUIRE(actualParams.hasFlags());
711 // Check if flags indicate marking disabled
712 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
713 }
714 else {
715 BOOST_ERROR("Disable: Response does not contain ControlParameters");
716 }
717 });
718}
719
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700720BOOST_AUTO_TEST_CASE(SelfUpdating)
721{
722 createFace();
723
724 // Send a command that does nothing (will return 200) and does not contain a FaceId
725 ControlParameters sentParams;
726
727 updateFace(sentParams, true, [] (const ControlResponse& actual) {
728 ControlResponse expected(200, "OK");
729 BOOST_REQUIRE_EQUAL(actual.getCode(), expected.getCode());
730 BOOST_TEST_MESSAGE(actual.getText());
731 });
732}
733
734BOOST_AUTO_TEST_SUITE_END() // UpdateFace
735BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
736BOOST_AUTO_TEST_SUITE_END() // Mgmt
737
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400738} // namespace nfd::tests