blob: 904b5503c82d96f0323b72cf89fb0e2b5390674f [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/*
Eric Newberry0c3e57b2018-01-25 20:54:46 -07003 * Copyright (c) 2014-2018, 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"
29#include "nfd-manager-common-fixture.hpp"
Yanbiao Li58ba3f92017-02-15 14:27:18 +000030
Junxiao Shicbc8e942016-09-06 03:17:45 +000031#include <ndn-cxx/lp/tags.hpp>
Eric Newberryb5aa7f52016-09-03 20:36:12 -070032
Yanbiao Li58ba3f92017-02-15 14:27:18 +000033#include <thread>
34
Eric Newberry0c3e57b2018-01-25 20:54:46 -070035#include <boost/logic/tribool.hpp>
36
Eric Newberryb5aa7f52016-09-03 20:36:12 -070037namespace nfd {
38namespace tests {
39
40BOOST_AUTO_TEST_SUITE(Mgmt)
41BOOST_AUTO_TEST_SUITE(TestFaceManager)
42
Davide Pesavento3cf75dc2018-03-17 00:38:03 -040043namespace mpl = boost::mpl;
44
Eric Newberryb5aa7f52016-09-03 20:36:12 -070045class FaceManagerUpdateFixture : public FaceManagerCommandFixture
46{
47public:
Eric Newberryb5aa7f52016-09-03 20:36:12 -070048 ~FaceManagerUpdateFixture()
49 {
50 destroyFace();
51 }
52
53 void
54 createFace(const std::string& uri = "tcp4://127.0.0.1:26363",
55 ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
Eric Newberry0c3e57b2018-01-25 20:54:46 -070056 ndn::optional<time::nanoseconds> baseCongestionMarkingInterval = {},
57 ndn::optional<uint64_t> defaultCongestionThreshold = {},
Eric Newberry2642cd22017-07-13 21:34:53 -040058 bool enableLocalFields = false,
Eric Newberry0c3e57b2018-01-25 20:54:46 -070059 bool enableReliability = false,
60 boost::logic::tribool enableCongestionMarking = boost::logic::indeterminate)
Eric Newberryb5aa7f52016-09-03 20:36:12 -070061 {
62 ControlParameters params;
63 params.setUri(uri);
64 params.setFacePersistency(persistency);
Eric Newberry0c3e57b2018-01-25 20:54:46 -070065
66 if (baseCongestionMarkingInterval) {
67 params.setBaseCongestionMarkingInterval(*baseCongestionMarkingInterval);
68 }
69
70 if (defaultCongestionThreshold) {
71 params.setDefaultCongestionThreshold(*defaultCongestionThreshold);
72 }
73
Eric Newberryb5aa7f52016-09-03 20:36:12 -070074 params.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, enableLocalFields);
Eric Newberry2642cd22017-07-13 21:34:53 -040075 params.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, enableReliability);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070076
Eric Newberry0c3e57b2018-01-25 20:54:46 -070077 if (!boost::logic::indeterminate(enableCongestionMarking)) {
78 params.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, enableCongestionMarking);
79 }
80
Yanbiao Li58ba3f92017-02-15 14:27:18 +000081 createFace(params);
82 }
83
84 void
Davide Pesavento3cf75dc2018-03-17 00:38:03 -040085 createFace(const ControlParameters& createParams, bool isForOnDemandFace = false)
Yanbiao Li58ba3f92017-02-15 14:27:18 +000086 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +000087 Interest req = makeControlCommandRequest("/localhost/nfd/faces/create", createParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -070088
Yanbiao Li58ba3f92017-02-15 14:27:18 +000089 // if this creation if for on-demand face then create it on node2
90 FaceManagerCommandNode& target = isForOnDemandFace ? this->node2 : this->node1;
91
Eric Newberryb5aa7f52016-09-03 20:36:12 -070092 bool hasCallbackFired = false;
Yanbiao Li58ba3f92017-02-15 14:27:18 +000093 signal::ScopedConnection connection = target.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +000094 [&, req, isForOnDemandFace, this] (const Data& response) {
95 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -070096 return;
97 }
98
99 ControlResponse create(response.getContent().blockFromValue());
100 BOOST_REQUIRE_EQUAL(create.getCode(), 200);
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000101 BOOST_REQUIRE(create.getBody().hasWire());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700102
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000103 ControlParameters faceParams(create.getBody());
104 BOOST_REQUIRE(faceParams.hasFaceId());
105 this->faceId = faceParams.getFaceId();
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700106
107 hasCallbackFired = true;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000108
109 if (isForOnDemandFace) {
110 auto face = target.faceTable.get(static_cast<FaceId>(this->faceId));
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000111 // to force creation of on-demand face
112 face->sendInterest(*make_shared<Interest>("/hello/world"));
113 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700114 });
115
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000116 target.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400117 advanceClocks(1_ms, 5);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700118
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000119 if (isForOnDemandFace) {
120 std::this_thread::sleep_for(std::chrono::milliseconds(100)); // allow wallclock time for socket IO
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400121 advanceClocks(1_ms, 5); // let node1 accept Interest and create on-demand face
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000122 }
123
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700124 BOOST_REQUIRE(hasCallbackFired);
125 }
126
127 void
128 updateFace(const ControlParameters& requestParams,
129 bool isSelfUpdating,
130 const function<void(const ControlResponse& resp)>& checkResp)
131 {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000132 Interest req = makeControlCommandRequest("/localhost/nfd/faces/update", requestParams);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700133 if (isSelfUpdating) {
134 // Attach IncomingFaceIdTag to interest
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000135 req.setTag(make_shared<lp::IncomingFaceIdTag>(faceId));
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700136 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700137
138 bool hasCallbackFired = false;
139 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Davide Pesaventoac238f22017-09-12 15:19:40 -0400140 [req, &hasCallbackFired, &checkResp] (const Data& response) {
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000141 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700142 return;
143 }
144
145 ControlResponse actual(response.getContent().blockFromValue());
146 checkResp(actual);
147
148 hasCallbackFired = true;
149 });
150
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000151 this->node1.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400152 advanceClocks(1_ms, 5);
153 BOOST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700154 }
155
156private:
157 void
158 destroyFace()
159 {
160 if (faceId == 0) {
161 return;
162 }
163
164 ControlParameters params;
165 params.setFaceId(faceId);
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000166 Interest req = makeControlCommandRequest("/localhost/nfd/faces/destroy", params);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700167
168 bool hasCallbackFired = false;
169 signal::ScopedConnection connection = this->node1.face.onSendData.connect(
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000170 [this, req, &hasCallbackFired] (const Data& response) {
171 if (!req.getName().isPrefixOf(response.getName())) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700172 return;
173 }
174
175 ControlResponse destroy(response.getContent().blockFromValue());
176 BOOST_CHECK_EQUAL(destroy.getCode(), 200);
177
178 faceId = 0;
179 hasCallbackFired = true;
180 });
181
Junxiao Shi8a1f1702017-07-03 00:05:08 +0000182 this->node1.face.receive(req);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400183 advanceClocks(1_ms, 5);
184 BOOST_REQUIRE(hasCallbackFired);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700185 }
186
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400187protected:
188 FaceId faceId = 0;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700189};
190
191BOOST_FIXTURE_TEST_SUITE(UpdateFace, FaceManagerUpdateFixture)
192
193BOOST_AUTO_TEST_CASE(FaceDoesNotExist)
194{
195 ControlParameters requestParams;
196 requestParams.setFaceId(65535);
197
198 updateFace(requestParams, false, [] (const ControlResponse& actual) {
199 ControlResponse expected(404, "Specified face does not exist");
200 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
201 BOOST_TEST_MESSAGE(actual.getText());
202 });
203}
204
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000205template<bool CAN_CHANGE_PERSISTENCY>
206class UpdatePersistencyDummyTransport : public face::Transport
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700207{
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000208public:
209 UpdatePersistencyDummyTransport()
210 {
211 this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT);
212 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700213
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000214protected:
215 bool
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400216 canChangePersistencyToImpl(ndn::nfd::FacePersistency) const final
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000217 {
218 return CAN_CHANGE_PERSISTENCY;
219 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700220
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000221 void
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400222 doClose() final
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000223 {
224 }
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700225
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000226private:
227 void
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400228 doSend(face::Transport::Packet&&) final
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000229 {
230 }
231};
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700232
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400233using UpdatePersistencyTests = mpl::vector<
234 mpl::pair<UpdatePersistencyDummyTransport<true>, CommandSuccess>,
235 mpl::pair<UpdatePersistencyDummyTransport<false>, CommandFailure<409>>
236>;
Yanbiao Li58ba3f92017-02-15 14:27:18 +0000237
238BOOST_FIXTURE_TEST_CASE_TEMPLATE(UpdatePersistency, T, UpdatePersistencyTests, FaceManagerUpdateFixture)
239{
240 using TransportType = typename T::first;
241 using ResultType = typename T::second;
242
243 auto face = make_shared<face::Face>(make_unique<face::GenericLinkService>(),
244 make_unique<TransportType>());
245 this->node1.faceTable.add(face);
246
247 auto parameters = ControlParameters()
248 .setFaceId(face->getId())
249 .setFacePersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
250
251 updateFace(parameters, false, [] (const ControlResponse& actual) {
252 BOOST_TEST_MESSAGE(actual.getText());
253 BOOST_CHECK_EQUAL(actual.getCode(), ResultType::getExpected().getCode());
254
255 // the response for either 200 or 409 will have a content body
256 BOOST_REQUIRE(actual.getBody().hasWire());
257
258 ControlParameters resp;
259 resp.wireDecode(actual.getBody());
260 BOOST_CHECK_EQUAL(resp.getFacePersistency(), ndn::nfd::FACE_PERSISTENCY_PERMANENT);
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700261 });
262}
263
264class TcpLocalFieldsEnable
265{
266public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400267 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700268 getUri()
269 {
270 return "tcp4://127.0.0.1:26363";
271 }
272
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400273 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700274 getPersistency()
275 {
276 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
277 }
278
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400279 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700280 getInitLocalFieldsEnabled()
281 {
282 return false;
283 }
284
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400285 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700286 getLocalFieldsEnabled()
287 {
288 return true;
289 }
290
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400291 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700292 getLocalFieldsEnabledMask()
293 {
294 return true;
295 }
296
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400297 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700298 shouldHaveWire()
299 {
300 return false;
301 }
302};
303
304class TcpLocalFieldsDisable
305{
306public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400307 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700308 getUri()
309 {
310 return "tcp4://127.0.0.1:26363";
311 }
312
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400313 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700314 getPersistency()
315 {
316 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
317 }
318
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400319 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700320 getInitLocalFieldsEnabled()
321 {
322 return true;
323 }
324
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400325 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700326 getLocalFieldsEnabled()
327 {
328 return false;
329 }
330
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400331 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700332 getLocalFieldsEnabledMask()
333 {
334 return true;
335 }
336
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400337 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700338 shouldHaveWire()
339 {
340 return false;
341 }
342};
343
344// UDP faces are non-local by definition
345class UdpLocalFieldsEnable
346{
347public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400348 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700349 getUri()
350 {
351 return "udp4://127.0.0.1:26363";
352 }
353
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400354 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700355 getPersistency()
356 {
357 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
358 }
359
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400360 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700361 getInitLocalFieldsEnabled()
362 {
363 return false;
364 }
365
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400366 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700367 getLocalFieldsEnabled()
368 {
369 return true;
370 }
371
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400372 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700373 getLocalFieldsEnabledMask()
374 {
375 return true;
376 }
377
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400378 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700379 shouldHaveWire()
380 {
381 return true;
382 }
383};
384
385// UDP faces are non-local by definition
386// In this test case, attempt to disable local fields on face with local fields already disabled
387class UdpLocalFieldsDisable
388{
389public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400390 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700391 getUri()
392 {
393 return "udp4://127.0.0.1:26363";
394 }
395
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400396 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700397 getPersistency()
398 {
399 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
400 }
401
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400402 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700403 getInitLocalFieldsEnabled()
404 {
405 return false;
406 }
407
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400408 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700409 getLocalFieldsEnabled()
410 {
411 return false;
412 }
413
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400414 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700415 getLocalFieldsEnabledMask()
416 {
417 return true;
418 }
419
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400420 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700421 shouldHaveWire()
422 {
423 return false;
424 }
425};
426
427// In this test case, set Flags to enable local fields on non-local face, but exclude local fields
428// from Mask. This test case will pass as no action is taken due to the missing Mask bit.
429class UdpLocalFieldsEnableNoMaskBit
430{
431public:
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400432 static std::string
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700433 getUri()
434 {
435 return "udp4://127.0.0.1:26363";
436 }
437
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400438 static constexpr ndn::nfd::FacePersistency
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700439 getPersistency()
440 {
441 return ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
442 }
443
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400444 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700445 getInitLocalFieldsEnabled()
446 {
447 return false;
448 }
449
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400450 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700451 getLocalFieldsEnabled()
452 {
453 return true;
454 }
455
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400456 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700457 getLocalFieldsEnabledMask()
458 {
459 return false;
460 }
461
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400462 static constexpr bool
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700463 shouldHaveWire()
464 {
465 return false;
466 }
467};
468
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400469using LocalFieldFaces = mpl::vector<
470 mpl::pair<TcpLocalFieldsEnable, CommandSuccess>,
471 mpl::pair<TcpLocalFieldsDisable, CommandSuccess>,
472 mpl::pair<UdpLocalFieldsEnable, CommandFailure<409>>,
473 mpl::pair<UdpLocalFieldsDisable, CommandSuccess>,
474 mpl::pair<UdpLocalFieldsEnableNoMaskBit, CommandSuccess>
475>;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700476
477BOOST_AUTO_TEST_CASE_TEMPLATE(UpdateLocalFields, T, LocalFieldFaces)
478{
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400479 using TestType = typename T::first;
480 using ResultType = typename T::second;
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700481
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400482 createFace(TestType::getUri(), TestType::getPersistency(), {}, {},
483 TestType::getInitLocalFieldsEnabled());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700484
485 ControlParameters requestParams;
486 requestParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400487 requestParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, TestType::getLocalFieldsEnabled());
488 if (!TestType::getLocalFieldsEnabledMask()) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700489 requestParams.unsetFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED);
490 }
491
492 updateFace(requestParams, false, [] (const ControlResponse& actual) {
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400493 ControlResponse expected(ResultType::getExpected());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700494 BOOST_TEST_MESSAGE(actual.getText());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400495 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700496
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400497 if (TestType::shouldHaveWire() && actual.getBody().hasWire()) {
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700498 ControlParameters actualParams(actual.getBody());
499
500 BOOST_CHECK(!actualParams.hasFacePersistency());
501 BOOST_CHECK(actualParams.hasFlags());
502 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
503 BOOST_CHECK(actualParams.hasFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
504 }
505 });
506}
507
508BOOST_AUTO_TEST_CASE(UpdateLocalFieldsEnableDisable)
509{
510 createFace();
511
512 ControlParameters enableParams;
513 enableParams.setFaceId(faceId);
514 enableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, true);
515
516 ControlParameters disableParams;
517 disableParams.setFaceId(faceId);
518 disableParams.setFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED, false);
519
520 updateFace(enableParams, false, [] (const ControlResponse& actual) {
521 ControlResponse expected(200, "OK");
522 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
523 BOOST_TEST_MESSAGE(actual.getText());
524
525 if (actual.getBody().hasWire()) {
526 ControlParameters actualParams(actual.getBody());
527
528 BOOST_CHECK(actualParams.hasFaceId());
529 BOOST_CHECK(actualParams.hasFacePersistency());
530 BOOST_REQUIRE(actualParams.hasFlags());
531 // Check if flags indicate local fields enabled
532 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
533 }
534 else {
535 BOOST_ERROR("Enable: Response does not contain ControlParameters");
536 }
537 });
538
539 updateFace(disableParams, false, [] (const ControlResponse& actual) {
540 ControlResponse expected(200, "OK");
541 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
542 BOOST_TEST_MESSAGE(actual.getText());
543
544 if (actual.getBody().hasWire()) {
545 ControlParameters actualParams(actual.getBody());
546
547 BOOST_CHECK(actualParams.hasFaceId());
548 BOOST_CHECK(actualParams.hasFacePersistency());
549 BOOST_REQUIRE(actualParams.hasFlags());
550 // Check if flags indicate local fields disabled
551 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LOCAL_FIELDS_ENABLED));
552 }
553 else {
554 BOOST_ERROR("Disable: Response does not contain ControlParameters");
555 }
556 });
557}
558
Eric Newberry2642cd22017-07-13 21:34:53 -0400559BOOST_AUTO_TEST_CASE(UpdateReliabilityEnableDisable)
560{
561 createFace("udp4://127.0.0.1:26363");
562
563 ControlParameters enableParams;
564 enableParams.setFaceId(faceId);
565 enableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, true);
566
567 ControlParameters disableParams;
568 disableParams.setFaceId(faceId);
569 disableParams.setFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED, false);
570
571 updateFace(enableParams, false, [] (const ControlResponse& actual) {
572 ControlResponse expected(200, "OK");
573 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
574 BOOST_TEST_MESSAGE(actual.getText());
575
576 if (actual.getBody().hasWire()) {
577 ControlParameters actualParams(actual.getBody());
578
579 BOOST_CHECK(actualParams.hasFaceId());
580 BOOST_CHECK(actualParams.hasFacePersistency());
581 BOOST_REQUIRE(actualParams.hasFlags());
582 // Check if flags indicate reliability enabled
583 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
584 }
585 else {
586 BOOST_ERROR("Enable: Response does not contain ControlParameters");
587 }
588 });
589
590 updateFace(disableParams, false, [] (const ControlResponse& actual) {
591 ControlResponse expected(200, "OK");
592 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
593 BOOST_TEST_MESSAGE(actual.getText());
594
595 if (actual.getBody().hasWire()) {
596 ControlParameters actualParams(actual.getBody());
597
598 BOOST_CHECK(actualParams.hasFaceId());
599 BOOST_CHECK(actualParams.hasFacePersistency());
600 BOOST_REQUIRE(actualParams.hasFlags());
601 // Check if flags indicate reliability disabled
602 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED));
603 }
604 else {
605 BOOST_ERROR("Disable: Response does not contain ControlParameters");
606 }
607 });
608}
609
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700610BOOST_AUTO_TEST_CASE(UpdateCongestionMarkingEnableDisable)
611{
612 createFace("udp4://127.0.0.1:26363");
613
614 ControlParameters enableParams;
615 enableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400616 enableParams.setBaseCongestionMarkingInterval(50_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700617 enableParams.setDefaultCongestionThreshold(10000);
618 enableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, true);
619
620 ControlParameters disableParams;
621 disableParams.setFaceId(faceId);
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400622 disableParams.setBaseCongestionMarkingInterval(70_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700623 disableParams.setDefaultCongestionThreshold(5000);
624 disableParams.setFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED, false);
625
626 updateFace(enableParams, false, [] (const ControlResponse& actual) {
627 ControlResponse expected(200, "OK");
628 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
629 BOOST_TEST_MESSAGE(actual.getText());
630
631 if (actual.getBody().hasWire()) {
632 ControlParameters actualParams(actual.getBody());
633
634 BOOST_CHECK(actualParams.hasFaceId());
635 BOOST_CHECK(actualParams.hasFacePersistency());
636 // Check that congestion marking parameters changed
637 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400638 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 50_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700639 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
640 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 10000);
641 BOOST_REQUIRE(actualParams.hasFlags());
642 // Check if flags indicate congestion marking enabled
643 BOOST_CHECK(actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
644 }
645 else {
646 BOOST_ERROR("Enable: Response does not contain ControlParameters");
647 }
648 });
649
650 updateFace(disableParams, false, [] (const ControlResponse& actual) {
651 ControlResponse expected(200, "OK");
652 BOOST_CHECK_EQUAL(actual.getCode(), expected.getCode());
653 BOOST_TEST_MESSAGE(actual.getText());
654
655 if (actual.getBody().hasWire()) {
656 ControlParameters actualParams(actual.getBody());
657
658 BOOST_CHECK(actualParams.hasFaceId());
659 BOOST_CHECK(actualParams.hasFacePersistency());
660 // Check that congestion marking parameters changed, even though feature disabled
661 BOOST_REQUIRE(actualParams.hasBaseCongestionMarkingInterval());
Davide Pesavento3cf75dc2018-03-17 00:38:03 -0400662 BOOST_CHECK_EQUAL(actualParams.getBaseCongestionMarkingInterval(), 70_ms);
Eric Newberry0c3e57b2018-01-25 20:54:46 -0700663 BOOST_REQUIRE(actualParams.hasDefaultCongestionThreshold());
664 BOOST_CHECK_EQUAL(actualParams.getDefaultCongestionThreshold(), 5000);
665 BOOST_REQUIRE(actualParams.hasFlags());
666 // Check if flags indicate marking disabled
667 BOOST_CHECK(!actualParams.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED));
668 }
669 else {
670 BOOST_ERROR("Disable: Response does not contain ControlParameters");
671 }
672 });
673}
674
Eric Newberryb5aa7f52016-09-03 20:36:12 -0700675BOOST_AUTO_TEST_CASE(SelfUpdating)
676{
677 createFace();
678
679 // Send a command that does nothing (will return 200) and does not contain a FaceId
680 ControlParameters sentParams;
681
682 updateFace(sentParams, true, [] (const ControlResponse& actual) {
683 ControlResponse expected(200, "OK");
684 BOOST_REQUIRE_EQUAL(actual.getCode(), expected.getCode());
685 BOOST_TEST_MESSAGE(actual.getText());
686 });
687}
688
689BOOST_AUTO_TEST_SUITE_END() // UpdateFace
690BOOST_AUTO_TEST_SUITE_END() // TestFaceManager
691BOOST_AUTO_TEST_SUITE_END() // Mgmt
692
693} // namespace tests
694} // namespace nfd