fib: fix route unregister bug during update
refs: #5179
Change-Id: I19952ebcb0c78c405f3d820694a7b0f1cf7a3fe6
diff --git a/src/route/fib.cpp b/src/route/fib.cpp
index 1004889..2d34a36 100644
--- a/src/route/fib.cpp
+++ b/src/route/fib.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2020, The University of Memphis,
+ * Copyright (c) 2014-2021, The University of Memphis,
* Regents of the University of California
*
* This file is part of NLSR (Named-data Link State Routing).
@@ -54,7 +54,7 @@
// Only unregister the prefix if it ISN'T a neighbor.
if (it != m_table.end() && isNotNeighbor((it->second).name)) {
- for (const auto& nexthop : (it->second).nexthopList.getNextHops()) {
+ for (const auto& nexthop : (it->second).nexthopSet) {
unregisterPrefix((it->second).name, nexthop.getConnectingFaceUri());
}
m_table.erase(it);
@@ -62,16 +62,17 @@
}
void
-Fib::addNextHopsToFibEntryAndNfd(FibEntry& entry, const NexthopList& hopsToAdd)
+Fib::addNextHopsToFibEntryAndNfd(FibEntry& entry, const NextHopsUriSortedSet& hopsToAdd)
{
const ndn::Name& name = entry.name;
bool shouldRegister = isNotNeighbor(name);
- for (const auto& hop : hopsToAdd.getNextHops())
+ for (const auto& hop : hopsToAdd)
{
// Add nexthop to FIB entry
- entry.nexthopList.addNextHop(hop);
+ NLSR_LOG_DEBUG("Adding " << hop.getConnectingFaceUri() << " to " << entry.name);
+ entry.nexthopSet.addNextHop(hop);
if (shouldRegister) {
// Add nexthop to NDN-FIB
@@ -92,7 +93,7 @@
// the length of the list of all next hops.
unsigned int maxFaces = getNumberOfFacesForName(allHops);
- NexthopList hopsToAdd;
+ NextHopsUriSortedSet hopsToAdd;
unsigned int nFaces = 0;
// Create a list of next hops to be installed with length == maxFaces
@@ -129,10 +130,11 @@
FibEntry& entry = (entryIt->second);
addNextHopsToFibEntryAndNfd(entry, hopsToAdd);
- std::set<NextHop, NextHopComparator> hopsToRemove;
- std::set_difference(entry.nexthopList.begin(), entry.nexthopList.end(),
+ std::set<NextHop, NextHopUriSortedComparator> hopsToRemove;
+ std::set_difference(entry.nexthopSet.begin(), entry.nexthopSet.end(),
hopsToAdd.begin(), hopsToAdd.end(),
- std::inserter(hopsToRemove, hopsToRemove.end()), NextHopComparator());
+ std::inserter(hopsToRemove, hopsToRemove.begin()),
+ NextHopUriSortedComparator());
bool isUpdatable = isNotNeighbor(entry.name);
// Remove the uninstalled next hops from NFD and FIB entry
@@ -141,7 +143,7 @@
unregisterPrefix(entry.name, hop.getConnectingFaceUri());
}
NLSR_LOG_DEBUG("Removing " << hop.getConnectingFaceUri() << " from " << entry.name);
- entry.nexthopList.removeNextHop(hop);
+ entry.nexthopSet.removeNextHop(hop);
}
// Increment sequence number
@@ -161,7 +163,7 @@
{
NLSR_LOG_DEBUG("Clean called");
for (const auto& it : m_table) {
- for (const auto& hop : it.second.nexthopList.getNextHops()) {
+ for (const auto& hop : it.second.nexthopSet) {
unregisterPrefix(it.second.name, hop.getConnectingFaceUri());
}
}
@@ -339,7 +341,7 @@
entry.seqNo += 1;
- for (const NextHop& hop : entry.nexthopList) {
+ for (const NextHop& hop : entry.nexthopSet) {
registerPrefix(entry.name,
ndn::FaceUri(hop.getConnectingFaceUri()),
hop.getRouteCostAsAdjustedInteger(),
@@ -355,9 +357,9 @@
{
NLSR_LOG_DEBUG("-------------------FIB-----------------------------");
for (const auto& entry : m_table) {
- NLSR_LOG_DEBUG("Name Prefix: " << entry.second.name);
+ NLSR_LOG_DEBUG("Name prefix: " << entry.first);
NLSR_LOG_DEBUG("Seq No: " << entry.second.seqNo);
- NLSR_LOG_DEBUG(entry.second.nexthopList);
+ NLSR_LOG_DEBUG("Nexthop List: \n" << entry.second.nexthopSet);
}
}