blob: 148d2c900b4f86b30d574d0839ec16b1166653d0 [file] [log] [blame]
Nick Gordonb50e51b2016-07-22 16:05:57 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -04002/*
3 * Copyright (c) 2014-2022, 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/>.
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040019 */
Nick Gordonb50e51b2016-07-22 16:05:57 -050020
21#ifndef NLSR_ROUTING_TABLE_POOL_ENTRY_HPP
22#define NLSR_ROUTING_TABLE_POOL_ENTRY_HPP
23
Nick Gordond0a7df32017-05-30 16:44:34 -050024#include "routing-table-entry.hpp"
25#include "nexthop-list.hpp"
26
Nick Gordonb50e51b2016-07-22 16:05:57 -050027#include <ndn-cxx/name.hpp>
Nick Gordonc0c6bcf2017-08-15 18:11:21 -050028#include <unordered_map>
Nick Gordonb50e51b2016-07-22 16:05:57 -050029
30namespace nlsr {
Nick Gordond0a7df32017-05-30 16:44:34 -050031
32/*! \brief A deduplication system for the NamePrefixTable
33 *
34 * The NamePrefixTable associates name prefixes to a router. To do
35 * this, it needs to know if certain routers are reachable. This in
36 * turn requires access to entries from the RoutingTable, which are
37 * associated with name prefixes. Doing this naively copies the entry
38 * from the RoutingTable each time, which is costly. This class
39 * provides a deduplication system where the NamePrefixTable can
40 * maintain a collection of RoutingTablePoolEntries. Then, this new
41 * class can be associated with the name prefixes instead of the
42 * original entries, which provides a minimal memory solution.
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040043 *
Nick Gordond0a7df32017-05-30 16:44:34 -050044 * \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:
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040051 RoutingTablePoolEntry() = default;
Nick Gordonb50e51b2016-07-22 16:05:57 -050052
53 RoutingTablePoolEntry(const ndn::Name& dest)
54 {
55 m_destination = dest;
56 m_useCount = 1;
57 }
58
59 RoutingTablePoolEntry(RoutingTableEntry& rte, uint64_t useCount)
60 {
61 m_destination = rte.getDestination();
62 m_nexthopList = rte.getNexthopList();
63 m_useCount = useCount;
64 }
65
66 RoutingTablePoolEntry(const ndn::Name& dest, uint64_t useCount)
67 {
68 m_destination = dest;
69 m_useCount = useCount;
70 }
71
72 uint64_t
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040073 getUseCount() const
Nick Gordonb50e51b2016-07-22 16:05:57 -050074 {
75 return m_useCount;
76 }
77
78 uint64_t
79 incrementUseCount()
80 {
81 return ++m_useCount;
82 }
83
84 uint64_t
85 decrementUseCount()
86 {
87 if (m_useCount != 0) {
88 return --m_useCount;
89 }
90 return 0;
91 }
92
93 void
94 setNexthopList(NexthopList nhl)
95 {
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -040096 m_nexthopList = std::move(nhl);
Nick Gordonb50e51b2016-07-22 16:05:57 -050097 }
98
Nick Gordonc0c6bcf2017-08-15 18:11:21 -050099public:
Davide Pesaventoc1d0e8e2022-06-15 14:26:02 -0400100 std::unordered_map<ndn::Name, std::weak_ptr<NamePrefixTableEntry>> namePrefixTableEntries;
Nick Gordonc0c6bcf2017-08-15 18:11:21 -0500101
Nick Gordonb50e51b2016-07-22 16:05:57 -0500102private:
103 uint64_t m_useCount;
Nick Gordonb50e51b2016-07-22 16:05:57 -0500104};
105
106bool
107operator==(const RoutingTablePoolEntry& lhs, const RoutingTablePoolEntry& rhs);
108
109std::ostream&
110operator<<(std::ostream& os, RoutingTablePoolEntry& rtpe);
111
112} // namespace nlsr
113
114#endif // NLSR_ROUTING_TABLE_POOL_ENTRY_HPP