40 : m_ownRouterName(ownRouterName)
42 , m_routingTable(routingTable)
44 m_afterRoutingChangeConnection = afterRoutingChangeSignal.connect(
45 [
this] (
const std::list<RoutingTableEntry>& entries) {
49 m_afterLsdbModified = afterLsdbModifiedSignal.connect(
50 [
this] (std::shared_ptr<Lsa> lsa,
LsdbUpdate updateType,
51 const auto& namesToAdd,
const auto& namesToRemove) {
59 m_afterRoutingChangeConnection.disconnect();
60 m_afterLsdbModified.disconnect();
65 const std::list<nlsr::PrefixInfo>& namesToAdd,
66 const std::list<nlsr::PrefixInfo>& namesToRemove)
68 if (m_ownRouterName == lsa->getOriginRouter()) {
71 NLSR_LOG_TRACE(
"Got update from Lsdb for router: " << lsa->getOriginRouter());
74 addEntry(lsa->getOriginRouter(), lsa->getOriginRouter());
77 auto nlsa = std::static_pointer_cast<NameLsa>(lsa);
78 for (
const auto &prefix : nlsa->getNpl().getPrefixInfo()) {
79 if (prefix.getName() != m_ownRouterName) {
80 m_nexthopCost[
DestNameKey(lsa->getOriginRouter(), prefix.getName())] = prefix.getCost();
82 addEntry(prefix.getName(), lsa->getOriginRouter(), ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
92 for (
const auto &prefix : namesToAdd) {
93 if (prefix.getName() != m_ownRouterName) {
94 m_nexthopCost[
DestNameKey(lsa->getOriginRouter(), prefix.getName())] = prefix.getCost();
96 addEntry(prefix.getName(), lsa->getOriginRouter(), ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
100 for (
const auto &prefix : namesToRemove) {
101 if (prefix.getName() != m_ownRouterName) {
102 m_nexthopCost.erase(m_nexthopCost.find(
DestNameKey(lsa->getOriginRouter(), prefix.getName())));
103 removeEntry(prefix.getName(), lsa->getOriginRouter());
108 removeEntry(lsa->getOriginRouter(), lsa->getOriginRouter());
110 auto nlsa = std::static_pointer_cast<NameLsa>(lsa);
111 for (
const auto& name : nlsa->getNpl().getNames()) {
112 if (name != m_ownRouterName) {
113 m_nexthopCost.erase(m_nexthopCost.find(
DestNameKey(lsa->getOriginRouter(), name)));
126 const NextHop newNextHop =
NextHop(nh.getConnectingFaceUri(), nh.getRouteCost() +
127 m_nexthopCost[
DestNameKey(destRouterName, nameToCheck)]);
137 auto nameItr = std::find_if(m_table.begin(), m_table.end(),
138 [&] (
const auto& entry) { return name == entry->getNamePrefix(); });
141 auto rtpeItr = m_rtpool.find(destRouter);
145 std::shared_ptr<RoutingTablePoolEntry> rtpePtr(
nullptr);
148 if (rtpeItr == m_rtpool.end()) {
153 if (routeEntryPtr ==
nullptr) {
166 rtpePtr = (*rtpeItr).second;
169 std::shared_ptr<NamePrefixTableEntry> npte;
171 if (nameItr == m_table.end()) {
173 <<
" to a new name prefix: " << name);
175 npte = std::make_shared<NamePrefixTableEntry>(name, ndn::nfd::ROUTE_FLAG_CHILD_INHERIT);
176 npte->addRoutingTableEntry(rtpePtr);
177 npte->generateNhlfromRteList();
178 m_table.push_back(npte);
181 if (npte->getNexthopList().size() > 0) {
182 NLSR_LOG_TRACE(
"Updating FIB with next hops for " << npte->getNamePrefix());
192 NLSR_LOG_TRACE(npte->getNamePrefix() <<
" has no next hops; removing from FIB");
199 " to existing prefix: " << *npte);
201 if (npte->getFlags() != routeFlags && npte->getNexthopList().size() == 0) {
202 npte->setFlags(routeFlags);
204 npte->addRoutingTableEntry(rtpePtr);
205 npte->generateNhlfromRteList();
206 if (npte->getNexthopList().size() > 0) {
211 NLSR_LOG_TRACE(npte->getNamePrefix() <<
" has no next hops; removing from FIB");
217 rtpePtr->namePrefixTableEntries.try_emplace(npte->getNamePrefix(),
218 std::weak_ptr<NamePrefixTableEntry>(npte));
224 NLSR_LOG_DEBUG(
"Removing origin: " << destRouter <<
" from " << name);
227 auto rtpeItr = m_rtpool.find(destRouter);
231 if (rtpeItr == m_rtpool.end()) {
233 <<
" found, so it cannot be removed from prefix: " << name);
236 std::shared_ptr<RoutingTablePoolEntry> rtpePtr = rtpeItr->second;
239 auto nameItr = std::find_if(m_table.begin(), m_table.end(),
240 [&] (
const auto& entry) { return entry->getNamePrefix() == name; });
241 if (nameItr != m_table.end()) {
242 std::shared_ptr<NamePrefixTableEntry> npte = *nameItr;
244 <<
" from prefix: " << **nameItr);
248 if (npte->removeRoutingTableEntry(rtpePtr) == 0) {
267 if (npte->getRteListSize() == 0) {
269 <<
" removing from table and FIB");
270 m_table.erase(nameItr);
275 <<
" updating FIB with next hops");
276 (*nameItr)->generateNhlfromRteList();
281 NLSR_LOG_DEBUG(
"Attempted to remove origin: " << rtpePtr->getDestination()
282 <<
" from non-existent prefix: " << name);
292 for (
auto&& poolEntryPair : m_rtpool) {
293 auto&& poolEntry = poolEntryPair.second;
294 auto sourceEntry = std::find_if(entries.begin(), entries.end(),
296 return poolEntry->getDestination() == entry.getDestination();
299 if (sourceEntry != entries.end()
300 && poolEntry->getNexthopList() != sourceEntry->getNexthopList()) {
301 NLSR_LOG_DEBUG(
"Routing entry: " << poolEntry->getDestination() <<
" has changed next-hops.");
302 poolEntry->setNexthopList(sourceEntry->getNexthopList());
303 for (
const auto& nameEntry : poolEntry->namePrefixTableEntries) {
304 auto nameEntryFullPtr = nameEntry.second.lock();
305 addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination(), nameEntryFullPtr->getFlags());
308 else if (sourceEntry == entries.end()) {
309 NLSR_LOG_DEBUG(
"Routing entry: " << poolEntry->getDestination() <<
" now has no next-hops.");
310 poolEntry->getNexthopList().clear();
311 for (
const auto& nameEntry : poolEntry->namePrefixTableEntries) {
312 auto nameEntryFullPtr = nameEntry.second.lock();
313 addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination(), nameEntryFullPtr->getFlags());
317 NLSR_LOG_TRACE(
"No change in routing entry:" << poolEntry->getDestination()
318 <<
", no action necessary.");
326std::shared_ptr<RoutingTablePoolEntry>
330 std::make_shared<RoutingTablePoolEntry>(rtpe)).first;
331 return poolIt->second;
343 if (m_rtpool.erase(rtpePtr->getDestination()) != 1) {
345 << rtpePtr->getDestination()
346 <<
" from NPT routing table entry storage pool.");
359 os <<
"----------------NPT----------------------\n";
361 for (
const auto& entryPtr : table) {
362 os << *entryPtr << std::endl;
Maps names to lists of next hops, and exports this information to NFD.
void remove(const ndn::Name &name)
Completely remove a name prefix from the FIB.
void update(const ndn::Name &name, const NexthopList &allHops, uint64_t routeFlags)
Set the nexthop list of a name.
ndn::signal::Signal< Lsdb, std::shared_ptr< Lsa >, LsdbUpdate, std::list< nlsr::PrefixInfo >, std::list< nlsr::PrefixInfo > > AfterLsdbModified
std::shared_ptr< RoutingTablePoolEntry > addRtpeToPool(RoutingTablePoolEntry &rtpe)
Adds a pool entry to the pool.
void addEntry(const ndn::Name &name, const ndn::Name &destRouter, uint64_t routeFlags=ndn::nfd::ROUTE_FLAG_CAPTURE)
Adds a destination to the specified name prefix.
void removeEntry(const ndn::Name &name, const ndn::Name &destRouter)
Removes a destination from a name prefix table entry.
void updateFromLsdb(std::shared_ptr< Lsa > lsa, LsdbUpdate updateType, const std::list< nlsr::PrefixInfo > &namesToAdd, const std::list< nlsr::PrefixInfo > &namesToRemove)
Add, update, or remove Names according to the Lsdb update.
void updateWithNewRoute(const std::list< RoutingTableEntry > &entries)
Updates all routing information in the NPT.
std::tuple< ndn::Name, ndn::Name > DestNameKey
NexthopList adjustNexthopCosts(const NexthopList &nhlist, const ndn::Name &nameToCheck, const ndn::Name &destRouterName)
NamePrefixTable(const ndn::Name &ownRouterName, Fib &fib, RoutingTable &routingTable, AfterRoutingChange &afterRoutingChangeSignal, Lsdb::AfterLsdbModified &afterLsdbModifiedSignal)
void deleteRtpeFromPool(std::shared_ptr< RoutingTablePoolEntry > rtpePtr)
Removes a pool entry from the pool.
Data abstraction for Nexthop.
const std::set< NextHop, T > & getNextHops() const
void addNextHop(const NextHop &nh)
Adds a next hop to the list.
Data abstraction for RouteTableInfo.
const ndn::Name & getDestination() const
RoutingTableEntry * findRoutingTableEntry(const ndn::Name &destRouter)
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define NLSR_LOG_DEBUG(x)
#define INIT_LOGGER(name)
#define NLSR_LOG_TRACE(x)
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
ndn::signal::Signal< RoutingTable, std::list< RoutingTableEntry > > AfterRoutingChange