Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | c6a8522 | 2017-01-03 16:54:34 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 4 | * Regents of the University of California |
| 5 | * |
| 6 | * This file is part of NLSR (Named-data Link State Routing). |
| 7 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 8 | * |
| 9 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 10 | * of the GNU General Public License as published by the Free Software Foundation, |
| 11 | * either version 3 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 14 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 20 | **/ |
| 21 | |
| 22 | #ifndef NLSR_ROUTING_TABLE_POOL_ENTRY_HPP |
| 23 | #define NLSR_ROUTING_TABLE_POOL_ENTRY_HPP |
| 24 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 25 | #include "routing-table-entry.hpp" |
| 26 | #include "nexthop-list.hpp" |
| 27 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 28 | #include <iostream> |
| 29 | #include <ndn-cxx/name.hpp> |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 30 | #include <unordered_map> |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 31 | |
| 32 | namespace nlsr { |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 33 | |
| 34 | /*! \brief A deduplication system for the NamePrefixTable |
| 35 | * |
| 36 | * The NamePrefixTable associates name prefixes to a router. To do |
| 37 | * this, it needs to know if certain routers are reachable. This in |
| 38 | * turn requires access to entries from the RoutingTable, which are |
| 39 | * associated with name prefixes. Doing this naively copies the entry |
| 40 | * from the RoutingTable each time, which is costly. This class |
| 41 | * provides a deduplication system where the NamePrefixTable can |
| 42 | * maintain a collection of RoutingTablePoolEntries. Then, this new |
| 43 | * class can be associated with the name prefixes instead of the |
| 44 | * original entries, which provides a minimal memory solution. |
| 45 | * \sa NamePrefixTable |
| 46 | */ |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 47 | class NamePrefixTableEntry; |
| 48 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 49 | class RoutingTablePoolEntry : public RoutingTableEntry |
| 50 | { |
| 51 | public: |
| 52 | RoutingTablePoolEntry() |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | ~RoutingTablePoolEntry() |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | RoutingTablePoolEntry(const ndn::Name& dest) |
| 61 | { |
| 62 | m_destination = dest; |
| 63 | m_useCount = 1; |
| 64 | } |
| 65 | |
| 66 | RoutingTablePoolEntry(RoutingTableEntry& rte, uint64_t useCount) |
| 67 | { |
| 68 | m_destination = rte.getDestination(); |
| 69 | m_nexthopList = rte.getNexthopList(); |
| 70 | m_useCount = useCount; |
| 71 | } |
| 72 | |
| 73 | RoutingTablePoolEntry(const ndn::Name& dest, uint64_t useCount) |
| 74 | { |
| 75 | m_destination = dest; |
| 76 | m_useCount = useCount; |
| 77 | } |
| 78 | |
| 79 | uint64_t |
| 80 | getUseCount() |
| 81 | { |
| 82 | return m_useCount; |
| 83 | } |
| 84 | |
| 85 | uint64_t |
| 86 | incrementUseCount() |
| 87 | { |
| 88 | return ++m_useCount; |
| 89 | } |
| 90 | |
| 91 | uint64_t |
| 92 | decrementUseCount() |
| 93 | { |
| 94 | if (m_useCount != 0) { |
| 95 | return --m_useCount; |
| 96 | } |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | void |
| 101 | setNexthopList(NexthopList nhl) |
| 102 | { |
| 103 | m_nexthopList = nhl; |
| 104 | } |
| 105 | |
Nick Gordon | c0c6bcf | 2017-08-15 18:11:21 -0500 | [diff] [blame] | 106 | public: |
| 107 | std::unordered_map<ndn::Name, std::weak_ptr<NamePrefixTableEntry>> |
| 108 | namePrefixTableEntries; |
| 109 | |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 110 | private: |
| 111 | uint64_t m_useCount; |
| 112 | |
| 113 | }; |
| 114 | |
| 115 | bool |
| 116 | operator==(const RoutingTablePoolEntry& lhs, const RoutingTablePoolEntry& rhs); |
| 117 | |
| 118 | std::ostream& |
| 119 | operator<<(std::ostream& os, RoutingTablePoolEntry& rtpe); |
| 120 | |
| 121 | } // namespace nlsr |
| 122 | |
| 123 | #endif // NLSR_ROUTING_TABLE_POOL_ENTRY_HPP |