tools: nfdc route list and nfd route show commands
refs #3866
Change-Id: Ic8feab0ce9e5707c1cf382cdea7264e28e3edb30
diff --git a/tests/tools/nfdc/rib-module.t.cpp b/tests/tools/nfdc/rib-module.t.cpp
index 2cdc21d..0c5bc31 100644
--- a/tests/tools/nfdc/rib-module.t.cpp
+++ b/tests/tools/nfdc/rib-module.t.cpp
@@ -36,6 +36,158 @@
BOOST_AUTO_TEST_SUITE(Nfdc)
BOOST_FIXTURE_TEST_SUITE(TestRibModule, StatusFixture<RibModule>)
+class RouteListFixture : public ExecuteCommandFixture
+{
+protected:
+ bool
+ respondRibDataset(const Interest& interest)
+ {
+ if (!Name("/localhost/nfd/rib/list").isPrefixOf(interest.getName())) {
+ return false;
+ }
+
+ RibEntry entry1;
+ entry1.setName("/5BBmTevRJ");
+ entry1.addRoute(Route()
+ .setFaceId(6720)
+ .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT)
+ .setCost(2956)
+ .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT | ndn::nfd::ROUTE_FLAG_CAPTURE)
+ .setExpirationPeriod(time::milliseconds(29950035)));
+ entry1.addRoute(Route()
+ .setFaceId(6720)
+ .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
+ .setCost(425)
+ .setFlags(ndn::nfd::ROUTE_FLAGS_NONE));
+ entry1.addRoute(Route()
+ .setFaceId(8599)
+ .setOrigin(ndn::nfd::ROUTE_ORIGIN_STATIC)
+ .setCost(9140)
+ .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT));
+
+ RibEntry entry2;
+ entry2.setName("/aDPTKCio");
+ entry2.addRoute(Route()
+ .setFaceId(31066)
+ .setOrigin(ndn::nfd::ROUTE_ORIGIN_CLIENT)
+ .setCost(4617)
+ .setFlags(ndn::nfd::ROUTE_FLAG_CAPTURE));
+
+ this->sendDataset(interest.getName(), entry1, entry2);
+ return true;
+ }
+};
+
+BOOST_FIXTURE_TEST_SUITE(ListShowCommand, RouteListFixture)
+
+const std::string NOFILTER_OUTPUT = std::string(R"TEXT(
+prefix=/5BBmTevRJ nexthop=6720 origin=65 cost=2956 flags=child-inherit|capture expires=29950s
+prefix=/5BBmTevRJ nexthop=6720 origin=255 cost=425 flags=none expires=never
+prefix=/5BBmTevRJ nexthop=8599 origin=255 cost=9140 flags=child-inherit expires=never
+prefix=/aDPTKCio nexthop=31066 origin=65 cost=4617 flags=capture expires=never
+)TEXT").substr(1);
+
+BOOST_AUTO_TEST_CASE(ListNoFilter)
+{
+ this->processInterest = [this] (const Interest& interest) {
+ BOOST_CHECK(this->respondRibDataset(interest));
+ };
+
+ this->execute("route");
+ BOOST_CHECK_EQUAL(exitCode, 0);
+ BOOST_CHECK(out.is_equal(NOFILTER_OUTPUT));
+ BOOST_CHECK(err.is_empty());
+}
+
+const std::string NEXTHOP_OUTPUT = std::string(R"TEXT(
+prefix=/5BBmTevRJ nexthop=6720 origin=65 cost=2956 flags=child-inherit|capture expires=29950s
+prefix=/5BBmTevRJ nexthop=6720 origin=255 cost=425 flags=none expires=never
+prefix=/aDPTKCio nexthop=31066 origin=65 cost=4617 flags=capture expires=never
+)TEXT").substr(1);
+
+BOOST_AUTO_TEST_CASE(ListByNexthop)
+{
+ this->processInterest = [this] (const Interest& interest) {
+ BOOST_CHECK(this->respondFaceQuery(interest) || this->respondRibDataset(interest));
+ };
+
+ this->execute("route list udp4://225.131.75.231:56363");
+ BOOST_CHECK_EQUAL(exitCode, 0);
+ BOOST_CHECK(out.is_equal(NEXTHOP_OUTPUT));
+ BOOST_CHECK(err.is_empty());
+}
+
+const std::string ORIGIN_OUTPUT = std::string(R"TEXT(
+prefix=/5BBmTevRJ nexthop=6720 origin=255 cost=425 flags=none expires=never
+prefix=/5BBmTevRJ nexthop=8599 origin=255 cost=9140 flags=child-inherit expires=never
+)TEXT").substr(1);
+
+BOOST_AUTO_TEST_CASE(ListByOrigin)
+{
+ this->processInterest = [this] (const Interest& interest) {
+ BOOST_CHECK(this->respondRibDataset(interest));
+ };
+
+ this->execute("route list origin 255");
+ BOOST_CHECK_EQUAL(exitCode, 0);
+ BOOST_CHECK(out.is_equal(ORIGIN_OUTPUT));
+ BOOST_CHECK(err.is_empty());
+}
+
+const std::string PREFIX_OUTPUT = std::string(R"TEXT(
+prefix=/5BBmTevRJ nexthop=6720 origin=65 cost=2956 flags=child-inherit|capture expires=29950s
+prefix=/5BBmTevRJ nexthop=6720 origin=255 cost=425 flags=none expires=never
+prefix=/5BBmTevRJ nexthop=8599 origin=255 cost=9140 flags=child-inherit expires=never
+)TEXT").substr(1);
+
+BOOST_AUTO_TEST_CASE(ShowByPrefix)
+{
+ this->processInterest = [this] (const Interest& interest) {
+ BOOST_CHECK(this->respondRibDataset(interest));
+ };
+
+ this->execute("route show 5BBmTevRJ");
+ BOOST_CHECK_EQUAL(exitCode, 0);
+ BOOST_CHECK(out.is_equal(PREFIX_OUTPUT));
+ BOOST_CHECK(err.is_empty());
+}
+
+BOOST_AUTO_TEST_CASE(FaceNotExist)
+{
+ this->processInterest = [this] (const Interest& interest) {
+ BOOST_CHECK(this->respondFaceQuery(interest));
+ };
+
+ this->execute("route list 23728");
+ BOOST_CHECK_EQUAL(exitCode, 3);
+ BOOST_CHECK(out.is_empty());
+ BOOST_CHECK(err.is_equal("Face not found\n"));
+}
+
+BOOST_AUTO_TEST_CASE(RouteNotExist)
+{
+ this->processInterest = [this] (const Interest& interest) {
+ BOOST_CHECK(this->respondFaceQuery(interest) || this->respondRibDataset(interest));
+ };
+
+ this->execute("route list 10156");
+ BOOST_CHECK_EQUAL(exitCode, 6);
+ BOOST_CHECK(out.is_empty());
+ BOOST_CHECK(err.is_equal("Route not found\n"));
+}
+
+BOOST_AUTO_TEST_CASE(ErrorDataset)
+{
+ this->processInterest = nullptr; // no response to dataset
+
+ this->execute("route list");
+ BOOST_CHECK_EQUAL(exitCode, 1);
+ BOOST_CHECK(out.is_empty());
+ BOOST_CHECK(err.is_equal("Error 10060 when fetching RIB dataset: Timeout\n"));
+}
+
+BOOST_AUTO_TEST_SUITE_END() // ListShowCommand
+
BOOST_FIXTURE_TEST_SUITE(AddCommand, ExecuteCommandFixture)
BOOST_AUTO_TEST_CASE(NormalByFaceId)
@@ -339,10 +491,11 @@
const std::string STATUS_TEXT =
"RIB:\n"
- " / route={faceid=262 (origin=255 cost=9 RibCapture), faceid=272 (origin=255 cost=50), "
- "faceid=274 (origin=255 cost=78 ChildInherit RibCapture), "
- "faceid=276 (origin=255 cost=79 expires=47s ChildInherit)}\n"
- " /localhost/nfd route={faceid=258 (origin=0 cost=0 ChildInherit)}\n";
+ " / routes={nexthop=262 origin=255 cost=9 flags=capture expires=never, "
+ "nexthop=272 origin=255 cost=50 flags=none expires=never, "
+ "nexthop=274 origin=255 cost=78 flags=child-inherit|capture expires=never, "
+ "nexthop=276 origin=255 cost=79 flags=child-inherit expires=47s}\n"
+ " /localhost/nfd routes={nexthop=258 origin=0 cost=0 flags=child-inherit expires=never}\n";
BOOST_AUTO_TEST_CASE(Status)
{