blob: ff84dfe7af7f538aa064c3f684f1d5d13b9e53e1 [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 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 Gordonb50e51b2016-07-22 16:05:57 -050046class RoutingTablePoolEntry : public RoutingTableEntry
47{
48public:
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
103private:
104 uint64_t m_useCount;
105
106};
107
108bool
109operator==(const RoutingTablePoolEntry& lhs, const RoutingTablePoolEntry& rhs);
110
111std::ostream&
112operator<<(std::ostream& os, RoutingTablePoolEntry& rtpe);
113
114} // namespace nlsr
115
116#endif // NLSR_ROUTING_TABLE_POOL_ENTRY_HPP