blob: 4cd6fb6686b43f6b16263dfdbd124ed54529f6ad [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 Pesavento78ddcab2019-02-28 22:00:03 -05003 * Copyright (c) 2014-2019, 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"
Eric Newberryb5aa7f52016-09-03 20:36:12 -070028#include "face-manager-command-fixture.hpp"
Yanbiao Li58ba3f92017-02-15 14:27:18 +000029
Junxiao Shicbc8e942016-09-06 03:17:45 +000030#include <ndn-cxx/lp/tags.hpp>
Eric Newberryb5aa7f52016-09-03 20:36:12 -070031
Yanbiao Li58ba3f92017-02-15 14:27:18 +000032#include <thread>
33
Eric Newberry0c3e57b2018-01-25 20:54:46 -070034#include <boost/logic/tribool.hpp>
35
Eric Newberryb5aa7f52016-09-03 20:36:12 -070036namespace nfd {
37namespace tests {
38
39BOOST_AUTO_TEST_SUITE(Mgmt)
40BOOST_AUTO_TEST_SUITE(TestFaceManager)
41
Davide Pesavento3cf75dc2018-03-17 00:38:03 -040042namespace mpl = boost::mpl;
43
Eric Newberryb5aa7f52016-09-03 20:36:12 -070044class FaceManagerUpdateFixture : public FaceManagerCommandFixture
45{
46public:
Eric Newberryb5aa7f52016-09-03 20:36:12 -070047 ~FaceManagerUpdateFixture()
48 {
49 destroyFace();
50 }
51
52 void
53 createFace(const std::string& uri = "tcp4://127.0.0.1:26363",
54 ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Davide Pesavento87fc0f82018-04-11 23:43:51 -040055 optional<time::nanoseconds> baseCongestionMarkingInterval = {},
56 optional<uint64_t> defaultCongestionThreshold = {},
Eric Newberry2642cd22017-07-13 21:34:53 -040057 bool enableLocalFields = false,
Eric Newberry0c3e57b2018-01-25 20:54:46 -070058 bool enableReliability = false,
59 boost::logic::tribool enableCongestionMarking = boost::logic::indeterminate)
Eric Newberryb5aa7f52016-09-03 20:36:12 -070060 {
61 ControlParameters params;
62 params.setUri(uri);
63 params.setFacePersistency(persistency);
Eric Newberry0c3e57b2018-01-25 20:54:46 -070064
65 if (baseCongestionMarkingInterval) {
66 params.setBaseCongestionMarkingInterval(*baseCongestionMarkingInterval);
67 }
68
69 if (defaultCongestionThreshold) {
70 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
71 }
72
Eric Newberryb5aa7f52016-09-03 20:36:12 -070073 params.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, enableLocalFields);
Eric Newberry2642cd22017-07-13 21:34:53 -040074 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, enableReliability);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070075
Eric Newberry0c3e57b2018-01-25 20:54:46 -070076 if (!boost::logic::indeterminate(enableCongestionMarking)) {
Davide Pesaventofa2aa502019-03-22 13:30:02 -040077 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, bool(enableCongestionMarking));
Eric Newberry0c3e57b2018-01-25 20:54:46 -070078 }
79
Yanbiao Li58ba3f92017-02-15 14:27:18 +000080 createFace(params);
81 }
82
83 void
Davide Pesavento3cf75dc2018-03-17 00:38:03 -040084 createFace(const ControlParameters& createParams, bool isForOnDemandFace = false)
Yanbiao Li58ba3f92017-02-15 14:27:18 +000085 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +000086 Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", createParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070087
Yanbiao Li58ba3f92017-02-15 14:27:18 +000088 // if this creation if for on-demand face then create it on node2
89 FaceManagerCommandNode& target = isForOnDemandFace ? this->node2 : this->node1;
90
Eric Newberryb5aa7f52016-09-03 20:36:12 -070091 bool hasCallbackFired = false;
Yanbiao Li58ba3f92017-02-15 14:27:18 +000092 signal::ScopedConnection connection = target.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +000093 [&, req, isForOnDemandFace, this] (const Data& response) {
94 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -070095 return;
96 }
97
98 ControlResponse create(response.getContent().blockFromValue());
99 BOOST_REQUIRE_EQUAL(create.getCode(), 200);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000100 BOOST_REQUIRE(create.getBody().hasWire());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700101
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000102 ControlParameters faceParams(create.getBody());
103 BOOST_REQUIRE(faceParams.hasFaceId());
104 this->faceId = faceParams.getFaceId();
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700105
106 hasCallbackFired = true;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000107
108 if (isForOnDemandFace) {
109 auto face = target.faceTable.get(static_cast<FaceId>(this->faceId));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000110 // to force creation of on-demand face
111 face->sendInterest(*make_shared<Interest>("/hello/world"));
112 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700113 });
114
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000115 target.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400116 advanceClocks(1_ms, 5);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700117
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000118 if (isForOnDemandFace) {
119 std::this_thread::sleep_for(std::chrono::milliseconds(100)); // allow wallclock time for socket IO
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400120 advanceClocks(1_ms, 5); // let node1 accept Interest and create on-demand face
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000121 }
122
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700123 BOOST_REQUIRE(hasCallbackFired);
124 }
125
126 void
127 updateFace(const ControlParameters& requestParams,
128 bool isSelfUpdating,
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400129 const std::function<void(const ControlResponse& resp)>& checkResp)
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700130 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000131 Interest req = makeControlCommandRequest("/localhost/nfd/faces/update", requestParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700132 if (isSelfUpdating) {
133 // Attach IncomingFaceIdTag to interest
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000134 req.setTag(make_shared<lp::IncomingFaceIdTag>(faceId));
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700135 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700136
137 bool hasCallbackFired = false;
138 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Davide Pesaventoac238f22017-09-12 15:19:40 -0400139 [req, &hasCallbackFired, &checkResp] (const Data& response) {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000140 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700141 return;
142 }
143
144 ControlResponse actual(response.getContent().blockFromValue());
145 checkResp(actual);
146
147 hasCallbackFired = true;
148 });
149
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000150 this->node1.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400151 advanceClocks(1_ms, 5);
152 BOOST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700153 }
154
155private:
156 void
157 destroyFace()
158 {
159 if (faceId == 0) {
160 return;
161 }
162
163 ControlParameters params;
164 params.setFaceId(faceId);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000165 Interest req = makeControlCommandRequest("/localhost/nfd/faces/destroy", params);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700166
167 bool hasCallbackFired = false;
168 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000169 [this, req, &hasCallbackFired] (const Data& response) {
170 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700171 return;
172 }
173
174 ControlResponse destroy(response.getContent().blockFromValue());
175 BOOST_CHECK_EQUAL(destroy.getCode(), 200);
176
177 faceId = 0;
178 hasCallbackFired = true;
179 });
180
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000181 this->node1.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400182 advanceClocks(1_ms, 5);
183 BOOST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700184 }
185
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400186protected:
187 FaceId faceId = 0;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700188};
189
190BOOST_FIXTURE_TEST_SUITE(UpdateFace, FaceManagerUpdateFixture)
191
192BOOST_AUTO_TEST_CASE(FaceDoesNotExist)
193{
194 ControlParameters requestParams;
195 requestParams.setFaceId(65535);
196
197 updateFace(requestParams, false, [] (const ControlResponse& actual) {
198 ControlResponse expected(404, "Specified face does not exist");
199 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
200 BOOST_TEST_MESSAGE(actual.getText());
201 });
202}
203
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000204template<bool CAN_CHANGE_PERSISTENCY>
205class UpdatePersistencyDummyTransport : public face::Transport
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700206{
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000207public:
208 UpdatePersistencyDummyTransport()
209 {
210 this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
211 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700212
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000213protected:
214 bool
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400215 canChangePersistencyToImpl(ndn::nfd::FacePersistency) const final
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000216 {
217 return CAN_CHANGE_PERSISTENCY;
218 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700219
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000220 void
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400221 doClose() final
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000222 {
223 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700224
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000225private:
226 void
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400227 doSend(face::Transport::Packet&&) final
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000228 {
229 }
230};
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700231
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400232using UpdatePersistencyTests = mpl::vector<
233 mpl::pair<UpdatePersistencyDummyTransport<true>, CommandSuccess>,
234 mpl::pair<UpdatePersistencyDummyTransport<false>, CommandFailure<409>>
235>;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000236
237BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePersistency, T, UpdatePersistencyTests, FaceManagerUpdateFixture)
238{
239 using TransportType = typename T::first;
240 using ResultType = typename T::second;
241
242 auto face = make_shared<face::Face>(make_unique<face::GenericLinkService>(),
243 make_unique<TransportType>());
244 this->node1.faceTable.add(face);
245
246 auto parameters = ControlParameters()
247 .setFaceId(face->getId())
248 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
249
250 updateFace(parameters, false, [] (const ControlResponse& actual) {
251 BOOST_TEST_MESSAGE(actual.getText());
252 BOOST_CHECK_EQUAL(actual.getCode(), ResultType::getExpected().getCode());
253
254 // the response for either 200 or 409 will have a content body
255 BOOST_REQUIRE(actual.getBody().hasWire());
256
257 ControlParameters resp;
258 resp.wireDecode(actual.getBody());
259 BOOST_CHECK_EQUAL(resp.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700260 });
261}
262
263class TcpLocalFieldsEnable
264{
265public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400266 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700267 getUri()
268 {
269 return "tcp4://127.0.0.1:26363";
270 }
271
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400272 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700273 getPersistency()
274 {
275 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
276 }
277
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400278 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700279 getInitLocalFieldsEnabled()
280 {
281 return false;
282 }
283
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400284 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700285 getLocalFieldsEnabled()
286 {
287 return true;
288 }
289
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400290 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700291 getLocalFieldsEnabledMask()
292 {
293 return true;
294 }
295
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400296 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700297 shouldHaveWire()
298 {
299 return false;
300 }
301};
302
303class TcpLocalFieldsDisable
304{
305public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400306 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700307 getUri()
308 {
309 return "tcp4://127.0.0.1:26363";
310 }
311
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400312 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700313 getPersistency()
314 {
315 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
316 }
317
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400318 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700319 getInitLocalFieldsEnabled()
320 {
321 return true;
322 }
323
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400324 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700325 getLocalFieldsEnabled()
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 getLocalFieldsEnabledMask()
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 shouldHaveWire()
338 {
339 return false;
340 }
341};
342
343// UDP faces are non-local by definition
344class UdpLocalFieldsEnable
345{
346public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400347 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700348 getUri()
349 {
350 return "udp4://127.0.0.1:26363";
351 }
352
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400353 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700354 getPersistency()
355 {
356 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
357 }
358
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400359 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700360 getInitLocalFieldsEnabled()
361 {
362 return false;
363 }
364
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400365 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700366 getLocalFieldsEnabled()
367 {
368 return true;
369 }
370
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400371 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700372 getLocalFieldsEnabledMask()
373 {
374 return true;
375 }
376
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400377 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700378 shouldHaveWire()
379 {
380 return true;
381 }
382};
383
384// UDP faces are non-local by definition
385// In this test case, attempt to disable local fields on face with local fields already disabled
386class UdpLocalFieldsDisable
387{
388public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400389 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700390 getUri()
391 {
392 return "udp4://127.0.0.1:26363";
393 }
394
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400395 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700396 getPersistency()
397 {
398 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
399 }
400
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400401 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700402 getInitLocalFieldsEnabled()
403 {
404 return false;
405 }
406
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400407 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700408 getLocalFieldsEnabled()
409 {
410 return false;
411 }
412
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400413 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700414 getLocalFieldsEnabledMask()
415 {
416 return true;
417 }
418
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400419 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700420 shouldHaveWire()
421 {
422 return false;
423 }
424};
425
426// In this test case, set Flags to enable local fields on non-local face, but exclude local fields
427// from Mask. This test case will pass as no action is taken due to the missing Mask bit.
428class UdpLocalFieldsEnableNoMaskBit
429{
430public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400431 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700432 getUri()
433 {
434 return "udp4://127.0.0.1:26363";
435 }
436
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400437 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700438 getPersistency()
439 {
440 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
441 }
442
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400443 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700444 getInitLocalFieldsEnabled()
445 {
446 return false;
447 }
448
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400449 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700450 getLocalFieldsEnabled()
451 {
452 return true;
453 }
454
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400455 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700456 getLocalFieldsEnabledMask()
457 {
458 return false;
459 }
460
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400461 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700462 shouldHaveWire()
463 {
464 return false;
465 }
466};
467
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400468using LocalFieldFaces = mpl::vector<
469 mpl::pair<TcpLocalFieldsEnable, CommandSuccess>,
470 mpl::pair<TcpLocalFieldsDisable, CommandSuccess>,
471 mpl::pair<UdpLocalFieldsEnable, CommandFailure<409>>,
472 mpl::pair<UdpLocalFieldsDisable, CommandSuccess>,
473 mpl::pair<UdpLocalFieldsEnableNoMaskBit, CommandSuccess>
474>;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700475
476BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateLocalFields, T, LocalFieldFaces)
477{
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400478 using TestType = typename T::first;
479 using ResultType = typename T::second;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700480
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400481 createFace(TestType::getUri(), TestType::getPersistency(), {}, {},
482 TestType::getInitLocalFieldsEnabled());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700483
484 ControlParameters requestParams;
485 requestParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400486 requestParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, TestType::getLocalFieldsEnabled());
487 if (!TestType::getLocalFieldsEnabledMask()) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700488 requestParams.unsetFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED);
489 }
490
491 updateFace(requestParams, false, [] (const ControlResponse& actual) {
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400492 ControlResponse expected(ResultType::getExpected());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700493 BOOST_TEST_MESSAGE(actual.getText());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400494 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700495
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400496 if (TestType::shouldHaveWire() && actual.getBody().hasWire()) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700497 ControlParameters actualParams(actual.getBody());
498
499 BOOST_CHECK(!actualParams.hasFacePersistency());
500 BOOST_CHECK(actualParams.hasFlags());
501 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
502 BOOST_CHECK(actualParams.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
503 }
504 });
505}
506
507BOOST_AUTO_TEST_CASE(UpdateLocalFieldsEnableDisable)
508{
509 createFace();
510
511 ControlParameters enableParams;
512 enableParams.setFaceId(faceId);
513 enableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true);
514
515 ControlParameters disableParams;
516 disableParams.setFaceId(faceId);
517 disableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false);
518
519 updateFace(enableParams, false, [] (const ControlResponse& actual) {
520 ControlResponse expected(200, "OK");
521 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
522 BOOST_TEST_MESSAGE(actual.getText());
523
524 if (actual.getBody().hasWire()) {
525 ControlParameters actualParams(actual.getBody());
526
527 BOOST_CHECK(actualParams.hasFaceId());
528 BOOST_CHECK(actualParams.hasFacePersistency());
529 BOOST_REQUIRE(actualParams.hasFlags());
530 // Check if flags indicate local fields enabled
531 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
532 }
533 else {
534 BOOST_ERROR("Enable: Response does not contain ControlParameters");
535 }
536 });
537
538 updateFace(disableParams, false, [] (const ControlResponse& actual) {
539 ControlResponse expected(200, "OK");
540 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
541 BOOST_TEST_MESSAGE(actual.getText());
542
543 if (actual.getBody().hasWire()) {
544 ControlParameters actualParams(actual.getBody());
545
546 BOOST_CHECK(actualParams.hasFaceId());
547 BOOST_CHECK(actualParams.hasFacePersistency());
548 BOOST_REQUIRE(actualParams.hasFlags());
549 // Check if flags indicate local fields disabled
550 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
551 }
552 else {
553 BOOST_ERROR("Disable: Response does not contain ControlParameters");
554 }
555 });
556}
557
Eric Newberry2642cd22017-07-13 21:34:53 -0400558BOOST_AUTO_TEST_CASE(UpdateReliabilityEnableDisable)
559{
560 createFace("udp4://127.0.0.1:26363");
561
562 ControlParameters enableParams;
563 enableParams.setFaceId(faceId);
564 enableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true);
565
566 ControlParameters disableParams;
567 disableParams.setFaceId(faceId);
568 disableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false);
569
570 updateFace(enableParams, false, [] (const ControlResponse& actual) {
571 ControlResponse expected(200, "OK");
572 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
573 BOOST_TEST_MESSAGE(actual.getText());
574
575 if (actual.getBody().hasWire()) {
576 ControlParameters actualParams(actual.getBody());
577
578 BOOST_CHECK(actualParams.hasFaceId());
579 BOOST_CHECK(actualParams.hasFacePersistency());
580 BOOST_REQUIRE(actualParams.hasFlags());
581 // Check if flags indicate reliability enabled
582 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
583 }
584 else {
585 BOOST_ERROR("Enable: Response does not contain ControlParameters");
586 }
587 });
588
589 updateFace(disableParams, false, [] (const ControlResponse& actual) {
590 ControlResponse expected(200, "OK");
591 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
592 BOOST_TEST_MESSAGE(actual.getText());
593
594 if (actual.getBody().hasWire()) {
595 ControlParameters actualParams(actual.getBody());
596
597 BOOST_CHECK(actualParams.hasFaceId());
598 BOOST_CHECK(actualParams.hasFacePersistency());
599 BOOST_REQUIRE(actualParams.hasFlags());
600 // Check if flags indicate reliability disabled
601 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
602 }
603 else {
604 BOOST_ERROR("Disable: Response does not contain ControlParameters");
605 }
606 });
607}
608
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700609BOOST_AUTO_TEST_CASE(UpdateCongestionMarkingEnableDisable)
610{
611 createFace("udp4://127.0.0.1:26363");
612
613 ControlParameters enableParams;
614 enableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400615 enableParams.setBaseCongestionMarkingInterval(50_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700616 enableParams.setDefaultCongestionThreshold(10000);
617 enableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true);
618
619 ControlParameters disableParams;
620 disableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400621 disableParams.setBaseCongestionMarkingInterval(70_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700622 disableParams.setDefaultCongestionThreshold(5000);
623 disableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false);
624
625 updateFace(enableParams, false, [] (const ControlResponse& actual) {
626 ControlResponse expected(200, "OK");
627 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
628 BOOST_TEST_MESSAGE(actual.getText());
629
630 if (actual.getBody().hasWire()) {
631 ControlParameters actualParams(actual.getBody());
632
633 BOOST_CHECK(actualParams.hasFaceId());
634 BOOST_CHECK(actualParams.hasFacePersistency());
635 // Check that congestion marking parameters changed
636 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400637 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 50_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700638 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
639 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 10000);
640 BOOST_REQUIRE(actualParams.hasFlags());
641 // Check if flags indicate congestion marking enabled
642 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
643 }
644 else {
645 BOOST_ERROR("Enable: Response does not contain ControlParameters");
646 }
647 });
648
649 updateFace(disableParams, false, [] (const ControlResponse& actual) {
650 ControlResponse expected(200, "OK");
651 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
652 BOOST_TEST_MESSAGE(actual.getText());
653
654 if (actual.getBody().hasWire()) {
655 ControlParameters actualParams(actual.getBody());
656
657 BOOST_CHECK(actualParams.hasFaceId());
658 BOOST_CHECK(actualParams.hasFacePersistency());
659 // Check that congestion marking parameters changed, even though feature disabled
660 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400661 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 70_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700662 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
663 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 5000);
664 BOOST_REQUIRE(actualParams.hasFlags());
665 // Check if flags indicate marking disabled
666 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
667 }
668 else {
669 BOOST_ERROR("Disable: Response does not contain ControlParameters");
670 }
671 });
672}
673
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700674BOOST_AUTO_TEST_CASE(SelfUpdating)
675{
676 createFace();
677
678 // Send a command that does nothing (will return 200) and does not contain a FaceId
679 ControlParameters sentParams;
680
681 updateFace(sentParams, true, [] (const ControlResponse& actual) {
682 ControlResponse expected(200, "OK");
683 BOOST_REQUIRE_EQUAL(actual.getCode(), expected.getCode());
684 BOOST_TEST_MESSAGE(actual.getText());
685 });
686}
687
688BOOST_AUTO_TEST_SUITE_END() // UpdateFace
689BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
690BOOST_AUTO_TEST_SUITE_END() // Mgmt
691
692} // namespace tests
693} // namespace nfd