blob: 624fca60809e5468905826a044da6e5cbac55639 [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 Pesavento14e71f02019-03-28 17:35:25 -04003 * Copyright (c) 2014-2019, 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
31namespace nfd {
32namespace tools {
Junxiao Shi331ade72016-08-19 14:07:19 +000033namespace nfdc {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000034namespace tests {
35
Junxiao Shi331ade72016-08-19 14:07:19 +000036BOOST_AUTO_TEST_SUITE(Nfdc)
Junxiao Shi1f481fa2017-01-26 15:14:43 +000037BOOST_FIXTURE_TEST_SUITE(TestRibModule, StatusFixture<RibModule>)
Junxiao Shi38f4ce92016-08-04 10:01:52 +000038
Junxiao Shi1d62e622017-03-08 22:39:28 +000039class RouteListFixture : public ExecuteCommandFixture
40{
41protected:
42 bool
43 respondRibDataset(const Interest& interest)
44 {
45 if (!Name("/localhost/nfd/rib/list").isPrefixOf(interest.getName())) {
46 return false;
47 }
48
49 RibEntry entry1;
50 entry1.setName("/5BBmTevRJ");
51 entry1.addRoute(Route()
52 .setFaceId(6720)
53 .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT)
54 .setCost(2956)
55 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE)
Davide Pesavento14e71f02019-03-28 17:35:25 -040056 .setExpirationPeriod(29950035_ms));
Junxiao Shi1d62e622017-03-08 22:39:28 +000057 entry1.addRoute(Route()
58 .setFaceId(6720)
59 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
60 .setCost(425)
61 .setFlags(ndn::nfd::ROUTE_FLAGS_NONE));
62 entry1.addRoute(Route()
63 .setFaceId(8599)
64 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
65 .setCost(9140)
66 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT));
67
68 RibEntry entry2;
69 entry2.setName("/aDPTKCio");
70 entry2.addRoute(Route()
71 .setFaceId(31066)
72 .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT)
73 .setCost(4617)
74 .setFlags(ndn::nfd::ROUTE_FLAG_CAPTURE));
75
76 this->sendDataset(interest.getName(), entry1, entry2);
77 return true;
78 }
79};
80
81BOOST_FIXTURE_TEST_SUITE(ListShowCommand, RouteListFixture)
82
83const std::string NOFILTER_OUTPUT = std::string(R"TEXT(
Junxiao Shi8eda6822017-04-12 02:53:14 +000084prefix=/5BBmTevRJ nexthop=6720 origin=client cost=2956 flags=child-inherit|capture expires=29950s
85prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never
86prefix=/5BBmTevRJ nexthop=8599 origin=static cost=9140 flags=child-inherit expires=never
87prefix=/aDPTKCio nexthop=31066 origin=client cost=4617 flags=capture expires=never
Junxiao Shi1d62e622017-03-08 22:39:28 +000088)TEXT").substr(1);
89
90BOOST_AUTO_TEST_CASE(ListNoFilter)
91{
92 this->processInterest = [this] (const Interest& interest) {
93 BOOST_CHECK(this->respondRibDataset(interest));
94 };
95
96 this->execute("route");
97 BOOST_CHECK_EQUAL(exitCode, 0);
98 BOOST_CHECK(out.is_equal(NOFILTER_OUTPUT));
99 BOOST_CHECK(err.is_empty());
100}
101
102const std::string NEXTHOP_OUTPUT = std::string(R"TEXT(
Junxiao Shi8eda6822017-04-12 02:53:14 +0000103prefix=/5BBmTevRJ nexthop=6720 origin=client cost=2956 flags=child-inherit|capture expires=29950s
104prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never
105prefix=/aDPTKCio nexthop=31066 origin=client cost=4617 flags=capture expires=never
Junxiao Shi1d62e622017-03-08 22:39:28 +0000106)TEXT").substr(1);
107
108BOOST_AUTO_TEST_CASE(ListByNexthop)
109{
110 this->processInterest = [this] (const Interest& interest) {
111 BOOST_CHECK(this->respondFaceQuery(interest) || this->respondRibDataset(interest));
112 };
113
114 this->execute("route list udp4://225.131.75.231:56363");
115 BOOST_CHECK_EQUAL(exitCode, 0);
116 BOOST_CHECK(out.is_equal(NEXTHOP_OUTPUT));
117 BOOST_CHECK(err.is_empty());
118}
119
120const std::string ORIGIN_OUTPUT = std::string(R"TEXT(
Junxiao Shi8eda6822017-04-12 02:53:14 +0000121prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never
122prefix=/5BBmTevRJ nexthop=8599 origin=static cost=9140 flags=child-inherit expires=never
Junxiao Shi1d62e622017-03-08 22:39:28 +0000123)TEXT").substr(1);
124
Junxiao Shi8eda6822017-04-12 02:53:14 +0000125BOOST_AUTO_TEST_CASE(ListByOriginNumeric)
Junxiao Shi1d62e622017-03-08 22:39:28 +0000126{
127 this->processInterest = [this] (const Interest& interest) {
128 BOOST_CHECK(this->respondRibDataset(interest));
129 };
130
131 this->execute("route list origin 255");
132 BOOST_CHECK_EQUAL(exitCode, 0);
133 BOOST_CHECK(out.is_equal(ORIGIN_OUTPUT));
134 BOOST_CHECK(err.is_empty());
135}
136
Junxiao Shi8eda6822017-04-12 02:53:14 +0000137BOOST_AUTO_TEST_CASE(ListByOriginString)
138{
139 this->processInterest = [this] (const Interest& interest) {
140 BOOST_CHECK(this->respondRibDataset(interest));
141 };
142
143 this->execute("route list origin static");
144 BOOST_CHECK_EQUAL(exitCode, 0);
145 BOOST_CHECK(out.is_equal(ORIGIN_OUTPUT));
146 BOOST_CHECK(err.is_empty());
147}
148
Junxiao Shi1d62e622017-03-08 22:39:28 +0000149const std::string PREFIX_OUTPUT = std::string(R"TEXT(
Junxiao Shi8eda6822017-04-12 02:53:14 +0000150prefix=/5BBmTevRJ nexthop=6720 origin=client cost=2956 flags=child-inherit|capture expires=29950s
151prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never
152prefix=/5BBmTevRJ nexthop=8599 origin=static cost=9140 flags=child-inherit expires=never
Junxiao Shi1d62e622017-03-08 22:39:28 +0000153)TEXT").substr(1);
154
155BOOST_AUTO_TEST_CASE(ShowByPrefix)
156{
157 this->processInterest = [this] (const Interest& interest) {
158 BOOST_CHECK(this->respondRibDataset(interest));
159 };
160
161 this->execute("route show 5BBmTevRJ");
162 BOOST_CHECK_EQUAL(exitCode, 0);
163 BOOST_CHECK(out.is_equal(PREFIX_OUTPUT));
164 BOOST_CHECK(err.is_empty());
165}
166
167BOOST_AUTO_TEST_CASE(FaceNotExist)
168{
169 this->processInterest = [this] (const Interest& interest) {
170 BOOST_CHECK(this->respondFaceQuery(interest));
171 };
172
173 this->execute("route list 23728");
174 BOOST_CHECK_EQUAL(exitCode, 3);
175 BOOST_CHECK(out.is_empty());
176 BOOST_CHECK(err.is_equal("Face not found\n"));
177}
178
179BOOST_AUTO_TEST_CASE(RouteNotExist)
180{
181 this->processInterest = [this] (const Interest& interest) {
182 BOOST_CHECK(this->respondFaceQuery(interest) || this->respondRibDataset(interest));
183 };
184
185 this->execute("route list 10156");
186 BOOST_CHECK_EQUAL(exitCode, 6);
187 BOOST_CHECK(out.is_empty());
188 BOOST_CHECK(err.is_equal("Route not found\n"));
189}
190
191BOOST_AUTO_TEST_CASE(ErrorDataset)
192{
193 this->processInterest = nullptr; // no response to dataset
194
195 this->execute("route list");
196 BOOST_CHECK_EQUAL(exitCode, 1);
197 BOOST_CHECK(out.is_empty());
Eric Newberry359135c2018-06-26 21:02:12 -0700198 BOOST_CHECK(err.is_equal("Error 10060 when fetching RIB dataset: Timeout exceeded\n"));
Junxiao Shi1d62e622017-03-08 22:39:28 +0000199}
200
201BOOST_AUTO_TEST_SUITE_END() // ListShowCommand
202
Junxiao Shi918e5d42017-02-25 03:58:21 +0000203BOOST_FIXTURE_TEST_SUITE(AddCommand, ExecuteCommandFixture)
204
205BOOST_AUTO_TEST_CASE(NormalByFaceId)
206{
207 this->processInterest = [this] (const Interest& interest) {
208 if (this->respondFaceQuery(interest)) {
209 return;
210 }
211
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000212 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/register");
Junxiao Shi918e5d42017-02-25 03:58:21 +0000213 ndn::nfd::RibRegisterCommand cmd;
214 cmd.validateRequest(req);
215 cmd.applyDefaultsToRequest(req);
216 BOOST_CHECK_EQUAL(req.getName(), "/vxXoEaWeDB");
217 BOOST_CHECK_EQUAL(req.getFaceId(), 10156);
218 BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC);
219 BOOST_CHECK_EQUAL(req.getCost(), 0);
220 BOOST_CHECK_EQUAL(req.getFlags(), ndn::nfd::ROUTE_FLAGS_NONE);
221 BOOST_CHECK_EQUAL(req.hasExpirationPeriod(), false);
222
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000223 this->succeedCommand(interest, req);
Junxiao Shi918e5d42017-02-25 03:58:21 +0000224 };
225
226 this->execute("route add /vxXoEaWeDB 10156 no-inherit");
227 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi8eda6822017-04-12 02:53:14 +0000228 BOOST_CHECK(out.is_equal("route-add-accepted prefix=/vxXoEaWeDB nexthop=10156 origin=static "
Junxiao Shi918e5d42017-02-25 03:58:21 +0000229 "cost=0 flags=none expires=never\n"));
230 BOOST_CHECK(err.is_empty());
231}
232
233BOOST_AUTO_TEST_CASE(NormalByFaceUri)
234{
235 this->processInterest = [this] (const Interest& interest) {
236 if (this->respondFaceQuery(interest)) {
237 return;
238 }
239
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000240 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/register");
Junxiao Shi918e5d42017-02-25 03:58:21 +0000241 ndn::nfd::RibRegisterCommand cmd;
242 cmd.validateRequest(req);
243 cmd.applyDefaultsToRequest(req);
244 BOOST_CHECK_EQUAL(req.getName(), "/FLQAsaYnYf");
245 BOOST_CHECK_EQUAL(req.getFaceId(), 2249);
246 BOOST_CHECK_EQUAL(req.getOrigin(), 17591);
247 BOOST_CHECK_EQUAL(req.getCost(), 702);
248 BOOST_CHECK_EQUAL(req.getFlags(), ndn::nfd::ROUTE_FLAG_CHILD_INHERIT |
249 ndn::nfd::ROUTE_FLAG_CAPTURE);
250 BOOST_REQUIRE_EQUAL(req.hasExpirationPeriod(), true);
Davide Pesavento14e71f02019-03-28 17:35:25 -0400251 BOOST_REQUIRE_EQUAL(req.getExpirationPeriod(), 727411987_ms);
Junxiao Shi918e5d42017-02-25 03:58:21 +0000252
253 ControlParameters resp = req;
Davide Pesavento14e71f02019-03-28 17:35:25 -0400254 resp.setExpirationPeriod(727411154_ms); // server side may change expiration
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000255 this->succeedCommand(interest, resp);
Junxiao Shi918e5d42017-02-25 03:58:21 +0000256 };
257
258 this->execute("route add /FLQAsaYnYf tcp4://32.121.182.82:6363 "
259 "origin 17591 cost 702 capture expires 727411987");
260 BOOST_CHECK_EQUAL(exitCode, 0);
261 BOOST_CHECK(out.is_equal("route-add-accepted prefix=/FLQAsaYnYf nexthop=2249 origin=17591 "
262 "cost=702 flags=child-inherit|capture expires=727411154ms\n"));
263 BOOST_CHECK(err.is_empty());
264}
265
266BOOST_AUTO_TEST_CASE(FaceNotExist)
267{
268 this->processInterest = [this] (const Interest& interest) {
269 BOOST_CHECK(this->respondFaceQuery(interest));
270 };
271
272 this->execute("route add /GJiKDus5i 23728");
273 BOOST_CHECK_EQUAL(exitCode, 3);
274 BOOST_CHECK(out.is_empty());
275 BOOST_CHECK(err.is_equal("Face not found\n"));
276}
277
278BOOST_AUTO_TEST_CASE(Ambiguous)
279{
280 this->processInterest = [this] (const Interest& interest) {
281 BOOST_CHECK(this->respondFaceQuery(interest));
282 };
283
284 this->execute("route add /BQqjjnVsz udp4://225.131.75.231:56363");
285 BOOST_CHECK_EQUAL(exitCode, 5);
286 BOOST_CHECK(out.is_empty());
287 BOOST_CHECK(err.is_equal("Multiple faces match specified remote FaceUri. "
288 "Re-run the command with a FaceId: "
289 "6720 (local=udp4://202.83.168.28:56363), "
290 "31066 (local=udp4://25.90.26.32:56363)\n"));
291}
292
293BOOST_AUTO_TEST_CASE(ErrorCanonization)
294{
295 this->execute("route add /bxJfGsVtDt udp6://32.38.164.64:10445");
296 BOOST_CHECK_EQUAL(exitCode, 4);
297 BOOST_CHECK(out.is_empty());
298 BOOST_CHECK(err.is_equal("Error during remote FaceUri canonization: "
Eric Newberry7d8695d2017-05-29 15:49:10 -0700299 "IPv4/v6 mismatch\n"));
Junxiao Shi918e5d42017-02-25 03:58:21 +0000300}
301
302BOOST_AUTO_TEST_CASE(ErrorDataset)
303{
304 this->processInterest = nullptr; // no response to dataset or command
305
306 this->execute("route add /q1Qf7go7 udp://159.242.33.78");
307 BOOST_CHECK_EQUAL(exitCode, 1);
308 BOOST_CHECK(out.is_empty());
Eric Newberry359135c2018-06-26 21:02:12 -0700309 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout exceeded\n"));
Junxiao Shi918e5d42017-02-25 03:58:21 +0000310}
311
312BOOST_AUTO_TEST_CASE(ErrorCommand)
313{
314 this->processInterest = [this] (const Interest& interest) {
315 if (this->respondFaceQuery(interest)) {
316 return;
317 }
318
Junxiao Shi1a25a6e2017-03-06 03:09:47 +0000319 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/register");
Junxiao Shi918e5d42017-02-25 03:58:21 +0000320 // no response to command
321 };
322
323 this->execute("route add /bYiMbEuE 10156");
324 BOOST_CHECK_EQUAL(exitCode, 1);
325 BOOST_CHECK(out.is_empty());
326 BOOST_CHECK(err.is_equal("Error 10060 when adding route: request timed out\n"));
327}
328
329BOOST_AUTO_TEST_SUITE_END() // AddCommand
330
Junxiao Shi084b7952017-02-26 22:00:53 +0000331BOOST_FIXTURE_TEST_SUITE(RemoveCommand, ExecuteCommandFixture)
332
333BOOST_AUTO_TEST_CASE(NormalByFaceId)
334{
335 this->processInterest = [this] (const Interest& interest) {
336 if (this->respondFaceQuery(interest)) {
337 return;
338 }
339
340 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister");
341 ndn::nfd::RibUnregisterCommand cmd;
342 cmd.validateRequest(req);
343 cmd.applyDefaultsToRequest(req);
344 BOOST_CHECK_EQUAL(req.getName(), "/2B5NUGjpt");
345 BOOST_CHECK_EQUAL(req.getFaceId(), 10156);
346 BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC);
347
348 this->succeedCommand(interest, req);
349 };
350
351 this->execute("route remove /2B5NUGjpt 10156");
352 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi8eda6822017-04-12 02:53:14 +0000353 BOOST_CHECK(out.is_equal("route-removed prefix=/2B5NUGjpt nexthop=10156 origin=static\n"));
Junxiao Shi084b7952017-02-26 22:00:53 +0000354 BOOST_CHECK(err.is_empty());
355}
356
357BOOST_AUTO_TEST_CASE(NormalByFaceUri)
358{
359 this->processInterest = [this] (const Interest& interest) {
360 if (this->respondFaceQuery(interest)) {
361 return;
362 }
363
364 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister");
365 ndn::nfd::RibUnregisterCommand cmd;
366 cmd.validateRequest(req);
367 cmd.applyDefaultsToRequest(req);
368 BOOST_CHECK_EQUAL(req.getName(), "/wHdNn0BtUF");
369 BOOST_CHECK_EQUAL(req.getFaceId(), 2249);
370 BOOST_CHECK_EQUAL(req.getOrigin(), 15246);
371
372 this->succeedCommand(interest, req);
373 };
374
375 this->execute("route remove /wHdNn0BtUF tcp4://32.121.182.82:6363 origin 15246");
376 BOOST_CHECK_EQUAL(exitCode, 0);
377 BOOST_CHECK(out.is_equal("route-removed prefix=/wHdNn0BtUF nexthop=2249 origin=15246\n"));
378 BOOST_CHECK(err.is_empty());
379}
380
381BOOST_AUTO_TEST_CASE(MultipleFaces)
382{
383 std::set<uint64_t> faceIds{6720, 31066};
384 this->processInterest = [this, &faceIds] (const Interest& interest) {
385 if (this->respondFaceQuery(interest)) {
386 return;
387 }
388
389 ControlParameters req = MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister");
390 ndn::nfd::RibUnregisterCommand cmd;
391 cmd.validateRequest(req);
392 cmd.applyDefaultsToRequest(req);
393 BOOST_CHECK_EQUAL(req.getName(), "/nm5y8X8b2");
Alexander Afanasyev0c63c632017-12-05 11:17:09 -0500394 BOOST_CHECK_MESSAGE(faceIds.erase(req.getFaceId()), "expected face " + to_string(req.getFaceId()));
Junxiao Shi084b7952017-02-26 22:00:53 +0000395 BOOST_CHECK_EQUAL(req.getOrigin(), ndn::nfd::ROUTE_ORIGIN_STATIC);
396
397 this->succeedCommand(interest, req);
398 };
399
400 this->execute("route remove /nm5y8X8b2 udp4://225.131.75.231:56363");
401 BOOST_CHECK(faceIds.empty());
402 BOOST_CHECK_EQUAL(exitCode, 0);
Junxiao Shi8eda6822017-04-12 02:53:14 +0000403 BOOST_CHECK(out.is_equal("route-removed prefix=/nm5y8X8b2 nexthop=6720 origin=static\n"
404 "route-removed prefix=/nm5y8X8b2 nexthop=31066 origin=static\n"));
Junxiao Shi084b7952017-02-26 22:00:53 +0000405 BOOST_CHECK(err.is_empty());
406}
407
408BOOST_AUTO_TEST_CASE(FaceNotExist)
409{
410 this->processInterest = [this] (const Interest& interest) {
411 BOOST_CHECK(this->respondFaceQuery(interest));
412 };
413
414 this->execute("route remove /HeGRjzwFM 23728");
415 BOOST_CHECK_EQUAL(exitCode, 3);
416 BOOST_CHECK(out.is_empty());
417 BOOST_CHECK(err.is_equal("Face not found\n"));
418}
419
420BOOST_AUTO_TEST_CASE(ErrorDataset)
421{
422 this->processInterest = nullptr; // no response to dataset or command
423
424 this->execute("route remove /YX4xQQN3v5 udp://26.97.248.3");
425 BOOST_CHECK_EQUAL(exitCode, 1);
426 BOOST_CHECK(out.is_empty());
Eric Newberry359135c2018-06-26 21:02:12 -0700427 BOOST_CHECK(err.is_equal("Error 10060 when querying face: Timeout exceeded\n"));
Junxiao Shi084b7952017-02-26 22:00:53 +0000428}
429
430BOOST_AUTO_TEST_CASE(ErrorCommand)
431{
432 this->processInterest = [this] (const Interest& interest) {
433 if (this->respondFaceQuery(interest)) {
434 return;
435 }
436
437 MOCK_NFD_MGMT_REQUIRE_COMMAND_IS("/localhost/nfd/rib/unregister");
438 // no response to command
439 };
440
441 this->execute("route remove /mvGRoxD2 10156");
442 BOOST_CHECK_EQUAL(exitCode, 1);
443 BOOST_CHECK(out.is_empty());
444 BOOST_CHECK(err.is_equal("Error 10060 when removing route: request timed out\n"));
445}
446
447BOOST_AUTO_TEST_SUITE_END() // RemoveCommand
448
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000449const std::string STATUS_XML = stripXmlSpaces(R"XML(
450 <rib>
451 <ribEntry>
452 <prefix>/</prefix>
453 <routes>
454 <route>
455 <faceId>262</faceId>
Junxiao Shi8eda6822017-04-12 02:53:14 +0000456 <origin>static</origin>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000457 <cost>9</cost>
458 <flags>
459 <ribCapture/>
460 </flags>
461 </route>
462 <route>
463 <faceId>272</faceId>
Junxiao Shi8eda6822017-04-12 02:53:14 +0000464 <origin>static</origin>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000465 <cost>50</cost>
466 <flags/>
467 </route>
468 <route>
469 <faceId>274</faceId>
Junxiao Shi8eda6822017-04-12 02:53:14 +0000470 <origin>static</origin>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000471 <cost>78</cost>
472 <flags>
473 <childInherit/>
474 <ribCapture/>
475 </flags>
476 </route>
477 <route>
478 <faceId>276</faceId>
Junxiao Shi8eda6822017-04-12 02:53:14 +0000479 <origin>static</origin>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000480 <cost>79</cost>
481 <flags>
482 <childInherit/>
483 </flags>
484 <expirationPeriod>PT47S</expirationPeriod>
485 </route>
486 </routes>
487 </ribEntry>
488 <ribEntry>
489 <prefix>/localhost/nfd</prefix>
490 <routes>
491 <route>
492 <faceId>258</faceId>
Junxiao Shi8eda6822017-04-12 02:53:14 +0000493 <origin>app</origin>
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000494 <cost>0</cost>
495 <flags>
496 <childInherit/>
497 </flags>
498 </route>
499 </routes>
500 </ribEntry>
501 </rib>
502)XML");
503
504const std::string STATUS_TEXT =
505 "RIB:\n"
Junxiao Shi8eda6822017-04-12 02:53:14 +0000506 " / routes={nexthop=262 origin=static cost=9 flags=capture expires=never, "
507 "nexthop=272 origin=static cost=50 flags=none expires=never, "
508 "nexthop=274 origin=static cost=78 flags=child-inherit|capture expires=never, "
509 "nexthop=276 origin=static cost=79 flags=child-inherit expires=47s}\n"
510 " /localhost/nfd routes={nexthop=258 origin=app cost=0 flags=child-inherit expires=never}\n";
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000511
512BOOST_AUTO_TEST_CASE(Status)
513{
514 this->fetchStatus();
515 RibEntry payload1;
516 payload1.setName("/")
517 .addRoute(Route().setFaceId(262)
518 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
519 .setCost(9)
520 .setFlags(ndn::nfd::ROUTE_FLAG_CAPTURE))
521 .addRoute(Route().setFaceId(272)
522 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
523 .setCost(50)
524 .setFlags(ndn::nfd::ROUTE_FLAGS_NONE))
525 .addRoute(Route().setFaceId(274)
526 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
527 .setCost(78)
528 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE))
529 .addRoute(Route().setFaceId(276)
530 .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
531 .setCost(79)
532 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)
Davide Pesavento14e71f02019-03-28 17:35:25 -0400533 .setExpirationPeriod(47292_ms));
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000534 RibEntry payload2;
535 payload2.setName("/localhost/nfd")
536 .addRoute(Route().setFaceId(258)
537 .setOrigin(ndn::nfd::ROUTE_ORIGIN_APP)
538 .setCost(0)
539 .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT));
540 this->sendDataset("/localhost/nfd/rib/list", payload1, payload2);
541 this->prepareStatusOutput();
542
543 BOOST_CHECK(statusXml.is_equal(STATUS_XML));
544 BOOST_CHECK(statusText.is_equal(STATUS_TEXT));
545}
546
547BOOST_AUTO_TEST_SUITE_END() // TestRibModule
Junxiao Shi331ade72016-08-19 14:07:19 +0000548BOOST_AUTO_TEST_SUITE_END() // Nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000549
550} // namespace tests
Junxiao Shi331ade72016-08-19 14:07:19 +0000551} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000552} // namespace tools
553} // namespace nfd