akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2014-2021, 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 | 5d93aa5 | 2020-06-13 18:57:45 -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_HPP |
| 23 | #define NLSR_NAME_PREFIX_TABLE_HPP |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 24 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 25 | #include "name-prefix-table-entry.hpp" |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 26 | #include "routing-table-pool-entry.hpp" |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 27 | #include "signals.hpp" |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 28 | #include "test-access-control.hpp" |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 29 | #include "route/fib.hpp" |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 30 | #include "lsdb.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 31 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 32 | #include <list> |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 33 | #include <unordered_map> |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 34 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 35 | namespace nlsr { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 36 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 37 | class NamePrefixTable |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 38 | { |
| 39 | public: |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 40 | using RoutingTableEntryPool = |
| 41 | std::unordered_map<ndn::Name, std::shared_ptr<RoutingTablePoolEntry>>; |
| 42 | using NptEntryList = std::list<std::shared_ptr<NamePrefixTableEntry>>; |
| 43 | using const_iterator = NptEntryList::const_iterator; |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 44 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 45 | NamePrefixTable(const ndn::Name& ownRouterName, Fib& fib, RoutingTable& routingTable, |
| 46 | AfterRoutingChange& afterRoutingChangeSignal, |
| 47 | Lsdb::AfterLsdbModified& afterLsdbModifiedSignal); |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 48 | |
| 49 | ~NamePrefixTable(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 50 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 51 | /*! \brief Add, update, or remove Names according to the Lsdb update |
| 52 | \param lsa The LSA class pointer |
| 53 | \param updateType Update type from Lsdb (INSTALLED, UPDATED, REMOVED) |
| 54 | \param namesToAdd If LSA is UPDATED, then these are the names to add |
| 55 | \param namesToRemove If LSA is UPDATED, then these are the names to remove |
| 56 | */ |
| 57 | void |
| 58 | updateFromLsdb(std::shared_ptr<Lsa> lsa, LsdbUpdate updateType, |
| 59 | const std::list<ndn::Name>& namesToAdd, |
| 60 | const std::list<ndn::Name>& namesToRemove); |
| 61 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 62 | /*! \brief Adds a destination to the specified name prefix. |
| 63 | \param name The name prefix |
| 64 | \param destRouter The destination router prefix |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 65 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 66 | This method adds a router to a name prefix table entry. If the |
| 67 | name prefix table entry does not exist, it is created. The method |
| 68 | will first look through its local pool of cached entries to find |
| 69 | the routing information for destRouter. If it is not found there, |
| 70 | it will construct one and fill it with information from an |
| 71 | appropriate RoutingTableEntry in the routing table. If there isn't |
| 72 | a match, it will instantiate it with no next hops. The FIB will be |
| 73 | notified of the change to the NPT entry, too. |
| 74 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 75 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 76 | addEntry(const ndn::Name& name, const ndn::Name& destRouter); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 77 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 78 | /*! \brief Removes a destination from a name prefix table entry. |
| 79 | \param name The name prefix |
| 80 | \param destRouter The destination. |
| 81 | |
| 82 | This method removes a destination from an entry. It will not fail |
| 83 | if an invalid name/destination pair are passed. After removal, if |
| 84 | the RoutingTablePoolEntry has a use count of 0, it is deleted from |
| 85 | the table. Additionally, if the name prefix has no routing table |
| 86 | entries associated with it, it is deleted from the NPT. In any |
| 87 | case, the FIB is informed of the changes. |
| 88 | */ |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 89 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 90 | removeEntry(const ndn::Name& name, const ndn::Name& destRouter); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 91 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 92 | /*! \brief Updates all routing information in the NPT. |
| 93 | |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 94 | Takes in a list of entries that are assumed to be exhaustive, and |
| 95 | updates each pool entry with the next hop information contained in |
| 96 | the corresponding entry in entries. If no entry is found, it is |
| 97 | assumed that the destination for that pool entry is inaccessible, |
| 98 | and its next hop information is deleted. |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 99 | */ |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 100 | void |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 101 | updateWithNewRoute(const std::list<RoutingTableEntry>& entries); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 102 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 103 | /*! \brief Adds a pool entry to the pool. |
| 104 | \param rtpe The entry. |
| 105 | |
| 106 | \return A shared_ptr to the entry, now in the pool. |
| 107 | |
| 108 | Adds a RoutingTablePoolEntry to the NPT's local pool. Shared |
| 109 | pointers are used because it eliminates complicated hacks to deal |
| 110 | with lifetime issues, and to simplify memory management. |
| 111 | */ |
| 112 | std::shared_ptr<RoutingTablePoolEntry> |
| 113 | addRtpeToPool(RoutingTablePoolEntry& rtpe); |
| 114 | |
| 115 | /*! \brief Removes a pool entry from the pool. |
| 116 | \param rtpePtr The shared_ptr to the entry. |
| 117 | |
| 118 | Removes a pool entry from the pool. Comparing these shared_ptrs |
| 119 | should not be a problem, because the same pointer is moved around, |
| 120 | all sourced from this central location. A more robust solution is |
| 121 | certainly possible, though. |
| 122 | */ |
| 123 | void |
| 124 | deleteRtpeFromPool(std::shared_ptr<RoutingTablePoolEntry> rtpePtr); |
| 125 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 126 | void |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 127 | writeLog(); |
| 128 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 129 | const_iterator |
| 130 | begin() const; |
| 131 | |
| 132 | const_iterator |
| 133 | end() const; |
| 134 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 135 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 136 | RoutingTableEntryPool m_rtpool; |
| 137 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 138 | NptEntryList m_table; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 139 | |
| 140 | private: |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 141 | const ndn::Name& m_ownRouterName; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 142 | Fib& m_fib; |
| 143 | RoutingTable& m_routingTable; |
Nick Gordon | b7b5839 | 2017-08-17 16:29:21 -0500 | [diff] [blame] | 144 | ndn::util::signal::Connection m_afterRoutingChangeConnection; |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 145 | ndn::util::signal::Connection m_afterLsdbModified; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 146 | }; |
| 147 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 148 | inline NamePrefixTable::const_iterator |
| 149 | NamePrefixTable::begin() const |
| 150 | { |
| 151 | return m_table.begin(); |
| 152 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 153 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 154 | inline NamePrefixTable::const_iterator |
| 155 | NamePrefixTable::end() const |
| 156 | { |
| 157 | return m_table.end(); |
| 158 | } |
| 159 | |
| 160 | std::ostream& |
| 161 | operator<<(std::ostream& os, const NamePrefixTable& table); |
| 162 | |
| 163 | } // namespace nlsr |
| 164 | |
| 165 | #endif // NLSR_NAME_PREFIX_TABLE_HPP |