tools: nfdc route commands accept and print RouteOrigin strings
refs #3987
Change-Id: I47594546e3fe9279fff5ea6ade9ce38cb3b05b6c
diff --git a/tests/tools/nfdc/command-definition.t.cpp b/tests/tools/nfdc/command-definition.t.cpp
index 3eab402..34b5969 100644
--- a/tests/tools/nfdc/command-definition.t.cpp
+++ b/tests/tools/nfdc/command-definition.t.cpp
@@ -309,6 +309,28 @@
BOOST_CHECK_THROW(cs.parse(std::vector<std::string>{"a", "on-demand"}), CommandDefinition::Error);
}
+BOOST_AUTO_TEST_CASE(RouteOriginType)
+{
+ CommandDefinition cs("noun", "verb");
+ cs.addArg("a", ArgValueType::ROUTE_ORIGIN, Required::YES);
+
+ CommandArguments ca;
+
+ ca = cs.parse(std::vector<std::string>{"a", "Nlsr"});
+ BOOST_CHECK_EQUAL(ca.size(), 1);
+ BOOST_CHECK(ca.at("a").type() == typeid(RouteOrigin));
+ BOOST_CHECK_EQUAL(ca.get<RouteOrigin>("a"),
+ RouteOrigin::ROUTE_ORIGIN_NLSR);
+
+ ca = cs.parse(std::vector<std::string>{"a", "27"});
+ BOOST_CHECK_EQUAL(ca.size(), 1);
+ BOOST_CHECK(ca.at("a").type() == typeid(RouteOrigin));
+ BOOST_CHECK_EQUAL(ca.get<RouteOrigin>("a"),
+ static_cast<RouteOrigin>(27));
+
+ BOOST_CHECK_THROW(cs.parse(std::vector<std::string>{"a", "not-RouteOrigin"}), CommandDefinition::Error);
+}
+
BOOST_AUTO_TEST_SUITE_END() // ParseValue
BOOST_AUTO_TEST_SUITE_END() // TestCommandDefinition
diff --git a/tests/tools/nfdc/rib-module.t.cpp b/tests/tools/nfdc/rib-module.t.cpp
index 0c5bc31..7081eed 100644
--- a/tests/tools/nfdc/rib-module.t.cpp
+++ b/tests/tools/nfdc/rib-module.t.cpp
@@ -81,10 +81,10 @@
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
+prefix=/5BBmTevRJ nexthop=6720 origin=client cost=2956 flags=child-inherit|capture expires=29950s
+prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never
+prefix=/5BBmTevRJ nexthop=8599 origin=static cost=9140 flags=child-inherit expires=never
+prefix=/aDPTKCio nexthop=31066 origin=client cost=4617 flags=capture expires=never
)TEXT").substr(1);
BOOST_AUTO_TEST_CASE(ListNoFilter)
@@ -100,9 +100,9 @@
}
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
+prefix=/5BBmTevRJ nexthop=6720 origin=client cost=2956 flags=child-inherit|capture expires=29950s
+prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never
+prefix=/aDPTKCio nexthop=31066 origin=client cost=4617 flags=capture expires=never
)TEXT").substr(1);
BOOST_AUTO_TEST_CASE(ListByNexthop)
@@ -118,11 +118,11 @@
}
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
+prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never
+prefix=/5BBmTevRJ nexthop=8599 origin=static cost=9140 flags=child-inherit expires=never
)TEXT").substr(1);
-BOOST_AUTO_TEST_CASE(ListByOrigin)
+BOOST_AUTO_TEST_CASE(ListByOriginNumeric)
{
this->processInterest = [this] (const Interest& interest) {
BOOST_CHECK(this->respondRibDataset(interest));
@@ -134,10 +134,22 @@
BOOST_CHECK(err.is_empty());
}
+BOOST_AUTO_TEST_CASE(ListByOriginString)
+{
+ this->processInterest = [this] (const Interest& interest) {
+ BOOST_CHECK(this->respondRibDataset(interest));
+ };
+
+ this->execute("route list origin static");
+ 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
+prefix=/5BBmTevRJ nexthop=6720 origin=client cost=2956 flags=child-inherit|capture expires=29950s
+prefix=/5BBmTevRJ nexthop=6720 origin=static cost=425 flags=none expires=never
+prefix=/5BBmTevRJ nexthop=8599 origin=static cost=9140 flags=child-inherit expires=never
)TEXT").substr(1);
BOOST_AUTO_TEST_CASE(ShowByPrefix)
@@ -213,7 +225,7 @@
this->execute("route add /vxXoEaWeDB 10156 no-inherit");
BOOST_CHECK_EQUAL(exitCode, 0);
- BOOST_CHECK(out.is_equal("route-add-accepted prefix=/vxXoEaWeDB nexthop=10156 origin=255 "
+ BOOST_CHECK(out.is_equal("route-add-accepted prefix=/vxXoEaWeDB nexthop=10156 origin=static "
"cost=0 flags=none expires=never\n"));
BOOST_CHECK(err.is_empty());
}
@@ -338,7 +350,7 @@
this->execute("route remove /2B5NUGjpt 10156");
BOOST_CHECK_EQUAL(exitCode, 0);
- BOOST_CHECK(out.is_equal("route-removed prefix=/2B5NUGjpt nexthop=10156 origin=255\n"));
+ BOOST_CHECK(out.is_equal("route-removed prefix=/2B5NUGjpt nexthop=10156 origin=static\n"));
BOOST_CHECK(err.is_empty());
}
@@ -388,8 +400,8 @@
this->execute("route remove /nm5y8X8b2 udp4://225.131.75.231:56363");
BOOST_CHECK(faceIds.empty());
BOOST_CHECK_EQUAL(exitCode, 0);
- BOOST_CHECK(out.is_equal("route-removed prefix=/nm5y8X8b2 nexthop=6720 origin=255\n"
- "route-removed prefix=/nm5y8X8b2 nexthop=31066 origin=255\n"));
+ BOOST_CHECK(out.is_equal("route-removed prefix=/nm5y8X8b2 nexthop=6720 origin=static\n"
+ "route-removed prefix=/nm5y8X8b2 nexthop=31066 origin=static\n"));
BOOST_CHECK(err.is_empty());
}
@@ -441,7 +453,7 @@
<routes>
<route>
<faceId>262</faceId>
- <origin>255</origin>
+ <origin>static</origin>
<cost>9</cost>
<flags>
<ribCapture/>
@@ -449,13 +461,13 @@
</route>
<route>
<faceId>272</faceId>
- <origin>255</origin>
+ <origin>static</origin>
<cost>50</cost>
<flags/>
</route>
<route>
<faceId>274</faceId>
- <origin>255</origin>
+ <origin>static</origin>
<cost>78</cost>
<flags>
<childInherit/>
@@ -464,7 +476,7 @@
</route>
<route>
<faceId>276</faceId>
- <origin>255</origin>
+ <origin>static</origin>
<cost>79</cost>
<flags>
<childInherit/>
@@ -478,7 +490,7 @@
<routes>
<route>
<faceId>258</faceId>
- <origin>0</origin>
+ <origin>app</origin>
<cost>0</cost>
<flags>
<childInherit/>
@@ -491,11 +503,11 @@
const std::string STATUS_TEXT =
"RIB:\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";
+ " / routes={nexthop=262 origin=static cost=9 flags=capture expires=never, "
+ "nexthop=272 origin=static cost=50 flags=none expires=never, "
+ "nexthop=274 origin=static cost=78 flags=child-inherit|capture expires=never, "
+ "nexthop=276 origin=static cost=79 flags=child-inherit expires=47s}\n"
+ " /localhost/nfd routes={nexthop=258 origin=app cost=0 flags=child-inherit expires=never}\n";
BOOST_AUTO_TEST_CASE(Status)
{
diff --git a/tools/nfdc/command-arguments.hpp b/tools/nfdc/command-arguments.hpp
index 1bec816..010c1c2 100644
--- a/tools/nfdc/command-arguments.hpp
+++ b/tools/nfdc/command-arguments.hpp
@@ -37,6 +37,7 @@
namespace nfdc {
using ndn::nfd::FacePersistency;
+using ndn::nfd::RouteOrigin;
using ndn::util::FaceUri;
/** \brief contains named command arguments
diff --git a/tools/nfdc/command-definition.cpp b/tools/nfdc/command-definition.cpp
index 18eee1e..a2ceb33 100644
--- a/tools/nfdc/command-definition.cpp
+++ b/tools/nfdc/command-definition.cpp
@@ -54,6 +54,8 @@
return os << "FaceId or FaceUri";
case ArgValueType::FACE_PERSISTENCY:
return os << "FacePersistency";
+ case ArgValueType::ROUTE_ORIGIN:
+ return os << "RouteOrigin";
}
return os << static_cast<int>(vt);
}
@@ -80,6 +82,8 @@
return "face";
case ArgValueType::FACE_PERSISTENCY:
return "persistency";
+ case ArgValueType::ROUTE_ORIGIN:
+ return "origin";
}
BOOST_ASSERT(false);
return "";
@@ -260,6 +264,9 @@
case ArgValueType::FACE_PERSISTENCY:
return parseFacePersistency(token);
+
+ case ArgValueType::ROUTE_ORIGIN:
+ return boost::lexical_cast<RouteOrigin>(token);
}
BOOST_ASSERT(false);
diff --git a/tools/nfdc/command-definition.hpp b/tools/nfdc/command-definition.hpp
index 47c6af3..813e744 100644
--- a/tools/nfdc/command-definition.hpp
+++ b/tools/nfdc/command-definition.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2016, Regents of the University of California,
+ * Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -90,7 +90,13 @@
*
* The argument appears in CommandArguments as ndn::nfd::FacePersistency.
*/
- FACE_PERSISTENCY
+ FACE_PERSISTENCY,
+
+ /** \brief route origin
+ *
+ * The argument appears in CommandArguments as ndn::nfd::RouteOrigin.
+ */
+ ROUTE_ORIGIN,
};
std::ostream&
diff --git a/tools/nfdc/rib-module.cpp b/tools/nfdc/rib-module.cpp
index d7f04cd..ffcb18c 100644
--- a/tools/nfdc/rib-module.cpp
+++ b/tools/nfdc/rib-module.cpp
@@ -38,7 +38,7 @@
defRouteList
.setTitle("print RIB routes")
.addArg("nexthop", ArgValueType::FACE_ID_OR_URI, Required::NO, Positional::YES)
- .addArg("origin", ArgValueType::UNSIGNED, Required::NO, Positional::NO);
+ .addArg("origin", ArgValueType::ROUTE_ORIGIN, Required::NO, Positional::NO);
parser.addCommand(defRouteList, &RibModule::list);
CommandDefinition defRouteShow("route", "show");
@@ -52,7 +52,7 @@
.setTitle("add a route")
.addArg("prefix", ArgValueType::NAME, Required::YES, Positional::YES)
.addArg("nexthop", ArgValueType::FACE_ID_OR_URI, Required::YES, Positional::YES)
- .addArg("origin", ArgValueType::UNSIGNED, Required::NO, Positional::NO)
+ .addArg("origin", ArgValueType::ROUTE_ORIGIN, Required::NO, Positional::NO)
.addArg("cost", ArgValueType::UNSIGNED, Required::NO, Positional::NO)
.addArg("no-inherit", ArgValueType::NONE, Required::NO, Positional::NO)
.addArg("capture", ArgValueType::NONE, Required::NO, Positional::NO)
@@ -64,7 +64,7 @@
.setTitle("remove a route")
.addArg("prefix", ArgValueType::NAME, Required::YES, Positional::YES)
.addArg("nexthop", ArgValueType::FACE_ID_OR_URI, Required::YES, Positional::YES)
- .addArg("origin", ArgValueType::UNSIGNED, Required::NO, Positional::NO);
+ .addArg("origin", ArgValueType::ROUTE_ORIGIN, Required::NO, Positional::NO);
parser.addCommand(defRouteRemove, &RibModule::remove);
}
@@ -73,7 +73,7 @@
{
auto nexthopIt = ctx.args.find("nexthop");
std::set<uint64_t> nexthops;
- auto origin = ctx.args.getOptional<uint64_t>("origin");
+ auto origin = ctx.args.getOptional<RouteOrigin>("origin");
if (nexthopIt != ctx.args.end()) {
FindFace findFace(ctx);
@@ -144,7 +144,7 @@
{
auto prefix = ctx.args.get<Name>("prefix");
const boost::any& nexthop = ctx.args.at("nexthop");
- auto origin = ctx.args.get<uint64_t>("origin", ndn::nfd::ROUTE_ORIGIN_STATIC);
+ auto origin = ctx.args.get<RouteOrigin>("origin", ndn::nfd::ROUTE_ORIGIN_STATIC);
auto cost = ctx.args.get<uint64_t>("cost", 0);
bool wantChildInherit = !ctx.args.get<bool>("no-inherit", false);
bool wantCapture = ctx.args.get<bool>("capture", false);
@@ -191,7 +191,7 @@
text::ItemAttributes ia;
ctx.out << ia("prefix") << resp.getName()
<< ia("nexthop") << resp.getFaceId()
- << ia("origin") << resp.getOrigin()
+ << ia("origin") << static_cast<RouteOrigin>(resp.getOrigin())
<< ia("cost") << resp.getCost()
<< ia("flags") << static_cast<ndn::nfd::RouteFlags>(resp.getFlags());
if (resp.hasExpirationPeriod()) {
@@ -212,7 +212,7 @@
{
auto prefix = ctx.args.get<Name>("prefix");
const boost::any& nexthop = ctx.args.at("nexthop");
- auto origin = ctx.args.get<uint64_t>("origin", ndn::nfd::ROUTE_ORIGIN_STATIC);
+ auto origin = ctx.args.get<RouteOrigin>("origin", ndn::nfd::ROUTE_ORIGIN_STATIC);
FindFace findFace(ctx);
FindFace::Code res = findFace.execute(nexthop, true);
@@ -245,7 +245,7 @@
text::ItemAttributes ia;
ctx.out << ia("prefix") << resp.getName()
<< ia("nexthop") << resp.getFaceId()
- << ia("origin") << resp.getOrigin()
+ << ia("origin") << static_cast<RouteOrigin>(resp.getOrigin())
<< '\n';
},
ctx.makeCommandFailureHandler("removing route"),
@@ -290,7 +290,7 @@
for (const Route& route : item.getRoutes()) {
os << "<route>"
<< "<faceId>" << route.getFaceId() << "</faceId>"
- << "<origin>" << route.getOrigin() << "</origin>"
+ << "<origin>" << static_cast<RouteOrigin>(route.getOrigin()) << "</origin>"
<< "<cost>" << route.getCost() << "</cost>";
if (route.getFlags() == ndn::nfd::ROUTE_FLAGS_NONE) {
os << "<flags/>";
@@ -352,7 +352,7 @@
os << ia("prefix") << entry.getName();
}
os << ia("nexthop") << route.getFaceId();
- os << ia("origin") << static_cast<uint64_t>(route.getOrigin());
+ os << ia("origin") << static_cast<RouteOrigin>(route.getOrigin());
os << ia("cost") << route.getCost();
os << ia("flags") << static_cast<ndn::nfd::RouteFlags>(route.getFlags());