blob: 14e7c7dd76bc10a0d5be129020f0376abe11593c [file] [log] [blame]
Nick Gordonb50e51b2016-07-22 16:05:57 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, 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 <iostream>
29#include <ndn-cxx/name.hpp>
Nick Gordonc0c6bcf2017-08-15 18:11:21 -050030#include <unordered_map>
Nick Gordonb50e51b2016-07-22 16:05:57 -050031
32namespace nlsr {
Nick Gordond0a7df32017-05-30 16:44:34 -050033
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 Gordonc0c6bcf2017-08-15 18:11:21 -050047class NamePrefixTableEntry;
48
Nick Gordonb50e51b2016-07-22 16:05:57 -050049class RoutingTablePoolEntry : public RoutingTableEntry
50{
51public:
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 Gordonc0c6bcf2017-08-15 18:11:21 -0500106public:
107 std::unordered_map<ndn::Name, std::weak_ptr<NamePrefixTableEntry>>
108 namePrefixTableEntries;
109
Nick Gordonb50e51b2016-07-22 16:05:57 -0500110private:
111 uint64_t m_useCount;
112
113};
114
115bool
116operator==(const RoutingTablePoolEntry& lhs, const RoutingTablePoolEntry& rhs);
117
118std::ostream&
119operator<<(std::ostream& os, RoutingTablePoolEntry& rtpe);
120
121} // namespace nlsr
122
123#endif // NLSR_ROUTING_TABLE_POOL_ENTRY_HPP