akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 4b9d30f | 2020-05-01 02:48:34 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2020, The University of Memphis, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [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 | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 21 | |
| 22 | #include "name-prefix-table-entry.hpp" |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 23 | |
| 24 | #include "common.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 25 | #include "nexthop.hpp" |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 26 | #include "logger.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 27 | |
| 28 | namespace nlsr { |
| 29 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 30 | INIT_LOGGER(route.NamePrefixTableEntry); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 31 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 32 | void |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 33 | NamePrefixTableEntry::generateNhlfromRteList() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | { |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 35 | m_nexthopList.clear(); |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 36 | for (auto iterator = m_rteList.begin(); iterator != m_rteList.end(); ++iterator) { |
| 37 | for (auto nhItr = (*iterator)->getNexthopList().getNextHops().begin(); |
| 38 | nhItr != (*iterator)->getNexthopList().getNextHops().end(); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 39 | ++nhItr) { |
| 40 | m_nexthopList.addNextHop((*nhItr)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 45 | uint64_t |
Davide Pesavento | 4b9d30f | 2020-05-01 02:48:34 -0400 | [diff] [blame] | 46 | NamePrefixTableEntry::removeRoutingTableEntry(std::shared_ptr<RoutingTablePoolEntry> entryPtr) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 47 | { |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 48 | auto iterator = std::find(m_rteList.begin(), m_rteList.end(), entryPtr); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 49 | |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 50 | if (iterator != m_rteList.end()) { |
| 51 | (*iterator)->decrementUseCount(); |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 52 | // Remove this NamePrefixEntry from the RoutingTablePoolEntry |
| 53 | (*iterator)->namePrefixTableEntries.erase(getNamePrefix()); |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 54 | m_rteList.erase(iterator); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 55 | } |
| 56 | else { |
dmcoomes | 5bcb39e | 2017-10-31 15:07:55 -0500 | [diff] [blame] | 57 | NLSR_LOG_ERROR("Routing entry for: " << entryPtr->getDestination() |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 58 | << " not found in NPT entry: " << getNamePrefix()); |
| 59 | } |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 60 | return entryPtr->getUseCount(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void |
Davide Pesavento | 4b9d30f | 2020-05-01 02:48:34 -0400 | [diff] [blame] | 64 | NamePrefixTableEntry::addRoutingTableEntry(std::shared_ptr<RoutingTablePoolEntry> entryPtr) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 65 | { |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 66 | auto iterator = std::find(m_rteList.begin(), m_rteList.end(), entryPtr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 67 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 68 | // Ensure that this is a new entry |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 69 | if (iterator == m_rteList.end()) { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 70 | // Adding a new routing entry to the NPT entry |
Ashlesh Gawande | 90173ad | 2017-08-09 15:19:50 -0500 | [diff] [blame] | 71 | entryPtr->incrementUseCount(); |
| 72 | m_rteList.push_back(entryPtr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 73 | } |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 74 | // Note: we don't need to update in the else case because these are |
| 75 | // pointers, and they are centrally-located in the NPT and will all |
| 76 | // be updated there. |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 77 | } |
| 78 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 79 | bool |
| 80 | operator==(const NamePrefixTableEntry& lhs, const NamePrefixTableEntry& rhs) |
| 81 | { |
Davide Pesavento | 4b9d30f | 2020-05-01 02:48:34 -0400 | [diff] [blame] | 82 | return lhs.getNamePrefix() == rhs.getNamePrefix(); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | bool |
| 86 | operator==(const NamePrefixTableEntry& lhs, const ndn::Name& rhs) |
| 87 | { |
Davide Pesavento | 4b9d30f | 2020-05-01 02:48:34 -0400 | [diff] [blame] | 88 | return lhs.getNamePrefix() == rhs; |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 89 | } |
| 90 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 91 | std::ostream& |
| 92 | operator<<(std::ostream& os, const NamePrefixTableEntry& entry) |
| 93 | { |
| 94 | os << "Name: " << entry.getNamePrefix() << "\n"; |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 95 | |
Davide Pesavento | 4b9d30f | 2020-05-01 02:48:34 -0400 | [diff] [blame] | 96 | for (const auto& entryPtr : entry.getRteList()) { |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 97 | os << " Destination: " << entryPtr->getDestination() << "\n"; |
| 98 | os << entryPtr->getNexthopList(); |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 99 | } |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 100 | return os; |
| 101 | } |
| 102 | |
| 103 | } // namespace nlsr |