blob: b19fe40b308068b2994feb698d57e4450e2ec56b [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande0421bc62020-05-08 20:42:19 -07002/*
awlane6d7c37f2025-03-07 11:53:58 -06003 * Copyright (c) 2014-2025, The University of Memphis,
Vince Lehmancae33b62015-06-05 09:21:30 -05004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070020 */
Vince Lehmancae33b62015-06-05 09:21:30 -050021
akmhoquefdbddb12014-05-02 18:35:19 -050022#ifndef NLSR_NAME_PREFIX_TABLE_ENTRY_HPP
23#define NLSR_NAME_PREFIX_TABLE_ENTRY_HPP
akmhoque53353462014-04-22 08:43:45 -050024
Nick Gordonb50e51b2016-07-22 16:05:57 -050025#include "routing-table-pool-entry.hpp"
Nick Gordonb50e51b2016-07-22 16:05:57 -050026#include "test-access-control.hpp"
awlane6d7c37f2025-03-07 11:53:58 -060027#include "nexthop.hpp"
Vince Lehmancae33b62015-06-05 09:21:30 -050028
akmhoque53353462014-04-22 08:43:45 -050029#include <list>
30#include <utility>
akmhoque53353462014-04-22 08:43:45 -050031
32namespace nlsr {
33
akmhoquec8a10f72014-04-25 18:42:55 -050034class NamePrefixTableEntry
akmhoque53353462014-04-22 08:43:45 -050035{
36public:
akmhoquec8a10f72014-04-25 18:42:55 -050037 NamePrefixTableEntry()
akmhoque53353462014-04-22 08:43:45 -050038 {
39 }
40
awlanefc0b45a2025-05-07 15:51:02 -050041 NamePrefixTableEntry(const ndn::Name& namePrefix, uint64_t routeFlags)
akmhoque31d1d4b2014-05-05 22:08:14 -050042 : m_namePrefix(namePrefix)
awlanefc0b45a2025-05-07 15:51:02 -050043 , m_flags(routeFlags)
akmhoque31d1d4b2014-05-05 22:08:14 -050044 , m_nexthopList()
akmhoque53353462014-04-22 08:43:45 -050045 {
akmhoque53353462014-04-22 08:43:45 -050046 }
47
akmhoque31d1d4b2014-05-05 22:08:14 -050048 const ndn::Name&
akmhoquefdbddb12014-05-02 18:35:19 -050049 getNamePrefix() const
akmhoque53353462014-04-22 08:43:45 -050050 {
51 return m_namePrefix;
52 }
53
Nick Gordonb50e51b2016-07-22 16:05:57 -050054 const std::list<std::shared_ptr<RoutingTablePoolEntry>>&
Vince Lehmancae33b62015-06-05 09:21:30 -050055 getRteList() const
akmhoque53353462014-04-22 08:43:45 -050056 {
57 return m_rteList;
58 }
59
Nick Gordond0a7df32017-05-30 16:44:34 -050060 /*! \brief Resets the next hop lists of all routing table entries
61 * that advertise this name prefix.
62 */
akmhoque53353462014-04-22 08:43:45 -050063 void
64 resetRteListNextHop()
65 {
akmhoque157b0a42014-05-13 00:26:37 -050066 if (m_rteList.size() > 0) {
Nick Gordonb50e51b2016-07-22 16:05:57 -050067 for (auto it = m_rteList.begin(); it != m_rteList.end(); ++it) {
Ashlesh Gawande0421bc62020-05-08 20:42:19 -070068 (*it)->getNexthopList().clear();
akmhoque53353462014-04-22 08:43:45 -050069 }
70 }
71 }
72
akmhoquefdbddb12014-05-02 18:35:19 -050073 size_t
akmhoque53353462014-04-22 08:43:45 -050074 getRteListSize()
75 {
76 return m_rteList.size();
77 }
78
Ashlesh Gawandee8d8bd52018-08-09 17:18:51 -050079 const NexthopList&
80 getNexthopList() const
akmhoque53353462014-04-22 08:43:45 -050081 {
akmhoquefdbddb12014-05-02 18:35:19 -050082 return m_nexthopList;
akmhoque53353462014-04-22 08:43:45 -050083 }
84
awlane6d7c37f2025-03-07 11:53:58 -060085 NexthopList&
86 getNexthopListForModification()
87 {
88 return m_nexthopList;
89 }
90
awlanefc0b45a2025-05-07 15:51:02 -050091 void
92 setFlags(uint64_t flags)
93 {
94 m_flags = flags;
95 }
96
97 uint64_t
98 getFlags() const
99 {
100 return m_flags;
101 }
102
Nick Gordond0a7df32017-05-30 16:44:34 -0500103 /*! \brief Collect all next-hops that are advertised by this entry's
104 * routing entries.
105 */
akmhoque53353462014-04-22 08:43:45 -0500106 void
107 generateNhlfromRteList();
108
Nick Gordonb50e51b2016-07-22 16:05:57 -0500109 /*! \brief Removes a routing entry from this NPT entry.
Nick Gordond0a7df32017-05-30 16:44:34 -0500110 * \return The number of NPTs using the just-removed routing entry.
111 */
Nick Gordonb50e51b2016-07-22 16:05:57 -0500112 uint64_t
113 removeRoutingTableEntry(std::shared_ptr<RoutingTablePoolEntry> rtpePtr);
akmhoque53353462014-04-22 08:43:45 -0500114
Nick Gordonb50e51b2016-07-22 16:05:57 -0500115 /*! \brief Adds a routing entry to this NPT entry.
Nick Gordond0a7df32017-05-30 16:44:34 -0500116 * \param rtpePtr The routing entry.
117 *
118 * Adds a routing table pool entry to this NPT entry's list
119 * (reminder: each RTPE has a next-hop list). They are used to
120 * calculate this entry's overall next-hop list.
121 */
akmhoque53353462014-04-22 08:43:45 -0500122 void
Nick Gordonb50e51b2016-07-22 16:05:57 -0500123 addRoutingTableEntry(std::shared_ptr<RoutingTablePoolEntry> rtpePtr);
akmhoque53353462014-04-22 08:43:45 -0500124
akmhoque674b0b12014-05-20 14:33:28 -0500125 void
126 writeLog();
127
akmhoque53353462014-04-22 08:43:45 -0500128private:
akmhoque31d1d4b2014-05-05 22:08:14 -0500129 ndn::Name m_namePrefix;
awlanefc0b45a2025-05-07 15:51:02 -0500130 uint64_t m_flags;
Nick Gordonb50e51b2016-07-22 16:05:57 -0500131
132PUBLIC_WITH_TESTS_ELSE_PRIVATE:
133 std::list<std::shared_ptr<RoutingTablePoolEntry>> m_rteList;
akmhoquefdbddb12014-05-02 18:35:19 -0500134 NexthopList m_nexthopList;
akmhoque53353462014-04-22 08:43:45 -0500135};
136
Nick Gordonb50e51b2016-07-22 16:05:57 -0500137bool
138operator==(const NamePrefixTableEntry& lhs, const NamePrefixTableEntry& rhs);
139
140bool
141operator==(const NamePrefixTableEntry& lhs, const ndn::Name& rhs);
142
Vince Lehmancae33b62015-06-05 09:21:30 -0500143std::ostream&
144operator<<(std::ostream& os, const NamePrefixTableEntry& entry);
akmhoque53353462014-04-22 08:43:45 -0500145
Vince Lehmancae33b62015-06-05 09:21:30 -0500146} // namespace nlsr
147
148#endif // NLSR_NAME_PREFIX_TABLE_ENTRY_HPP