rib: Insert RIB command prefixes into RIB
refs: #2312
Change-Id: I9452f60d4c2162ad265603d3d5d44f083452ec58
diff --git a/rib/rib-manager.cpp b/rib/rib-manager.cpp
index 44214a3..ae64820 100644
--- a/rib/rib-manager.cpp
+++ b/rib/rib-manager.cpp
@@ -106,7 +106,7 @@
ControlParameters()
.setName(commandPrefix)
.setFaceId(0),
- bind(&RibManager::onNrdCommandPrefixAddNextHopSuccess, this, cref(commandPrefix)),
+ bind(&RibManager::onNrdCommandPrefixAddNextHopSuccess, this, cref(commandPrefix), _1),
bind(&RibManager::onNrdCommandPrefixAddNextHopError, this, cref(commandPrefix), _2));
m_face.setInterestFilter(commandPrefix, onRequest);
@@ -529,9 +529,22 @@
}
void
-RibManager::onNrdCommandPrefixAddNextHopSuccess(const Name& prefix)
+RibManager::onNrdCommandPrefixAddNextHopSuccess(const Name& prefix,
+ const ndn::nfd::ControlParameters& result)
{
NFD_LOG_DEBUG("Successfully registered " + prefix.toUri() + " with NFD");
+
+ // Routes must be inserted into the RIB so route flags can be applied
+ Route route;
+ route.faceId = result.getFaceId();
+ route.origin = ndn::nfd::ROUTE_ORIGIN_APP;
+ route.expires = time::steady_clock::TimePoint::max();
+ route.flags = ndn::nfd::ROUTE_FLAG_CHILD_INHERIT;
+
+ m_managedRib.insert(prefix, route);
+
+ m_registeredFaces.insert(route.faceId);
+ m_managedRib.clearFibUpdates();
}
void
diff --git a/rib/rib-manager.hpp b/rib/rib-manager.hpp
index efaf760..3819d5a 100644
--- a/rib/rib-manager.hpp
+++ b/rib/rib-manager.hpp
@@ -142,9 +142,12 @@
const ControlParameters& parameters,
const Route& route);
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
void
- onNrdCommandPrefixAddNextHopSuccess(const Name& prefix);
+ onNrdCommandPrefixAddNextHopSuccess(const Name& prefix,
+ const ndn::nfd::ControlParameters& result);
+private:
void
onNrdCommandPrefixAddNextHopError(const Name& name, const std::string& msg);
@@ -272,8 +275,11 @@
const SignedVerbDispatchTable m_signedVerbDispatch;
static const Name COMMAND_PREFIX; // /localhost/nrd
+
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd
+private:
// number of components in an invalid, but not malformed, unsigned command.
// (/localhost/nrd + verb + options) = 4
static const size_t COMMAND_UNSIGNED_NCOMPS;
diff --git a/tests/rib/rib-manager.cpp b/tests/rib/rib-manager.cpp
index cca1659..2f5c61c 100644
--- a/tests/rib/rib-manager.cpp
+++ b/tests/rib/rib-manager.cpp
@@ -353,6 +353,41 @@
BOOST_CHECK_EQUAL(entry->hasFaceId(2), false);
}
+BOOST_FIXTURE_TEST_CASE(LocalHopInherit, AuthorizedRibManager)
+{
+ using nfd::rib::RibManager;
+
+ // Simulate NFD response
+ ControlParameters result;
+ result.setFaceId(261);
+
+ manager->onNrdCommandPrefixAddNextHopSuccess(RibManager::REMOTE_COMMAND_PREFIX, result);
+
+ // Register route that localhop prefix should inherit
+ ControlParameters parameters;
+ parameters
+ .setName("/localhop/nfd")
+ .setFaceId(262)
+ .setCost(25)
+ .setFlags(ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
+
+ Name commandName("/localhost/nfd/rib/register");
+
+ receiveCommandInterest(commandName, parameters);
+
+ // REMOTE_COMMAND_PREFIX should have its original route and the inherited route
+ auto it = manager->m_managedRib.find(RibManager::REMOTE_COMMAND_PREFIX);
+
+ BOOST_REQUIRE(it != manager->m_managedRib.end());
+ const RibEntry::RouteList& inheritedRoutes = (*(it->second)).getInheritedRoutes();
+
+ BOOST_CHECK_EQUAL(inheritedRoutes.size(), 1);
+ auto routeIt = inheritedRoutes.begin();
+
+ BOOST_CHECK_EQUAL(routeIt->faceId, 262);
+ BOOST_CHECK_EQUAL(routeIt->cost, 25);
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests