mgmt: use RouteOrigin type in Route and ControlParameters
Change-Id: I1fb7e29efbb7ae9523ca294df03478498ef04322
Refs: #3903
diff --git a/src/mgmt/nfd/control-parameters.cpp b/src/mgmt/nfd/control-parameters.cpp
index a414567..a489c3f 100644
--- a/src/mgmt/nfd/control-parameters.cpp
+++ b/src/mgmt/nfd/control-parameters.cpp
@@ -169,7 +169,7 @@
val = m_wire.find(tlv::nfd::Origin);
m_hasFields[CONTROL_PARAMETER_ORIGIN] = val != m_wire.elements_end();
if (this->hasOrigin()) {
- m_origin = static_cast<uint64_t>(readNonNegativeInteger(*val));
+ m_origin = static_cast<RouteOrigin>(readNonNegativeInteger(*val));
}
val = m_wire.find(tlv::nfd::Cost);
diff --git a/src/mgmt/nfd/control-parameters.hpp b/src/mgmt/nfd/control-parameters.hpp
index cd432ca..df19488 100644
--- a/src/mgmt/nfd/control-parameters.hpp
+++ b/src/mgmt/nfd/control-parameters.hpp
@@ -276,7 +276,7 @@
return m_hasFields[CONTROL_PARAMETER_ORIGIN];
}
- uint64_t
+ RouteOrigin
getOrigin() const
{
BOOST_ASSERT(this->hasOrigin());
@@ -284,7 +284,7 @@
}
ControlParameters&
- setOrigin(uint64_t origin)
+ setOrigin(RouteOrigin origin)
{
m_wire.reset();
m_origin = origin;
@@ -526,7 +526,7 @@
std::string m_uri;
std::string m_localUri;
LocalControlFeature m_localControlFeature;
- uint64_t m_origin;
+ RouteOrigin m_origin;
uint64_t m_cost;
uint64_t m_flags;
uint64_t m_mask;
diff --git a/src/mgmt/nfd/rib-entry.cpp b/src/mgmt/nfd/rib-entry.cpp
index 315b4bd..619fd5e 100644
--- a/src/mgmt/nfd/rib-entry.cpp
+++ b/src/mgmt/nfd/rib-entry.cpp
@@ -36,7 +36,7 @@
Route::Route()
: m_faceId(INVALID_FACE_ID)
- , m_origin(0)
+ , m_origin(ROUTE_ORIGIN_APP)
, m_cost(0)
, m_flags(ROUTE_FLAG_CHILD_INHERIT)
{
@@ -56,7 +56,7 @@
}
Route&
-Route::setOrigin(uint64_t origin)
+Route::setOrigin(RouteOrigin origin)
{
m_origin = origin;
m_wire.reset();
@@ -159,7 +159,7 @@
}
if (val != m_wire.elements_end() && val->type() == tlv::nfd::Origin) {
- m_origin = readNonNegativeInteger(*val);
+ m_origin = static_cast<RouteOrigin>(readNonNegativeInteger(*val));
++val;
}
else {
diff --git a/src/mgmt/nfd/rib-entry.hpp b/src/mgmt/nfd/rib-entry.hpp
index 8b82238..e515e64 100644
--- a/src/mgmt/nfd/rib-entry.hpp
+++ b/src/mgmt/nfd/rib-entry.hpp
@@ -66,17 +66,14 @@
Route&
setFaceId(uint64_t faceId);
- uint64_t
+ RouteOrigin
getOrigin() const
{
return m_origin;
}
- /** @brief set Origin
- * @param origin a code defined in ndn::nfd::RouteOrigin
- */
Route&
- setOrigin(uint64_t origin);
+ setOrigin(RouteOrigin origin);
uint64_t
getCost() const
@@ -93,9 +90,6 @@
return m_flags;
}
- /** @brief set route inheritance flags
- * @param flags a bitwise OR'ed code from ndn::nfd::RouteFlags
- */
Route&
setFlags(uint64_t flags);
@@ -129,7 +123,7 @@
private:
uint64_t m_faceId;
- uint64_t m_origin;
+ RouteOrigin m_origin;
uint64_t m_cost;
uint64_t m_flags;
optional<time::milliseconds> m_expirationPeriod;
diff --git a/src/util/dummy-client-face.cpp b/src/util/dummy-client-face.cpp
index f84d997..af1f702 100644
--- a/src/util/dummy-client-face.cpp
+++ b/src/util/dummy-client-face.cpp
@@ -199,7 +199,7 @@
nfd::ControlParameters params(interest.getName().get(-5).blockFromValue());
params.setFaceId(1);
- params.setOrigin(0);
+ params.setOrigin(nfd::ROUTE_ORIGIN_APP);
if (interest.getName().get(3) == name::Component("register")) {
params.setCost(0);
}
diff --git a/tests/unit-tests/mgmt/nfd/control-command.t.cpp b/tests/unit-tests/mgmt/nfd/control-command.t.cpp
index f812088..6e60ad2 100644
--- a/tests/unit-tests/mgmt/nfd/control-command.t.cpp
+++ b/tests/unit-tests/mgmt/nfd/control-command.t.cpp
@@ -333,7 +333,7 @@
command.applyDefaultsToRequest(p1);
BOOST_REQUIRE(p1.hasOrigin());
- BOOST_CHECK_EQUAL(p1.getOrigin(), static_cast<uint64_t>(ROUTE_ORIGIN_APP));
+ BOOST_CHECK_EQUAL(p1.getOrigin(), ROUTE_ORIGIN_APP);
BOOST_REQUIRE(p1.hasCost());
BOOST_CHECK_EQUAL(p1.getCost(), 0);
BOOST_REQUIRE(p1.hasFlags());
diff --git a/tests/unit-tests/mgmt/nfd/control-parameters.t.cpp b/tests/unit-tests/mgmt/nfd/control-parameters.t.cpp
index 96d8519..30db9ed 100644
--- a/tests/unit-tests/mgmt/nfd/control-parameters.t.cpp
+++ b/tests/unit-tests/mgmt/nfd/control-parameters.t.cpp
@@ -133,17 +133,17 @@
ControlParameters parameters;
parameters.setName("ndn:/example")
.setFaceId(4)
- .setOrigin(128)
+ .setOrigin(ROUTE_ORIGIN_NLSR)
.setCost(6)
.setFlags(0x01)
- .setExpirationPeriod(time::milliseconds(1800000));
+ .setExpirationPeriod(time::minutes(30));
Block wire = parameters.wireEncode();
ControlParameters decoded(wire);
BOOST_CHECK_EQUAL(decoded.getName(), Name("ndn:/example"));
BOOST_CHECK_EQUAL(decoded.getFaceId(), 4);
- BOOST_CHECK_EQUAL(decoded.getOrigin(), 128);
+ BOOST_CHECK_EQUAL(decoded.getOrigin(), ROUTE_ORIGIN_NLSR);
BOOST_CHECK_EQUAL(decoded.getCost(), 6);
BOOST_CHECK_EQUAL(decoded.getFlags(), 0x01);
BOOST_CHECK_EQUAL(decoded.getExpirationPeriod(), time::milliseconds(1800000));
diff --git a/tests/unit-tests/mgmt/nfd/rib-entry.t.cpp b/tests/unit-tests/mgmt/nfd/rib-entry.t.cpp
index 28e4fd7..15c14d1 100644
--- a/tests/unit-tests/mgmt/nfd/rib-entry.t.cpp
+++ b/tests/unit-tests/mgmt/nfd/rib-entry.t.cpp
@@ -37,9 +37,9 @@
{
return Route()
.setFaceId(1)
- .setOrigin(128)
+ .setOrigin(ROUTE_ORIGIN_NLSR)
.setCost(100)
- .setFlags(ndn::nfd::ROUTE_FLAG_CAPTURE);
+ .setFlags(ROUTE_FLAG_CAPTURE);
}
static RibEntry
@@ -125,9 +125,9 @@
RibEntry entry1 = makeRibEntry();
entry1.addRoute(Route()
.setFaceId(2)
- .setOrigin(0)
+ .setOrigin(ROUTE_ORIGIN_APP)
.setCost(32)
- .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT)
+ .setFlags(ROUTE_FLAG_CHILD_INHERIT)
.setExpirationPeriod(time::seconds(5)));
const Block& wire = entry1.wireEncode();
@@ -208,7 +208,7 @@
{
Route route;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(route),
- "Route(FaceId: 0, Origin: 0, Cost: 0, Flags: 0x1, ExpirationPeriod: infinite)");
+ "Route(FaceId: 0, Origin: app, Cost: 0, Flags: 0x1, ExpirationPeriod: infinite)");
RibEntry entry;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(entry),
@@ -219,14 +219,14 @@
entry = makeRibEntry();
entry.addRoute(Route()
.setFaceId(2)
- .setOrigin(0)
+ .setOrigin(ROUTE_ORIGIN_STATIC)
.setCost(32)
- .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT));
+ .setFlags(ROUTE_FLAG_CHILD_INHERIT));
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(entry),
"RibEntry(Prefix: /hello/world,\n"
- " Routes: [Route(FaceId: 1, Origin: 128, Cost: 100, Flags: 0x2, "
+ " Routes: [Route(FaceId: 1, Origin: nlsr, Cost: 100, Flags: 0x2, "
"ExpirationPeriod: 10000 milliseconds),\n"
- " Route(FaceId: 2, Origin: 0, Cost: 32, Flags: 0x1, "
+ " Route(FaceId: 2, Origin: static, Cost: 32, Flags: 0x1, "
"ExpirationPeriod: infinite)]\n"
" )");
}