blob: bb6acad67484516cddb0194fd07afb9233572f5e [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
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040028namespace ndn::tests {
Junxiao Shi034c1882016-06-24 18:06:51 +000029
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040030using namespace ndn::nfd;
Junxiao Shi034c1882016-06-24 18:06:51 +000031
Junxiao Shi7357ef22016-09-07 02:39:37 +000032BOOST_AUTO_TEST_SUITE(Mgmt)
33BOOST_AUTO_TEST_SUITE(Nfd)
Junxiao Shi034c1882016-06-24 18:06:51 +000034
35class ControllerStatusDatasetFixture : public ControllerFixture
36{
37protected:
Davide Pesaventoc860bd12022-10-04 03:23:43 -040038 /** \brief Send one WireEncodable as Data reply.
Junxiao Shi034c1882016-06-24 18:06:51 +000039 * \param prefix dataset prefix without version and segment
40 * \param payload payload block
41 * \note payload must fit in one Data
42 */
43 template<typename T>
44 void
45 sendDataset(const Name& prefix, const T& payload)
46 {
Junxiao Shi034c1882016-06-24 18:06:51 +000047 auto data = this->prepareDatasetReply(prefix);
48 data->setContent(payload.wireEncode());
49 face.receive(*signData(data));
50 }
51
Davide Pesaventoc860bd12022-10-04 03:23:43 -040052 /** \brief Send two WireEncodables as Data reply.
Junxiao Shi034c1882016-06-24 18:06:51 +000053 * \param prefix dataset prefix without version and segment
54 * \param payload1 first vector item
55 * \param payload2 second vector item
56 * \note all payloads must fit in one Data
57 */
58 template<typename T1, typename T2>
59 void
60 sendDataset(const Name& prefix, const T1& payload1, const T2& payload2)
61 {
62 // The test suite allows up to two items, and put them in the same Data packet,
63 // because this test suite focuses on Controller::fetch<StatusDataset>,
64 // and is not intended to cover SegmentFetcher behavior.
65
Davide Pesaventofbea4fc2022-02-08 07:26:04 -050066 EncodingBuffer buffer;
Junxiao Shi034c1882016-06-24 18:06:51 +000067 payload2.wireEncode(buffer);
68 payload1.wireEncode(buffer);
69
70 auto data = this->prepareDatasetReply(prefix);
Davide Pesaventofbea4fc2022-02-08 07:26:04 -050071 data->setContent(buffer);
Junxiao Shi034c1882016-06-24 18:06:51 +000072 face.receive(*signData(data));
73 }
74
75private:
Davide Pesavento09103432023-03-24 20:30:41 -040076 std::shared_ptr<Data>
Junxiao Shi034c1882016-06-24 18:06:51 +000077 prepareDatasetReply(const Name& prefix)
78 {
79 Name name = prefix;
80 name.appendVersion().appendSegment(0);
81
82 // These warnings assist in debugging a `hasResult` check failure.
83 // They usually indicate a misspelled prefix or incorrect timing in the test case.
84 if (face.sentInterests.size() < 1) {
85 BOOST_WARN_MESSAGE(false, "no Interest expressed");
86 }
87 else {
88 BOOST_WARN_MESSAGE(face.sentInterests.back().getName().isPrefixOf(name),
89 "last Interest " << face.sentInterests.back().getName() <<
90 " cannot be satisfied by this Data " << name);
91 }
92
Davide Pesavento09103432023-03-24 20:30:41 -040093 auto data = std::make_shared<Data>(name);
Junxiao Shi2ad2fbe2019-05-24 03:11:05 +000094 data->setFreshnessPeriod(1_s);
Junxiao Shiebfe4a22018-04-01 23:53:40 +000095 data->setFinalBlock(name[-1]);
Junxiao Shi034c1882016-06-24 18:06:51 +000096 return data;
97 }
98};
99
Junxiao Shi7357ef22016-09-07 02:39:37 +0000100BOOST_FIXTURE_TEST_SUITE(TestStatusDataset, ControllerStatusDatasetFixture)
Junxiao Shi034c1882016-06-24 18:06:51 +0000101
102BOOST_AUTO_TEST_SUITE(Failures)
103
104BOOST_AUTO_TEST_CASE(Timeout)
105{
106 CommandOptions options;
Davide Pesavento0f830802018-01-16 23:58:58 -0500107 options.setTimeout(3000_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000108 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500109 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000110 datasetFailCallback,
Junxiao Shi034c1882016-06-24 18:06:51 +0000111 options);
Ashlesh Gawande3e3a9892018-11-16 20:26:15 -0600112 this->advanceClocks(500_ms);
113 BOOST_CHECK_EQUAL(controller.m_fetchers.size(), 1);
Junxiao Shi034c1882016-06-24 18:06:51 +0000114
Ashlesh Gawande3e3a9892018-11-16 20:26:15 -0600115 this->advanceClocks(500_ms, 6);
116 BOOST_CHECK_EQUAL(controller.m_fetchers.size(), 0);
Junxiao Shi034c1882016-06-24 18:06:51 +0000117 BOOST_REQUIRE_EQUAL(failCodes.size(), 1);
118 BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_TIMEOUT);
119}
120
121BOOST_AUTO_TEST_CASE(DataHasNoSegment)
122{
123 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500124 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000125 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500126 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000127
Junxiao Shi2ad2fbe2019-05-24 03:11:05 +0000128 auto data = makeData("/localhost/nfd/faces/list/%FD%00");
129 data->setFreshnessPeriod(1_s);
130 face.receive(*data);
Davide Pesavento0f830802018-01-16 23:58:58 -0500131 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000132
133 BOOST_REQUIRE_EQUAL(failCodes.size(), 1);
134 BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_SERVER);
135}
136
Junxiao Shi0f3f0b42016-07-14 13:26:37 +0000137BOOST_AUTO_TEST_CASE(ValidationFailure)
138{
139 this->setValidationResult(false);
140
141 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500142 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000143 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500144 this->advanceClocks(500_ms);
Junxiao Shi0f3f0b42016-07-14 13:26:37 +0000145
146 FaceStatus payload;
147 payload.setFaceId(5744);
148 this->sendDataset("/localhost/nfd/faces/list", payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500149 this->advanceClocks(500_ms);
Junxiao Shi0f3f0b42016-07-14 13:26:37 +0000150
151 BOOST_REQUIRE_EQUAL(failCodes.size(), 1);
152 BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_VALIDATION);
153}
154
Junxiao Shi034c1882016-06-24 18:06:51 +0000155BOOST_AUTO_TEST_CASE(Nack)
156{
157 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500158 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000159 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500160 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000161
162 BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1);
163 face.receive(lp::Nack(face.sentInterests.back()));
Davide Pesavento0f830802018-01-16 23:58:58 -0500164 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000165
166 BOOST_REQUIRE_EQUAL(failCodes.size(), 1);
167 BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_NACK);
168}
169
170BOOST_AUTO_TEST_CASE(ParseError1)
171{
172 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500173 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000174 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500175 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000176
177 Name payload; // Name is not valid FaceStatus
178 this->sendDataset("/localhost/nfd/faces/list", payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500179 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000180
181 BOOST_REQUIRE_EQUAL(failCodes.size(), 1);
182 BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_SERVER);
183}
184
185BOOST_AUTO_TEST_CASE(ParseError2)
186{
187 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500188 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000189 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500190 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000191
192 FaceStatus payload1;
193 payload1.setFaceId(10930);
194 Name payload2; // Name is not valid FaceStatus
195 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500196 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000197
198 BOOST_REQUIRE_EQUAL(failCodes.size(), 1);
199 BOOST_CHECK_EQUAL(failCodes.back(), Controller::ERROR_SERVER);
200}
201
202BOOST_AUTO_TEST_SUITE_END() // Failures
203
Junxiao Shi600f7112016-07-16 11:57:18 +0000204BOOST_AUTO_TEST_SUITE(NoCallback)
205
206BOOST_AUTO_TEST_CASE(Success)
207{
208 controller.fetch<FaceDataset>(
209 nullptr,
Junxiao Shie7c7f152016-08-20 22:36:22 +0000210 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500211 this->advanceClocks(500_ms);
Ashlesh Gawande3e3a9892018-11-16 20:26:15 -0600212 BOOST_CHECK_EQUAL(controller.m_fetchers.size(), 1);
Junxiao Shi600f7112016-07-16 11:57:18 +0000213
214 FaceStatus payload;
215 payload.setFaceId(2577);
216 this->sendDataset("/localhost/nfd/faces/list", payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500217 BOOST_CHECK_NO_THROW(this->advanceClocks(500_ms));
Junxiao Shi600f7112016-07-16 11:57:18 +0000218
219 BOOST_CHECK_EQUAL(failCodes.size(), 0);
Ashlesh Gawande3e3a9892018-11-16 20:26:15 -0600220 BOOST_CHECK_EQUAL(controller.m_fetchers.size(), 0);
Junxiao Shi600f7112016-07-16 11:57:18 +0000221}
222
223BOOST_AUTO_TEST_CASE(Failure)
224{
225 CommandOptions options;
Davide Pesavento0f830802018-01-16 23:58:58 -0500226 options.setTimeout(3000_ms);
Junxiao Shi600f7112016-07-16 11:57:18 +0000227 controller.fetch<FaceDataset>(
Davide Pesavento221a72d2021-12-30 17:48:36 -0500228 [] (auto&&) { BOOST_FAIL("fetchDataset should not succeed"); },
Junxiao Shi600f7112016-07-16 11:57:18 +0000229 nullptr,
230 options);
Davide Pesavento0f830802018-01-16 23:58:58 -0500231 BOOST_CHECK_NO_THROW(this->advanceClocks(500_ms, 7));
Junxiao Shi600f7112016-07-16 11:57:18 +0000232}
233
234BOOST_AUTO_TEST_SUITE_END() // NoCallback
235
Junxiao Shi034c1882016-06-24 18:06:51 +0000236BOOST_AUTO_TEST_SUITE(Datasets)
237
238BOOST_AUTO_TEST_CASE(StatusGeneral)
239{
240 bool hasResult = false;
241 controller.fetch<ForwarderGeneralStatusDataset>(
242 [&hasResult] (const ForwarderStatus& result) {
243 hasResult = true;
244 BOOST_CHECK_EQUAL(result.getNfdVersion(), "0.4.2");
245 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000246 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500247 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000248
249 ForwarderStatus payload;
250 payload.setNfdVersion("0.4.2");
251 this->sendDataset("/localhost/nfd/status/general", payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500252 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000253
254 BOOST_CHECK(hasResult);
255 BOOST_CHECK_EQUAL(failCodes.size(), 0);
256}
257
258BOOST_AUTO_TEST_CASE(FaceList)
259{
260 bool hasResult = false;
261 controller.fetch<FaceDataset>(
262 [&hasResult] (const std::vector<FaceStatus>& result) {
263 hasResult = true;
264 BOOST_CHECK_EQUAL(result.size(), 2);
265 BOOST_CHECK_EQUAL(result.front().getFaceId(), 24485);
266 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000267 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500268 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000269
270 FaceStatus payload1;
271 payload1.setFaceId(24485);
272 FaceStatus payload2;
273 payload2.setFaceId(12987);
274 this->sendDataset("/localhost/nfd/faces/list", payload1, payload2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500275 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000276
277 BOOST_CHECK(hasResult);
278 BOOST_CHECK_EQUAL(failCodes.size(), 0);
279}
280
281BOOST_AUTO_TEST_CASE(FaceQuery)
282{
283 FaceQueryFilter filter;
284 filter.setUriScheme("udp4");
285 bool hasResult = false;
286 controller.fetch<FaceQueryDataset>(
287 filter,
288 [&hasResult] (const std::vector<FaceStatus>& result) {
289 hasResult = true;
290 BOOST_CHECK_EQUAL(result.size(), 1);
291 BOOST_CHECK_EQUAL(result.front().getFaceId(), 8795);
292 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000293 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500294 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000295
296 Name prefix("/localhost/nfd/faces/query");
Davide Pesavento2f92b6e2022-04-10 16:42:01 -0400297 prefix.append(filter.wireEncode());
Junxiao Shi034c1882016-06-24 18:06:51 +0000298 FaceStatus payload;
299 payload.setFaceId(8795);
300 this->sendDataset(prefix, payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500301 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000302
303 BOOST_CHECK(hasResult);
304 BOOST_CHECK_EQUAL(failCodes.size(), 0);
305}
306
307BOOST_AUTO_TEST_CASE(FaceQueryWithOptions)
308{
309 FaceQueryFilter filter;
310 filter.setUriScheme("udp4");
311 CommandOptions options;
Davide Pesavento0f830802018-01-16 23:58:58 -0500312 options.setTimeout(3000_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000313 bool hasResult = false;
314 controller.fetch<FaceQueryDataset>(
315 filter,
316 [&hasResult] (const std::vector<FaceStatus>& result) {
317 hasResult = true;
318 BOOST_CHECK_EQUAL(result.size(), 1);
319 BOOST_CHECK_EQUAL(result.front().getFaceId(), 14022);
320 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000321 datasetFailCallback,
Junxiao Shi034c1882016-06-24 18:06:51 +0000322 options);
Davide Pesavento0f830802018-01-16 23:58:58 -0500323 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000324
325 Name prefix("/localhost/nfd/faces/query");
Davide Pesavento2f92b6e2022-04-10 16:42:01 -0400326 prefix.append(filter.wireEncode());
Junxiao Shi034c1882016-06-24 18:06:51 +0000327 FaceStatus payload;
328 payload.setFaceId(14022);
329 this->sendDataset(prefix, payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500330 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000331
332 BOOST_CHECK(hasResult);
333 BOOST_CHECK_EQUAL(failCodes.size(), 0);
334}
335
Junxiao Shi1eacb972016-07-07 22:51:07 +0000336BOOST_AUTO_TEST_CASE(FaceChannels)
337{
338 bool hasResult = false;
339 controller.fetch<ChannelDataset>(
340 [&hasResult] (const std::vector<ChannelStatus>& result) {
341 hasResult = true;
342 BOOST_CHECK_EQUAL(result.size(), 2);
343 BOOST_CHECK_EQUAL(result.front().getLocalUri(), "tcp4://192.0.2.1:6363");
344 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000345 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500346 this->advanceClocks(500_ms);
Junxiao Shi1eacb972016-07-07 22:51:07 +0000347
348 ChannelStatus payload1;
349 payload1.setLocalUri("tcp4://192.0.2.1:6363");
350 ChannelStatus payload2;
351 payload2.setLocalUri("udp4://192.0.2.1:6363");
352 this->sendDataset("/localhost/nfd/faces/channels", payload1, payload2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500353 this->advanceClocks(500_ms);
Junxiao Shi1eacb972016-07-07 22:51:07 +0000354
355 BOOST_CHECK(hasResult);
356 BOOST_CHECK_EQUAL(failCodes.size(), 0);
357}
358
Junxiao Shi034c1882016-06-24 18:06:51 +0000359BOOST_AUTO_TEST_CASE(FibList)
360{
361 bool hasResult = false;
362 controller.fetch<FibDataset>(
363 [&hasResult] (const std::vector<FibEntry>& result) {
364 hasResult = true;
365 BOOST_CHECK_EQUAL(result.size(), 2);
366 BOOST_CHECK_EQUAL(result.front().getPrefix(), "/wYs7fzYcfG");
367 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000368 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500369 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000370
371 FibEntry payload1;
372 payload1.setPrefix("/wYs7fzYcfG");
373 FibEntry payload2;
374 payload2.setPrefix("/LKvmnzY5S");
375 this->sendDataset("/localhost/nfd/fib/list", payload1, payload2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500376 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000377
378 BOOST_CHECK(hasResult);
379 BOOST_CHECK_EQUAL(failCodes.size(), 0);
380}
381
Junxiao Shi7f012472017-12-07 20:40:47 +0000382BOOST_AUTO_TEST_CASE(CsInfo)
383{
384 using ndn::nfd::CsInfo;
385
386 bool hasResult = false;
387 controller.fetch<CsInfoDataset>(
388 [&hasResult] (const CsInfo& result) {
389 hasResult = true;
390 BOOST_CHECK_EQUAL(result.getNHits(), 4539);
391 },
392 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500393 this->advanceClocks(500_ms);
Junxiao Shi7f012472017-12-07 20:40:47 +0000394
395 CsInfo payload;
396 payload.setNHits(4539);
397 this->sendDataset("/localhost/nfd/cs/info", payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500398 this->advanceClocks(500_ms);
Junxiao Shi7f012472017-12-07 20:40:47 +0000399
400 BOOST_CHECK(hasResult);
401 BOOST_CHECK_EQUAL(failCodes.size(), 0);
402}
403
Junxiao Shi034c1882016-06-24 18:06:51 +0000404BOOST_AUTO_TEST_CASE(StrategyChoiceList)
405{
406 bool hasResult = false;
407 controller.fetch<StrategyChoiceDataset>(
408 [&hasResult] (const std::vector<StrategyChoice>& result) {
409 hasResult = true;
410 BOOST_CHECK_EQUAL(result.size(), 2);
411 BOOST_CHECK_EQUAL(result.front().getName(), "/8MLz6N3B");
412 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000413 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500414 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000415
416 StrategyChoice payload1;
417 payload1.setName("/8MLz6N3B");
418 StrategyChoice payload2;
419 payload2.setName("/svqcBu0YwU");
420 this->sendDataset("/localhost/nfd/strategy-choice/list", payload1, payload2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500421 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000422
423 BOOST_CHECK(hasResult);
424 BOOST_CHECK_EQUAL(failCodes.size(), 0);
425}
426
427BOOST_AUTO_TEST_CASE(RibList)
428{
429 bool hasResult = false;
430 controller.fetch<RibDataset>(
431 [&hasResult] (const std::vector<RibEntry>& result) {
432 hasResult = true;
433 BOOST_CHECK_EQUAL(result.size(), 2);
434 BOOST_CHECK_EQUAL(result.front().getName(), "/zXxBth97ee");
435 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000436 datasetFailCallback);
Davide Pesavento0f830802018-01-16 23:58:58 -0500437 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000438
439 RibEntry payload1;
440 payload1.setName("/zXxBth97ee");
441 RibEntry payload2;
442 payload2.setName("/rJ8CvUpr4G");
443 this->sendDataset("/localhost/nfd/rib/list", payload1, payload2);
Davide Pesavento0f830802018-01-16 23:58:58 -0500444 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000445
446 BOOST_CHECK(hasResult);
447 BOOST_CHECK_EQUAL(failCodes.size(), 0);
448}
449
450BOOST_AUTO_TEST_CASE(RibListWithOptions)
451{
452 CommandOptions options;
453 options.setPrefix("/localhop/nfd");
454 bool hasResult = false;
455 controller.fetch<RibDataset>(
456 [&hasResult] (const std::vector<RibEntry>& result) {
457 hasResult = true;
458 BOOST_CHECK_EQUAL(result.size(), 1);
459 BOOST_CHECK_EQUAL(result.front().getName(), "/e6L5K4ascd");
460 },
Junxiao Shie7c7f152016-08-20 22:36:22 +0000461 datasetFailCallback,
Junxiao Shi034c1882016-06-24 18:06:51 +0000462 options);
Davide Pesavento0f830802018-01-16 23:58:58 -0500463 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000464
465 RibEntry payload;
466 payload.setName("/e6L5K4ascd");
467 this->sendDataset("/localhop/nfd/rib/list", payload);
Davide Pesavento0f830802018-01-16 23:58:58 -0500468 this->advanceClocks(500_ms);
Junxiao Shi034c1882016-06-24 18:06:51 +0000469
470 BOOST_CHECK(hasResult);
471 BOOST_CHECK_EQUAL(failCodes.size(), 0);
472}
473
474BOOST_AUTO_TEST_SUITE_END() // Datasets
475
Junxiao Shi7357ef22016-09-07 02:39:37 +0000476BOOST_AUTO_TEST_SUITE_END() // TestStatusDataset
477BOOST_AUTO_TEST_SUITE_END() // Nfd
478BOOST_AUTO_TEST_SUITE_END() // Mgmt
Junxiao Shi034c1882016-06-24 18:06:51 +0000479
Davide Pesavento47ce2ee2023-05-09 01:33:33 -0400480} // namespace ndn::tests