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-2022, 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 
33 namespace nfd::rib {
34 
38 class RibEntry : public std::enable_shared_from_this<RibEntry>
39 {
40 public:
41  using RouteList = std::list<Route>;
42  using iterator = RouteList::iterator;
43  using const_iterator = RouteList::const_iterator;
44 
45  void
46  setName(const Name& prefix);
47 
48  const Name&
49  getName() const;
50 
51  shared_ptr<RibEntry>
52  getParent() const;
53 
54  bool
55  hasParent() const;
56 
57  void
58  addChild(shared_ptr<RibEntry> child);
59 
60  void
61  removeChild(shared_ptr<RibEntry> child);
62 
63  const std::list<shared_ptr<RibEntry>>&
64  getChildren() const;
65 
66  bool
67  hasChildren() const;
68 
79  std::pair<RibEntry::iterator, bool>
80  insertRoute(const Route& route);
81 
85  void
86  eraseRoute(const Route& route);
87 
92  iterator
93  eraseRoute(RouteList::iterator route);
94 
95  bool
96  hasFaceId(uint64_t faceId) const;
97 
98  const RouteList&
99  getRoutes() const;
100 
101  size_t
102  getNRoutes() const;
103 
104  iterator
105  findRoute(const Route& route);
106 
108  findRoute(const Route& route) const;
109 
110  bool
111  hasRoute(const Route& route);
112 
113  void
114  addInheritedRoute(const Route& route);
115 
116  void
117  removeInheritedRoute(const Route& route);
118 
124  const RouteList&
125  getInheritedRoutes() const;
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;
144 
149  bool
150  hasChildInheritOnFaceId(uint64_t faceId) const;
151 
155  const Route*
156  getRouteWithLowestCostByFaceId(uint64_t faceId) const;
157 
158  const Route*
159  getRouteWithSecondLowestCostByFaceId(uint64_t faceId) const;
160 
164  const Route*
165  getRouteWithLowestCostAndChildInheritByFaceId(uint64_t faceId) const;
166 
179  ndn::PrefixAnnouncement
180  getPrefixAnnouncement(time::milliseconds minExpiration = 15_s,
181  time::milliseconds maxExpiration = 1_h) const;
182 
184  begin() const;
185 
187  end() const;
188 
189  iterator
190  begin();
191 
192  iterator
193  end();
194 
195 private:
196  void
197  setParent(shared_ptr<RibEntry> parent);
198 
199 private:
200  Name m_name;
201  std::list<shared_ptr<RibEntry>> m_children;
202  shared_ptr<RibEntry> m_parent;
203  RouteList m_routes;
204  RouteList m_inheritedRoutes;
205 
212  uint64_t m_nRoutesWithCaptureSet = 0;
213 };
214 
215 inline void
216 RibEntry::setName(const Name& prefix)
217 {
218  m_name = prefix;
219 }
220 
221 inline const Name&
223 {
224  return m_name;
225 }
226 
227 inline void
228 RibEntry::setParent(shared_ptr<RibEntry> parent)
229 {
230  m_parent = std::move(parent);
231 }
232 
233 inline shared_ptr<RibEntry>
235 {
236  return m_parent;
237 }
238 
239 inline const std::list<shared_ptr<RibEntry>>&
241 {
242  return m_children;
243 }
244 
245 inline const RibEntry::RouteList&
247 {
248  return m_routes;
249 }
250 
251 inline const RibEntry::RouteList&
253 {
254  return m_inheritedRoutes;
255 }
256 
259 {
260  return m_routes.begin();
261 }
262 
265 {
266  return m_routes.end();
267 }
268 
269 inline RibEntry::iterator
271 {
272  return m_routes.begin();
273 }
274 
275 inline RibEntry::iterator
277 {
278  return m_routes.end();
279 }
280 
281 std::ostream&
282 operator<<(std::ostream& os, const RibEntry& entry);
283 
284 } // namespace nfd::rib
285 
286 #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.
Definition: rib-entry.cpp:146
const Route * getRouteWithLowestCostByFaceId(uint64_t faceId) const
Returns the route with the lowest cost that has the passed face ID.
Definition: rib-entry.cpp:177
iterator findRoute(const Route &route)
Definition: rib-entry.cpp:42
void addInheritedRoute(const Route &route)
Definition: rib-entry.cpp:134
void removeInheritedRoute(const Route &route)
Definition: rib-entry.cpp:140
shared_ptr< RibEntry > getParent() const
Definition: rib-entry.hpp:234
const_iterator end() const
Definition: rib-entry.hpp:264
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 RouteList & getInheritedRoutes() const
Returns the routes this namespace has inherited.
Definition: rib-entry.hpp:252
const RouteList & getRoutes() const
Definition: rib-entry.hpp:246
size_t getNRoutes() const
Definition: rib-entry.cpp:94
const_iterator begin() const
Definition: rib-entry.hpp:258
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 Name & getName() const
Definition: rib-entry.hpp:222
const std::list< shared_ptr< RibEntry > > & getChildren() const
Definition: rib-entry.hpp:240
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.
Definition: rib-entry.cpp:223
bool hasParent() const
RouteList::iterator iterator
Definition: rib-entry.hpp:42
bool hasChildren() const
void addChild(shared_ptr< RibEntry > child)
Definition: rib-entry.cpp:100
ndn::PrefixAnnouncement getPrefixAnnouncement(time::milliseconds minExpiration=15_s, time::milliseconds maxExpiration=1_h) const
Retrieve a prefix announcement suitable for readvertising this route.
Definition: rib-entry.cpp:247
bool hasCapture() const
Definition: rib-entry.cpp:159
void removeChild(shared_ptr< RibEntry > child)
Definition: rib-entry.cpp:108
const Route * getRouteWithSecondLowestCostByFaceId(uint64_t faceId) const
Definition: rib-entry.cpp:199
bool hasFaceId(uint64_t faceId) const
Definition: rib-entry.cpp:87
void setName(const Name &prefix)
Definition: rib-entry.hpp:216
bool hasRoute(const Route &route)
Definition: rib-entry.cpp:80
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...
Definition: rib-entry.cpp:165
std::list< Route > RouteList
Definition: rib-entry.hpp:41
bool hasInheritedRoute(const Route &route) const
Determines if the entry has an inherited route with a matching face ID.
Definition: rib-entry.cpp:153
Represents a route for a name prefix.
Definition: route.hpp:43
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)
Definition: fib-update.hpp:73