blob: 202e360ff5ddf9b8df7403f459e5b6dc5446e002 [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 Pesavento1d2d3372025-01-14 12:04:12 -05003 * Copyright (c) 2014-2025, 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 {
Davide Pesavento1d2d3372025-01-14 12:04:12 -050085 Interest req = makeControlCommandRequest(CREATE_REQUEST, 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;
Davide Pesavento4296fe32025-01-14 23:00:41 -050091 signal::ScopedConnection conn = target.face.onSendData.connect([&] (const Data& response) {
92 if (!req.getName().isPrefixOf(response.getName())) {
93 return;
94 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -070095
Davide Pesavento4296fe32025-01-14 23:00:41 -050096 ControlResponse create(response.getContent().blockFromValue());
97 BOOST_TEST_REQUIRE(create.getCode() == 200);
98 ControlParameters faceParams(create.getBody());
99 BOOST_TEST_REQUIRE(faceParams.hasFaceId());
100 this->faceId = faceParams.getFaceId();
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700101
Davide Pesavento4296fe32025-01-14 23:00:41 -0500102 hasCallbackFired = true;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700103
Davide Pesavento4296fe32025-01-14 23:00:41 -0500104 if (isForOnDemandFace) {
105 auto face = target.faceTable.get(this->faceId);
106 // to force creation of on-demand face
107 face->sendInterest(*makeInterest("/hello/world"));
108 }
109 });
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700110
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000111 target.face.receive(req);
Davide Pesavento1d2d3372025-01-14 12:04:12 -0500112 advanceClocks(1_ms, 10);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700113
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000114 if (isForOnDemandFace) {
115 std::this_thread::sleep_for(std::chrono::milliseconds(100)); // allow wallclock time for socket IO
Davide Pesavento1d2d3372025-01-14 12:04:12 -0500116 advanceClocks(1_ms, 10); // let node1 accept Interest and create on-demand face
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000117 }
118
Davide Pesavento4296fe32025-01-14 23:00:41 -0500119 BOOST_TEST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700120 }
121
122 void
Davide Pesavento4296fe32025-01-14 23:00:41 -0500123 updateFace(const ControlParameters& requestParams, bool isSelfUpdating,
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400124 const std::function<void(const ControlResponse& resp)>& checkResp)
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700125 {
Davide Pesavento1d2d3372025-01-14 12:04:12 -0500126 Interest req = makeControlCommandRequest(UPDATE_REQUEST, requestParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700127 if (isSelfUpdating) {
128 // Attach IncomingFaceIdTag to interest
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000129 req.setTag(make_shared<lp::IncomingFaceIdTag>(faceId));
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700130 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700131
132 bool hasCallbackFired = false;
Davide Pesavento4296fe32025-01-14 23:00:41 -0500133 signal::ScopedConnection conn = node1.face.onSendData.connect([&] (const Data& response) {
134 if (!req.getName().isPrefixOf(response.getName())) {
135 return;
136 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700137
Davide Pesavento4296fe32025-01-14 23:00:41 -0500138 ControlResponse actual(response.getContent().blockFromValue());
139 checkResp(actual);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700140
Davide Pesavento4296fe32025-01-14 23:00:41 -0500141 hasCallbackFired = true;
142 });
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700143
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000144 this->node1.face.receive(req);
Davide Pesavento1d2d3372025-01-14 12:04:12 -0500145 advanceClocks(1_ms, 10);
Davide Pesavento4296fe32025-01-14 23:00:41 -0500146 BOOST_TEST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700147 }
148
149private:
150 void
151 destroyFace()
152 {
153 if (faceId == 0) {
154 return;
155 }
156
157 ControlParameters params;
158 params.setFaceId(faceId);
Davide Pesavento1d2d3372025-01-14 12:04:12 -0500159 Interest req = makeControlCommandRequest(DESTROY_REQUEST, params);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700160
161 bool hasCallbackFired = false;
Davide Pesavento4296fe32025-01-14 23:00:41 -0500162 signal::ScopedConnection conn = node1.face.onSendData.connect([&] (const Data& response) {
163 if (!req.getName().isPrefixOf(response.getName())) {
164 return;
165 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700166
Davide Pesavento4296fe32025-01-14 23:00:41 -0500167 ControlResponse destroy(response.getContent().blockFromValue());
168 BOOST_CHECK_EQUAL(destroy.getCode(), 200);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700169
Davide Pesavento4296fe32025-01-14 23:00:41 -0500170 faceId = 0;
171 hasCallbackFired = true;
172 });
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700173
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000174 this->node1.face.receive(req);
Davide Pesavento1d2d3372025-01-14 12:04:12 -0500175 advanceClocks(1_ms, 10);
Davide Pesavento4296fe32025-01-14 23:00:41 -0500176 BOOST_TEST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700177 }
178
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400179protected:
180 FaceId faceId = 0;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700181};
182
183BOOST_FIXTURE_TEST_SUITE(UpdateFace, FaceManagerUpdateFixture)
184
185BOOST_AUTO_TEST_CASE(FaceDoesNotExist)
186{
187 ControlParameters requestParams;
188 requestParams.setFaceId(65535);
189
190 updateFace(requestParams, false, [] (const ControlResponse& actual) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500191 BOOST_TEST(actual.getCode() == 404);
192 BOOST_TEST(actual.getText() == "Specified face does not exist");
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700193 });
194}
195
Davide Pesaventof56cf632024-01-27 22:22:06 -0500196using UpdatePersistencyTests = boost::mp11::mp_list<
197 boost::mp11::mp_list<DummyTransportBase<true>, CommandSuccess>,
198 boost::mp11::mp_list<DummyTransportBase<false>, CommandFailure<409>>
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400199>;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000200
201BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePersistency, T, UpdatePersistencyTests, FaceManagerUpdateFixture)
202{
Davide Pesaventof56cf632024-01-27 22:22:06 -0500203 using TransportType = boost::mp11::mp_first<T>;
204 using ResultType = boost::mp11::mp_second<T>;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000205
206 auto face = make_shared<face::Face>(make_unique<face::GenericLinkService>(),
207 make_unique<TransportType>());
208 this->node1.faceTable.add(face);
209
210 auto parameters = ControlParameters()
211 .setFaceId(face->getId())
212 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
213
214 updateFace(parameters, false, [] (const ControlResponse& actual) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500215 BOOST_TEST(actual.getCode() == ResultType::getExpected().getCode(), actual.getText());
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000216
Davide Pesavento4296fe32025-01-14 23:00:41 -0500217 // the response for either 200 or 409 will have a content body
218 ControlParameters resp(actual.getBody());
219 BOOST_CHECK_EQUAL(resp.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700220 });
221}
222
Eric Newberry13ff2592020-03-06 17:32:29 -0800223BOOST_AUTO_TEST_CASE(UpdateMtu)
224{
225 createFace("udp4://127.0.0.1:26363");
226
227 ControlParameters validParams;
228 validParams.setFaceId(faceId);
229 validParams.setMtu(4000);
230
231 ControlParameters mtuTooLow;
232 mtuTooLow.setFaceId(faceId);
233 mtuTooLow.setMtu(63);
234
235 updateFace(validParams, false, [] (const ControlResponse& actual) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500236 BOOST_TEST(actual.getCode() == 200, actual.getText());
Eric Newberry13ff2592020-03-06 17:32:29 -0800237
Davide Pesavento4296fe32025-01-14 23:00:41 -0500238 ControlParameters actualParams(actual.getBody());
239 BOOST_TEST(actualParams.hasFaceId());
240 BOOST_TEST_REQUIRE(actualParams.hasMtu());
241 // Check for changed MTU
242 BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000);
Eric Newberry13ff2592020-03-06 17:32:29 -0800243 });
244
245 updateFace(mtuTooLow, false, [] (const ControlResponse& actual) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500246 BOOST_TEST(actual.getCode() == 409);
247 BOOST_TEST(actual.getText() == "Invalid properties specified");
Eric Newberry13ff2592020-03-06 17:32:29 -0800248
Davide Pesavento4296fe32025-01-14 23:00:41 -0500249 ControlParameters actualParams(actual.getBody());
250 BOOST_TEST(!actualParams.hasFaceId());
251 BOOST_TEST_REQUIRE(actualParams.hasMtu());
252 // Check for returned invalid parameter
253 BOOST_CHECK_EQUAL(actualParams.getMtu(), 63);
Eric Newberry13ff2592020-03-06 17:32:29 -0800254 });
255}
256
257BOOST_AUTO_TEST_CASE(UpdateMtuUnsupportedFace)
258{
259 createFace("tcp4://127.0.0.1:26363");
260
261 ControlParameters updateParams;
262 updateParams.setFaceId(faceId);
263 updateParams.setMtu(4000);
264
265 updateFace(updateParams, false, [] (const ControlResponse& actual) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500266 BOOST_TEST(actual.getCode() == 409);
267 BOOST_TEST(actual.getText() == "Invalid properties specified");
Eric Newberry13ff2592020-03-06 17:32:29 -0800268
Davide Pesavento4296fe32025-01-14 23:00:41 -0500269 ControlParameters actualParams(actual.getBody());
270 BOOST_TEST(!actualParams.hasFaceId());
271 BOOST_TEST_REQUIRE(actualParams.hasMtu());
272 // Check for returned invalid parameter
273 BOOST_CHECK_EQUAL(actualParams.getMtu(), 4000);
Eric Newberry13ff2592020-03-06 17:32:29 -0800274 });
275}
276
Davide Pesavento4296fe32025-01-14 23:00:41 -0500277template<bool EnableLocalFields>
278struct TcpLocalFields
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700279{
Davide Pesavento4296fe32025-01-14 23:00:41 -0500280 static inline const std::string uri = "tcp4://127.0.0.1:26363";
281 static constexpr bool localFieldsInit = !EnableLocalFields;
282 static constexpr bool localFieldsEnabled = EnableLocalFields;
283 static constexpr bool mask = true;
284 static constexpr bool shouldHaveBody = false;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700285};
286
Davide Pesavento4296fe32025-01-14 23:00:41 -0500287// UDP faces are non-local by definition.
288struct UdpLocalFieldsEnable
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700289{
Davide Pesavento4296fe32025-01-14 23:00:41 -0500290 static inline const std::string uri = "udp4://127.0.0.1:26363";
291 static constexpr bool localFieldsInit = false;
292 static constexpr bool localFieldsEnabled = true;
293 static constexpr bool mask = true;
294 static constexpr bool shouldHaveBody = true;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700295};
296
Davide Pesavento4296fe32025-01-14 23:00:41 -0500297// UDP faces are non-local by definition.
298// In this test case, attempt to disable local fields on face with local fields already disabled.
299struct UdpLocalFieldsDisable
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700300{
Davide Pesavento4296fe32025-01-14 23:00:41 -0500301 static inline const std::string uri = "udp4://127.0.0.1:26363";
302 static constexpr bool localFieldsInit = false;
303 static constexpr bool localFieldsEnabled = false;
304 static constexpr bool mask = true;
305 static constexpr bool shouldHaveBody = false;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700306};
307
308// In this test case, set Flags to enable local fields on non-local face, but exclude local fields
309// from Mask. This test case will pass as no action is taken due to the missing Mask bit.
Davide Pesavento4296fe32025-01-14 23:00:41 -0500310struct UdpLocalFieldsEnableNoMaskBit
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700311{
Davide Pesavento4296fe32025-01-14 23:00:41 -0500312 static inline const std::string uri = "udp4://127.0.0.1:26363";
313 static constexpr bool localFieldsInit = false;
314 static constexpr bool localFieldsEnabled = true;
315 static constexpr bool mask = false;
316 static constexpr bool shouldHaveBody = false;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700317};
318
Davide Pesaventof56cf632024-01-27 22:22:06 -0500319using LocalFieldFaces = boost::mp11::mp_list<
Davide Pesavento4296fe32025-01-14 23:00:41 -0500320 boost::mp11::mp_list<TcpLocalFields<true>, CommandSuccess>,
321 boost::mp11::mp_list<TcpLocalFields<false>, CommandSuccess>,
Davide Pesaventof56cf632024-01-27 22:22:06 -0500322 boost::mp11::mp_list<UdpLocalFieldsEnable, CommandFailure<409>>,
323 boost::mp11::mp_list<UdpLocalFieldsDisable, CommandSuccess>,
324 boost::mp11::mp_list<UdpLocalFieldsEnableNoMaskBit, CommandSuccess>
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400325>;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700326
327BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateLocalFields, T, LocalFieldFaces)
328{
Davide Pesaventof56cf632024-01-27 22:22:06 -0500329 using TestType = boost::mp11::mp_first<T>;
330 using ResultType = boost::mp11::mp_second<T>;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700331
Davide Pesavento4296fe32025-01-14 23:00:41 -0500332 createFace(TestType::uri, ndn::nfd::FACE_PERSISTENCY_PERSISTENT, {}, {}, TestType::localFieldsInit);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700333
334 ControlParameters requestParams;
335 requestParams.setFaceId(faceId);
Davide Pesavento4296fe32025-01-14 23:00:41 -0500336 requestParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, TestType::localFieldsEnabled);
337 if constexpr (!TestType::mask) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700338 requestParams.unsetFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED);
339 }
340
341 updateFace(requestParams, false, [] (const ControlResponse& actual) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500342 BOOST_TEST(actual.getCode() == ResultType::getExpected().getCode(), actual.getText());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700343
Davide Pesavento4296fe32025-01-14 23:00:41 -0500344 if constexpr (TestType::shouldHaveBody) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700345 ControlParameters actualParams(actual.getBody());
Davide Pesavento4296fe32025-01-14 23:00:41 -0500346 BOOST_TEST(!actualParams.hasFacePersistency());
347 BOOST_TEST(actualParams.hasFlags());
348 BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
349 BOOST_TEST(actualParams.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700350 }
351 });
352}
353
354BOOST_AUTO_TEST_CASE(UpdateLocalFieldsEnableDisable)
355{
356 createFace();
357
358 ControlParameters enableParams;
359 enableParams.setFaceId(faceId);
360 enableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true);
361
362 ControlParameters disableParams;
363 disableParams.setFaceId(faceId);
364 disableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false);
365
366 updateFace(enableParams, false, [] (const ControlResponse& actual) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500367 BOOST_TEST(actual.getCode() == 200, actual.getText());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700368
Davide Pesavento4296fe32025-01-14 23:00:41 -0500369 ControlParameters actualParams(actual.getBody());
370 BOOST_TEST(actualParams.hasFaceId());
371 BOOST_TEST(actualParams.hasFacePersistency());
372 BOOST_TEST_REQUIRE(actualParams.hasFlags());
373 // Check if flags indicate local fields enabled
374 BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700375 });
376
377 updateFace(disableParams, false, [] (const ControlResponse& actual) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500378 BOOST_TEST(actual.getCode() == 200, actual.getText());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700379
Davide Pesavento4296fe32025-01-14 23:00:41 -0500380 ControlParameters actualParams(actual.getBody());
381 BOOST_TEST(actualParams.hasFaceId());
382 BOOST_TEST(actualParams.hasFacePersistency());
383 BOOST_TEST_REQUIRE(actualParams.hasFlags());
384 // Check if flags indicate local fields disabled
385 BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700386 });
387}
388
Eric Newberry2642cd22017-07-13 21:34:53 -0400389BOOST_AUTO_TEST_CASE(UpdateReliabilityEnableDisable)
390{
391 createFace("udp4://127.0.0.1:26363");
392
393 ControlParameters enableParams;
394 enableParams.setFaceId(faceId);
395 enableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true);
396
397 ControlParameters disableParams;
398 disableParams.setFaceId(faceId);
399 disableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false);
400
401 updateFace(enableParams, false, [] (const ControlResponse& actual) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500402 BOOST_TEST(actual.getCode() == 200, actual.getText());
Eric Newberry2642cd22017-07-13 21:34:53 -0400403
Davide Pesavento4296fe32025-01-14 23:00:41 -0500404 ControlParameters actualParams(actual.getBody());
405 BOOST_TEST(actualParams.hasFaceId());
406 BOOST_TEST(actualParams.hasFacePersistency());
407 BOOST_TEST_REQUIRE(actualParams.hasFlags());
408 // Check if flags indicate reliability enabled
409 BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
Eric Newberry2642cd22017-07-13 21:34:53 -0400410 });
411
412 updateFace(disableParams, false, [] (const ControlResponse& actual) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500413 BOOST_TEST(actual.getCode() == 200, actual.getText());
Eric Newberry2642cd22017-07-13 21:34:53 -0400414
Davide Pesavento4296fe32025-01-14 23:00:41 -0500415 ControlParameters actualParams(actual.getBody());
416 BOOST_TEST(actualParams.hasFaceId());
417 BOOST_TEST(actualParams.hasFacePersistency());
418 BOOST_TEST_REQUIRE(actualParams.hasFlags());
419 // Check if flags indicate reliability disabled
420 BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
Eric Newberry2642cd22017-07-13 21:34:53 -0400421 });
422}
423
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700424BOOST_AUTO_TEST_CASE(UpdateCongestionMarkingEnableDisable)
425{
426 createFace("udp4://127.0.0.1:26363");
427
428 ControlParameters enableParams;
429 enableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400430 enableParams.setBaseCongestionMarkingInterval(50_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700431 enableParams.setDefaultCongestionThreshold(10000);
432 enableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true);
433
434 ControlParameters disableParams;
435 disableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400436 disableParams.setBaseCongestionMarkingInterval(70_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700437 disableParams.setDefaultCongestionThreshold(5000);
438 disableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false);
439
440 updateFace(enableParams, false, [] (const ControlResponse& actual) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500441 BOOST_TEST(actual.getCode() == 200, actual.getText());
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700442
Davide Pesavento4296fe32025-01-14 23:00:41 -0500443 ControlParameters actualParams(actual.getBody());
444 BOOST_TEST(actualParams.hasFaceId());
445 BOOST_TEST(actualParams.hasFacePersistency());
446 // Check that congestion marking parameters changed
447 BOOST_TEST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
448 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 50_ms);
449 BOOST_TEST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
450 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 10000);
451 BOOST_TEST_REQUIRE(actualParams.hasFlags());
452 // Check if flags indicate congestion marking enabled
453 BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700454 });
455
456 updateFace(disableParams, false, [] (const ControlResponse& actual) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500457 BOOST_TEST(actual.getCode() == 200, actual.getText());
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700458
Davide Pesavento4296fe32025-01-14 23:00:41 -0500459 ControlParameters actualParams(actual.getBody());
460 BOOST_TEST(actualParams.hasFaceId());
461 BOOST_TEST(actualParams.hasFacePersistency());
462 // Check that congestion marking parameters changed, even though feature disabled
463 BOOST_TEST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
464 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 70_ms);
465 BOOST_TEST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
466 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 5000);
467 BOOST_TEST_REQUIRE(actualParams.hasFlags());
468 // Check if flags indicate marking disabled
469 BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700470 });
471}
472
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700473BOOST_AUTO_TEST_CASE(SelfUpdating)
474{
475 createFace();
476
Davide Pesavento4296fe32025-01-14 23:00:41 -0500477 // Send a command that does nothing and does not contain a FaceId
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700478 ControlParameters sentParams;
479
Davide Pesavento4296fe32025-01-14 23:00:41 -0500480 // Success case: FaceId is obtained automatically from IncomingFaceIdTag
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700481 updateFace(sentParams, true, [] (const ControlResponse& actual) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500482 BOOST_TEST(actual.getCode() == 200, actual.getText());
483 });
484
485 // Error case: IncomingFaceIdTag is missing
486 updateFace(sentParams, false, [] (const ControlResponse& actual) {
487 BOOST_TEST(actual.getCode() == 404);
488 BOOST_TEST(actual.getText() == "No FaceId specified and IncomingFaceId not available");
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700489 });
490}
491
492BOOST_AUTO_TEST_SUITE_END() // UpdateFace
493BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
494BOOST_AUTO_TEST_SUITE_END() // Mgmt
495
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400496} // namespace nfd::tests