37 std::unique_ptr<AfterRoutingChange>& afterRoutingChangeSignal)
39 , m_routingTable(routingTable)
41 m_afterRoutingChangeConnection = afterRoutingChangeSignal->connect(
42 [
this] (
const std::list<RoutingTableEntry>& entries) {
49 m_afterRoutingChangeConnection.disconnect();
57 NptEntryList::iterator nameItr =
58 std::find_if(m_table.begin(),
60 [&] (
const std::shared_ptr<NamePrefixTableEntry>& entry) {
61 return name == entry->getNamePrefix();
65 RoutingTableEntryPool::iterator rtpeItr = m_rtpool.find(destRouter);
69 std::shared_ptr<RoutingTablePoolEntry> rtpePtr(
nullptr);
72 if (rtpeItr == m_rtpool.end()) {
77 if (routeEntryPtr ==
nullptr) {
90 rtpePtr = (*rtpeItr).second;
93 std::shared_ptr<NamePrefixTableEntry> npte;
95 if (nameItr == m_table.end()) {
97 <<
" to a new name prefix: " << name);
98 npte = make_shared<NamePrefixTableEntry>(name);
99 npte->addRoutingTableEntry(rtpePtr);
100 npte->generateNhlfromRteList();
101 m_table.push_back(npte);
103 if (npte->getNexthopList().size() > 0) {
104 NLSR_LOG_TRACE(
"Updating FIB with next hops for " << npte->getNamePrefix());
105 m_fib.
update(name, npte->getNexthopList());
114 NLSR_LOG_TRACE(npte->getNamePrefix() <<
" has no next hops; removing from FIB");
121 " to existing prefix: " << **nameItr);
122 (*nameItr)->addRoutingTableEntry(rtpePtr);
123 (*nameItr)->generateNhlfromRteList();
125 if ((*nameItr)->getNexthopList().size() > 0) {
126 NLSR_LOG_TRACE(
"Updating FIB with next hops for " << (**nameItr));
127 m_fib.
update(name, (*nameItr)->getNexthopList());
130 NLSR_LOG_TRACE(npte->getNamePrefix() <<
" has no next hops; removing from FIB");
135 rtpePtr->namePrefixTableEntries.emplace(
136 std::make_pair(npte->getNamePrefix(), std::weak_ptr<NamePrefixTableEntry>(npte)));
142 NLSR_LOG_DEBUG(
"Removing origin: " << destRouter <<
" from " << name);
145 RoutingTableEntryPool::iterator rtpeItr = m_rtpool.find(destRouter);
149 if (rtpeItr == m_rtpool.end()) {
151 <<
" found, so it cannot be removed from prefix: " 155 std::shared_ptr<RoutingTablePoolEntry> rtpePtr = rtpeItr->second;
158 NptEntryList::iterator nameItr =
159 std::find_if(m_table.begin(), m_table.end(),
160 [&] (
const std::shared_ptr<NamePrefixTableEntry>& entry) {
161 return entry->getNamePrefix() == name;
163 if (nameItr != m_table.end()) {
165 <<
" from prefix: " << **nameItr);
169 if ((*nameItr)->removeRoutingTableEntry(rtpePtr) == 0) {
188 if ((*nameItr)->getRteListSize() == 0) {
190 <<
" removing from table and FIB");
191 m_table.erase(nameItr);
196 <<
" updating FIB with next hops");
197 (*nameItr)->generateNhlfromRteList();
198 m_fib.
update(name, (*nameItr)->getNexthopList());
202 NLSR_LOG_DEBUG(
"Attempted to remove origin: " << rtpePtr->getDestination()
203 <<
" from non-existent prefix: " << name);
213 for (
auto&& poolEntryPair : m_rtpool) {
214 auto&& poolEntry = poolEntryPair.second;
215 auto sourceEntry = std::find_if(entries.begin(), entries.end(),
217 return poolEntry->getDestination() == entry.getDestination();
220 if (sourceEntry != entries.end()
221 && poolEntry->getNexthopList() != sourceEntry->getNexthopList()) {
222 NLSR_LOG_DEBUG(
"Routing entry: " << poolEntry->getDestination() <<
" has changed next-hops.");
223 poolEntry->setNexthopList(sourceEntry->getNexthopList());
224 for (
const auto& nameEntry : poolEntry->namePrefixTableEntries) {
225 auto nameEntryFullPtr = nameEntry.second.lock();
226 addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination());
229 else if (sourceEntry == entries.end()) {
230 NLSR_LOG_DEBUG(
"Routing entry: " << poolEntry->getDestination() <<
" now has no next-hops.");
231 poolEntry->getNexthopList().reset();
232 for (
const auto& nameEntry : poolEntry->namePrefixTableEntries) {
233 auto nameEntryFullPtr = nameEntry.second.lock();
234 addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination());
238 NLSR_LOG_TRACE(
"No change in routing entry:" << poolEntry->getDestination()
239 <<
", no action necessary.");
247 std::shared_ptr<RoutingTablePoolEntry>
250 RoutingTableEntryPool::iterator poolItr =
252 std::make_shared<RoutingTablePoolEntry>
255 return poolItr->second;
267 if (m_rtpool.erase(rtpePtr->getDestination()) != 1) {
269 << rtpePtr->getDestination()
270 <<
" from NPT routing table entry storage pool.");
283 os <<
"----------------NPT----------------------\n";
285 for (
const auto& entryPtr : table) {
286 os << *entryPtr << std::endl;
void update(const ndn::Name &name, const NexthopList &allHops)
Set the nexthop list of a name.
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
NamePrefixTable(Fib &fib, RoutingTable &routingTable, std::unique_ptr< AfterRoutingChange > &afterRoutingChangeSignal)
std::shared_ptr< RoutingTablePoolEntry > addRtpeToPool(RoutingTablePoolEntry &rtpe)
Adds a pool entry to the pool.
void deleteRtpeFromPool(std::shared_ptr< RoutingTablePoolEntry > rtpePtr)
Removes a pool entry from the pool.
#define NLSR_LOG_DEBUG(x)
void updateWithNewRoute(const std::list< RoutingTableEntry > &entries)
Updates all routing information in the NPT.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
Maps names to lists of next hops, and exports this information to NFD.
#define INIT_LOGGER(name)
void removeEntry(const ndn::Name &name, const ndn::Name &destRouter)
Removes a destination from a name prefix table entry.
const ndn::Name & getDestination() const
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
void remove(const ndn::Name &name)
Completely remove a name prefix from the FIB.
RoutingTableEntry * findRoutingTableEntry(const ndn::Name &destRouter)
#define NLSR_LOG_TRACE(x)
void addEntry(const ndn::Name &name, const ndn::Name &destRouter)
Adds a destination to the specified name prefix.