blob: b50625db444a60fa9045554a21d1dc0c6e520ce6 [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev0c63c632017-12-05 11:17:09 -05002/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shi38f4ce92016-08-04 10:01:52 +00004 * 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
Junxiao Shi331ade72016-08-19 14:07:19 +000026#include "nfdc/rib-module.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000027
Junxiao Shi918e5d42017-02-25 03:58:21 +000028#include "execute-command-fixture.hpp"
Junxiao Shi1f481fa2017-01-26 15:14:43 +000029#include "status-fixture.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000030
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040031namespace nfd::tools::nfdc::tests {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000032
Junxiao Shi331ade72016-08-19 14:07:19 +000033BOOST_AUTO_TEST_SUITE(Nfdc)
Junxiao Shi1f481fa2017-01-26 15:14:43 +000034BOOST_FIXTURE_TEST_SUITE(TestRibModule, StatusFixture<RibModule>)
Junxiao Shi38f4ce92016-08-04 10:01:52 +000035
Junxiao Shi1d62e622017-03-08 22:39:28 +000036class RouteListFixture : public ExecuteCommandFixture
37{
38protected:
39 bool
40 respondRibDataset(const Interest& interest)
41 {
42 if (!Name("/localhost/nfd/rib/list").isPrefixOf(interest.getName())) {
43 return false;
44 }
45
46 RibEntry entry1;
47 entry1.setName("/5BBmTevRJ");
48 entry1.addRoute(Route()
49 .setFaceId(6720)
50 .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT)
51 .setCost(2956)
52 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE)
Davide Pesavento14e71f02019-03-28 17:35:25 -040053 .setExpirationPeriod(29950035_ms));
Junxiao Shi1d62e622017-03-08 22:39:28 +000054 entry1.addRoute(Route()
55 .setFaceId(6720)
56 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
57 .setCost(425)
58 .setFlags(ndn::nfd::ROUTE_FLAGS_NONE));
59 entry1.addRoute(Route()
60 .setFaceId(8599)
61 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
62 .setCost(9140)
63 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT));
64
65 RibEntry entry2;
66 entry2.setName("/aDPTKCio");
67 entry2.addRoute(Route()
68 .setFaceId(31066)
69 .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT)
70 .setCost(4617)
71 .setFlags(ndn::nfd::ROUTE_FLAG_CAPTURE));
72
73 this->sendDataset(interest.getName(), entry1, entry2);
74 return true;
75 }
76};
77
78BOOST_FIXTURE_TEST_SUITE(ListShowCommand, RouteListFixture)
79
80const std::string NOFILTER_OUTPUT = std::string(R"TEXT(
Junxiao Shi8eda6822017-04-12 02:53:14 +000081prefix=/5BBmTevRJ nexthop=6720 origin=client cost=2956 flags=child-inherit|capture expires=29950s
82prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never
83prefix=/5BBmTevRJ nexthop=8599 origin=static cost=9140 flags=child-inherit expires=never
84prefix=/aDPTKCio nexthop=31066 origin=client cost=4617 flags=capture expires=never
Junxiao Shi1d62e622017-03-08 22:39:28 +000085)TEXT").substr(1);
86
87BOOST_AUTO_TEST_CASE(ListNoFilter)
88{
89 this->processInterest = [this] (const Interest& interest) {
90 BOOST_CHECK(this->respondRibDataset(interest));
91 };
92
93 this->execute("route");
94 BOOST_CHECK_EQUAL(exitCode, 0);
95 BOOST_CHECK(out.is_equal(NOFILTER_OUTPUT));
96 BOOST_CHECK(err.is_empty());
97}
98
99const std::string NEXTHOP_OUTPUT = std::string(R"TEXT(
Junxiao Shi8eda6822017-04-12 02:53:14 +0000100prefix=/5BBmTevRJ nexthop=6720 origin=client cost=2956 flags=child-inherit|capture expires=29950s
101prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never
102prefix=/aDPTKCio nexthop=31066 origin=client cost=4617 flags=capture expires=never
Junxiao Shi1d62e622017-03-08 22:39:28 +0000103)TEXT").substr(1);
104
105BOOST_AUTO_TEST_CASE(ListByNexthop)
106{
107 this->processInterest = [this] (const Interest& interest) {
108 BOOST_CHECK(this->respondFaceQuery(interest) || this->respondRibDataset(interest));
109 };
110
111 this->execute("route list udp4://225.131.75.231:56363");
112 BOOST_CHECK_EQUAL(exitCode, 0);
113 BOOST_CHECK(out.is_equal(NEXTHOP_OUTPUT));
114 BOOST_CHECK(err.is_empty());
115}
116
117const std::string ORIGIN_OUTPUT = std::string(R"TEXT(
Junxiao Shi8eda6822017-04-12 02:53:14 +0000118prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never
119prefix=/5BBmTevRJ nexthop=8599 origin=static cost=9140 flags=child-inherit expires=never
Junxiao Shi1d62e622017-03-08 22:39:28 +0000120)TEXT").substr(1);
121
Junxiao Shi8eda6822017-04-12 02:53:14 +0000122BOOST_AUTO_TEST_CASE(ListByOriginNumeric)
Junxiao Shi1d62e622017-03-08 22:39:28 +0000123{
124 this->processInterest = [this] (const Interest& interest) {
125 BOOST_CHECK(this->respondRibDataset(interest));
126 };
127
128 this->execute("route list origin 255");
129 BOOST_CHECK_EQUAL(exitCode, 0);
130 BOOST_CHECK(out.is_equal(ORIGIN_OUTPUT));
131 BOOST_CHECK(err.is_empty());
132}
133
Junxiao Shi8eda6822017-04-12 02:53:14 +0000134BOOST_AUTO_TEST_CASE(ListByOriginString)
135{
136 this->processInterest = [this] (const Interest& interest) {
137 BOOST_CHECK(this->respondRibDataset(interest));
138 };
139
140 this->execute("route list origin static");
141 BOOST_CHECK_EQUAL(exitCode, 0);
142 BOOST_CHECK(out.is_equal(ORIGIN_OUTPUT));
143 BOOST_CHECK(err.is_empty());
144}
145
Junxiao Shi1d62e622017-03-08 22:39:28 +0000146const std::string PREFIX_OUTPUT = std::string(R"TEXT(
Junxiao Shi8eda6822017-04-12 02:53:14 +0000147prefix=/5BBmTevRJ nexthop=6720 origin=client cost=2956 flags=child-inherit|capture expires=29950s
148prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never
149prefix=/5BBmTevRJ nexthop=8599 origin=static cost=9140 flags=child-inherit expires=never
Junxiao Shi1d62e622017-03-08 22:39:28 +0000150)TEXT").substr(1);
151
152BOOST_AUTO_TEST_CASE(ShowByPrefix)
153{
154 this->processInterest = [this] (const Interest& interest) {
155 BOOST_CHECK(this->respondRibDataset(interest));
156 };
157
158 this->execute("route show 5BBmTevRJ");
159 BOOST_CHECK_EQUAL(exitCode, 0);
160 BOOST_CHECK(out.is_equal(PREFIX_OUTPUT));
161 BOOST_CHECK(err.is_empty());
162}
163
164BOOST_AUTO_TEST_CASE(FaceNotExist)
165{
166 this->processInterest = [this] (const Interest& interest) {
167 BOOST_CHECK(this->respondFaceQuery(interest));
168 };
169
170 this->execute("route list 23728");
171 BOOST_CHECK_EQUAL(exitCode, 3);
172 BOOST_CHECK(out.is_empty());
173 BOOST_CHECK(err.is_equal("Face not found\n"));
174}
175
176BOOST_AUTO_TEST_CASE(RouteNotExist)
177{
178 this->processInterest = [this] (const Interest& interest) {
179 BOOST_CHECK(this->respondFaceQuery(interest) || this->respondRibDataset(interest));
180 };
181
182 this->execute("route list 10156");
183 BOOST_CHECK_EQUAL(exitCode, 6);
184 BOOST_CHECK(out.is_empty());
185 BOOST_CHECK(err.is_equal("Route not found\n"));
186}
187
188BOOST_AUTO_TEST_CASE(ErrorDataset)
189{
190 this->processInterest = nullptr; // no response to dataset
191
192 this->execute("route list");
193 BOOST_CHECK_EQUAL(exitCode, 1);
194 BOOST_CHECK(out.is_empty());
Eric Newberry359135c2018-06-26 21:02:12 -0700195 BOOST_CHECK(err.is_equal("Error 10060 when fetching RIB dataset: Timeout exceeded\n"));
Junxiao Shi1d62e622017-03-08 22:39:28 +0000196}
197
198BOOST_AUTO_TEST_SUITE_END() // ListShowCommand
199
Junxiao Shi918e5d42017-02-25 03:58:21 +0000200BOOST_FIXTURE_TEST_SUITE(AddCommand, ExecuteCommandFixture)
201
202BOOST_AUTO_TEST_CASE(NormalByFaceId)
203{
204 this->processInterest = [this] (const Interest& interest) {
205 if (this->respondFaceQuery(interest)) {
206 return;
207 }
208
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000209 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/register");
Junxiao Shi918e5d42017-02-25 03:58:21 +0000210 ndn::nfd::RibRegisterCommand cmd;
211 cmd.validateRequest(req);
212 cmd.applyDefaultsToRequest(req);
213 BOOST_CHECK_EQUAL(req.getName(), "/vxXoEaWeDB");
214 BOOST_CHECK_EQUAL(req.getFaceId(), 10156);
215 BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC);
216 BOOST_CHECK_EQUAL(req.getCost(), 0);
217 BOOST_CHECK_EQUAL(req.getFlags(), ndn::nfd::ROUTE_FLAGS_NONE);
218 BOOST_CHECK_EQUAL(req.hasExpirationPeriod(), false);
219
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000220 this->succeedCommand(interest, req);
Junxiao Shi918e5d42017-02-25 03:58:21 +0000221 };
222
223 this->execute("route add /vxXoEaWeDB 10156 no-inherit");
224 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi8eda6822017-04-12 02:53:14 +0000225 BOOST_CHECK(out.is_equal("route-add-accepted prefix=/vxXoEaWeDB nexthop=10156 origin=static "
Junxiao Shi918e5d42017-02-25 03:58:21 +0000226 "cost=0 flags=none expires=never\n"));
227 BOOST_CHECK(err.is_empty());
228}
229
230BOOST_AUTO_TEST_CASE(NormalByFaceUri)
231{
232 this->processInterest = [this] (const Interest& interest) {
233 if (this->respondFaceQuery(interest)) {
234 return;
235 }
236
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000237 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/register");
Junxiao Shi918e5d42017-02-25 03:58:21 +0000238 ndn::nfd::RibRegisterCommand cmd;
239 cmd.validateRequest(req);
240 cmd.applyDefaultsToRequest(req);
241 BOOST_CHECK_EQUAL(req.getName(), "/FLQAsaYnYf");
242 BOOST_CHECK_EQUAL(req.getFaceId(), 2249);
243 BOOST_CHECK_EQUAL(req.getOrigin(), 17591);
244 BOOST_CHECK_EQUAL(req.getCost(), 702);
245 BOOST_CHECK_EQUAL(req.getFlags(), ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
246 ndn::nfd::ROUTE_FLAG_CAPTURE);
247 BOOST_REQUIRE_EQUAL(req.hasExpirationPeriod(), true);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400248 BOOST_REQUIRE_EQUAL(req.getExpirationPeriod(), 727411987_ms);
Junxiao Shi918e5d42017-02-25 03:58:21 +0000249
250 ControlParameters resp = req;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400251 resp.setExpirationPeriod(727411154_ms); // server side may change expiration
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000252 this->succeedCommand(interest, resp);
Junxiao Shi918e5d42017-02-25 03:58:21 +0000253 };
254
255 this->execute("route add /FLQAsaYnYf tcp4://32.121.182.82:6363 "
256 "origin 17591 cost 702 capture expires 727411987");
257 BOOST_CHECK_EQUAL(exitCode, 0);
258 BOOST_CHECK(out.is_equal("route-add-accepted prefix=/FLQAsaYnYf nexthop=2249 origin=17591 "
259 "cost=702 flags=child-inherit|capture expires=727411154ms\n"));
260 BOOST_CHECK(err.is_empty());
261}
262
Eric Newberryd656aff2020-04-03 00:30:38 -0700263BOOST_AUTO_TEST_CASE(FaceNotExistFaceId)
Junxiao Shi918e5d42017-02-25 03:58:21 +0000264{
265 this->processInterest = [this] (const Interest& interest) {
266 BOOST_CHECK(this->respondFaceQuery(interest));
267 };
268
269 this->execute("route add /GJiKDus5i 23728");
270 BOOST_CHECK_EQUAL(exitCode, 3);
271 BOOST_CHECK(out.is_empty());
272 BOOST_CHECK(err.is_equal("Face not found\n"));
273}
274
Eric Newberryd656aff2020-04-03 00:30:38 -0700275BOOST_AUTO_TEST_CASE(FaceNotExistFaceUri)
276{
277 this->processInterest = [this] (const Interest& interest) {
278 if (Name("/localhost/nfd/faces/query").isPrefixOf(interest.getName())) {
279 this->respondFaceQuery(interest);
280 }
281 else if (Name("/localhost/nfd/faces/create").isPrefixOf(interest.getName())) {
282 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/faces/create");
283 ndn::nfd::FaceCreateCommand cmd;
284 cmd.validateRequest(req);
285 cmd.applyDefaultsToRequest(req);
286 BOOST_CHECK_EQUAL(req.getUri(), "udp4://202.83.168.28:6363");
287
288 ControlParameters resp = req;
289 resp.setFaceId(255);
290 resp.setLocalUri("udp4://32.121.182.82:50000");
291 resp.setFacePersistency(FacePersistency::FACE_PERSISTENCY_PERSISTENT);
292 resp.setBaseCongestionMarkingInterval(100_ms);
293 resp.setDefaultCongestionThreshold(65536);
294 resp.setMtu(8800);
295 resp.setFlags(0);
296 this->succeedCommand(interest, resp);
297 }
298 else if (Name("/localhost/nfd/rib/register").isPrefixOf(interest.getName())) {
299 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/register");
300 ndn::nfd::RibRegisterCommand cmd;
301 cmd.validateRequest(req);
302 cmd.applyDefaultsToRequest(req);
303 BOOST_CHECK_EQUAL(req.getName(), "/634jfAfdf");
304 BOOST_CHECK_EQUAL(req.getFaceId(), 255);
305 BOOST_CHECK_EQUAL(req.getOrigin(), 17591);
306 BOOST_CHECK_EQUAL(req.getCost(), 702);
307 BOOST_CHECK_EQUAL(req.getFlags(), ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
308 ndn::nfd::ROUTE_FLAG_CAPTURE);
309 BOOST_REQUIRE_EQUAL(req.hasExpirationPeriod(), true);
310 BOOST_REQUIRE_EQUAL(req.getExpirationPeriod(), 727411987_ms);
311
312 ControlParameters resp = req;
313 resp.setExpirationPeriod(727411154_ms); // server side may change expiration
314 this->succeedCommand(interest, resp);
315 }
316 };
317
318 this->execute("route add /634jfAfdf udp4://202.83.168.28:6363 "
319 "origin 17591 cost 702 capture expires 727411987");
320 BOOST_CHECK(out.is_equal("face-created id=255 local=udp4://32.121.182.82:50000 "
321 "remote=udp4://202.83.168.28:6363 persistency=persistent "
322 "reliability=off congestion-marking=off "
323 "congestion-marking-interval=100ms default-congestion-threshold=65536B "
324 "mtu=8800\n"
325 "route-add-accepted prefix=/634jfAfdf nexthop=255 origin=17591 "
326 "cost=702 flags=child-inherit|capture expires=727411154ms\n"));
327 BOOST_CHECK(err.is_empty());
328 BOOST_CHECK_EQUAL(exitCode, 0);
329}
330
331BOOST_AUTO_TEST_CASE(FaceNotExistNotCanonizable)
332{
333 this->processInterest = [this] (const Interest& interest) {
334 BOOST_CHECK(this->respondFaceQuery(interest));
335 };
336
337 this->execute("route add /634jfAfdf udp6://202.83.168.28:6363 "
338 "origin 17591 cost 702 capture expires 727411987");
339 BOOST_CHECK(out.is_empty());
340 BOOST_CHECK(err.is_equal("Error during canonization of 'udp6://202.83.168.28:6363': "
341 "IPv4/v6 mismatch\n"));
342 BOOST_CHECK_EQUAL(exitCode, 4);
343}
344
Junxiao Shi918e5d42017-02-25 03:58:21 +0000345BOOST_AUTO_TEST_CASE(Ambiguous)
346{
347 this->processInterest = [this] (const Interest& interest) {
348 BOOST_CHECK(this->respondFaceQuery(interest));
349 };
350
351 this->execute("route add /BQqjjnVsz udp4://225.131.75.231:56363");
352 BOOST_CHECK_EQUAL(exitCode, 5);
353 BOOST_CHECK(out.is_empty());
354 BOOST_CHECK(err.is_equal("Multiple faces match specified remote FaceUri. "
355 "Re-run the command with a FaceId: "
356 "6720 (local=udp4://202.83.168.28:56363), "
357 "31066 (local=udp4://25.90.26.32:56363)\n"));
358}
359
360BOOST_AUTO_TEST_CASE(ErrorCanonization)
361{
362 this->execute("route add /bxJfGsVtDt udp6://32.38.164.64:10445");
363 BOOST_CHECK_EQUAL(exitCode, 4);
364 BOOST_CHECK(out.is_empty());
Eric Newberryd656aff2020-04-03 00:30:38 -0700365 BOOST_CHECK(err.is_equal("Error during canonization of 'udp6://32.38.164.64:10445': "
Eric Newberry7d8695d2017-05-29 15:49:10 -0700366 "IPv4/v6 mismatch\n"));
Junxiao Shi918e5d42017-02-25 03:58:21 +0000367}
368
369BOOST_AUTO_TEST_CASE(ErrorDataset)
370{
371 this->processInterest = nullptr; // no response to dataset or command
372
373 this->execute("route add /q1Qf7go7 udp://159.242.33.78");
374 BOOST_CHECK_EQUAL(exitCode, 1);
375 BOOST_CHECK(out.is_empty());
Eric Newberry359135c2018-06-26 21:02:12 -0700376 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout exceeded\n"));
Junxiao Shi918e5d42017-02-25 03:58:21 +0000377}
378
379BOOST_AUTO_TEST_CASE(ErrorCommand)
380{
381 this->processInterest = [this] (const Interest& interest) {
382 if (this->respondFaceQuery(interest)) {
383 return;
384 }
385
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000386 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/register");
Junxiao Shi918e5d42017-02-25 03:58:21 +0000387 // no response to command
388 };
389
390 this->execute("route add /bYiMbEuE 10156");
391 BOOST_CHECK_EQUAL(exitCode, 1);
392 BOOST_CHECK(out.is_empty());
393 BOOST_CHECK(err.is_equal("Error 10060 when adding route: request timed out\n"));
394}
395
396BOOST_AUTO_TEST_SUITE_END() // AddCommand
397
Junxiao Shi084b7952017-02-26 22:00:53 +0000398BOOST_FIXTURE_TEST_SUITE(RemoveCommand, ExecuteCommandFixture)
399
400BOOST_AUTO_TEST_CASE(NormalByFaceId)
401{
402 this->processInterest = [this] (const Interest& interest) {
403 if (this->respondFaceQuery(interest)) {
404 return;
405 }
406
407 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister");
408 ndn::nfd::RibUnregisterCommand cmd;
409 cmd.validateRequest(req);
410 cmd.applyDefaultsToRequest(req);
411 BOOST_CHECK_EQUAL(req.getName(), "/2B5NUGjpt");
412 BOOST_CHECK_EQUAL(req.getFaceId(), 10156);
413 BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC);
414
415 this->succeedCommand(interest, req);
416 };
417
418 this->execute("route remove /2B5NUGjpt 10156");
419 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi8eda6822017-04-12 02:53:14 +0000420 BOOST_CHECK(out.is_equal("route-removed prefix=/2B5NUGjpt nexthop=10156 origin=static\n"));
Junxiao Shi084b7952017-02-26 22:00:53 +0000421 BOOST_CHECK(err.is_empty());
422}
423
424BOOST_AUTO_TEST_CASE(NormalByFaceUri)
425{
426 this->processInterest = [this] (const Interest& interest) {
427 if (this->respondFaceQuery(interest)) {
428 return;
429 }
430
431 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister");
432 ndn::nfd::RibUnregisterCommand cmd;
433 cmd.validateRequest(req);
434 cmd.applyDefaultsToRequest(req);
435 BOOST_CHECK_EQUAL(req.getName(), "/wHdNn0BtUF");
436 BOOST_CHECK_EQUAL(req.getFaceId(), 2249);
437 BOOST_CHECK_EQUAL(req.getOrigin(), 15246);
438
439 this->succeedCommand(interest, req);
440 };
441
442 this->execute("route remove /wHdNn0BtUF tcp4://32.121.182.82:6363 origin 15246");
443 BOOST_CHECK_EQUAL(exitCode, 0);
444 BOOST_CHECK(out.is_equal("route-removed prefix=/wHdNn0BtUF nexthop=2249 origin=15246\n"));
445 BOOST_CHECK(err.is_empty());
446}
447
448BOOST_AUTO_TEST_CASE(MultipleFaces)
449{
450 std::set<uint64_t> faceIds{6720, 31066};
451 this->processInterest = [this, &faceIds] (const Interest& interest) {
452 if (this->respondFaceQuery(interest)) {
453 return;
454 }
455
456 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister");
457 ndn::nfd::RibUnregisterCommand cmd;
458 cmd.validateRequest(req);
459 cmd.applyDefaultsToRequest(req);
460 BOOST_CHECK_EQUAL(req.getName(), "/nm5y8X8b2");
Alexander Afanasyev0c63c632017-12-05 11:17:09 -0500461 BOOST_CHECK_MESSAGE(faceIds.erase(req.getFaceId()), "expected face " + to_string(req.getFaceId()));
Junxiao Shi084b7952017-02-26 22:00:53 +0000462 BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC);
463
464 this->succeedCommand(interest, req);
465 };
466
467 this->execute("route remove /nm5y8X8b2 udp4://225.131.75.231:56363");
468 BOOST_CHECK(faceIds.empty());
469 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi8eda6822017-04-12 02:53:14 +0000470 BOOST_CHECK(out.is_equal("route-removed prefix=/nm5y8X8b2 nexthop=6720 origin=static\n"
471 "route-removed prefix=/nm5y8X8b2 nexthop=31066 origin=static\n"));
Junxiao Shi084b7952017-02-26 22:00:53 +0000472 BOOST_CHECK(err.is_empty());
473}
474
475BOOST_AUTO_TEST_CASE(FaceNotExist)
476{
477 this->processInterest = [this] (const Interest& interest) {
478 BOOST_CHECK(this->respondFaceQuery(interest));
479 };
480
481 this->execute("route remove /HeGRjzwFM 23728");
482 BOOST_CHECK_EQUAL(exitCode, 3);
483 BOOST_CHECK(out.is_empty());
484 BOOST_CHECK(err.is_equal("Face not found\n"));
485}
486
487BOOST_AUTO_TEST_CASE(ErrorDataset)
488{
489 this->processInterest = nullptr; // no response to dataset or command
490
491 this->execute("route remove /YX4xQQN3v5 udp://26.97.248.3");
492 BOOST_CHECK_EQUAL(exitCode, 1);
493 BOOST_CHECK(out.is_empty());
Eric Newberry359135c2018-06-26 21:02:12 -0700494 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout exceeded\n"));
Junxiao Shi084b7952017-02-26 22:00:53 +0000495}
496
497BOOST_AUTO_TEST_CASE(ErrorCommand)
498{
499 this->processInterest = [this] (const Interest& interest) {
500 if (this->respondFaceQuery(interest)) {
501 return;
502 }
503
504 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister");
505 // no response to command
506 };
507
508 this->execute("route remove /mvGRoxD2 10156");
509 BOOST_CHECK_EQUAL(exitCode, 1);
510 BOOST_CHECK(out.is_empty());
511 BOOST_CHECK(err.is_equal("Error 10060 when removing route: request timed out\n"));
512}
513
514BOOST_AUTO_TEST_SUITE_END() // RemoveCommand
515
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000516const std::string STATUS_XML = stripXmlSpaces(R"XML(
517 <rib>
518 <ribEntry>
519 <prefix>/</prefix>
520 <routes>
521 <route>
522 <faceId>262</faceId>
Junxiao Shi8eda6822017-04-12 02:53:14 +0000523 <origin>static</origin>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000524 <cost>9</cost>
525 <flags>
526 <ribCapture/>
527 </flags>
528 </route>
529 <route>
530 <faceId>272</faceId>
Junxiao Shi8eda6822017-04-12 02:53:14 +0000531 <origin>static</origin>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000532 <cost>50</cost>
533 <flags/>
534 </route>
535 <route>
536 <faceId>274</faceId>
Junxiao Shi8eda6822017-04-12 02:53:14 +0000537 <origin>static</origin>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000538 <cost>78</cost>
539 <flags>
540 <childInherit/>
541 <ribCapture/>
542 </flags>
543 </route>
544 <route>
545 <faceId>276</faceId>
Junxiao Shi8eda6822017-04-12 02:53:14 +0000546 <origin>static</origin>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000547 <cost>79</cost>
548 <flags>
549 <childInherit/>
550 </flags>
551 <expirationPeriod>PT47S</expirationPeriod>
552 </route>
553 </routes>
554 </ribEntry>
555 <ribEntry>
556 <prefix>/localhost/nfd</prefix>
557 <routes>
558 <route>
559 <faceId>258</faceId>
Junxiao Shi8eda6822017-04-12 02:53:14 +0000560 <origin>app</origin>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000561 <cost>0</cost>
562 <flags>
563 <childInherit/>
564 </flags>
565 </route>
566 </routes>
567 </ribEntry>
568 </rib>
569)XML");
570
571const std::string STATUS_TEXT =
572 "RIB:\n"
Junxiao Shi8eda6822017-04-12 02:53:14 +0000573 " / routes={nexthop=262 origin=static cost=9 flags=capture expires=never, "
574 "nexthop=272 origin=static cost=50 flags=none expires=never, "
575 "nexthop=274 origin=static cost=78 flags=child-inherit|capture expires=never, "
576 "nexthop=276 origin=static cost=79 flags=child-inherit expires=47s}\n"
577 " /localhost/nfd routes={nexthop=258 origin=app cost=0 flags=child-inherit expires=never}\n";
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000578
579BOOST_AUTO_TEST_CASE(Status)
580{
581 this->fetchStatus();
582 RibEntry payload1;
583 payload1.setName("/")
584 .addRoute(Route().setFaceId(262)
585 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
586 .setCost(9)
587 .setFlags(ndn::nfd::ROUTE_FLAG_CAPTURE))
588 .addRoute(Route().setFaceId(272)
589 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
590 .setCost(50)
591 .setFlags(ndn::nfd::ROUTE_FLAGS_NONE))
592 .addRoute(Route().setFaceId(274)
593 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
594 .setCost(78)
595 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE))
596 .addRoute(Route().setFaceId(276)
597 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
598 .setCost(79)
599 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)
Davide Pesavento14e71f02019-03-28 17:35:25 -0400600 .setExpirationPeriod(47292_ms));
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000601 RibEntry payload2;
602 payload2.setName("/localhost/nfd")
603 .addRoute(Route().setFaceId(258)
604 .setOrigin(ndn::nfd::ROUTE_ORIGIN_APP)
605 .setCost(0)
606 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT));
607 this->sendDataset("/localhost/nfd/rib/list", payload1, payload2);
608 this->prepareStatusOutput();
609
610 BOOST_CHECK(statusXml.is_equal(STATUS_XML));
611 BOOST_CHECK(statusText.is_equal(STATUS_TEXT));
612}
613
614BOOST_AUTO_TEST_SUITE_END() // TestRibModule
Junxiao Shi331ade72016-08-19 14:07:19 +0000615BOOST_AUTO_TEST_SUITE_END() // Nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000616
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400617} // namespace nfd::tools::nfdc::tests