named-data / NLSR

Named Data Link State Routing
https://docs.named-data.net/NLSR
GNU General Public License v3.0
48 stars 37 forks source link

About the problems encountered when using nlsrc withdraw <name> #13

Open Morningstar678 opened 2 years ago

Morningstar678 commented 2 years ago

Problem Description:On a simple NFD-connected topology, after a prefix is withdrawn using nlsrc withdraw , all routing information for that prefix on adjacent NFDs is removed. Cause of the problem: NLSR calculates routing information according to LSDB, forms FIB table, specifically: prefix+NextHops (faceID, cost), and registers routing information to NFD through Interest-Data, where the formal parameters of register() method are prefix, faceURI, Cost, and The formal parameters of the unregister() method are prefix, faceURI, and Cost, and the formal parameters of the unregister() method are prefix, faceURI, so it can be assumed that when NLSR registers the route with NFD, it registers all the route information under a certain prefix. Solution: Modify void Fib::update(const ndn::Name& name, const NexthopList& allHops) in the fib.cpp file in the NLSR-0.4.3\src\route directory(In fact every version of NLSR has this problem, version 0.4.3 has been tested)The code is modified as follows:

`void Fib::update(const ndn::Name& name, const NexthopList& allHops)
{ NLSR_LOG_DEBUG("Fib::update called");

// Get the max possible faces which is the minumum of the configuration setting and // the length of the list of all next hops. unsigned int maxFaces = getNumberOfFacesForName(allHops);

NexthopList hopsToAdd; unsigned int nFaces = 0;

// Create a list of next hops to be installed with length == maxFaces for (NexthopList::iterator it = allHops.cbegin(); it != allHops.cend() && nFaces < maxFaces; ++it, ++nFaces) { hopsToAdd.addNextHop(*it); }

std::map<ndn::Name, FibEntry>::iterator entryIt = m_table.find(name);

// New FIB entry that has nextHops if (entryIt == m_table.end() && hopsToAdd.size() != 0) { NLSR_LOG_DEBUG("New FIB Entry");

FibEntry entry(name);

addNextHopsToFibEntryAndNfd(entry, hopsToAdd);

m_table.emplace(name, entry);

entryIt = m_table.find(name);

} // Existing FIB entry that may or may not have nextHops else { // Existing FIB entry NLSR_LOG_DEBUG("Existing FIB Entry");

// Remove empty FIB entry
if (hopsToAdd.size() == 0) {
  remove(name);
  return;
}

FibEntry& entry = (entryIt->second);//

//**addNextHopsToFibEntryAndNfd(entry, hopsToAdd);**//Adjust the position of the row

std::set<NextHop, NextHopComparator> hopsToRemove;
std::set_difference(entry.getNexthopList().begin(), entry.getNexthopList().end(),
                    hopsToAdd.begin(), hopsToAdd.end(),
                    std::inserter(hopsToRemove, hopsToRemove.end()), NextHopComparator());

bool isUpdatable = isPrefixUpdatable(entry.getName());
// Remove the uninstalled next hops from NFD and FIB entry
for (const auto& hop: hopsToRemove){
  if (isUpdatable) {
    unregisterPrefix(entry.getName(), hop.getConnectingFaceUri());
  }
  NLSR_LOG_DEBUG("Removing " << hop.getConnectingFaceUri() << " from " << entry.getName());
  entry.getNexthopList().removeNextHop(hop);
}
  addNextHopsToFibEntryAndNfd(entry, hopsToAdd);         //  Adjust here
// Increment sequence number
entry.setSeqNo(entry.getSeqNo() + 1);

entryIt = m_table.find(name);

} if (entryIt != m_table.end() && !entryIt->second.getRefreshEventId()) { scheduleEntryRefresh(entryIt->second, [this] (FibEntry& entry) { scheduleLoop(entry); }); } }

agawande commented 2 years ago

Does this happen with the latest commit from github? I had fixed a similar bug earlier which is not part of any release yet I think: https://redmine.named-data.net/issues/5179 https://github.com/named-data/NLSR/commit/6f0f35d96d6c28fea8a066de47c03b647a841f85 https://github.com/named-data/NLSR/blob/master/tests/route/test-fib.cpp#L361

Can you please write a unit test against the latest commit from github documenting the problem?