37 std::unique_ptr<AfterRoutingChange>& afterRoutingChangeSignal)
40 m_afterRoutingChangeConnection = afterRoutingChangeSignal->connect(
41 [
this] (
const std::list<RoutingTableEntry>& entries) {
48 m_afterRoutingChangeConnection.disconnect();
52 npteCompare(std::shared_ptr<NamePrefixTableEntry>& npte,
const ndn::Name& name)
54 return npte->getNamePrefix() == name;
62 NptEntryList::iterator nameItr =
63 std::find_if(m_table.begin(),
65 [&] (
const std::shared_ptr<NamePrefixTableEntry>& entry) {
66 return name == entry->getNamePrefix();
70 RoutingTableEntryPool::iterator rtpeItr = m_rtpool.find(destRouter);
74 std::shared_ptr<RoutingTablePoolEntry> rtpePtr(
nullptr);
77 if (rtpeItr == m_rtpool.end()) {
83 if (routeEntryPtr ==
nullptr) {
96 rtpePtr = (*rtpeItr).second;
99 std::shared_ptr<NamePrefixTableEntry> npte;
101 if (nameItr == m_table.end()) {
103 <<
" to a new name prefix: " << name);
104 npte = make_shared<NamePrefixTableEntry>(name);
105 npte->addRoutingTableEntry(rtpePtr);
106 npte->generateNhlfromRteList();
107 m_table.push_back(npte);
109 if (npte->getNexthopList().size() > 0) {
127 <<
" to existing prefix: " << *nameItr);
128 (*nameItr)->addRoutingTableEntry(rtpePtr);
129 (*nameItr)->generateNhlfromRteList();
131 if ((*nameItr)->getNexthopList().size() > 0) {
133 m_nlsr.
getFib().
update(name, (*nameItr)->getNexthopList());
136 NLSR_LOG_TRACE((*nameItr) <<
" has no next hops; removing from FIB");
141 rtpePtr->namePrefixTableEntries.emplace(
142 std::make_pair(npte->getNamePrefix(), std::weak_ptr<NamePrefixTableEntry>(npte)));
148 NLSR_LOG_DEBUG(
"Removing origin: " << destRouter <<
" from " << name);
151 RoutingTableEntryPool::iterator rtpeItr = m_rtpool.find(destRouter);
155 if (rtpeItr == m_rtpool.end()) {
157 <<
" found, so it cannot be removed from prefix: " 161 std::shared_ptr<RoutingTablePoolEntry> rtpePtr = rtpeItr->second;
164 NptEntryList::iterator nameItr =
165 std::find_if(m_table.begin(), m_table.end(),
166 [&] (
const std::shared_ptr<NamePrefixTableEntry>& entry) {
167 return entry->getNamePrefix() == name;
169 if (nameItr != m_table.end()) {
171 <<
" from prefix: " << **nameItr);
175 if ((*nameItr)->removeRoutingTableEntry(rtpePtr) == 0) {
194 if ((*nameItr)->getRteListSize() == 0) {
196 <<
" removing from table and FIB");
197 m_table.erase(nameItr);
202 <<
" updating FIB with next hops");
203 (*nameItr)->generateNhlfromRteList();
204 m_nlsr.
getFib().
update(name, (*nameItr)->getNexthopList());
208 NLSR_LOG_DEBUG(
"Attempted to remove origin: " << rtpePtr->getDestination()
209 <<
" from non-existent prefix: " << name);
219 for (
auto&& poolEntryPair : m_rtpool) {
220 auto&& poolEntry = poolEntryPair.second;
221 auto sourceEntry = std::find_if(entries.begin(), entries.end(),
223 return poolEntry->getDestination() == entry.getDestination();
226 if (sourceEntry != entries.end()
227 && poolEntry->getNexthopList() != sourceEntry->getNexthopList()) {
228 NLSR_LOG_DEBUG(
"Routing entry: " << poolEntry->getDestination() <<
" has changed next-hops.");
229 poolEntry->setNexthopList(sourceEntry->getNexthopList());
230 for (
const auto& nameEntry : poolEntry->namePrefixTableEntries) {
231 auto nameEntryFullPtr = nameEntry.second.lock();
232 addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination());
235 else if (sourceEntry == entries.end()) {
236 NLSR_LOG_DEBUG(
"Routing entry: " << poolEntry->getDestination() <<
" now has no next-hops.");
237 poolEntry->getNexthopList().reset();
238 for (
const auto& nameEntry : poolEntry->namePrefixTableEntries) {
239 auto nameEntryFullPtr = nameEntry.second.lock();
240 addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination());
244 NLSR_LOG_TRACE(
"No change in routing entry:" << poolEntry->getDestination()
245 <<
", no action necessary.");
253 std::shared_ptr<RoutingTablePoolEntry>
256 RoutingTableEntryPool::iterator poolItr =
258 std::make_shared<RoutingTablePoolEntry>
261 return poolItr->second;
273 if (m_rtpool.erase(rtpePtr->getDestination()) != 1) {
275 << rtpePtr->getDestination()
276 <<
" from NPT routing table entry storage pool.");
289 os <<
"----------------NPT----------------------\n";
291 for (
const auto& entryPtr : table) {
292 os << *entryPtr << std::endl;
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
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)
RoutingTable & getRoutingTable()
void updateWithNewRoute(const std::list< RoutingTableEntry > &entries)
Updates all routing information in the NPT.
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California.
#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
bool npteCompare(std::shared_ptr< NamePrefixTableEntry > &npte, const ndn::Name &name)
Copyright (c) 2014-2017, 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)
void update(const ndn::Name &name, NexthopList &allHops)
Set the nexthop list of a name.
#define NLSR_LOG_TRACE(x)
NamePrefixTable(Nlsr &nlsr, std::unique_ptr< AfterRoutingChange > &afterRoutingChangeSignal)
void addEntry(const ndn::Name &name, const ndn::Name &destRouter)
Adds a destination to the specified name prefix.