blob: 45e70d26736799bbb6035207dd4b6c5a6f11b0be [file] [log] [blame]
Yanbiao Li73860e32015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi60286192017-07-26 01:07:48 +00002/*
Davide Pesavento1d2d3372025-01-14 12:04:12 -05003 * Copyright (c) 2014-2025, Regents of the University of California,
Yanbiao Li73860e32015-08-19 16:30:16 -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"
Eric Newberry0c3e57b2018-01-25 20:54:46 -070027#include "face/generic-link-service.hpp"
Davide Pesaventof56cf632024-01-27 22:22:06 -050028
Eric Newberry42602412016-08-27 09:33:18 -070029#include "face-manager-command-fixture.hpp"
Junxiao Shib84e6742016-07-19 13:16:22 +000030
Davide Pesaventof56cf632024-01-27 22:22:06 -050031#include <boost/mp11/list.hpp>
32
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040033namespace nfd::tests {
Yanbiao Li73860e32015-08-19 16:30:16 -070034
Yanbiao Li73860e32015-08-19 16:30:16 -070035BOOST_AUTO_TEST_SUITE(Mgmt)
36BOOST_AUTO_TEST_SUITE(TestFaceManager)
37
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040038BOOST_FIXTURE_TEST_SUITE(CreateFace, GlobalIoFixture)
Yanbiao Li73860e32015-08-19 16:30:16 -070039
Yanbiao Li73860e32015-08-19 16:30:16 -070040class TcpFaceOnDemand
41{
42public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -040043 static ControlParameters
Yanbiao Li73860e32015-08-19 16:30:16 -070044 getParameters()
45 {
46 return ControlParameters()
47 .setUri("tcp4://127.0.0.1:26363")
48 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
49 }
50};
51
52class TcpFacePersistent
53{
54public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -040055 static ControlParameters
Yanbiao Li73860e32015-08-19 16:30:16 -070056 getParameters()
57 {
58 return ControlParameters()
59 .setUri("tcp4://127.0.0.1:26363")
60 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
61 }
62};
63
64class TcpFacePermanent
65{
66public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -040067 static ControlParameters
Yanbiao Li73860e32015-08-19 16:30:16 -070068 getParameters()
69 {
70 return ControlParameters()
71 .setUri("tcp4://127.0.0.1:26363")
72 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
73 }
74};
75
76class UdpFaceOnDemand
77{
78public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -040079 static ControlParameters
Yanbiao Li73860e32015-08-19 16:30:16 -070080 getParameters()
81 {
82 return ControlParameters()
83 .setUri("udp4://127.0.0.1:26363")
84 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_ON_DEMAND);
85 }
86};
87
Yanbiao Li73860e32015-08-19 16:30:16 -070088class UdpFacePersistent
89{
90public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -040091 static ControlParameters
Yanbiao Li73860e32015-08-19 16:30:16 -070092 getParameters()
93 {
94 return ControlParameters()
95 .setUri("udp4://127.0.0.1:26363")
96 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
97 }
98};
99
100class UdpFacePermanent
101{
102public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400103 static ControlParameters
Yanbiao Li73860e32015-08-19 16:30:16 -0700104 getParameters()
105 {
106 return ControlParameters()
107 .setUri("udp4://127.0.0.1:26363")
108 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
109 }
110};
111
Eric Newberryf40551a2016-09-05 15:41:16 -0700112class LocalTcpFaceLocalFieldsEnabled
113{
114public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400115 static ControlParameters
Eric Newberryf40551a2016-09-05 15:41:16 -0700116 getParameters()
117 {
118 return ControlParameters()
119 .setUri("tcp4://127.0.0.1:26363")
Eric Newberryf40551a2016-09-05 15:41:16 -0700120 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true);
121 }
122};
123
124class LocalTcpFaceLocalFieldsDisabled
125{
126public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400127 static ControlParameters
Eric Newberryf40551a2016-09-05 15:41:16 -0700128 getParameters()
129 {
130 return ControlParameters()
131 .setUri("tcp4://127.0.0.1:26363")
Eric Newberryf40551a2016-09-05 15:41:16 -0700132 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false);
133 }
134};
135
136class NonLocalUdpFaceLocalFieldsEnabled // won't work because non-local scope
137{
138public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400139 static ControlParameters
Eric Newberryf40551a2016-09-05 15:41:16 -0700140 getParameters()
141 {
142 return ControlParameters()
143 .setUri("udp4://127.0.0.1:26363")
Eric Newberryf40551a2016-09-05 15:41:16 -0700144 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true);
145 }
146};
147
148class NonLocalUdpFaceLocalFieldsDisabled
149{
150public:
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400151 static ControlParameters
Eric Newberryf40551a2016-09-05 15:41:16 -0700152 getParameters()
153 {
154 return ControlParameters()
155 .setUri("udp4://127.0.0.1:26363")
Eric Newberryf40551a2016-09-05 15:41:16 -0700156 .setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false);
157 }
158};
159
Eric Newberry2642cd22017-07-13 21:34:53 -0400160class TcpFaceLpReliabilityEnabled
161{
162public:
163 static ControlParameters
164 getParameters()
165 {
166 return ControlParameters()
167 .setUri("tcp4://127.0.0.1:26363")
Eric Newberry2642cd22017-07-13 21:34:53 -0400168 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true);
169 }
170};
171
172class TcpFaceLpReliabilityDisabled
173{
174public:
175 static ControlParameters
176 getParameters()
177 {
178 return ControlParameters()
179 .setUri("tcp4://127.0.0.1:26363")
Eric Newberry2642cd22017-07-13 21:34:53 -0400180 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false);
181 }
182};
183
184class UdpFaceLpReliabilityEnabled
185{
186public:
187 static ControlParameters
188 getParameters()
189 {
190 return ControlParameters()
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700191 .setUri("udp4://127.0.0.1:26363")
Eric Newberry2642cd22017-07-13 21:34:53 -0400192 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true);
193 }
194};
195
196class UdpFaceLpReliabilityDisabled
197{
198public:
199 static ControlParameters
200 getParameters()
201 {
202 return ControlParameters()
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700203 .setUri("udp4://127.0.0.1:26363")
Eric Newberry2642cd22017-07-13 21:34:53 -0400204 .setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false);
205 }
206};
207
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700208class TcpFaceCongestionMarkingEnabled
209{
210public:
211 static ControlParameters
212 getParameters()
213 {
214 return ControlParameters()
215 .setUri("tcp4://127.0.0.1:26363")
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700216 .setBaseCongestionMarkingInterval(50_ms)
217 .setDefaultCongestionThreshold(1000)
218 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true);
219 }
220};
221
222class TcpFaceCongestionMarkingDisabled
223{
224public:
225 static ControlParameters
226 getParameters()
227 {
228 return ControlParameters()
229 .setUri("tcp4://127.0.0.1:26363")
Davide Pesavento4296fe32025-01-14 23:00:41 -0500230 .setBaseCongestionMarkingInterval(50_ms)
231 .setDefaultCongestionThreshold(1000)
232 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false);
233 }
234};
235
236class UdpFaceCongestionMarkingEnabled
237{
238public:
239 static ControlParameters
240 getParameters()
241 {
242 return ControlParameters()
243 .setUri("udp4://127.0.0.1:26363")
244 .setBaseCongestionMarkingInterval(50_ms)
245 .setDefaultCongestionThreshold(1000)
246 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true);
247 }
248};
249
250class UdpFaceCongestionMarkingDisabled
251{
252public:
253 static ControlParameters
254 getParameters()
255 {
256 return ControlParameters()
257 .setUri("udp4://127.0.0.1:26363")
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700258 .setBaseCongestionMarkingInterval(50_ms)
259 .setDefaultCongestionThreshold(1000)
260 .setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false);
261 }
262};
263
Eric Newberry812d6152018-06-06 15:06:01 -0700264class TcpFaceMtuOverride
265{
266public:
267 static ControlParameters
268 getParameters()
269 {
270 return ControlParameters()
271 .setUri("tcp4://127.0.0.1:26363")
Eric Newberry812d6152018-06-06 15:06:01 -0700272 .setMtu(1000);
273 }
274};
275
276class UdpFaceMtuOverride
277{
278public:
279 static ControlParameters
280 getParameters()
281 {
282 return ControlParameters()
283 .setUri("udp4://127.0.0.1:26363")
Eric Newberry812d6152018-06-06 15:06:01 -0700284 .setMtu(1000);
285 }
286};
287
Davide Pesavento4296fe32025-01-14 23:00:41 -0500288class RemoteUriMalformed
Junxiao Shi38c7d9e2017-04-13 14:22:50 +0000289{
290public:
291 static ControlParameters
292 getParameters()
293 {
294 return ControlParameters()
295 .setUri("tcp4://127.0.0.1:not-a-port");
296 }
297};
298
Davide Pesavento4296fe32025-01-14 23:00:41 -0500299class RemoteUriNonCanonical
Junxiao Shi38c7d9e2017-04-13 14:22:50 +0000300{
301public:
302 static ControlParameters
303 getParameters()
304 {
305 return ControlParameters()
306 .setUri("udp://localhost");
307 }
308};
309
Davide Pesavento4296fe32025-01-14 23:00:41 -0500310class LocalUriMalformed
311{
312public:
313 static ControlParameters
314 getParameters()
315 {
316 return ControlParameters()
317 .setUri("udp4://127.0.0.1:26363")
318 .setLocalUri("udp4://127.0.0.1:not-a-port");
319 }
320};
321
322class LocalUriNonCanonical
323{
324public:
325 static ControlParameters
326 getParameters()
327 {
328 return ControlParameters()
329 .setUri("udp4://127.0.0.1:26363")
330 .setLocalUri("udp://localhost");
331 }
332};
333
334class LocalUriUnsupported
335{
336public:
337 static ControlParameters
338 getParameters()
339 {
340 return ControlParameters()
341 .setUri("udp4://127.0.0.1:26363")
342 .setLocalUri("udp4://127.0.0.1:36363");
343 }
344};
345
346class UnsupportedProtocol
Junxiao Shi38c7d9e2017-04-13 14:22:50 +0000347{
348public:
349 static ControlParameters
350 getParameters()
351 {
352 return ControlParameters()
353 .setUri("dev://eth0");
354 }
355};
356
Davide Pesavento4296fe32025-01-14 23:00:41 -0500357// Pairs of FaceCreateCommand request and success/failure response
Davide Pesaventof56cf632024-01-27 22:22:06 -0500358using TestCases = boost::mp11::mp_list<
359 boost::mp11::mp_list<TcpFaceOnDemand, CommandFailure<406>>,
360 boost::mp11::mp_list<TcpFacePersistent, CommandSuccess>,
361 boost::mp11::mp_list<TcpFacePermanent, CommandSuccess>,
362 boost::mp11::mp_list<UdpFaceOnDemand, CommandFailure<406>>,
363 boost::mp11::mp_list<UdpFacePersistent, CommandSuccess>,
364 boost::mp11::mp_list<UdpFacePermanent, CommandSuccess>,
365 boost::mp11::mp_list<LocalTcpFaceLocalFieldsEnabled, CommandSuccess>,
366 boost::mp11::mp_list<LocalTcpFaceLocalFieldsDisabled, CommandSuccess>,
367 boost::mp11::mp_list<NonLocalUdpFaceLocalFieldsEnabled, CommandFailure<406>>,
368 boost::mp11::mp_list<NonLocalUdpFaceLocalFieldsDisabled, CommandSuccess>,
369 boost::mp11::mp_list<TcpFaceLpReliabilityEnabled, CommandSuccess>,
370 boost::mp11::mp_list<TcpFaceLpReliabilityDisabled, CommandSuccess>,
371 boost::mp11::mp_list<UdpFaceLpReliabilityEnabled, CommandSuccess>,
372 boost::mp11::mp_list<UdpFaceLpReliabilityDisabled, CommandSuccess>,
373 boost::mp11::mp_list<TcpFaceCongestionMarkingEnabled, CommandSuccess>,
374 boost::mp11::mp_list<TcpFaceCongestionMarkingDisabled, CommandSuccess>,
Davide Pesavento4296fe32025-01-14 23:00:41 -0500375 boost::mp11::mp_list<UdpFaceCongestionMarkingEnabled, CommandSuccess>,
376 boost::mp11::mp_list<UdpFaceCongestionMarkingDisabled, CommandSuccess>,
Davide Pesaventof56cf632024-01-27 22:22:06 -0500377 boost::mp11::mp_list<TcpFaceMtuOverride, CommandFailure<406>>,
378 boost::mp11::mp_list<UdpFaceMtuOverride, CommandSuccess>,
Davide Pesavento4296fe32025-01-14 23:00:41 -0500379 boost::mp11::mp_list<RemoteUriMalformed, CommandFailure<400>>,
380 boost::mp11::mp_list<RemoteUriNonCanonical, CommandFailure<400>>,
381 boost::mp11::mp_list<LocalUriMalformed, CommandFailure<400>>,
382 boost::mp11::mp_list<LocalUriNonCanonical, CommandFailure<400>>,
383 boost::mp11::mp_list<LocalUriUnsupported, CommandFailure<406>>,
384 boost::mp11::mp_list<UnsupportedProtocol, CommandFailure<406>>
Davide Pesaventof56cf632024-01-27 22:22:06 -0500385>;
Yanbiao Li73860e32015-08-19 16:30:16 -0700386
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400387BOOST_FIXTURE_TEST_CASE_TEMPLATE(NewFace, T, TestCases, FaceManagerCommandFixture)
Yanbiao Li73860e32015-08-19 16:30:16 -0700388{
Davide Pesavento4296fe32025-01-14 23:00:41 -0500389 using CreateRequest = boost::mp11::mp_first<T>;
Davide Pesaventof56cf632024-01-27 22:22:06 -0500390 using CreateResult = boost::mp11::mp_second<T>;
Yanbiao Li73860e32015-08-19 16:30:16 -0700391
Davide Pesavento4296fe32025-01-14 23:00:41 -0500392 Interest req = makeControlCommandRequest(this->CREATE_REQUEST, CreateRequest::getParameters());
Yanbiao Li73860e32015-08-19 16:30:16 -0700393
394 bool hasCallbackFired = false;
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000395 this->node1.face.onSendData.connect([this, req, &hasCallbackFired] (const Data& response) {
396 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberry42602412016-08-27 09:33:18 -0700397 return;
398 }
Yanbiao Li73860e32015-08-19 16:30:16 -0700399
Eric Newberry42602412016-08-27 09:33:18 -0700400 ControlResponse actual(response.getContent().blockFromValue());
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400401 ControlResponse expected(CreateResult::getExpected());
Davide Pesavento4296fe32025-01-14 23:00:41 -0500402 BOOST_TEST(expected.getCode() == actual.getCode(), actual.getText());
Yanbiao Li73860e32015-08-19 16:30:16 -0700403
Eric Newberry42602412016-08-27 09:33:18 -0700404 if (actual.getBody().hasWire()) {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500405 ControlParameters expectedParams(CreateRequest::getParameters());
406 ndn::nfd::FaceCreateCommand::applyDefaultsToRequest(expectedParams);
Eric Newberry42602412016-08-27 09:33:18 -0700407 ControlParameters actualParams(actual.getBody());
Yanbiao Li73860e32015-08-19 16:30:16 -0700408
Davide Pesavento4296fe32025-01-14 23:00:41 -0500409 BOOST_TEST(actualParams.hasFaceId());
410 BOOST_TEST(expectedParams.getUri() == actualParams.getUri());
411 BOOST_TEST(actualParams.hasLocalUri());
412 BOOST_TEST(actualParams.hasFlags());
413 BOOST_TEST(expectedParams.getFacePersistency() == actualParams.getFacePersistency());
Eric Newberry42602412016-08-27 09:33:18 -0700414
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700415 if (actual.getCode() == 200) {
416 if (expectedParams.hasFlags()) {
Eric Newberryf40551a2016-09-05 15:41:16 -0700417 BOOST_CHECK_EQUAL(expectedParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED),
418 actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
Eric Newberry2642cd22017-07-13 21:34:53 -0400419 BOOST_CHECK_EQUAL(expectedParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED),
420 actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
Eric Newberry17d18492018-02-10 22:50:06 -0700421 if (expectedParams.hasFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)) {
422 BOOST_CHECK_EQUAL(expectedParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED),
423 actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
424 }
425 else {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500426 // congestion marking is enabled by default
427 BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
Eric Newberry17d18492018-02-10 22:50:06 -0700428 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700429 }
430 else {
Davide Pesavento4296fe32025-01-14 23:00:41 -0500431 // local fields and reliability are disabled by default
432 // congestion marking is enabled by default on TCP, UDP, and Unix stream
433 BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
434 BOOST_TEST(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
435 BOOST_TEST(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700436 }
437
438 if (expectedParams.hasBaseCongestionMarkingInterval()) {
439 BOOST_CHECK_EQUAL(expectedParams.getBaseCongestionMarkingInterval(),
440 actualParams.getBaseCongestionMarkingInterval());
441 }
442 else {
443 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 100_ms);
444 }
445
446 if (expectedParams.hasDefaultCongestionThreshold()) {
447 BOOST_CHECK_EQUAL(expectedParams.getDefaultCongestionThreshold(),
448 actualParams.getDefaultCongestionThreshold());
449 }
450 else {
451 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 65536);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700452 }
Eric Newberry812d6152018-06-06 15:06:01 -0700453
454 if (expectedParams.hasMtu()) {
455 BOOST_CHECK_EQUAL(expectedParams.getMtu(), actualParams.getMtu());
456 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700457 }
Eric Newberry42602412016-08-27 09:33:18 -0700458 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700459
460 if (actual.getCode() != 200) {
Junxiao Shi38c7d9e2017-04-13 14:22:50 +0000461 FaceUri uri;
Davide Pesavento4296fe32025-01-14 23:00:41 -0500462 if (uri.parse(CreateRequest::getParameters().getUri())) {
Junxiao Shi38c7d9e2017-04-13 14:22:50 +0000463 // ensure face not created
Davide Pesaventob5eee202017-09-21 23:59:22 -0400464 const auto& faceTable = this->node1.faceTable;
Junxiao Shi38c7d9e2017-04-13 14:22:50 +0000465 BOOST_CHECK(std::none_of(faceTable.begin(), faceTable.end(), [uri] (Face& face) {
466 return face.getRemoteUri() == uri;
467 }));
468 }
469 else {
470 // do not check malformed FaceUri
471 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700472 }
473
Eric Newberry42602412016-08-27 09:33:18 -0700474 hasCallbackFired = true;
475 });
Yanbiao Li73860e32015-08-19 16:30:16 -0700476
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000477 this->node1.face.receive(req);
Davide Pesavento1d2d3372025-01-14 12:04:12 -0500478 this->advanceClocks(1_ms, 10);
Yanbiao Li73860e32015-08-19 16:30:16 -0700479
Davide Pesavento4296fe32025-01-14 23:00:41 -0500480 BOOST_TEST(hasCallbackFired);
Yanbiao Li73860e32015-08-19 16:30:16 -0700481}
482
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000483BOOST_FIXTURE_TEST_CASE(ExistingFace, FaceManagerCommandFixture)
Yanbiao Li73860e32015-08-19 16:30:16 -0700484{
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000485 using FaceType = UdpFacePersistent;
Yanbiao Li73860e32015-08-19 16:30:16 -0700486
487 {
488 // create face
Davide Pesavento1d2d3372025-01-14 12:04:12 -0500489 Interest req = makeControlCommandRequest(CREATE_REQUEST, FaceType::getParameters());
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000490 this->node1.face.receive(req);
Davide Pesavento1d2d3372025-01-14 12:04:12 -0500491 this->advanceClocks(1_ms, 10);
Yanbiao Li73860e32015-08-19 16:30:16 -0700492 }
493
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000494 // find the created face
Davide Pesaventoa3c9ddb2017-04-10 22:15:24 -0400495 auto foundFace = this->node1.findFaceByUri(FaceType::getParameters().getUri());
Davide Pesavento4296fe32025-01-14 23:00:41 -0500496 BOOST_TEST_REQUIRE(foundFace != nullptr);
Yanbiao Li73860e32015-08-19 16:30:16 -0700497
498 {
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000499 // re-create face
Davide Pesavento1d2d3372025-01-14 12:04:12 -0500500 Interest req = makeControlCommandRequest(CREATE_REQUEST, FaceType::getParameters());
Yanbiao Li73860e32015-08-19 16:30:16 -0700501
502 bool hasCallbackFired = false;
Junxiao Shib84e6742016-07-19 13:16:22 +0000503 this->node1.face.onSendData.connect(
Davide Pesaventoac238f22017-09-12 15:19:40 -0400504 [req, foundFace, &hasCallbackFired] (const Data& response) {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000505 if (!req.getName().isPrefixOf(response.getName())) {
Yanbiao Li73860e32015-08-19 16:30:16 -0700506 return;
507 }
508
509 ControlResponse actual(response.getContent().blockFromValue());
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000510 BOOST_REQUIRE_EQUAL(actual.getCode(), 409);
Yanbiao Li73860e32015-08-19 16:30:16 -0700511
Yanbiao Li73860e32015-08-19 16:30:16 -0700512 ControlParameters actualParams(actual.getBody());
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000513 BOOST_CHECK_EQUAL(foundFace->getId(), actualParams.getFaceId());
514 BOOST_CHECK_EQUAL(foundFace->getRemoteUri().toString(), actualParams.getUri());
515 BOOST_CHECK_EQUAL(foundFace->getPersistency(), actualParams.getFacePersistency());
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700516 auto linkService = dynamic_cast<face::GenericLinkService*>(foundFace->getLinkService());
517 BOOST_CHECK_EQUAL(linkService->getOptions().baseCongestionMarkingInterval,
518 actualParams.getBaseCongestionMarkingInterval());
519 BOOST_CHECK_EQUAL(linkService->getOptions().defaultCongestionThreshold,
520 actualParams.getDefaultCongestionThreshold());
Yanbiao Li73860e32015-08-19 16:30:16 -0700521
522 hasCallbackFired = true;
523 });
524
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000525 this->node1.face.receive(req);
Davide Pesavento1d2d3372025-01-14 12:04:12 -0500526 this->advanceClocks(1_ms, 10);
Yanbiao Li73860e32015-08-19 16:30:16 -0700527
Davide Pesavento4296fe32025-01-14 23:00:41 -0500528 BOOST_TEST(hasCallbackFired);
Yanbiao Li73860e32015-08-19 16:30:16 -0700529 }
530}
531
532BOOST_AUTO_TEST_SUITE_END() // CreateFace
533BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
534BOOST_AUTO_TEST_SUITE_END() // Mgmt
535
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400536} // namespace nfd::tests