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 | /* |
awlane | 6d7c37f | 2025-03-07 11:53:58 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2025, 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 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 22 | #ifndef NLSR_NAME_PREFIX_TABLE_ENTRY_HPP |
| 23 | #define NLSR_NAME_PREFIX_TABLE_ENTRY_HPP |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 24 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 25 | #include "routing-table-pool-entry.hpp" |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 26 | #include "test-access-control.hpp" |
awlane | 6d7c37f | 2025-03-07 11:53:58 -0600 | [diff] [blame] | 27 | #include "nexthop.hpp" |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 28 | |
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 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 34 | class NamePrefixTableEntry |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 35 | { |
| 36 | public: |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 37 | NamePrefixTableEntry() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 38 | { |
| 39 | } |
| 40 | |
awlane | fc0b45a | 2025-05-07 15:51:02 -0500 | [diff] [blame^] | 41 | NamePrefixTableEntry(const ndn::Name& namePrefix, uint64_t routeFlags) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 42 | : m_namePrefix(namePrefix) |
awlane | fc0b45a | 2025-05-07 15:51:02 -0500 | [diff] [blame^] | 43 | , m_flags(routeFlags) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 44 | , m_nexthopList() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 45 | { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 46 | } |
| 47 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 48 | const ndn::Name& |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 49 | getNamePrefix() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 50 | { |
| 51 | return m_namePrefix; |
| 52 | } |
| 53 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 54 | const std::list<std::shared_ptr<RoutingTablePoolEntry>>& |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 55 | getRteList() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 56 | { |
| 57 | return m_rteList; |
| 58 | } |
| 59 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 60 | /*! \brief Resets the next hop lists of all routing table entries |
| 61 | * that advertise this name prefix. |
| 62 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 63 | void |
| 64 | resetRteListNextHop() |
| 65 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 66 | if (m_rteList.size() > 0) { |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 67 | for (auto it = m_rteList.begin(); it != m_rteList.end(); ++it) { |
Ashlesh Gawande | 0421bc6 | 2020-05-08 20:42:19 -0700 | [diff] [blame] | 68 | (*it)->getNexthopList().clear(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 73 | size_t |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 74 | getRteListSize() |
| 75 | { |
| 76 | return m_rteList.size(); |
| 77 | } |
| 78 | |
Ashlesh Gawande | e8d8bd5 | 2018-08-09 17:18:51 -0500 | [diff] [blame] | 79 | const NexthopList& |
| 80 | getNexthopList() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 81 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 82 | return m_nexthopList; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 83 | } |
| 84 | |
awlane | 6d7c37f | 2025-03-07 11:53:58 -0600 | [diff] [blame] | 85 | NexthopList& |
| 86 | getNexthopListForModification() |
| 87 | { |
| 88 | return m_nexthopList; |
| 89 | } |
| 90 | |
awlane | fc0b45a | 2025-05-07 15:51:02 -0500 | [diff] [blame^] | 91 | void |
| 92 | setFlags(uint64_t flags) |
| 93 | { |
| 94 | m_flags = flags; |
| 95 | } |
| 96 | |
| 97 | uint64_t |
| 98 | getFlags() const |
| 99 | { |
| 100 | return m_flags; |
| 101 | } |
| 102 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 103 | /*! \brief Collect all next-hops that are advertised by this entry's |
| 104 | * routing entries. |
| 105 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 106 | void |
| 107 | generateNhlfromRteList(); |
| 108 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 109 | /*! \brief Removes a routing entry from this NPT entry. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 110 | * \return The number of NPTs using the just-removed routing entry. |
| 111 | */ |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 112 | uint64_t |
| 113 | removeRoutingTableEntry(std::shared_ptr<RoutingTablePoolEntry> rtpePtr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 114 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 115 | /*! \brief Adds a routing entry to this NPT entry. |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 116 | * \param rtpePtr The routing entry. |
| 117 | * |
| 118 | * Adds a routing table pool entry to this NPT entry's list |
| 119 | * (reminder: each RTPE has a next-hop list). They are used to |
| 120 | * calculate this entry's overall next-hop list. |
| 121 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 122 | void |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 123 | addRoutingTableEntry(std::shared_ptr<RoutingTablePoolEntry> rtpePtr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 124 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 125 | void |
| 126 | writeLog(); |
| 127 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 128 | private: |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 129 | ndn::Name m_namePrefix; |
awlane | fc0b45a | 2025-05-07 15:51:02 -0500 | [diff] [blame^] | 130 | uint64_t m_flags; |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 131 | |
| 132 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 133 | std::list<std::shared_ptr<RoutingTablePoolEntry>> m_rteList; |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 134 | NexthopList m_nexthopList; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 135 | }; |
| 136 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 137 | bool |
| 138 | operator==(const NamePrefixTableEntry& lhs, const NamePrefixTableEntry& rhs); |
| 139 | |
| 140 | bool |
| 141 | operator==(const NamePrefixTableEntry& lhs, const ndn::Name& rhs); |
| 142 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 143 | std::ostream& |
| 144 | operator<<(std::ostream& os, const NamePrefixTableEntry& entry); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 145 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 146 | } // namespace nlsr |
| 147 | |
| 148 | #endif // NLSR_NAME_PREFIX_TABLE_ENTRY_HPP |