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<ndn::Name>& namesToAdd,
66 const std::list<ndn::Name>& 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& name : nlsa->getNpl().getNames()) {
79 if (name != m_ownRouterName) {
80 addEntry(name, lsa->getOriginRouter());
90 for (
const auto& name : namesToAdd) {
91 if (name != m_ownRouterName) {
92 addEntry(name, lsa->getOriginRouter());
96 for (
const auto& name : namesToRemove) {
97 if (name != m_ownRouterName) {
103 removeEntry(lsa->getOriginRouter(), lsa->getOriginRouter());
105 auto nlsa = std::static_pointer_cast<NameLsa>(lsa);
106 for (
const auto& name : nlsa->getNpl().getNames()) {
107 if (name != m_ownRouterName) {
119 auto nameItr = std::find_if(m_table.begin(), m_table.end(),
120 [&] (
const auto& entry) { return name == entry->getNamePrefix(); });
123 auto rtpeItr = m_rtpool.find(destRouter);
127 std::shared_ptr<RoutingTablePoolEntry> rtpePtr(
nullptr);
130 if (rtpeItr == m_rtpool.end()) {
135 if (routeEntryPtr ==
nullptr) {
148 rtpePtr = (*rtpeItr).second;
151 std::shared_ptr<NamePrefixTableEntry> npte;
153 if (nameItr == m_table.end()) {
155 <<
" to a new name prefix: " << name);
156 npte = std::make_shared<NamePrefixTableEntry>(name);
157 npte->addRoutingTableEntry(rtpePtr);
158 npte->generateNhlfromRteList();
159 m_table.push_back(npte);
162 if (npte->getNexthopList().size() > 0) {
163 NLSR_LOG_TRACE(
"Updating FIB with next hops for " << npte->getNamePrefix());
164 m_fib.
update(name, npte->getNexthopList());
173 NLSR_LOG_TRACE(npte->getNamePrefix() <<
" has no next hops; removing from FIB");
180 " to existing prefix: " << **nameItr);
181 (*nameItr)->addRoutingTableEntry(rtpePtr);
182 (*nameItr)->generateNhlfromRteList();
184 if ((*nameItr)->getNexthopList().size() > 0) {
185 NLSR_LOG_TRACE(
"Updating FIB with next hops for " << (**nameItr));
186 m_fib.
update(name, (*nameItr)->getNexthopList());
189 NLSR_LOG_TRACE(npte->getNamePrefix() <<
" has no next hops; removing from FIB");
195 rtpePtr->namePrefixTableEntries.try_emplace(npte->getNamePrefix(),
196 std::weak_ptr<NamePrefixTableEntry>(npte));
202 NLSR_LOG_DEBUG(
"Removing origin: " << destRouter <<
" from " << name);
205 auto rtpeItr = m_rtpool.find(destRouter);
209 if (rtpeItr == m_rtpool.end()) {
211 <<
" found, so it cannot be removed from prefix: " << name);
214 std::shared_ptr<RoutingTablePoolEntry> rtpePtr = rtpeItr->second;
217 auto nameItr = std::find_if(m_table.begin(), m_table.end(),
218 [&] (
const auto& entry) { return entry->getNamePrefix() == name; });
219 if (nameItr != m_table.end()) {
221 <<
" from prefix: " << **nameItr);
225 if ((*nameItr)->removeRoutingTableEntry(rtpePtr) == 0) {
244 if ((*nameItr)->getRteListSize() == 0) {
246 <<
" removing from table and FIB");
247 m_table.erase(nameItr);
252 <<
" updating FIB with next hops");
253 (*nameItr)->generateNhlfromRteList();
254 m_fib.
update(name, (*nameItr)->getNexthopList());
258 NLSR_LOG_DEBUG(
"Attempted to remove origin: " << rtpePtr->getDestination()
259 <<
" from non-existent prefix: " << name);
269 for (
auto&& poolEntryPair : m_rtpool) {
270 auto&& poolEntry = poolEntryPair.second;
271 auto sourceEntry = std::find_if(entries.begin(), entries.end(),
273 return poolEntry->getDestination() == entry.getDestination();
276 if (sourceEntry != entries.end()
277 && poolEntry->getNexthopList() != sourceEntry->getNexthopList()) {
278 NLSR_LOG_DEBUG(
"Routing entry: " << poolEntry->getDestination() <<
" has changed next-hops.");
279 poolEntry->setNexthopList(sourceEntry->getNexthopList());
280 for (
const auto& nameEntry : poolEntry->namePrefixTableEntries) {
281 auto nameEntryFullPtr = nameEntry.second.lock();
282 addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination());
285 else if (sourceEntry == entries.end()) {
286 NLSR_LOG_DEBUG(
"Routing entry: " << poolEntry->getDestination() <<
" now has no next-hops.");
287 poolEntry->getNexthopList().clear();
288 for (
const auto& nameEntry : poolEntry->namePrefixTableEntries) {
289 auto nameEntryFullPtr = nameEntry.second.lock();
290 addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination());
294 NLSR_LOG_TRACE(
"No change in routing entry:" << poolEntry->getDestination()
295 <<
", no action necessary.");
303 std::shared_ptr<RoutingTablePoolEntry>
307 std::make_shared<RoutingTablePoolEntry>(rtpe)).first;
308 return poolIt->second;
320 if (m_rtpool.erase(rtpePtr->getDestination()) != 1) {
322 << rtpePtr->getDestination()
323 <<
" from NPT routing table entry storage pool.");
336 os <<
"----------------NPT----------------------\n";
338 for (
const auto& entryPtr : table) {
339 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)
Set the nexthop list of a name.
ndn::signal::Signal< Lsdb, std::shared_ptr< Lsa >, LsdbUpdate, std::list< ndn::Name >, std::list< ndn::Name > > AfterLsdbModified
std::shared_ptr< RoutingTablePoolEntry > addRtpeToPool(RoutingTablePoolEntry &rtpe)
Adds a pool entry to the pool.
void removeEntry(const ndn::Name &name, const ndn::Name &destRouter)
Removes a destination from a name prefix table entry.
void updateWithNewRoute(const std::list< RoutingTableEntry > &entries)
Updates all routing information in the NPT.
NamePrefixTable(const ndn::Name &ownRouterName, Fib &fib, RoutingTable &routingTable, AfterRoutingChange &afterRoutingChangeSignal, Lsdb::AfterLsdbModified &afterLsdbModifiedSignal)
void updateFromLsdb(std::shared_ptr< Lsa > lsa, LsdbUpdate updateType, const std::list< ndn::Name > &namesToAdd, const std::list< ndn::Name > &namesToRemove)
Add, update, or remove Names according to the Lsdb update.
void addEntry(const ndn::Name &name, const ndn::Name &destRouter)
Adds a destination to the specified name prefix.
void deleteRtpeFromPool(std::shared_ptr< RoutingTablePoolEntry > rtpePtr)
Removes a pool entry from the pool.
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