blob: ebc794ae86553d5fc605d0a494c3357aea498ae6 [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 Pesaventof56cf632024-01-27 22:22:06 -05003 * Copyright (c) 2014-2024, 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
Eric Newberry0c3e57b2018-01-25 20:54:46 -070034#include <boost/logic/tribool.hpp>
Davide Pesaventof56cf632024-01-27 22:22:06 -050035#include <boost/mp11/list.hpp>
36#include <thread>
Eric Newberry0c3e57b2018-01-25 20:54:46 -070037
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
43class FaceManagerUpdateFixture : public FaceManagerCommandFixture
44{
45public:
Davide Pesavento22085362021-03-18 22:08:03 -040046 ~FaceManagerUpdateFixture() override
Eric Newberryb5aa7f52016-09-03 20:36:12 -070047 {
48 destroyFace();
49 }
50
51 void
52 createFace(const std::string& uri = "tcp4://127.0.0.1:26363",
53 ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Davide Pesaventob7bfcb92022-05-22 23:55:23 -040054 std::optional<time::nanoseconds> baseCongestionMarkingInterval = std::nullopt,
55 std::optional<uint64_t> defaultCongestionThreshold = std::nullopt,
Eric Newberry2642cd22017-07-13 21:34:53 -040056 bool enableLocalFields = false,
Eric Newberry0c3e57b2018-01-25 20:54:46 -070057 bool enableReliability = false,
58 boost::logic::tribool enableCongestionMarking = boost::logic::indeterminate)
Eric Newberryb5aa7f52016-09-03 20:36:12 -070059 {
60 ControlParameters params;
61 params.setUri(uri);
62 params.setFacePersistency(persistency);
Eric Newberry0c3e57b2018-01-25 20:54:46 -070063
64 if (baseCongestionMarkingInterval) {
65 params.setBaseCongestionMarkingInterval(*baseCongestionMarkingInterval);
66 }
67
68 if (defaultCongestionThreshold) {
69 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
70 }
71
Eric Newberryb5aa7f52016-09-03 20:36:12 -070072 params.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, enableLocalFields);
Eric Newberry2642cd22017-07-13 21:34:53 -040073 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, enableReliability);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070074
Eric Newberry0c3e57b2018-01-25 20:54:46 -070075 if (!boost::logic::indeterminate(enableCongestionMarking)) {
Davide Pesaventofa2aa502019-03-22 13:30:02 -040076 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, bool(enableCongestionMarking));
Eric Newberry0c3e57b2018-01-25 20:54:46 -070077 }
78
Yanbiao Li58ba3f92017-02-15 14:27:18 +000079 createFace(params);
80 }
81
82 void
Davide Pesavento3cf75dc2018-03-17 00:38:03 -040083 createFace(const ControlParameters& createParams, bool isForOnDemandFace = false)
Yanbiao Li58ba3f92017-02-15 14:27:18 +000084 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +000085 Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", createParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070086
Yanbiao Li58ba3f92017-02-15 14:27:18 +000087 // if this creation if for on-demand face then create it on node2
88 FaceManagerCommandNode& target = isForOnDemandFace ? this->node2 : this->node1;
89
Eric Newberryb5aa7f52016-09-03 20:36:12 -070090 bool hasCallbackFired = false;
Yanbiao Li58ba3f92017-02-15 14:27:18 +000091 signal::ScopedConnection connection = target.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +000092 [&, req, isForOnDemandFace, this] (const Data& response) {
93 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -070094 return;
95 }
96
97 ControlResponse create(response.getContent().blockFromValue());
98 BOOST_REQUIRE_EQUAL(create.getCode(), 200);
Yanbiao Li58ba3f92017-02-15 14:27:18 +000099 BOOST_REQUIRE(create.getBody().hasWire());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700100
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000101 ControlParameters faceParams(create.getBody());
102 BOOST_REQUIRE(faceParams.hasFaceId());
103 this->faceId = faceParams.getFaceId();
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700104
105 hasCallbackFired = true;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000106
107 if (isForOnDemandFace) {
108 auto face = target.faceTable.get(static_cast<FaceId>(this->faceId));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000109 // to force creation of on-demand face
Davide Pesavento22085362021-03-18 22:08:03 -0400110 face->sendInterest(*makeInterest("/hello/world"));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000111 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700112 });
113
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000114 target.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400115 advanceClocks(1_ms, 5);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700116
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000117 if (isForOnDemandFace) {
118 std::this_thread::sleep_for(std::chrono::milliseconds(100)); // allow wallclock time for socket IO
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400119 advanceClocks(1_ms, 5); // let node1 accept Interest and create on-demand face
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000120 }
121
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700122 BOOST_REQUIRE(hasCallbackFired);
123 }
124
125 void
126 updateFace(const ControlParameters& requestParams,
127 bool isSelfUpdating,
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400128 const std::function<void(const ControlResponse& resp)>& checkResp)
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700129 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000130 Interest req = makeControlCommandRequest("/localhost/nfd/faces/update", requestParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700131 if (isSelfUpdating) {
132 // Attach IncomingFaceIdTag to interest
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000133 req.setTag(make_shared<lp::IncomingFaceIdTag>(faceId));
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700134 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700135
136 bool hasCallbackFired = false;
137 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Davide Pesaventoac238f22017-09-12 15:19:40 -0400138 [req, &hasCallbackFired, &checkResp] (const Data& response) {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000139 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700140 return;
141 }
142
143 ControlResponse actual(response.getContent().blockFromValue());
144 checkResp(actual);
145
146 hasCallbackFired = true;
147 });
148
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000149 this->node1.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400150 advanceClocks(1_ms, 5);
151 BOOST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700152 }
153
154private:
155 void
156 destroyFace()
157 {
158 if (faceId == 0) {
159 return;
160 }
161
162 ControlParameters params;
163 params.setFaceId(faceId);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000164 Interest req = makeControlCommandRequest("/localhost/nfd/faces/destroy", params);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700165
166 bool hasCallbackFired = false;
167 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000168 [this, req, &hasCallbackFired] (const Data& response) {
169 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700170 return;
171 }
172
173 ControlResponse destroy(response.getContent().blockFromValue());
174 BOOST_CHECK_EQUAL(destroy.getCode(), 200);
175
176 faceId = 0;
177 hasCallbackFired = true;
178 });
179
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000180 this->node1.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400181 advanceClocks(1_ms, 5);
182 BOOST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700183 }
184
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400185protected:
186 FaceId faceId = 0;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700187};
188
189BOOST_FIXTURE_TEST_SUITE(UpdateFace, FaceManagerUpdateFixture)
190
191BOOST_AUTO_TEST_CASE(FaceDoesNotExist)
192{
193 ControlParameters requestParams;
194 requestParams.setFaceId(65535);
195
196 updateFace(requestParams, false, [] (const ControlResponse& actual) {
197 ControlResponse expected(404, "Specified face does not exist");
198 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
199 BOOST_TEST_MESSAGE(actual.getText());
200 });
201}
202
Davide Pesaventof56cf632024-01-27 22:22:06 -0500203using UpdatePersistencyTests = boost::mp11::mp_list<
204 boost::mp11::mp_list<DummyTransportBase<true>, CommandSuccess>,
205 boost::mp11::mp_list<DummyTransportBase<false>, CommandFailure<409>>
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400206>;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000207
208BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePersistency, T, UpdatePersistencyTests, FaceManagerUpdateFixture)
209{
Davide Pesaventof56cf632024-01-27 22:22:06 -0500210 using TransportType = boost::mp11::mp_first<T>;
211 using ResultType = boost::mp11::mp_second<T>;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000212
213 auto face = make_shared<face::Face>(make_unique<face::GenericLinkService>(),
214 make_unique<TransportType>());
215 this->node1.faceTable.add(face);
216
217 auto parameters = ControlParameters()
218 .setFaceId(face->getId())
219 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
220
221 updateFace(parameters, false, [] (const ControlResponse& actual) {
222 BOOST_TEST_MESSAGE(actual.getText());
223 BOOST_CHECK_EQUAL(actual.getCode(), ResultType::getExpected().getCode());
224
225 // the response for either 200 or 409 will have a content body
226 BOOST_REQUIRE(actual.getBody().hasWire());
227
228 ControlParameters resp;
229 resp.wireDecode(actual.getBody());
230 BOOST_CHECK_EQUAL(resp.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700231 });
232}
233
Eric Newberry13ff2592020-03-06 17:32:29 -0800234BOOST_AUTO_TEST_CASE(UpdateMtu)
235{
236 createFace("udp4://127.0.0.1:26363");
237
238 ControlParameters validParams;
239 validParams.setFaceId(faceId);
240 validParams.setMtu(4000);
241
242 ControlParameters mtuTooLow;
243 mtuTooLow.setFaceId(faceId);
244 mtuTooLow.setMtu(63);
245
246 updateFace(validParams, false, [] (const ControlResponse& actual) {
247 BOOST_CHECK_EQUAL(actual.getCode(), 200);
248 BOOST_TEST_MESSAGE(actual.getText());
249
250 if (actual.getBody().hasWire()) {
251 ControlParameters actualParams(actual.getBody());
252
253 BOOST_CHECK(actualParams.hasFaceId());
254 BOOST_REQUIRE(actualParams.hasMtu());
255 // Check for changed MTU
256 BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000);
257 }
258 else {
259 BOOST_ERROR("Valid: Response does not contain ControlParameters");
260 }
261 });
262
263 updateFace(mtuTooLow, false, [] (const ControlResponse& actual) {
264 BOOST_CHECK_EQUAL(actual.getCode(), 409);
265 BOOST_TEST_MESSAGE(actual.getText());
266
267 if (actual.getBody().hasWire()) {
268 ControlParameters actualParams(actual.getBody());
269
270 BOOST_CHECK(!actualParams.hasFaceId());
271 BOOST_REQUIRE(actualParams.hasMtu());
272 // Check for returned invalid parameter
273 BOOST_CHECK_EQUAL(actualParams.getMtu(), 63);
274 }
275 else {
276 BOOST_ERROR("Too low: Response does not contain ControlParameters");
277 }
278 });
279}
280
281BOOST_AUTO_TEST_CASE(UpdateMtuUnsupportedFace)
282{
283 createFace("tcp4://127.0.0.1:26363");
284
285 ControlParameters updateParams;
286 updateParams.setFaceId(faceId);
287 updateParams.setMtu(4000);
288
289 updateFace(updateParams, false, [] (const ControlResponse& actual) {
290 BOOST_CHECK_EQUAL(actual.getCode(), 409);
291 BOOST_TEST_MESSAGE(actual.getText());
292
293 if (actual.getBody().hasWire()) {
294 ControlParameters actualParams(actual.getBody());
295
296 BOOST_CHECK(!actualParams.hasFaceId());
297 BOOST_REQUIRE(actualParams.hasMtu());
298 // Check for returned invalid parameter
299 BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000);
300 }
301 else {
302 BOOST_ERROR("Response does not contain ControlParameters");
303 }
304 });
305}
306
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700307class TcpLocalFieldsEnable
308{
309public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400310 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700311 getUri()
312 {
313 return "tcp4://127.0.0.1:26363";
314 }
315
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400316 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700317 getPersistency()
318 {
319 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
320 }
321
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400322 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700323 getInitLocalFieldsEnabled()
324 {
325 return false;
326 }
327
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400328 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700329 getLocalFieldsEnabled()
330 {
331 return true;
332 }
333
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400334 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700335 getLocalFieldsEnabledMask()
336 {
337 return true;
338 }
339
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400340 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700341 shouldHaveWire()
342 {
343 return false;
344 }
345};
346
347class TcpLocalFieldsDisable
348{
349public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400350 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700351 getUri()
352 {
353 return "tcp4://127.0.0.1:26363";
354 }
355
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400356 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700357 getPersistency()
358 {
359 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
360 }
361
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400362 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700363 getInitLocalFieldsEnabled()
364 {
365 return true;
366 }
367
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400368 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700369 getLocalFieldsEnabled()
370 {
371 return false;
372 }
373
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400374 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700375 getLocalFieldsEnabledMask()
376 {
377 return true;
378 }
379
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400380 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700381 shouldHaveWire()
382 {
383 return false;
384 }
385};
386
387// UDP faces are non-local by definition
388class UdpLocalFieldsEnable
389{
390public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400391 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700392 getUri()
393 {
394 return "udp4://127.0.0.1:26363";
395 }
396
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400397 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700398 getPersistency()
399 {
400 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
401 }
402
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400403 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700404 getInitLocalFieldsEnabled()
405 {
406 return false;
407 }
408
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400409 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700410 getLocalFieldsEnabled()
411 {
412 return true;
413 }
414
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400415 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700416 getLocalFieldsEnabledMask()
417 {
418 return true;
419 }
420
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400421 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700422 shouldHaveWire()
423 {
424 return true;
425 }
426};
427
428// UDP faces are non-local by definition
429// In this test case, attempt to disable local fields on face with local fields already disabled
430class UdpLocalFieldsDisable
431{
432public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400433 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700434 getUri()
435 {
436 return "udp4://127.0.0.1:26363";
437 }
438
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400439 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700440 getPersistency()
441 {
442 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
443 }
444
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400445 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700446 getInitLocalFieldsEnabled()
447 {
448 return false;
449 }
450
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400451 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700452 getLocalFieldsEnabled()
453 {
454 return false;
455 }
456
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400457 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700458 getLocalFieldsEnabledMask()
459 {
460 return true;
461 }
462
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400463 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700464 shouldHaveWire()
465 {
466 return false;
467 }
468};
469
470// In this test case, set Flags to enable local fields on non-local face, but exclude local fields
471// from Mask. This test case will pass as no action is taken due to the missing Mask bit.
472class UdpLocalFieldsEnableNoMaskBit
473{
474public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400475 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700476 getUri()
477 {
478 return "udp4://127.0.0.1:26363";
479 }
480
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400481 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700482 getPersistency()
483 {
484 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
485 }
486
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400487 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700488 getInitLocalFieldsEnabled()
489 {
490 return false;
491 }
492
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400493 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700494 getLocalFieldsEnabled()
495 {
496 return true;
497 }
498
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400499 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700500 getLocalFieldsEnabledMask()
501 {
502 return false;
503 }
504
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400505 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700506 shouldHaveWire()
507 {
508 return false;
509 }
510};
511
Davide Pesaventof56cf632024-01-27 22:22:06 -0500512using LocalFieldFaces = boost::mp11::mp_list<
513 boost::mp11::mp_list<TcpLocalFieldsEnable, CommandSuccess>,
514 boost::mp11::mp_list<TcpLocalFieldsDisable, CommandSuccess>,
515 boost::mp11::mp_list<UdpLocalFieldsEnable, CommandFailure<409>>,
516 boost::mp11::mp_list<UdpLocalFieldsDisable, CommandSuccess>,
517 boost::mp11::mp_list<UdpLocalFieldsEnableNoMaskBit, CommandSuccess>
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400518>;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700519
520BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateLocalFields, T, LocalFieldFaces)
521{
Davide Pesaventof56cf632024-01-27 22:22:06 -0500522 using TestType = boost::mp11::mp_first<T>;
523 using ResultType = boost::mp11::mp_second<T>;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700524
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400525 createFace(TestType::getUri(), TestType::getPersistency(), {}, {},
526 TestType::getInitLocalFieldsEnabled());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700527
528 ControlParameters requestParams;
529 requestParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400530 requestParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, TestType::getLocalFieldsEnabled());
531 if (!TestType::getLocalFieldsEnabledMask()) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700532 requestParams.unsetFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED);
533 }
534
535 updateFace(requestParams, false, [] (const ControlResponse& actual) {
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400536 ControlResponse expected(ResultType::getExpected());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700537 BOOST_TEST_MESSAGE(actual.getText());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400538 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700539
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400540 if (TestType::shouldHaveWire() && actual.getBody().hasWire()) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700541 ControlParameters actualParams(actual.getBody());
542
543 BOOST_CHECK(!actualParams.hasFacePersistency());
544 BOOST_CHECK(actualParams.hasFlags());
545 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
546 BOOST_CHECK(actualParams.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
547 }
548 });
549}
550
551BOOST_AUTO_TEST_CASE(UpdateLocalFieldsEnableDisable)
552{
553 createFace();
554
555 ControlParameters enableParams;
556 enableParams.setFaceId(faceId);
557 enableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true);
558
559 ControlParameters disableParams;
560 disableParams.setFaceId(faceId);
561 disableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false);
562
563 updateFace(enableParams, false, [] (const ControlResponse& actual) {
564 ControlResponse expected(200, "OK");
565 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
566 BOOST_TEST_MESSAGE(actual.getText());
567
568 if (actual.getBody().hasWire()) {
569 ControlParameters actualParams(actual.getBody());
570
571 BOOST_CHECK(actualParams.hasFaceId());
572 BOOST_CHECK(actualParams.hasFacePersistency());
573 BOOST_REQUIRE(actualParams.hasFlags());
574 // Check if flags indicate local fields enabled
575 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
576 }
577 else {
578 BOOST_ERROR("Enable: Response does not contain ControlParameters");
579 }
580 });
581
582 updateFace(disableParams, false, [] (const ControlResponse& actual) {
583 ControlResponse expected(200, "OK");
584 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
585 BOOST_TEST_MESSAGE(actual.getText());
586
587 if (actual.getBody().hasWire()) {
588 ControlParameters actualParams(actual.getBody());
589
590 BOOST_CHECK(actualParams.hasFaceId());
591 BOOST_CHECK(actualParams.hasFacePersistency());
592 BOOST_REQUIRE(actualParams.hasFlags());
593 // Check if flags indicate local fields disabled
594 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
595 }
596 else {
597 BOOST_ERROR("Disable: Response does not contain ControlParameters");
598 }
599 });
600}
601
Eric Newberry2642cd22017-07-13 21:34:53 -0400602BOOST_AUTO_TEST_CASE(UpdateReliabilityEnableDisable)
603{
604 createFace("udp4://127.0.0.1:26363");
605
606 ControlParameters enableParams;
607 enableParams.setFaceId(faceId);
608 enableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true);
609
610 ControlParameters disableParams;
611 disableParams.setFaceId(faceId);
612 disableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false);
613
614 updateFace(enableParams, false, [] (const ControlResponse& actual) {
615 ControlResponse expected(200, "OK");
616 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
617 BOOST_TEST_MESSAGE(actual.getText());
618
619 if (actual.getBody().hasWire()) {
620 ControlParameters actualParams(actual.getBody());
621
622 BOOST_CHECK(actualParams.hasFaceId());
623 BOOST_CHECK(actualParams.hasFacePersistency());
624 BOOST_REQUIRE(actualParams.hasFlags());
625 // Check if flags indicate reliability enabled
626 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
627 }
628 else {
629 BOOST_ERROR("Enable: Response does not contain ControlParameters");
630 }
631 });
632
633 updateFace(disableParams, false, [] (const ControlResponse& actual) {
634 ControlResponse expected(200, "OK");
635 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
636 BOOST_TEST_MESSAGE(actual.getText());
637
638 if (actual.getBody().hasWire()) {
639 ControlParameters actualParams(actual.getBody());
640
641 BOOST_CHECK(actualParams.hasFaceId());
642 BOOST_CHECK(actualParams.hasFacePersistency());
643 BOOST_REQUIRE(actualParams.hasFlags());
644 // Check if flags indicate reliability disabled
645 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
646 }
647 else {
648 BOOST_ERROR("Disable: Response does not contain ControlParameters");
649 }
650 });
651}
652
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700653BOOST_AUTO_TEST_CASE(UpdateCongestionMarkingEnableDisable)
654{
655 createFace("udp4://127.0.0.1:26363");
656
657 ControlParameters enableParams;
658 enableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400659 enableParams.setBaseCongestionMarkingInterval(50_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700660 enableParams.setDefaultCongestionThreshold(10000);
661 enableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true);
662
663 ControlParameters disableParams;
664 disableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400665 disableParams.setBaseCongestionMarkingInterval(70_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700666 disableParams.setDefaultCongestionThreshold(5000);
667 disableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false);
668
669 updateFace(enableParams, false, [] (const ControlResponse& actual) {
670 ControlResponse expected(200, "OK");
671 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
672 BOOST_TEST_MESSAGE(actual.getText());
673
674 if (actual.getBody().hasWire()) {
675 ControlParameters actualParams(actual.getBody());
676
677 BOOST_CHECK(actualParams.hasFaceId());
678 BOOST_CHECK(actualParams.hasFacePersistency());
679 // Check that congestion marking parameters changed
680 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400681 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 50_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700682 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
683 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 10000);
684 BOOST_REQUIRE(actualParams.hasFlags());
685 // Check if flags indicate congestion marking enabled
686 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
687 }
688 else {
689 BOOST_ERROR("Enable: Response does not contain ControlParameters");
690 }
691 });
692
693 updateFace(disableParams, false, [] (const ControlResponse& actual) {
694 ControlResponse expected(200, "OK");
695 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
696 BOOST_TEST_MESSAGE(actual.getText());
697
698 if (actual.getBody().hasWire()) {
699 ControlParameters actualParams(actual.getBody());
700
701 BOOST_CHECK(actualParams.hasFaceId());
702 BOOST_CHECK(actualParams.hasFacePersistency());
703 // Check that congestion marking parameters changed, even though feature disabled
704 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400705 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 70_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700706 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
707 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 5000);
708 BOOST_REQUIRE(actualParams.hasFlags());
709 // Check if flags indicate marking disabled
710 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
711 }
712 else {
713 BOOST_ERROR("Disable: Response does not contain ControlParameters");
714 }
715 });
716}
717
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700718BOOST_AUTO_TEST_CASE(SelfUpdating)
719{
720 createFace();
721
722 // Send a command that does nothing (will return 200) and does not contain a FaceId
723 ControlParameters sentParams;
724
725 updateFace(sentParams, true, [] (const ControlResponse& actual) {
726 ControlResponse expected(200, "OK");
727 BOOST_REQUIRE_EQUAL(actual.getCode(), expected.getCode());
728 BOOST_TEST_MESSAGE(actual.getText());
729 });
730}
731
732BOOST_AUTO_TEST_SUITE_END() // UpdateFace
733BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
734BOOST_AUTO_TEST_SUITE_END() // Mgmt
735
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400736} // namespace nfd::tests