akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame^] | 2 | /* |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2020, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame^] | 20 | */ |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 21 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 22 | #include "name-prefix-table.hpp" |
| 23 | |
| 24 | #include "logger.hpp" |
| 25 | #include "nlsr.hpp" |
| 26 | #include "routing-table.hpp" |
| 27 | |
| 28 | #include <algorithm> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 29 | #include <list> |
| 30 | #include <utility> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 31 | |
| 32 | namespace nlsr { |
| 33 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 34 | INIT_LOGGER(route.NamePrefixTable); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 35 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 36 | NamePrefixTable::NamePrefixTable(Fib& fib, RoutingTable& routingTable, |
Nick Gordon | d40a588 | 2017-09-05 15:34:58 -0500 | [diff] [blame] | 37 | std::unique_ptr<AfterRoutingChange>& afterRoutingChangeSignal) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 38 | : m_fib(fib) |
| 39 | , m_routingTable(routingTable) |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 40 | { |
| 41 | m_afterRoutingChangeConnection = afterRoutingChangeSignal->connect( |
| 42 | [this] (const std::list<RoutingTableEntry>& entries) { |
| 43 | updateWithNewRoute(entries); |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | NamePrefixTable::~NamePrefixTable() |
| 48 | { |
| 49 | m_afterRoutingChangeConnection.disconnect(); |
| 50 | } |
| 51 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 52 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 53 | NamePrefixTable::addEntry(const ndn::Name& name, const ndn::Name& destRouter) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 54 | { |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 55 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 56 | // Check if the advertised name prefix is in the table already. |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 57 | NptEntryList::iterator nameItr = |
| 58 | std::find_if(m_table.begin(), |
| 59 | m_table.end(), |
| 60 | [&] (const std::shared_ptr<NamePrefixTableEntry>& entry) { |
| 61 | return name == entry->getNamePrefix(); |
| 62 | }); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 63 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 64 | // Attempt to find a routing table pool entry (RTPE) we can use. |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 65 | RoutingTableEntryPool::iterator rtpeItr = m_rtpool.find(destRouter); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 66 | |
| 67 | // These declarations just to make the compiler happy... |
| 68 | RoutingTablePoolEntry rtpe; |
| 69 | std::shared_ptr<RoutingTablePoolEntry> rtpePtr(nullptr); |
| 70 | |
| 71 | // There isn't currently a routing table entry in the pool for this name |
| 72 | if (rtpeItr == m_rtpool.end()) { |
| 73 | // See if there is a routing table entry available we could use |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 74 | RoutingTableEntry* routeEntryPtr = m_routingTable.findRoutingTableEntry(destRouter); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 75 | |
| 76 | // We have to create a new routing table entry |
| 77 | if (routeEntryPtr == nullptr) { |
| 78 | rtpe = RoutingTablePoolEntry(destRouter, 0); |
| 79 | } |
| 80 | // There was already a usable one in the routing table |
| 81 | else { |
| 82 | rtpe = RoutingTablePoolEntry(*routeEntryPtr, 0); |
| 83 | } |
| 84 | |
| 85 | // Add the new pool object to the pool. |
| 86 | rtpePtr = addRtpeToPool(rtpe); |
| 87 | } |
| 88 | // There was one already, so just fetch that one. |
| 89 | else { |
| 90 | rtpePtr = (*rtpeItr).second; |
| 91 | } |
| 92 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 93 | std::shared_ptr<NamePrefixTableEntry> npte; |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 94 | // Either we have to make a new NPT entry or there already was one. |
| 95 | if (nameItr == m_table.end()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 96 | NLSR_LOG_DEBUG("Adding origin: " << rtpePtr->getDestination() |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 97 | << " to a new name prefix: " << name); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 98 | npte = make_shared<NamePrefixTableEntry>(name); |
| 99 | npte->addRoutingTableEntry(rtpePtr); |
| 100 | npte->generateNhlfromRteList(); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 101 | m_table.push_back(npte); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 102 | // If this entry has next hops, we need to inform the FIB |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 103 | if (npte->getNexthopList().size() > 0) { |
Ashlesh Gawande | e8d8bd5 | 2018-08-09 17:18:51 -0500 | [diff] [blame] | 104 | NLSR_LOG_TRACE("Updating FIB with next hops for " << npte->getNamePrefix()); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 105 | m_fib.update(name, npte->getNexthopList()); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 106 | } |
| 107 | // The routing table may recalculate and add a routing table entry |
| 108 | // with no next hops to replace an existing routing table entry. In |
| 109 | // this case, the name prefix is no longer reachable through a next |
| 110 | // hop and should be removed from the FIB. But, the prefix should |
| 111 | // remain in the Name Prefix Table as a future routing table |
| 112 | // calculation may add next hops. |
| 113 | else { |
Ashlesh Gawande | e8d8bd5 | 2018-08-09 17:18:51 -0500 | [diff] [blame] | 114 | NLSR_LOG_TRACE(npte->getNamePrefix() << " has no next hops; removing from FIB"); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 115 | m_fib.remove(name); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 116 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 117 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 118 | else { |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 119 | npte = *nameItr; |
Ashlesh Gawande | e5002b3 | 2018-12-20 21:07:31 -0600 | [diff] [blame] | 120 | NLSR_LOG_TRACE("Adding origin: " << rtpePtr->getDestination() << |
| 121 | " to existing prefix: " << **nameItr); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 122 | (*nameItr)->addRoutingTableEntry(rtpePtr); |
| 123 | (*nameItr)->generateNhlfromRteList(); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 124 | |
Nick Gordon | ff9a627 | 2017-10-12 13:38:29 -0500 | [diff] [blame] | 125 | if ((*nameItr)->getNexthopList().size() > 0) { |
Ashlesh Gawande | e5002b3 | 2018-12-20 21:07:31 -0600 | [diff] [blame] | 126 | NLSR_LOG_TRACE("Updating FIB with next hops for " << (**nameItr)); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 127 | m_fib.update(name, (*nameItr)->getNexthopList()); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 128 | } |
| 129 | else { |
Ashlesh Gawande | e8d8bd5 | 2018-08-09 17:18:51 -0500 | [diff] [blame] | 130 | NLSR_LOG_TRACE(npte->getNamePrefix() << " has no next hops; removing from FIB"); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 131 | m_fib.remove(name); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 132 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 133 | } |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 134 | // Add the reference to this NPT to the RTPE. |
| 135 | rtpePtr->namePrefixTableEntries.emplace( |
| 136 | std::make_pair(npte->getNamePrefix(), std::weak_ptr<NamePrefixTableEntry>(npte))); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 140 | NamePrefixTable::removeEntry(const ndn::Name& name, const ndn::Name& destRouter) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 141 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 142 | NLSR_LOG_DEBUG("Removing origin: " << destRouter << " from " << name); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 143 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 144 | // Fetch an iterator to the appropriate pair object in the pool. |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 145 | RoutingTableEntryPool::iterator rtpeItr = m_rtpool.find(destRouter); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 146 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 147 | // Simple error checking to prevent any unusual behavior in the case |
| 148 | // that we try to remove an entry that isn't there. |
| 149 | if (rtpeItr == m_rtpool.end()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 150 | NLSR_LOG_DEBUG("No entry for origin: " << destRouter |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 151 | << " found, so it cannot be removed from prefix: " |
| 152 | << name); |
| 153 | return; |
| 154 | } |
| 155 | std::shared_ptr<RoutingTablePoolEntry> rtpePtr = rtpeItr->second; |
| 156 | |
| 157 | // Ensure that the entry exists |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 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; |
| 162 | }); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 163 | if (nameItr != m_table.end()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 164 | NLSR_LOG_TRACE("Removing origin: " << rtpePtr->getDestination() |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 165 | << " from prefix: " << **nameItr); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 166 | |
| 167 | // Rather than iterating through the whole list periodically, just |
| 168 | // delete them here if they have no references. |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 169 | if ((*nameItr)->removeRoutingTableEntry(rtpePtr) == 0) { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 170 | deleteRtpeFromPool(rtpePtr); |
| 171 | } |
| 172 | |
| 173 | // If the prefix is a router prefix and it does not have any other |
| 174 | // routing table entries, the Adjacency/Coordinate LSA associated |
| 175 | // with that origin router has been removed from the LSDB and so |
| 176 | // the router prefix should be removed from the Name Prefix Table. |
| 177 | // |
| 178 | // If the prefix is an advertised name prefix: If another router |
| 179 | // advertises this name prefix, the RteList should have another |
| 180 | // entry for that router; the next hops should be recalculated |
| 181 | // and installed in the FIB. |
| 182 | // |
| 183 | // If no other router advertises this name prefix, the RteList |
| 184 | // should be empty and the prefix can be removed from the Name |
| 185 | // Prefix Table. Once a new Name LSA advertises this prefix, a |
| 186 | // new entry for the prefix will be created. |
| 187 | // |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 188 | if ((*nameItr)->getRteListSize() == 0) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 189 | NLSR_LOG_TRACE(**nameItr << " has no routing table entries;" |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 190 | << " removing from table and FIB"); |
| 191 | m_table.erase(nameItr); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 192 | m_fib.remove(name); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 193 | } |
| 194 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 195 | NLSR_LOG_TRACE(**nameItr << " has other routing table entries;" |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 196 | << " updating FIB with next hops"); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 197 | (*nameItr)->generateNhlfromRteList(); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 198 | m_fib.update(name, (*nameItr)->getNexthopList()); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 199 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 200 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 201 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 202 | NLSR_LOG_DEBUG("Attempted to remove origin: " << rtpePtr->getDestination() |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 203 | << " from non-existent prefix: " << name); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
| 207 | void |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 208 | NamePrefixTable::updateWithNewRoute(const std::list<RoutingTableEntry>& entries) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 209 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 210 | NLSR_LOG_DEBUG("Updating table with newly calculated routes"); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 211 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 212 | // Iterate over each pool entry we have |
| 213 | for (auto&& poolEntryPair : m_rtpool) { |
| 214 | auto&& poolEntry = poolEntryPair.second; |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 215 | auto sourceEntry = std::find_if(entries.begin(), entries.end(), |
| 216 | [&poolEntry] (const RoutingTableEntry& entry) { |
| 217 | return poolEntry->getDestination() == entry.getDestination(); |
| 218 | }); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 219 | // If this pool entry has a corresponding entry in the routing table now |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 220 | if (sourceEntry != entries.end() |
| 221 | && poolEntry->getNexthopList() != sourceEntry->getNexthopList()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 222 | NLSR_LOG_DEBUG("Routing entry: " << poolEntry->getDestination() << " has changed next-hops."); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 223 | poolEntry->setNexthopList(sourceEntry->getNexthopList()); |
| 224 | for (const auto& nameEntry : poolEntry->namePrefixTableEntries) { |
| 225 | auto nameEntryFullPtr = nameEntry.second.lock(); |
| 226 | addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination()); |
| 227 | } |
| 228 | } |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 229 | else if (sourceEntry == entries.end()) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 230 | NLSR_LOG_DEBUG("Routing entry: " << poolEntry->getDestination() << " now has no next-hops."); |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame^] | 231 | poolEntry->getNexthopList().clear(); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 232 | for (const auto& nameEntry : poolEntry->namePrefixTableEntries) { |
| 233 | auto nameEntryFullPtr = nameEntry.second.lock(); |
| 234 | addEntry(nameEntryFullPtr->getNamePrefix(), poolEntry->getDestination()); |
| 235 | } |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 236 | } |
| 237 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 238 | NLSR_LOG_TRACE("No change in routing entry:" << poolEntry->getDestination() |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 239 | << ", no action necessary."); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 244 | // Inserts the routing table pool entry into the NPT's RTE storage |
| 245 | // pool. This cannot fail, so the pool is guaranteed to contain the |
| 246 | // item after this occurs. |
| 247 | std::shared_ptr<RoutingTablePoolEntry> |
| 248 | NamePrefixTable::addRtpeToPool(RoutingTablePoolEntry& rtpe) |
| 249 | { |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 250 | RoutingTableEntryPool::iterator poolItr = |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 251 | m_rtpool.insert(std::make_pair(rtpe.getDestination(), |
| 252 | std::make_shared<RoutingTablePoolEntry> |
| 253 | (rtpe))) |
| 254 | .first; |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 255 | return poolItr->second; |
| 256 | } |
| 257 | |
| 258 | // Removes the routing table pool entry from the storage pool. The |
| 259 | // postconditions of this function are guaranteed to include that |
| 260 | // the storage pool does not contain such an item. Additionally, |
| 261 | // this function cannot fail, but nonetheless debug information is |
| 262 | // given in the case that this function is called with an entry that |
| 263 | // isn't in the pool. |
| 264 | void |
| 265 | NamePrefixTable::deleteRtpeFromPool(std::shared_ptr<RoutingTablePoolEntry> rtpePtr) |
| 266 | { |
| 267 | if (m_rtpool.erase(rtpePtr->getDestination()) != 1) { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 268 | NLSR_LOG_DEBUG("Attempted to delete non-existent origin: " |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 269 | << rtpePtr->getDestination() |
| 270 | << " from NPT routing table entry storage pool."); |
| 271 | } |
| 272 | } |
| 273 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 274 | void |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 275 | NamePrefixTable::writeLog() |
| 276 | { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 277 | NLSR_LOG_DEBUG(*this); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 278 | } |
| 279 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 280 | std::ostream& |
| 281 | operator<<(std::ostream& os, const NamePrefixTable& table) |
| 282 | { |
| 283 | os << "----------------NPT----------------------\n"; |
| 284 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 285 | for (const auto& entryPtr : table) { |
| 286 | os << *entryPtr << std::endl; |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | return os; |
| 290 | } |
| 291 | |
| 292 | } // namespace nlsr |