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 | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 30 | |
| 31 | namespace nlsr { |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame] | 32 | |
| 33 | /*! \brief A deduplication system for the NamePrefixTable |
| 34 | * |
| 35 | * The NamePrefixTable associates name prefixes to a router. To do |
| 36 | * this, it needs to know if certain routers are reachable. This in |
| 37 | * turn requires access to entries from the RoutingTable, which are |
| 38 | * associated with name prefixes. Doing this naively copies the entry |
| 39 | * from the RoutingTable each time, which is costly. This class |
| 40 | * provides a deduplication system where the NamePrefixTable can |
| 41 | * maintain a collection of RoutingTablePoolEntries. Then, this new |
| 42 | * class can be associated with the name prefixes instead of the |
| 43 | * original entries, which provides a minimal memory solution. |
| 44 | * \sa NamePrefixTable |
| 45 | */ |
Nick Gordon | b50e51b | 2016-07-22 16:05:57 -0500 | [diff] [blame] | 46 | class RoutingTablePoolEntry : public RoutingTableEntry |
| 47 | { |
| 48 | public: |
| 49 | RoutingTablePoolEntry() |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | ~RoutingTablePoolEntry() |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | RoutingTablePoolEntry(const ndn::Name& dest) |
| 58 | { |
| 59 | m_destination = dest; |
| 60 | m_useCount = 1; |
| 61 | } |
| 62 | |
| 63 | RoutingTablePoolEntry(RoutingTableEntry& rte, uint64_t useCount) |
| 64 | { |
| 65 | m_destination = rte.getDestination(); |
| 66 | m_nexthopList = rte.getNexthopList(); |
| 67 | m_useCount = useCount; |
| 68 | } |
| 69 | |
| 70 | RoutingTablePoolEntry(const ndn::Name& dest, uint64_t useCount) |
| 71 | { |
| 72 | m_destination = dest; |
| 73 | m_useCount = useCount; |
| 74 | } |
| 75 | |
| 76 | uint64_t |
| 77 | getUseCount() |
| 78 | { |
| 79 | return m_useCount; |
| 80 | } |
| 81 | |
| 82 | uint64_t |
| 83 | incrementUseCount() |
| 84 | { |
| 85 | return ++m_useCount; |
| 86 | } |
| 87 | |
| 88 | uint64_t |
| 89 | decrementUseCount() |
| 90 | { |
| 91 | if (m_useCount != 0) { |
| 92 | return --m_useCount; |
| 93 | } |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | void |
| 98 | setNexthopList(NexthopList nhl) |
| 99 | { |
| 100 | m_nexthopList = nhl; |
| 101 | } |
| 102 | |
| 103 | private: |
| 104 | uint64_t m_useCount; |
| 105 | |
| 106 | }; |
| 107 | |
| 108 | bool |
| 109 | operator==(const RoutingTablePoolEntry& lhs, const RoutingTablePoolEntry& rhs); |
| 110 | |
| 111 | std::ostream& |
| 112 | operator<<(std::ostream& os, RoutingTablePoolEntry& rtpe); |
| 113 | |
| 114 | } // namespace nlsr |
| 115 | |
| 116 | #endif // NLSR_ROUTING_TABLE_POOL_ENTRY_HPP |