blob: 511498dcc931d8bdce015eb2b723a1d4718ae1b2 [file] [log] [blame]
Junxiao Shi034c1882016-06-24 18:06:51 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi2bea5c42017-08-14 20:10:32 +00002/*
Davide Pesavento09103432023-03-24 20:30:41 -04003 * Copyright (c) 2013-2023 Regents of the University of California.
Junxiao Shi034c1882016-06-24 18:06:51 +00004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
Davide Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/mgmt/nfd/status-dataset.hpp"
23#include "ndn-cxx/mgmt/nfd/controller.hpp"
Junxiao Shi034c1882016-06-24 18:06:51 +000024
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050025#include "tests/test-common.hpp"
Davide Pesavento7e780642018-11-24 15:51:34 -050026#include "tests/unit/mgmt/nfd/controller-fixture.hpp"
Junxiao Shi034c1882016-06-24 18:06:51 +000027
28namespace ndn {
29namespace nfd {
30namespace tests {
31
Junxiao Shi85d90832016-08-04 03:19:46 +000032using namespace ndn::tests;
Junxiao Shi034c1882016-06-24 18:06:51 +000033
Junxiao Shi7357ef22016-09-07 02:39:37 +000034BOOST_AUTO_TEST_SUITE(Mgmt)
35BOOST_AUTO_TEST_SUITE(Nfd)
Junxiao Shi034c1882016-06-24 18:06:51 +000036
37class ControllerStatusDatasetFixture : public ControllerFixture
38{
39protected:
Davide Pesaventoc860bd12022-10-04 03:23:43 -040040 /** \brief Send one WireEncodable as Data reply.
Junxiao Shi034c1882016-06-24 18:06:51 +000041 * \param prefix dataset prefix without version and segment
42 * \param payload payload block
43 * \note payload must fit in one Data
44 */
45 template<typename T>
46 void
47 sendDataset(const Name& prefix, const T& payload)
48 {
Junxiao Shi034c1882016-06-24 18:06:51 +000049 auto data = this->prepareDatasetReply(prefix);
50 data->setContent(payload.wireEncode());
51 face.receive(*signData(data));
52 }
53
Davide Pesaventoc860bd12022-10-04 03:23:43 -040054 /** \brief Send two WireEncodables as Data reply.
Junxiao Shi034c1882016-06-24 18:06:51 +000055 * \param prefix dataset prefix without version and segment
56 * \param payload1 first vector item
57 * \param payload2 second vector item
58 * \note all payloads must fit in one Data
59 */
60 template<typename T1, typename T2>
61 void
62 sendDataset(const Name& prefix, const T1& payload1, const T2& payload2)
63 {
64 // The test suite allows up to two items, and put them in the same Data packet,
65 // because this test suite focuses on Controller::fetch<StatusDataset>,
66 // and is not intended to cover SegmentFetcher behavior.
67
Davide Pesaventofbea4fc2022-02-08 07:26:04 -050068 EncodingBuffer buffer;
Junxiao Shi034c1882016-06-24 18:06:51 +000069 payload2.wireEncode(buffer);
70 payload1.wireEncode(buffer);
71
72 auto data = this->prepareDatasetReply(prefix);
Davide Pesaventofbea4fc2022-02-08 07:26:04 -050073 data->setContent(buffer);
Junxiao Shi034c1882016-06-24 18:06:51 +000074 face.receive(*signData(data));
75 }
76
77private:
Davide Pesavento09103432023-03-24 20:30:41 -040078 std::shared_ptr<Data>
Junxiao Shi034c1882016-06-24 18:06:51 +000079 prepareDatasetReply(const Name& prefix)
80 {
81 Name name = prefix;
82 name.appendVersion().appendSegment(0);
83
84 // These warnings assist in debugging a `hasResult` check failure.
85 // They usually indicate a misspelled prefix or incorrect timing in the test case.
86 if (face.sentInterests.size() < 1) {
87 BOOST_WARN_MESSAGE(false, "no Interest expressed");
88 }
89 else {
90 BOOST_WARN_MESSAGE(face.sentInterests.back().getName().isPrefixOf(name),
91 "last Interest " << face.sentInterests.back().getName() <<
92 " cannot be satisfied by this Data " << name);
93 }
94
Davide Pesavento09103432023-03-24 20:30:41 -040095 auto data = std::make_shared<Data>(name);
Junxiao Shi2ad2fbe2019-05-24 03:11:05 +000096 data->setFreshnessPeriod(1_s);
Junxiao Shiebfe4a22018-04-01 23:53:40 +000097 data->setFinalBlock(name[-1]);
Junxiao Shi034c1882016-06-24 18:06:51 +000098 return data;
99 }
100};
101
Junxiao Shi7357ef22016-09-07 02:39:37 +0000102BOOST_FIXTURE_TEST_SUITE(TestStatusDataset, ControllerStatusDatasetFixture)
Junxiao Shi034c1882016-06-24 18:06:51 +0000103
104BOOST_AUTO_TEST_SUITE(Failures)
105
106BOOST_AUTO_TEST_CASE(Timeout)
107{
108 CommandOptions options;
Davide Pesavento0f830802018-01-16 23:58:58 -0500109 options.setTimeout(3000_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000110 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500111 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000112 datasetFailCallback,
Junxiao Shi034c1882016-06-24 18:06:51 +0000113 options);
Ashlesh Gawande3e3a9892018-11-16 20:26:15 -0600114 this->advanceClocks(500_ms);
115 BOOST_CHECK_EQUAL(controller.m_fetchers.size(), 1);
Junxiao Shi034c1882016-06-24 18:06:51 +0000116
Ashlesh Gawande3e3a9892018-11-16 20:26:15 -0600117 this->advanceClocks(500_ms, 6);
118 BOOST_CHECK_EQUAL(controller.m_fetchers.size(), 0);
Junxiao Shi034c1882016-06-24 18:06:51 +0000119 BOOST_REQUIRE_EQUAL(failCodes.size(), 1);
120 BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_TIMEOUT);
121}
122
123BOOST_AUTO_TEST_CASE(DataHasNoSegment)
124{
125 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500126 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000127 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500128 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000129
Junxiao Shi2ad2fbe2019-05-24 03:11:05 +0000130 auto data = makeData("/localhost/nfd/faces/list/%FD%00");
131 data->setFreshnessPeriod(1_s);
132 face.receive(*data);
Davide Pesavento0f830802018-01-16 23:58:58 -0500133 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000134
135 BOOST_REQUIRE_EQUAL(failCodes.size(), 1);
136 BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_SERVER);
137}
138
Junxiao Shi0f3f0b42016-07-14 13:26:37 +0000139BOOST_AUTO_TEST_CASE(ValidationFailure)
140{
141 this->setValidationResult(false);
142
143 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500144 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000145 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500146 this->advanceClocks(500_ms);
Junxiao Shi0f3f0b42016-07-14 13:26:37 +0000147
148 FaceStatus payload;
149 payload.setFaceId(5744);
150 this->sendDataset("/localhost/nfd/faces/list", payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500151 this->advanceClocks(500_ms);
Junxiao Shi0f3f0b42016-07-14 13:26:37 +0000152
153 BOOST_REQUIRE_EQUAL(failCodes.size(), 1);
154 BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_VALIDATION);
155}
156
Junxiao Shi034c1882016-06-24 18:06:51 +0000157BOOST_AUTO_TEST_CASE(Nack)
158{
159 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500160 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000161 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500162 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000163
164 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
165 face.receive(lp::Nack(face.sentInterests.back()));
Davide Pesavento0f830802018-01-16 23:58:58 -0500166 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000167
168 BOOST_REQUIRE_EQUAL(failCodes.size(), 1);
169 BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_NACK);
170}
171
172BOOST_AUTO_TEST_CASE(ParseError1)
173{
174 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500175 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000176 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500177 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000178
179 Name payload; // Name is not valid FaceStatus
180 this->sendDataset("/localhost/nfd/faces/list", payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500181 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000182
183 BOOST_REQUIRE_EQUAL(failCodes.size(), 1);
184 BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_SERVER);
185}
186
187BOOST_AUTO_TEST_CASE(ParseError2)
188{
189 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500190 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000191 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500192 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000193
194 FaceStatus payload1;
195 payload1.setFaceId(10930);
196 Name payload2; // Name is not valid FaceStatus
197 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500198 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000199
200 BOOST_REQUIRE_EQUAL(failCodes.size(), 1);
201 BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_SERVER);
202}
203
204BOOST_AUTO_TEST_SUITE_END() // Failures
205
Junxiao Shi600f7112016-07-16 11:57:18 +0000206BOOST_AUTO_TEST_SUITE(NoCallback)
207
208BOOST_AUTO_TEST_CASE(Success)
209{
210 controller.fetch<FaceDataset>(
211 nullptr,
Junxiao Shie7c7f152016-08-20 22:36:22 +0000212 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500213 this->advanceClocks(500_ms);
Ashlesh Gawande3e3a9892018-11-16 20:26:15 -0600214 BOOST_CHECK_EQUAL(controller.m_fetchers.size(), 1);
Junxiao Shi600f7112016-07-16 11:57:18 +0000215
216 FaceStatus payload;
217 payload.setFaceId(2577);
218 this->sendDataset("/localhost/nfd/faces/list", payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500219 BOOST_CHECK_NO_THROW(this->advanceClocks(500_ms));
Junxiao Shi600f7112016-07-16 11:57:18 +0000220
221 BOOST_CHECK_EQUAL(failCodes.size(), 0);
Ashlesh Gawande3e3a9892018-11-16 20:26:15 -0600222 BOOST_CHECK_EQUAL(controller.m_fetchers.size(), 0);
Junxiao Shi600f7112016-07-16 11:57:18 +0000223}
224
225BOOST_AUTO_TEST_CASE(Failure)
226{
227 CommandOptions options;
Davide Pesavento0f830802018-01-16 23:58:58 -0500228 options.setTimeout(3000_ms);
Junxiao Shi600f7112016-07-16 11:57:18 +0000229 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500230 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shi600f7112016-07-16 11:57:18 +0000231 nullptr,
232 options);
Davide Pesavento0f830802018-01-16 23:58:58 -0500233 BOOST_CHECK_NO_THROW(this->advanceClocks(500_ms, 7));
Junxiao Shi600f7112016-07-16 11:57:18 +0000234}
235
236BOOST_AUTO_TEST_SUITE_END() // NoCallback
237
Junxiao Shi034c1882016-06-24 18:06:51 +0000238BOOST_AUTO_TEST_SUITE(Datasets)
239
240BOOST_AUTO_TEST_CASE(StatusGeneral)
241{
242 bool hasResult = false;
243 controller.fetch<ForwarderGeneralStatusDataset>(
244 [&hasResult] (const ForwarderStatus& result) {
245 hasResult = true;
246 BOOST_CHECK_EQUAL(result.getNfdVersion(), "0.4.2");
247 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000248 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500249 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000250
251 ForwarderStatus payload;
252 payload.setNfdVersion("0.4.2");
253 this->sendDataset("/localhost/nfd/status/general", payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500254 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000255
256 BOOST_CHECK(hasResult);
257 BOOST_CHECK_EQUAL(failCodes.size(), 0);
258}
259
260BOOST_AUTO_TEST_CASE(FaceList)
261{
262 bool hasResult = false;
263 controller.fetch<FaceDataset>(
264 [&hasResult] (const std::vector<FaceStatus>& result) {
265 hasResult = true;
266 BOOST_CHECK_EQUAL(result.size(), 2);
267 BOOST_CHECK_EQUAL(result.front().getFaceId(), 24485);
268 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000269 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500270 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000271
272 FaceStatus payload1;
273 payload1.setFaceId(24485);
274 FaceStatus payload2;
275 payload2.setFaceId(12987);
276 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500277 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000278
279 BOOST_CHECK(hasResult);
280 BOOST_CHECK_EQUAL(failCodes.size(), 0);
281}
282
283BOOST_AUTO_TEST_CASE(FaceQuery)
284{
285 FaceQueryFilter filter;
286 filter.setUriScheme("udp4");
287 bool hasResult = false;
288 controller.fetch<FaceQueryDataset>(
289 filter,
290 [&hasResult] (const std::vector<FaceStatus>& result) {
291 hasResult = true;
292 BOOST_CHECK_EQUAL(result.size(), 1);
293 BOOST_CHECK_EQUAL(result.front().getFaceId(), 8795);
294 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000295 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500296 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000297
298 Name prefix("/localhost/nfd/faces/query");
Davide Pesavento2f92b6e2022-04-10 16:42:01 -0400299 prefix.append(filter.wireEncode());
Junxiao Shi034c1882016-06-24 18:06:51 +0000300 FaceStatus payload;
301 payload.setFaceId(8795);
302 this->sendDataset(prefix, payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500303 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000304
305 BOOST_CHECK(hasResult);
306 BOOST_CHECK_EQUAL(failCodes.size(), 0);
307}
308
309BOOST_AUTO_TEST_CASE(FaceQueryWithOptions)
310{
311 FaceQueryFilter filter;
312 filter.setUriScheme("udp4");
313 CommandOptions options;
Davide Pesavento0f830802018-01-16 23:58:58 -0500314 options.setTimeout(3000_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000315 bool hasResult = false;
316 controller.fetch<FaceQueryDataset>(
317 filter,
318 [&hasResult] (const std::vector<FaceStatus>& result) {
319 hasResult = true;
320 BOOST_CHECK_EQUAL(result.size(), 1);
321 BOOST_CHECK_EQUAL(result.front().getFaceId(), 14022);
322 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000323 datasetFailCallback,
Junxiao Shi034c1882016-06-24 18:06:51 +0000324 options);
Davide Pesavento0f830802018-01-16 23:58:58 -0500325 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000326
327 Name prefix("/localhost/nfd/faces/query");
Davide Pesavento2f92b6e2022-04-10 16:42:01 -0400328 prefix.append(filter.wireEncode());
Junxiao Shi034c1882016-06-24 18:06:51 +0000329 FaceStatus payload;
330 payload.setFaceId(14022);
331 this->sendDataset(prefix, payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500332 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000333
334 BOOST_CHECK(hasResult);
335 BOOST_CHECK_EQUAL(failCodes.size(), 0);
336}
337
Junxiao Shi1eacb972016-07-07 22:51:07 +0000338BOOST_AUTO_TEST_CASE(FaceChannels)
339{
340 bool hasResult = false;
341 controller.fetch<ChannelDataset>(
342 [&hasResult] (const std::vector<ChannelStatus>& result) {
343 hasResult = true;
344 BOOST_CHECK_EQUAL(result.size(), 2);
345 BOOST_CHECK_EQUAL(result.front().getLocalUri(), "tcp4://192.0.2.1:6363");
346 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000347 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500348 this->advanceClocks(500_ms);
Junxiao Shi1eacb972016-07-07 22:51:07 +0000349
350 ChannelStatus payload1;
351 payload1.setLocalUri("tcp4://192.0.2.1:6363");
352 ChannelStatus payload2;
353 payload2.setLocalUri("udp4://192.0.2.1:6363");
354 this->sendDataset("/localhost/nfd/faces/channels", payload1, payload2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500355 this->advanceClocks(500_ms);
Junxiao Shi1eacb972016-07-07 22:51:07 +0000356
357 BOOST_CHECK(hasResult);
358 BOOST_CHECK_EQUAL(failCodes.size(), 0);
359}
360
Junxiao Shi034c1882016-06-24 18:06:51 +0000361BOOST_AUTO_TEST_CASE(FibList)
362{
363 bool hasResult = false;
364 controller.fetch<FibDataset>(
365 [&hasResult] (const std::vector<FibEntry>& result) {
366 hasResult = true;
367 BOOST_CHECK_EQUAL(result.size(), 2);
368 BOOST_CHECK_EQUAL(result.front().getPrefix(), "/wYs7fzYcfG");
369 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000370 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500371 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000372
373 FibEntry payload1;
374 payload1.setPrefix("/wYs7fzYcfG");
375 FibEntry payload2;
376 payload2.setPrefix("/LKvmnzY5S");
377 this->sendDataset("/localhost/nfd/fib/list", payload1, payload2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500378 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000379
380 BOOST_CHECK(hasResult);
381 BOOST_CHECK_EQUAL(failCodes.size(), 0);
382}
383
Junxiao Shi7f012472017-12-07 20:40:47 +0000384BOOST_AUTO_TEST_CASE(CsInfo)
385{
386 using ndn::nfd::CsInfo;
387
388 bool hasResult = false;
389 controller.fetch<CsInfoDataset>(
390 [&hasResult] (const CsInfo& result) {
391 hasResult = true;
392 BOOST_CHECK_EQUAL(result.getNHits(), 4539);
393 },
394 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500395 this->advanceClocks(500_ms);
Junxiao Shi7f012472017-12-07 20:40:47 +0000396
397 CsInfo payload;
398 payload.setNHits(4539);
399 this->sendDataset("/localhost/nfd/cs/info", payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500400 this->advanceClocks(500_ms);
Junxiao Shi7f012472017-12-07 20:40:47 +0000401
402 BOOST_CHECK(hasResult);
403 BOOST_CHECK_EQUAL(failCodes.size(), 0);
404}
405
Junxiao Shi034c1882016-06-24 18:06:51 +0000406BOOST_AUTO_TEST_CASE(StrategyChoiceList)
407{
408 bool hasResult = false;
409 controller.fetch<StrategyChoiceDataset>(
410 [&hasResult] (const std::vector<StrategyChoice>& result) {
411 hasResult = true;
412 BOOST_CHECK_EQUAL(result.size(), 2);
413 BOOST_CHECK_EQUAL(result.front().getName(), "/8MLz6N3B");
414 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000415 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500416 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000417
418 StrategyChoice payload1;
419 payload1.setName("/8MLz6N3B");
420 StrategyChoice payload2;
421 payload2.setName("/svqcBu0YwU");
422 this->sendDataset("/localhost/nfd/strategy-choice/list", payload1, payload2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500423 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000424
425 BOOST_CHECK(hasResult);
426 BOOST_CHECK_EQUAL(failCodes.size(), 0);
427}
428
429BOOST_AUTO_TEST_CASE(RibList)
430{
431 bool hasResult = false;
432 controller.fetch<RibDataset>(
433 [&hasResult] (const std::vector<RibEntry>& result) {
434 hasResult = true;
435 BOOST_CHECK_EQUAL(result.size(), 2);
436 BOOST_CHECK_EQUAL(result.front().getName(), "/zXxBth97ee");
437 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000438 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500439 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000440
441 RibEntry payload1;
442 payload1.setName("/zXxBth97ee");
443 RibEntry payload2;
444 payload2.setName("/rJ8CvUpr4G");
445 this->sendDataset("/localhost/nfd/rib/list", payload1, payload2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500446 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000447
448 BOOST_CHECK(hasResult);
449 BOOST_CHECK_EQUAL(failCodes.size(), 0);
450}
451
452BOOST_AUTO_TEST_CASE(RibListWithOptions)
453{
454 CommandOptions options;
455 options.setPrefix("/localhop/nfd");
456 bool hasResult = false;
457 controller.fetch<RibDataset>(
458 [&hasResult] (const std::vector<RibEntry>& result) {
459 hasResult = true;
460 BOOST_CHECK_EQUAL(result.size(), 1);
461 BOOST_CHECK_EQUAL(result.front().getName(), "/e6L5K4ascd");
462 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000463 datasetFailCallback,
Junxiao Shi034c1882016-06-24 18:06:51 +0000464 options);
Davide Pesavento0f830802018-01-16 23:58:58 -0500465 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000466
467 RibEntry payload;
468 payload.setName("/e6L5K4ascd");
469 this->sendDataset("/localhop/nfd/rib/list", payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500470 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000471
472 BOOST_CHECK(hasResult);
473 BOOST_CHECK_EQUAL(failCodes.size(), 0);
474}
475
476BOOST_AUTO_TEST_SUITE_END() // Datasets
477
Junxiao Shi7357ef22016-09-07 02:39:37 +0000478BOOST_AUTO_TEST_SUITE_END() // TestStatusDataset
479BOOST_AUTO_TEST_SUITE_END() // Nfd
480BOOST_AUTO_TEST_SUITE_END() // Mgmt
Junxiao Shi034c1882016-06-24 18:06:51 +0000481
482} // namespace tests
483} // namespace nfd
484} // namespace ndn