Loading...
Searching...
No Matches
rib-entry.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2025, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#ifndef NFD_DAEMON_RIB_RIB_ENTRY_HPP
27#define NFD_DAEMON_RIB_RIB_ENTRY_HPP
28
29#include "route.hpp"
30
31#include <list>
32
33namespace nfd::rib {
34
38class RibEntry : public std::enable_shared_from_this<RibEntry>
39{
40public:
41 using RouteList = std::list<Route>;
42 using iterator = RouteList::iterator;
43 using const_iterator = RouteList::const_iterator;
44
45 const Name&
46 getName() const noexcept
47 {
48 return m_name;
49 }
50
51 void
52 setName(const Name& prefix)
53 {
54 m_name = prefix;
55 }
56
57 shared_ptr<RibEntry>
58 getParent() const
59 {
60 return m_parent;
61 }
62
63 const std::list<shared_ptr<RibEntry>>&
64 getChildren() const noexcept
65 {
66 return m_children;
67 }
68
69 void
70 addChild(shared_ptr<RibEntry> child);
71
72 void
73 removeChild(shared_ptr<RibEntry> child);
74
85 std::pair<RibEntry::iterator, bool>
86 insertRoute(const Route& route);
87
91 void
92 eraseRoute(const Route& route);
93
99 eraseRoute(RouteList::iterator route);
100
101 bool
102 hasFaceId(uint64_t faceId) const;
103
105 findRoute(const Route& route);
106
108 findRoute(const Route& route) const;
109
110 void
111 addInheritedRoute(const Route& route);
112
113 void
114 removeInheritedRoute(const Route& route);
115
121 const RouteList&
122 getInheritedRoutes() const noexcept
123 {
124 return m_inheritedRoutes;
125 }
126
133 RouteList::const_iterator
134 findInheritedRoute(const Route& route) const;
135
139 bool
140 hasInheritedRoute(const Route& route) const;
141
142 bool
143 hasCapture() const noexcept
144 {
145 return m_nRoutesWithCaptureSet > 0;
146 }
147
152 bool
153 hasChildInheritOnFaceId(uint64_t faceId) const;
154
158 const Route*
159 getRouteWithLowestCostByFaceId(uint64_t faceId) const;
160
161 const Route*
162 getRouteWithSecondLowestCostByFaceId(uint64_t faceId) const;
163
167 const Route*
169
182 ndn::PrefixAnnouncement
183 getPrefixAnnouncement(time::milliseconds minExpiration = 15_s,
184 time::milliseconds maxExpiration = 1_h) const;
185
186 const RouteList&
187 getRoutes() const noexcept
188 {
189 return m_routes;
190 }
191
192 bool
193 empty() const noexcept
194 {
195 return m_routes.empty();
196 }
197
199 begin() const noexcept
200 {
201 return m_routes.begin();
202 }
203
205 end() const noexcept
206 {
207 return m_routes.end();
208 }
209
211 begin() noexcept
212 {
213 return m_routes.begin();
214 }
215
217 end() noexcept
218 {
219 return m_routes.end();
220 }
221
222private:
223 Name m_name;
224 std::list<shared_ptr<RibEntry>> m_children;
225 shared_ptr<RibEntry> m_parent;
226 RouteList m_routes;
227 RouteList m_inheritedRoutes;
228
235 uint64_t m_nRoutesWithCaptureSet = 0;
236};
237
238std::ostream&
239operator<<(std::ostream& os, const RibEntry& entry);
240
241} // namespace nfd::rib
242
243#endif // NFD_DAEMON_RIB_RIB_ENTRY_HPP
Represents a RIB entry, which contains one or more Routes with the same prefix.
Definition rib-entry.hpp:39
RouteList::const_iterator findInheritedRoute(const Route &route) const
Finds an inherited route with a matching face ID.
const Route * getRouteWithLowestCostByFaceId(uint64_t faceId) const
Returns the route with the lowest cost that has the passed face ID.
iterator findRoute(const Route &route)
Definition rib-entry.cpp:42
void addInheritedRoute(const Route &route)
bool empty() const noexcept
void removeInheritedRoute(const Route &route)
shared_ptr< RibEntry > getParent() const
Definition rib-entry.hpp:58
std::pair< RibEntry::iterator, bool > insertRoute(const Route &route)
Inserts a new route into the entry's route list.
Definition rib-entry.cpp:56
const_iterator end() const noexcept
const RouteList & getRoutes() const noexcept
void eraseRoute(const Route &route)
Erases a Route with the same FaceId and origin.
Definition rib-entry.cpp:73
RouteList::const_iterator const_iterator
Definition rib-entry.hpp:43
const Route * getRouteWithLowestCostAndChildInheritByFaceId(uint64_t faceId) const
Returns the route with the lowest cost that has the passed face ID and its child inherit flag set.
RouteList::iterator iterator
Definition rib-entry.hpp:42
const RouteList & getInheritedRoutes() const noexcept
Returns the routes this namespace has inherited.
void addChild(shared_ptr< RibEntry > child)
Definition rib-entry.cpp:85
ndn::PrefixAnnouncement getPrefixAnnouncement(time::milliseconds minExpiration=15_s, time::milliseconds maxExpiration=1_h) const
Retrieve a prefix announcement suitable for readvertising this route.
void removeChild(shared_ptr< RibEntry > child)
Definition rib-entry.cpp:93
iterator begin() noexcept
const Route * getRouteWithSecondLowestCostByFaceId(uint64_t faceId) const
bool hasFaceId(uint64_t faceId) const
Definition rib-entry.cpp:79
const std::list< shared_ptr< RibEntry > > & getChildren() const noexcept
Definition rib-entry.hpp:64
void setName(const Name &prefix)
Definition rib-entry.hpp:52
const_iterator begin() const noexcept
bool hasChildInheritOnFaceId(uint64_t faceId) const
Determines if the entry has an inherited route with the passed face ID and its child inherit flag set...
std::list< Route > RouteList
Definition rib-entry.hpp:41
bool hasCapture() const noexcept
const Name & getName() const noexcept
Definition rib-entry.hpp:46
bool hasInheritedRoute(const Route &route) const
Determines if the entry has an inherited route with a matching face ID.
iterator end() noexcept
Represents a route for a name prefix.
Definition route.hpp:44
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)