rib: do the longest-prefix match in self-learning route renew helper
Change-Id: I7f6f349fda6925dc3847716fed123d745f11b02a
refs: #4683
diff --git a/rib/rib-manager.cpp b/rib/rib-manager.cpp
index 8762e39..35bc87f 100644
--- a/rib/rib-manager.cpp
+++ b/rib/rib-manager.cpp
@@ -362,7 +362,7 @@
BOOST_ASSERT(pa.getData());
if (!m_isLocalhopEnabled) {
- NFD_LOG_INFO("slAnnounce " << pa.getAnnouncedName() << ' ' << faceId <<
+ NFD_LOG_INFO("slAnnounce " << pa.getAnnouncedName() << " " << faceId <<
": localhop_security unconfigured");
cb(SlAnnounceResult::VALIDATION_FAILURE);
return;
@@ -375,12 +375,12 @@
beginAddRoute(pa.getAnnouncedName(), route, nullopt,
[=] (RibUpdateResult ribRes) {
auto res = getSlAnnounceResultFromRibUpdateResult(ribRes);
- NFD_LOG_INFO("slAnnounce " << pa.getAnnouncedName() << ' ' << faceId << ": " << res);
+ NFD_LOG_INFO("slAnnounce " << pa.getAnnouncedName() << " " << faceId << ": " << res);
cb(res);
});
},
[=] (const Data&, ndn::security::v2::ValidationError err) {
- NFD_LOG_INFO("slAnnounce " << pa.getAnnouncedName() << ' ' << faceId <<
+ NFD_LOG_INFO("slAnnounce " << pa.getAnnouncedName() << " " << faceId <<
" validation error: " << err);
cb(SlAnnounceResult::VALIDATION_FAILURE);
}
@@ -394,18 +394,20 @@
Route routeQuery;
routeQuery.faceId = faceId;
routeQuery.origin = ndn::nfd::ROUTE_ORIGIN_PREFIXANN;
- Route* oldRoute = m_rib.find(name, routeQuery);
+ Route* oldRoute = m_rib.findLongestPrefix(name, routeQuery);
+
if (oldRoute == nullptr || !oldRoute->announcement) {
- NFD_LOG_DEBUG("slRenew " << name << ' ' << faceId << ": not found");
+ NFD_LOG_DEBUG("slRenew " << name << " " << faceId << ": not found");
return cb(SlAnnounceResult::NOT_FOUND);
}
+ Name routeName = oldRoute->announcement->getAnnouncedName();
Route route = *oldRoute;
route.expires = std::min(route.annExpires, time::steady_clock::now() + maxLifetime);
- beginAddRoute(name, route, nullopt,
+ beginAddRoute(routeName, route, nullopt,
[=] (RibUpdateResult ribRes) {
auto res = getSlAnnounceResultFromRibUpdateResult(ribRes);
- NFD_LOG_INFO("slRenew " << name << ' ' << faceId << ": " << res);
+ NFD_LOG_INFO("slRenew " << name << " " << faceId << ": " << res << " " << routeName);
cb(res);
});
}
diff --git a/rib/rib.cpp b/rib/rib.cpp
index d209f63..bbd72f1 100644
--- a/rib/rib.cpp
+++ b/rib/rib.cpp
@@ -80,6 +80,20 @@
return nullptr;
}
+Route*
+Rib::findLongestPrefix(const Name& prefix, const Route& route) const
+{
+ Route* existingRoute = find(prefix, route);
+ if (existingRoute == nullptr) {
+ auto parent = findParent(prefix);
+ if (parent) {
+ existingRoute = find(parent->getName(), route);
+ }
+ }
+
+ return existingRoute;
+}
+
void
Rib::insert(const Name& prefix, const Route& route)
{
diff --git a/rib/rib.hpp b/rib/rib.hpp
index 5beea2d..a9278de 100644
--- a/rib/rib.hpp
+++ b/rib/rib.hpp
@@ -77,6 +77,9 @@
Route*
find(const Name& prefix, const Route& route) const;
+ Route*
+ findLongestPrefix(const Name& prefix, const Route& route) const;
+
const_iterator
begin() const;
diff --git a/tests/rib/rib.t.cpp b/tests/rib/rib.t.cpp
index 420a82d..3b9840c 100644
--- a/tests/rib/rib.t.cpp
+++ b/tests/rib/rib.t.cpp
@@ -216,6 +216,12 @@
BOOST_CHECK(rib.find(name2, route2) == nullptr);
BOOST_CHECK(rib.find(name1, route1) != nullptr);
+ Name name5("/hello/world/666");
+ Name name6("/hello/world/cs/ua/edu");
+ BOOST_CHECK(rib.findLongestPrefix(name1, route1) != nullptr);
+ BOOST_CHECK(rib.findLongestPrefix(name5, route1) != nullptr);
+ BOOST_CHECK(rib.findLongestPrefix(name6, route1) != nullptr);
+
rib.erase(name1, route1);
BOOST_CHECK_EQUAL(rib.size(), 1);
}
diff --git a/tests/rib/sl-announce.t.cpp b/tests/rib/sl-announce.t.cpp
index c7808d3..86b6025 100644
--- a/tests/rib/sl-announce.t.cpp
+++ b/tests/rib/sl-announce.t.cpp
@@ -248,7 +248,7 @@
BOOST_CHECK_EQUAL(slAnnounceSync(pa, 4506, 2_h), SlAnnounceResult::OK);
advanceClocks(1_h); // Route has 1_h remaining lifetime
- BOOST_CHECK_EQUAL(slRenewSync("/P2IYFqtr", 4506, 2_h), SlAnnounceResult::OK);
+ BOOST_CHECK_EQUAL(slRenewSync("/P2IYFqtr/2321", 4506, 2_h), SlAnnounceResult::OK);
Route* route = findAnnRoute("/P2IYFqtr", 4506);
BOOST_REQUIRE(route != nullptr);
@@ -262,7 +262,7 @@
BOOST_CHECK_EQUAL(slAnnounceSync(pa, 1589, 2_h), SlAnnounceResult::OK);
advanceClocks(1_h); // Route has 1_h remaining lifetime
- BOOST_CHECK_EQUAL(slRenewSync("/be01Yiba", 1589, 5_h), SlAnnounceResult::OK);
+ BOOST_CHECK_EQUAL(slRenewSync("/be01Yiba/4324", 1589, 5_h), SlAnnounceResult::OK);
Route* route = findAnnRoute("/be01Yiba", 1589);
BOOST_REQUIRE(route != nullptr);
@@ -276,7 +276,7 @@
BOOST_CHECK_EQUAL(slAnnounceSync(pa, 3851, 4_h), SlAnnounceResult::OK);
advanceClocks(1_h); // Route has 3_h remaining lifetime
- BOOST_CHECK_EQUAL(slRenewSync("/5XCHYCAd", 3851, 1_h), SlAnnounceResult::OK);
+ BOOST_CHECK_EQUAL(slRenewSync("/5XCHYCAd/98934", 3851, 1_h), SlAnnounceResult::OK);
Route* route = findAnnRoute("/5XCHYCAd", 3851);
BOOST_REQUIRE(route != nullptr);
@@ -290,7 +290,7 @@
BOOST_CHECK_EQUAL(slAnnounceSync(pa, 8031, 4_h), SlAnnounceResult::OK);
advanceClocks(1_h); // Route has 3_h remaining lifetime
- BOOST_CHECK_EQUAL(slRenewSync("/cdQ7KPNw", 8031, 0_s), SlAnnounceResult::EXPIRED);
+ BOOST_CHECK_EQUAL(slRenewSync("/cdQ7KPNw/8023", 8031, 0_s), SlAnnounceResult::EXPIRED);
BOOST_CHECK(findAnnRoute("/cdQ7KPNw", 8031) == nullptr);
}