akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Muktadir R Chowdhury | 800833b | 2016-07-29 13:43:59 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, 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/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [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 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 30 | INIT_LOGGER("NamePrefixTableEntry"); |
| 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 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 35 | m_nexthopList.reset(); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame^] | 36 | for (auto rtpeItr = m_rteList.begin(); rtpeItr != m_rteList.end(); ++rtpeItr) { |
| 37 | for (auto nhItr = (*rtpeItr)->getNexthopList().getNextHops().begin(); |
| 38 | nhItr != (*rtpeItr)->getNexthopList().getNextHops().end(); |
| 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 |
| 46 | NamePrefixTableEntry::removeRoutingTableEntry(shared_ptr<RoutingTablePoolEntry> |
| 47 | rtpePtr) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 48 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame^] | 49 | auto rtpeItr = std::find(m_rteList.begin(), m_rteList.end(), rtpePtr); |
| 50 | |
| 51 | if (rtpeItr != m_rteList.end()) { |
| 52 | (*rtpeItr)->decrementUseCount(); |
| 53 | m_rteList.erase(rtpeItr); |
| 54 | } |
| 55 | else { |
| 56 | _LOG_ERROR("Routing entry for: " << rtpePtr->getDestination() |
| 57 | << " not found in NPT entry: " << getNamePrefix()); |
| 58 | } |
| 59 | return (*rtpeItr)->getUseCount(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame^] | 63 | NamePrefixTableEntry::addRoutingTableEntry(shared_ptr<RoutingTablePoolEntry> |
| 64 | rtpePtr) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 65 | { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame^] | 66 | auto rtpeItr = std::find(m_rteList.begin(), m_rteList.end(), rtpePtr); |
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 |
| 69 | if (rtpeItr == m_rteList.end()) { |
| 70 | // Adding a new routing entry to the NPT entry |
| 71 | rtpePtr->incrementUseCount(); |
| 72 | m_rteList.push_back(rtpePtr); |
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 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 79 | void |
| 80 | NamePrefixTableEntry::writeLog() |
| 81 | { |
| 82 | _LOG_DEBUG("Name: " << m_namePrefix); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame^] | 83 | for (auto it = m_rteList.begin(); it != m_rteList.end(); ++it) { |
| 84 | _LOG_DEBUG("Destination: " << (*it)->getDestination()); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 85 | _LOG_DEBUG("Nexthops: "); |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame^] | 86 | (*it)->getNexthopList().writeLog(); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 87 | } |
| 88 | m_nexthopList.writeLog(); |
| 89 | } |
| 90 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame^] | 91 | bool |
| 92 | operator==(const NamePrefixTableEntry& lhs, const NamePrefixTableEntry& rhs) |
| 93 | { |
| 94 | return (lhs.getNamePrefix() == rhs.getNamePrefix()); |
| 95 | } |
| 96 | |
| 97 | bool |
| 98 | operator==(const NamePrefixTableEntry& lhs, const ndn::Name& rhs) |
| 99 | { |
| 100 | return (lhs.getNamePrefix() == rhs); |
| 101 | } |
| 102 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 103 | std::ostream& |
| 104 | operator<<(std::ostream& os, const NamePrefixTableEntry& entry) |
| 105 | { |
| 106 | os << "Name: " << entry.getNamePrefix() << "\n"; |
| 107 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame^] | 108 | for (const shared_ptr<RoutingTablePoolEntry> rtpePtr : entry.getRteList()) { |
| 109 | os << "Destination: " << rtpePtr->getDestination() << "\n"; |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | return os; |
| 113 | } |
| 114 | |
| 115 | } // namespace nlsr |