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 = std::make_shared<NamePrefixTableEntry>(name);
99 npte->addRoutingTableEntry(rtpePtr);
100 npte->generateNhlfromRteList();
101 m_table.push_back(npte);
104 if (npte->getNexthopList().size() > 0) {
105 NLSR_LOG_TRACE(
"Updating FIB with next hops for " << npte->getNamePrefix());
106 m_fib.
update(name, npte->getNexthopList());
115 NLSR_LOG_TRACE(npte->getNamePrefix() <<
" has no next hops; removing from FIB");
122 " to existing prefix: " << **nameItr);
123 (*nameItr)->addRoutingTableEntry(rtpePtr);
124 (*nameItr)->generateNhlfromRteList();
126 if ((*nameItr)->getNexthopList().size() > 0) {
127 NLSR_LOG_TRACE(
"Updating FIB with next hops for " << (**nameItr));
128 m_fib.
update(name, (*nameItr)->getNexthopList());
131 NLSR_LOG_TRACE(npte->getNamePrefix() <<
" has no next hops; removing from FIB");
137 rtpePtr->namePrefixTableEntries.emplace(
138 std::make_pair(npte->getNamePrefix(), std::weak_ptr<NamePrefixTableEntry>(npte)));
144 NLSR_LOG_DEBUG(
"Removing origin: " << destRouter <<
" from " << name);
147 RoutingTableEntryPool::iterator rtpeItr = m_rtpool.find(destRouter);
151 if (rtpeItr == m_rtpool.end()) {
153 <<
" found, so it cannot be removed from prefix: "
157 std::shared_ptr<RoutingTablePoolEntry> rtpePtr = rtpeItr->second;
160 NptEntryList::iterator nameItr =
161 std::find_if(m_table.begin(), m_table.end(),
162 [&] (
const std::shared_ptr<NamePrefixTableEntry>& entry) {
163 return entry->getNamePrefix() == name;
165 if (nameItr != m_table.end()) {
167 <<
" from prefix: " << **nameItr);
171 if ((*nameItr)->removeRoutingTableEntry(rtpePtr) == 0) {
190 if ((*nameItr)->getRteListSize() == 0) {
192 <<
" removing from table and FIB");
193 m_table.erase(nameItr);
198 <<
" updating FIB with next hops");
199 (*nameItr)->generateNhlfromRteList();
200 m_fib.
update(name, (*nameItr)->getNexthopList());
204 NLSR_LOG_DEBUG(
"Attempted to remove origin: " << rtpePtr->getDestination()
205 <<
" from non-existent prefix: " << name);
215 for (
auto&& poolEntryPair : m_rtpool) {
216 auto&& poolEntry = poolEntryPair.second;
217 auto sourceEntry = std::find_if(entries.begin(), entries.end(),
219 return poolEntry->getDestination() == entry.getDestination();
222 if (sourceEntry != entries.end()
223 && poolEntry->getNexthopList() != sourceEntry->getNexthopList()) {
224 NLSR_LOG_DEBUG(
"Routing entry: " << poolEntry->getDestination() <<
" has changed next-hops.");
225 poolEntry->setNexthopList(sourceEntry->getNexthopList());
226 for (
const auto& nameEntry : poolEntry->namePrefixTableEntries) {
227 auto nameEntryFullPtr = nameEntry.second.lock();
228 addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination());
231 else if (sourceEntry == entries.end()) {
232 NLSR_LOG_DEBUG(
"Routing entry: " << poolEntry->getDestination() <<
" now has no next-hops.");
233 poolEntry->getNexthopList().clear();
234 for (
const auto& nameEntry : poolEntry->namePrefixTableEntries) {
235 auto nameEntryFullPtr = nameEntry.second.lock();
236 addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination());
240 NLSR_LOG_TRACE(
"No change in routing entry:" << poolEntry->getDestination()
241 <<
", no action necessary.");
249 std::shared_ptr<RoutingTablePoolEntry>
252 RoutingTableEntryPool::iterator poolItr =
254 std::make_shared<RoutingTablePoolEntry>
257 return poolItr->second;
269 if (m_rtpool.erase(rtpePtr->getDestination()) != 1) {
271 << rtpePtr->getDestination()
272 <<
" from NPT routing table entry storage pool.");
285 os <<
"----------------NPT----------------------\n";
287 for (
const auto& entryPtr : table) {
288 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.
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.
NamePrefixTable(Fib &fib, RoutingTable &routingTable, std::unique_ptr< AfterRoutingChange > &afterRoutingChangeSignal)
void updateWithNewRoute(const std::list< RoutingTableEntry > &entries)
Updates all routing information in the NPT.
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)