blob: 48212c3dd690b6de9f46c105b227d62a4108ea6e [file] [log] [blame]
Nick Gordonb50e51b2016-07-22 16:05:57 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -08003 * Copyright (c) 2014-2020, The University of Memphis,
Nick Gordonb50e51b2016-07-22 16:05:57 -05004 * 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 Gordonb50e51b2016-07-22 16:05:57 -050020 **/
21
22#ifndef NLSR_ROUTING_TABLE_POOL_ENTRY_HPP
23#define NLSR_ROUTING_TABLE_POOL_ENTRY_HPP
24
Nick Gordond0a7df32017-05-30 16:44:34 -050025#include "routing-table-entry.hpp"
26#include "nexthop-list.hpp"
27
Nick Gordonb50e51b2016-07-22 16:05:57 -050028#include <ndn-cxx/name.hpp>
Nick Gordonc0c6bcf2017-08-15 18:11:21 -050029#include <unordered_map>
Nick Gordonb50e51b2016-07-22 16:05:57 -050030
31namespace nlsr {
Nick Gordond0a7df32017-05-30 16:44:34 -050032
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 Gordonc0c6bcf2017-08-15 18:11:21 -050046class NamePrefixTableEntry;
47
Nick Gordonb50e51b2016-07-22 16:05:57 -050048class RoutingTablePoolEntry : public RoutingTableEntry
49{
50public:
51 RoutingTablePoolEntry()
52 {
53 }
54
55 ~RoutingTablePoolEntry()
56 {
57 }
58
59 RoutingTablePoolEntry(const ndn::Name& dest)
60 {
61 m_destination = dest;
62 m_useCount = 1;
63 }
64
65 RoutingTablePoolEntry(RoutingTableEntry& rte, uint64_t useCount)
66 {
67 m_destination = rte.getDestination();
68 m_nexthopList = rte.getNexthopList();
69 m_useCount = useCount;
70 }
71
72 RoutingTablePoolEntry(const ndn::Name& dest, uint64_t useCount)
73 {
74 m_destination = dest;
75 m_useCount = useCount;
76 }
77
78 uint64_t
79 getUseCount()
80 {
81 return m_useCount;
82 }
83
84 uint64_t
85 incrementUseCount()
86 {
87 return ++m_useCount;
88 }
89
90 uint64_t
91 decrementUseCount()
92 {
93 if (m_useCount != 0) {
94 return --m_useCount;
95 }
96 return 0;
97 }
98
99 void
100 setNexthopList(NexthopList nhl)
101 {
102 m_nexthopList = nhl;
103 }
104
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500105public:
106 std::unordered_map<ndn::Name, std::weak_ptr<NamePrefixTableEntry>>
107 namePrefixTableEntries;
108
Nick Gordonb50e51b2016-07-22 16:05:57 -0500109private:
110 uint64_t m_useCount;
111
112};
113
114bool
115operator==(const RoutingTablePoolEntry& lhs, const RoutingTablePoolEntry& rhs);
116
117std::ostream&
118operator<<(std::ostream& os, RoutingTablePoolEntry& rtpe);
119
120} // namespace nlsr
121
122#endif // NLSR_ROUTING_TABLE_POOL_ENTRY_HPP