blob: f7e89f8b69610480a6b651087aac29d7e63f7fcc [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"
Davide Pesavento16916ae2019-03-29 23:53:26 -040028
Eric Newberryb5aa7f52016-09-03 20:36:12 -070029#include "face-manager-command-fixture.hpp"
Davide Pesavento16916ae2019-03-29 23:53:26 -040030#include "tests/daemon/face/dummy-transport.hpp"
Yanbiao Li58ba3f92017-02-15 14:27:18 +000031
Junxiao Shicbc8e942016-09-06 03:17:45 +000032#include <ndn-cxx/lp/tags.hpp>
Eric Newberryb5aa7f52016-09-03 20:36:12 -070033
Yanbiao Li58ba3f92017-02-15 14:27:18 +000034#include <thread>
35
Eric Newberry0c3e57b2018-01-25 20:54:46 -070036#include <boost/logic/tribool.hpp>
37
Eric Newberryb5aa7f52016-09-03 20:36:12 -070038namespace nfd {
39namespace tests {
40
41BOOST_AUTO_TEST_SUITE(Mgmt)
42BOOST_AUTO_TEST_SUITE(TestFaceManager)
43
Davide Pesavento3cf75dc2018-03-17 00:38:03 -040044namespace mpl = boost::mpl;
45
Eric Newberryb5aa7f52016-09-03 20:36:12 -070046class FaceManagerUpdateFixture : public FaceManagerCommandFixture
47{
48public:
Eric Newberryb5aa7f52016-09-03 20:36:12 -070049 ~FaceManagerUpdateFixture()
50 {
51 destroyFace();
52 }
53
54 void
55 createFace(const std::string& uri = "tcp4://127.0.0.1:26363",
56 ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Davide Pesavento87fc0f82018-04-11 23:43:51 -040057 optional<time::nanoseconds> baseCongestionMarkingInterval = {},
58 optional<uint64_t> defaultCongestionThreshold = {},
Eric Newberry2642cd22017-07-13 21:34:53 -040059 bool enableLocalFields = false,
Eric Newberry0c3e57b2018-01-25 20:54:46 -070060 bool enableReliability = false,
61 boost::logic::tribool enableCongestionMarking = boost::logic::indeterminate)
Eric Newberryb5aa7f52016-09-03 20:36:12 -070062 {
63 ControlParameters params;
64 params.setUri(uri);
65 params.setFacePersistency(persistency);
Eric Newberry0c3e57b2018-01-25 20:54:46 -070066
67 if (baseCongestionMarkingInterval) {
68 params.setBaseCongestionMarkingInterval(*baseCongestionMarkingInterval);
69 }
70
71 if (defaultCongestionThreshold) {
72 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
73 }
74
Eric Newberryb5aa7f52016-09-03 20:36:12 -070075 params.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, enableLocalFields);
Eric Newberry2642cd22017-07-13 21:34:53 -040076 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, enableReliability);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070077
Eric Newberry0c3e57b2018-01-25 20:54:46 -070078 if (!boost::logic::indeterminate(enableCongestionMarking)) {
Davide Pesaventofa2aa502019-03-22 13:30:02 -040079 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, bool(enableCongestionMarking));
Eric Newberry0c3e57b2018-01-25 20:54:46 -070080 }
81
Yanbiao Li58ba3f92017-02-15 14:27:18 +000082 createFace(params);
83 }
84
85 void
Davide Pesavento3cf75dc2018-03-17 00:38:03 -040086 createFace(const ControlParameters& createParams, bool isForOnDemandFace = false)
Yanbiao Li58ba3f92017-02-15 14:27:18 +000087 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +000088 Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", createParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070089
Yanbiao Li58ba3f92017-02-15 14:27:18 +000090 // if this creation if for on-demand face then create it on node2
91 FaceManagerCommandNode& target = isForOnDemandFace ? this->node2 : this->node1;
92
Eric Newberryb5aa7f52016-09-03 20:36:12 -070093 bool hasCallbackFired = false;
Yanbiao Li58ba3f92017-02-15 14:27:18 +000094 signal::ScopedConnection connection = target.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +000095 [&, req, isForOnDemandFace, this] (const Data& response) {
96 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -070097 return;
98 }
99
100 ControlResponse create(response.getContent().blockFromValue());
101 BOOST_REQUIRE_EQUAL(create.getCode(), 200);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000102 BOOST_REQUIRE(create.getBody().hasWire());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700103
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000104 ControlParameters faceParams(create.getBody());
105 BOOST_REQUIRE(faceParams.hasFaceId());
106 this->faceId = faceParams.getFaceId();
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700107
108 hasCallbackFired = true;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000109
110 if (isForOnDemandFace) {
111 auto face = target.faceTable.get(static_cast<FaceId>(this->faceId));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000112 // to force creation of on-demand face
ashiqopu075bb7d2019-03-10 01:38:21 +0000113 face->sendInterest(*make_shared<Interest>("/hello/world"), 0);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000114 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700115 });
116
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000117 target.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400118 advanceClocks(1_ms, 5);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700119
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000120 if (isForOnDemandFace) {
121 std::this_thread::sleep_for(std::chrono::milliseconds(100)); // allow wallclock time for socket IO
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400122 advanceClocks(1_ms, 5); // let node1 accept Interest and create on-demand face
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000123 }
124
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700125 BOOST_REQUIRE(hasCallbackFired);
126 }
127
128 void
129 updateFace(const ControlParameters& requestParams,
130 bool isSelfUpdating,
Davide Pesavento87fc0f82018-04-11 23:43:51 -0400131 const std::function<void(const ControlResponse& resp)>& checkResp)
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700132 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000133 Interest req = makeControlCommandRequest("/localhost/nfd/faces/update", requestParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700134 if (isSelfUpdating) {
135 // Attach IncomingFaceIdTag to interest
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000136 req.setTag(make_shared<lp::IncomingFaceIdTag>(faceId));
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700137 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700138
139 bool hasCallbackFired = false;
140 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Davide Pesaventoac238f22017-09-12 15:19:40 -0400141 [req, &hasCallbackFired, &checkResp] (const Data& response) {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000142 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700143 return;
144 }
145
146 ControlResponse actual(response.getContent().blockFromValue());
147 checkResp(actual);
148
149 hasCallbackFired = true;
150 });
151
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000152 this->node1.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400153 advanceClocks(1_ms, 5);
154 BOOST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700155 }
156
157private:
158 void
159 destroyFace()
160 {
161 if (faceId == 0) {
162 return;
163 }
164
165 ControlParameters params;
166 params.setFaceId(faceId);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000167 Interest req = makeControlCommandRequest("/localhost/nfd/faces/destroy", params);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700168
169 bool hasCallbackFired = false;
170 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000171 [this, req, &hasCallbackFired] (const Data& response) {
172 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700173 return;
174 }
175
176 ControlResponse destroy(response.getContent().blockFromValue());
177 BOOST_CHECK_EQUAL(destroy.getCode(), 200);
178
179 faceId = 0;
180 hasCallbackFired = true;
181 });
182
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000183 this->node1.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400184 advanceClocks(1_ms, 5);
185 BOOST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700186 }
187
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400188protected:
189 FaceId faceId = 0;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700190};
191
192BOOST_FIXTURE_TEST_SUITE(UpdateFace, FaceManagerUpdateFixture)
193
194BOOST_AUTO_TEST_CASE(FaceDoesNotExist)
195{
196 ControlParameters requestParams;
197 requestParams.setFaceId(65535);
198
199 updateFace(requestParams, false, [] (const ControlResponse& actual) {
200 ControlResponse expected(404, "Specified face does not exist");
201 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
202 BOOST_TEST_MESSAGE(actual.getText());
203 });
204}
205
Davide Pesavento16916ae2019-03-29 23:53:26 -0400206using nfd::face::tests::DummyTransportBase;
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400207using UpdatePersistencyTests = mpl::vector<
Davide Pesavento16916ae2019-03-29 23:53:26 -0400208 mpl::pair<DummyTransportBase<true>, CommandSuccess>,
209 mpl::pair<DummyTransportBase<false>, CommandFailure<409>>
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400210>;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000211
212BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePersistency, T, UpdatePersistencyTests, FaceManagerUpdateFixture)
213{
214 using TransportType = typename T::first;
215 using ResultType = typename T::second;
216
217 auto face = make_shared<face::Face>(make_unique<face::GenericLinkService>(),
218 make_unique<TransportType>());
219 this->node1.faceTable.add(face);
220
221 auto parameters = ControlParameters()
222 .setFaceId(face->getId())
223 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
224
225 updateFace(parameters, false, [] (const ControlResponse& actual) {
226 BOOST_TEST_MESSAGE(actual.getText());
227 BOOST_CHECK_EQUAL(actual.getCode(), ResultType::getExpected().getCode());
228
229 // the response for either 200 or 409 will have a content body
230 BOOST_REQUIRE(actual.getBody().hasWire());
231
232 ControlParameters resp;
233 resp.wireDecode(actual.getBody());
234 BOOST_CHECK_EQUAL(resp.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700235 });
236}
237
238class TcpLocalFieldsEnable
239{
240public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400241 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700242 getUri()
243 {
244 return "tcp4://127.0.0.1:26363";
245 }
246
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400247 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700248 getPersistency()
249 {
250 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
251 }
252
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400253 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700254 getInitLocalFieldsEnabled()
255 {
256 return false;
257 }
258
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400259 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700260 getLocalFieldsEnabled()
261 {
262 return true;
263 }
264
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400265 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700266 getLocalFieldsEnabledMask()
267 {
268 return true;
269 }
270
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400271 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700272 shouldHaveWire()
273 {
274 return false;
275 }
276};
277
278class TcpLocalFieldsDisable
279{
280public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400281 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700282 getUri()
283 {
284 return "tcp4://127.0.0.1:26363";
285 }
286
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400287 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700288 getPersistency()
289 {
290 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
291 }
292
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400293 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700294 getInitLocalFieldsEnabled()
295 {
296 return true;
297 }
298
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400299 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700300 getLocalFieldsEnabled()
301 {
302 return false;
303 }
304
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400305 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700306 getLocalFieldsEnabledMask()
307 {
308 return true;
309 }
310
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400311 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700312 shouldHaveWire()
313 {
314 return false;
315 }
316};
317
318// UDP faces are non-local by definition
319class UdpLocalFieldsEnable
320{
321public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400322 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700323 getUri()
324 {
325 return "udp4://127.0.0.1:26363";
326 }
327
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400328 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700329 getPersistency()
330 {
331 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
332 }
333
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400334 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700335 getInitLocalFieldsEnabled()
336 {
337 return false;
338 }
339
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400340 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700341 getLocalFieldsEnabled()
342 {
343 return true;
344 }
345
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400346 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700347 getLocalFieldsEnabledMask()
348 {
349 return true;
350 }
351
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400352 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700353 shouldHaveWire()
354 {
355 return true;
356 }
357};
358
359// UDP faces are non-local by definition
360// In this test case, attempt to disable local fields on face with local fields already disabled
361class UdpLocalFieldsDisable
362{
363public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400364 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700365 getUri()
366 {
367 return "udp4://127.0.0.1:26363";
368 }
369
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400370 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700371 getPersistency()
372 {
373 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
374 }
375
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400376 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700377 getInitLocalFieldsEnabled()
378 {
379 return false;
380 }
381
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400382 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700383 getLocalFieldsEnabled()
384 {
385 return false;
386 }
387
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400388 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700389 getLocalFieldsEnabledMask()
390 {
391 return true;
392 }
393
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400394 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700395 shouldHaveWire()
396 {
397 return false;
398 }
399};
400
401// In this test case, set Flags to enable local fields on non-local face, but exclude local fields
402// from Mask. This test case will pass as no action is taken due to the missing Mask bit.
403class UdpLocalFieldsEnableNoMaskBit
404{
405public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400406 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700407 getUri()
408 {
409 return "udp4://127.0.0.1:26363";
410 }
411
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400412 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700413 getPersistency()
414 {
415 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
416 }
417
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400418 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700419 getInitLocalFieldsEnabled()
420 {
421 return false;
422 }
423
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400424 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700425 getLocalFieldsEnabled()
426 {
427 return true;
428 }
429
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400430 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700431 getLocalFieldsEnabledMask()
432 {
433 return false;
434 }
435
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400436 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700437 shouldHaveWire()
438 {
439 return false;
440 }
441};
442
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400443using LocalFieldFaces = mpl::vector<
444 mpl::pair<TcpLocalFieldsEnable, CommandSuccess>,
445 mpl::pair<TcpLocalFieldsDisable, CommandSuccess>,
446 mpl::pair<UdpLocalFieldsEnable, CommandFailure<409>>,
447 mpl::pair<UdpLocalFieldsDisable, CommandSuccess>,
448 mpl::pair<UdpLocalFieldsEnableNoMaskBit, CommandSuccess>
449>;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700450
451BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateLocalFields, T, LocalFieldFaces)
452{
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400453 using TestType = typename T::first;
454 using ResultType = typename T::second;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700455
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400456 createFace(TestType::getUri(), TestType::getPersistency(), {}, {},
457 TestType::getInitLocalFieldsEnabled());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700458
459 ControlParameters requestParams;
460 requestParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400461 requestParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, TestType::getLocalFieldsEnabled());
462 if (!TestType::getLocalFieldsEnabledMask()) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700463 requestParams.unsetFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED);
464 }
465
466 updateFace(requestParams, false, [] (const ControlResponse& actual) {
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400467 ControlResponse expected(ResultType::getExpected());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700468 BOOST_TEST_MESSAGE(actual.getText());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400469 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700470
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400471 if (TestType::shouldHaveWire() && actual.getBody().hasWire()) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700472 ControlParameters actualParams(actual.getBody());
473
474 BOOST_CHECK(!actualParams.hasFacePersistency());
475 BOOST_CHECK(actualParams.hasFlags());
476 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
477 BOOST_CHECK(actualParams.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
478 }
479 });
480}
481
482BOOST_AUTO_TEST_CASE(UpdateLocalFieldsEnableDisable)
483{
484 createFace();
485
486 ControlParameters enableParams;
487 enableParams.setFaceId(faceId);
488 enableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true);
489
490 ControlParameters disableParams;
491 disableParams.setFaceId(faceId);
492 disableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false);
493
494 updateFace(enableParams, false, [] (const ControlResponse& actual) {
495 ControlResponse expected(200, "OK");
496 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
497 BOOST_TEST_MESSAGE(actual.getText());
498
499 if (actual.getBody().hasWire()) {
500 ControlParameters actualParams(actual.getBody());
501
502 BOOST_CHECK(actualParams.hasFaceId());
503 BOOST_CHECK(actualParams.hasFacePersistency());
504 BOOST_REQUIRE(actualParams.hasFlags());
505 // Check if flags indicate local fields enabled
506 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
507 }
508 else {
509 BOOST_ERROR("Enable: Response does not contain ControlParameters");
510 }
511 });
512
513 updateFace(disableParams, false, [] (const ControlResponse& actual) {
514 ControlResponse expected(200, "OK");
515 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
516 BOOST_TEST_MESSAGE(actual.getText());
517
518 if (actual.getBody().hasWire()) {
519 ControlParameters actualParams(actual.getBody());
520
521 BOOST_CHECK(actualParams.hasFaceId());
522 BOOST_CHECK(actualParams.hasFacePersistency());
523 BOOST_REQUIRE(actualParams.hasFlags());
524 // Check if flags indicate local fields disabled
525 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
526 }
527 else {
528 BOOST_ERROR("Disable: Response does not contain ControlParameters");
529 }
530 });
531}
532
Eric Newberry2642cd22017-07-13 21:34:53 -0400533BOOST_AUTO_TEST_CASE(UpdateReliabilityEnableDisable)
534{
535 createFace("udp4://127.0.0.1:26363");
536
537 ControlParameters enableParams;
538 enableParams.setFaceId(faceId);
539 enableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true);
540
541 ControlParameters disableParams;
542 disableParams.setFaceId(faceId);
543 disableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false);
544
545 updateFace(enableParams, false, [] (const ControlResponse& actual) {
546 ControlResponse expected(200, "OK");
547 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
548 BOOST_TEST_MESSAGE(actual.getText());
549
550 if (actual.getBody().hasWire()) {
551 ControlParameters actualParams(actual.getBody());
552
553 BOOST_CHECK(actualParams.hasFaceId());
554 BOOST_CHECK(actualParams.hasFacePersistency());
555 BOOST_REQUIRE(actualParams.hasFlags());
556 // Check if flags indicate reliability enabled
557 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
558 }
559 else {
560 BOOST_ERROR("Enable: Response does not contain ControlParameters");
561 }
562 });
563
564 updateFace(disableParams, false, [] (const ControlResponse& actual) {
565 ControlResponse expected(200, "OK");
566 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
567 BOOST_TEST_MESSAGE(actual.getText());
568
569 if (actual.getBody().hasWire()) {
570 ControlParameters actualParams(actual.getBody());
571
572 BOOST_CHECK(actualParams.hasFaceId());
573 BOOST_CHECK(actualParams.hasFacePersistency());
574 BOOST_REQUIRE(actualParams.hasFlags());
575 // Check if flags indicate reliability disabled
576 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
577 }
578 else {
579 BOOST_ERROR("Disable: Response does not contain ControlParameters");
580 }
581 });
582}
583
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700584BOOST_AUTO_TEST_CASE(UpdateCongestionMarkingEnableDisable)
585{
586 createFace("udp4://127.0.0.1:26363");
587
588 ControlParameters enableParams;
589 enableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400590 enableParams.setBaseCongestionMarkingInterval(50_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700591 enableParams.setDefaultCongestionThreshold(10000);
592 enableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true);
593
594 ControlParameters disableParams;
595 disableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400596 disableParams.setBaseCongestionMarkingInterval(70_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700597 disableParams.setDefaultCongestionThreshold(5000);
598 disableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false);
599
600 updateFace(enableParams, false, [] (const ControlResponse& actual) {
601 ControlResponse expected(200, "OK");
602 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
603 BOOST_TEST_MESSAGE(actual.getText());
604
605 if (actual.getBody().hasWire()) {
606 ControlParameters actualParams(actual.getBody());
607
608 BOOST_CHECK(actualParams.hasFaceId());
609 BOOST_CHECK(actualParams.hasFacePersistency());
610 // Check that congestion marking parameters changed
611 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400612 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 50_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700613 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
614 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 10000);
615 BOOST_REQUIRE(actualParams.hasFlags());
616 // Check if flags indicate congestion marking enabled
617 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
618 }
619 else {
620 BOOST_ERROR("Enable: Response does not contain ControlParameters");
621 }
622 });
623
624 updateFace(disableParams, false, [] (const ControlResponse& actual) {
625 ControlResponse expected(200, "OK");
626 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
627 BOOST_TEST_MESSAGE(actual.getText());
628
629 if (actual.getBody().hasWire()) {
630 ControlParameters actualParams(actual.getBody());
631
632 BOOST_CHECK(actualParams.hasFaceId());
633 BOOST_CHECK(actualParams.hasFacePersistency());
634 // Check that congestion marking parameters changed, even though feature disabled
635 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400636 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 70_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700637 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
638 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 5000);
639 BOOST_REQUIRE(actualParams.hasFlags());
640 // Check if flags indicate marking disabled
641 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
642 }
643 else {
644 BOOST_ERROR("Disable: Response does not contain ControlParameters");
645 }
646 });
647}
648
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700649BOOST_AUTO_TEST_CASE(SelfUpdating)
650{
651 createFace();
652
653 // Send a command that does nothing (will return 200) and does not contain a FaceId
654 ControlParameters sentParams;
655
656 updateFace(sentParams, true, [] (const ControlResponse& actual) {
657 ControlResponse expected(200, "OK");
658 BOOST_REQUIRE_EQUAL(actual.getCode(), expected.getCode());
659 BOOST_TEST_MESSAGE(actual.getText());
660 });
661}
662
663BOOST_AUTO_TEST_SUITE_END() // UpdateFace
664BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
665BOOST_AUTO_TEST_SUITE_END() // Mgmt
666
667} // namespace tests
668} // namespace nfd