blob: 161ebd4fa534fd5299cdd37e8a196a146ffa6dd8 [file] [log] [blame]
Vince12e49462014-06-09 13:29:32 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoc0822fa2018-05-10 21:54:10 -04002/*
3 * Copyright (c) 2014-2018, Regents of the University of California,
Alexander Afanasyev7c10b3b2015-01-20 12:24:27 -08004 * 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.
Vince12e49462014-06-09 13:29:32 -050010 *
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_RIB_RIB_ENTRY_HPP
27#define NFD_RIB_RIB_ENTRY_HPP
28
Vince Lehman218be0a2015-01-15 17:25:20 -060029#include "route.hpp"
Vince12e49462014-06-09 13:29:32 -050030
Davide Pesaventoc0822fa2018-05-10 21:54:10 -040031#include <list>
32
Vince12e49462014-06-09 13:29:32 -050033namespace nfd {
34namespace rib {
35
Davide Pesaventoc0822fa2018-05-10 21:54:10 -040036/** \brief Represents a RIB entry, which contains one or more Routes with the same prefix.
Vince12e49462014-06-09 13:29:32 -050037 */
Davide Pesaventoc0822fa2018-05-10 21:54:10 -040038class RibEntry : public std::enable_shared_from_this<RibEntry>
Vince12e49462014-06-09 13:29:32 -050039{
40public:
Vince Lehman218be0a2015-01-15 17:25:20 -060041 typedef std::list<Route> RouteList;
42 typedef RouteList::iterator iterator;
43 typedef RouteList::const_iterator const_iterator;
Vince12e49462014-06-09 13:29:32 -050044
45 RibEntry()
Vince Lehman218be0a2015-01-15 17:25:20 -060046 : m_nRoutesWithCaptureSet(0)
Vince12e49462014-06-09 13:29:32 -050047 {
48 }
49
50 void
51 setName(const Name& prefix);
52
53 const Name&
54 getName() const;
55
56 shared_ptr<RibEntry>
57 getParent() const;
58
59 bool
60 hasParent() const;
61
62 void
63 addChild(shared_ptr<RibEntry> child);
64
65 void
66 removeChild(shared_ptr<RibEntry> child);
67
Vince Lehman76c751c2014-11-18 17:36:38 -060068 const std::list<shared_ptr<RibEntry>>&
69 getChildren() const;
Vince12e49462014-06-09 13:29:32 -050070
71 bool
72 hasChildren() const;
73
Vince Lehman218be0a2015-01-15 17:25:20 -060074 /** \brief inserts a new route into the entry's route list
75 * If another route already exists with the same faceId and origin,
76 * the new route is not inserted.
Nick Gordon89c4cca2016-11-02 15:42:32 +000077 * \return a pair, whose first element is the iterator to the newly
78 * inserted element if the insert succeeds and to the
79 * previously-existing element otherwise, and whose second element
80 * is true if the insert succeeds and false otherwise.
Vince12e49462014-06-09 13:29:32 -050081 */
Nick Gordon89c4cca2016-11-02 15:42:32 +000082 std::pair<RibEntry::iterator, bool>
Vince Lehman218be0a2015-01-15 17:25:20 -060083 insertRoute(const Route& route);
Vince12e49462014-06-09 13:29:32 -050084
Vince Lehman218be0a2015-01-15 17:25:20 -060085 /** \brief erases a Route with the same faceId and origin
Vince12e49462014-06-09 13:29:32 -050086 */
Vince Lehman281ded72014-08-21 12:17:08 -050087 void
Vince Lehman218be0a2015-01-15 17:25:20 -060088 eraseRoute(const Route& route);
Vince12e49462014-06-09 13:29:32 -050089
Vince Lehman218be0a2015-01-15 17:25:20 -060090 /** \brief erases a Route with the passed iterator
Vince12e49462014-06-09 13:29:32 -050091 * \return{ an iterator to the element that followed the erased iterator }
92 */
93 iterator
Vince Lehman218be0a2015-01-15 17:25:20 -060094 eraseRoute(RouteList::iterator route);
Vince12e49462014-06-09 13:29:32 -050095
96 bool
97 hasFaceId(const uint64_t faceId) const;
98
Davide Pesaventod396b612017-02-20 22:11:50 -050099 const RouteList&
100 getRoutes() const;
Vince12e49462014-06-09 13:29:32 -0500101
Vince Lehman76c751c2014-11-18 17:36:38 -0600102 size_t
103 getNRoutes() const;
104
Vince12e49462014-06-09 13:29:32 -0500105 iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600106 findRoute(const Route& route);
Vince12e49462014-06-09 13:29:32 -0500107
Vince Lehman76c751c2014-11-18 17:36:38 -0600108 const_iterator
109 findRoute(const Route& route) const;
110
Vince Lehman4387e782014-06-19 16:57:45 -0500111 bool
Vince Lehman218be0a2015-01-15 17:25:20 -0600112 hasRoute(const Route& route);
Vince Lehman4387e782014-06-19 16:57:45 -0500113
114 void
Vince Lehman218be0a2015-01-15 17:25:20 -0600115 addInheritedRoute(const Route& route);
Vince Lehman4387e782014-06-19 16:57:45 -0500116
117 void
Vince Lehman218be0a2015-01-15 17:25:20 -0600118 removeInheritedRoute(const Route& route);
Vince Lehman4387e782014-06-19 16:57:45 -0500119
Vince Lehman218be0a2015-01-15 17:25:20 -0600120 /** \brief Returns the routes this namespace has inherited.
121 * The inherited routes returned represent inherited routes this namespace has in the FIB.
122 * \return{ routes inherited by this namespace }
Vince Lehman4387e782014-06-19 16:57:45 -0500123 */
Vince Lehman76c751c2014-11-18 17:36:38 -0600124 const RouteList&
125 getInheritedRoutes() const;
Vince Lehman4387e782014-06-19 16:57:45 -0500126
Vince Lehman218be0a2015-01-15 17:25:20 -0600127 /** \brief Finds an inherited route with a matching face ID.
128 * \return{ An iterator to the matching route if one is found;
Vince Lehman4387e782014-06-19 16:57:45 -0500129 * otherwise, an iterator to the end of the entry's
Vince Lehman218be0a2015-01-15 17:25:20 -0600130 * inherited route list }
Vince Lehman4387e782014-06-19 16:57:45 -0500131 */
Vince Lehman76c751c2014-11-18 17:36:38 -0600132 RouteList::const_iterator
133 findInheritedRoute(const Route& route) const;
Vince Lehman4387e782014-06-19 16:57:45 -0500134
Vince Lehman218be0a2015-01-15 17:25:20 -0600135 /** \brief Determines if the entry has an inherited route with a matching face ID.
136 * \return{ True, if a matching inherited route is found; otherwise, false. }
Vince Lehman4387e782014-06-19 16:57:45 -0500137 */
138 bool
Vince Lehman76c751c2014-11-18 17:36:38 -0600139 hasInheritedRoute(const Route& route) const;
Vince Lehman4387e782014-06-19 16:57:45 -0500140
141 bool
142 hasCapture() const;
143
Vince Lehman218be0a2015-01-15 17:25:20 -0600144 /** \brief Determines if the entry has an inherited route with the passed
Vince Lehman4387e782014-06-19 16:57:45 -0500145 * face ID and its child inherit flag set.
Vince Lehman218be0a2015-01-15 17:25:20 -0600146 * \return{ True, if a matching inherited route is found; otherwise, false. }
Vince Lehman4387e782014-06-19 16:57:45 -0500147 */
148 bool
149 hasChildInheritOnFaceId(uint64_t faceId) const;
150
Vince Lehman218be0a2015-01-15 17:25:20 -0600151 /** \brief Returns the route with the lowest cost that has the passed face ID.
152 * \return{ The route with the lowest cost that has the passed face ID}
Vince Lehman4387e782014-06-19 16:57:45 -0500153 */
Vince Lehman9dcfc402015-03-26 03:18:54 -0500154 const Route*
Vince Lehman76c751c2014-11-18 17:36:38 -0600155 getRouteWithLowestCostByFaceId(uint64_t faceId) const;
156
Vince Lehman9dcfc402015-03-26 03:18:54 -0500157 const Route*
Vince Lehman76c751c2014-11-18 17:36:38 -0600158 getRouteWithSecondLowestCostByFaceId(uint64_t faceId) const;
Vince Lehman4387e782014-06-19 16:57:45 -0500159
Vince Lehman218be0a2015-01-15 17:25:20 -0600160 /** \brief Returns the route with the lowest cost that has the passed face ID
Vince Lehman4387e782014-06-19 16:57:45 -0500161 * and its child inherit flag set.
Vince Lehman218be0a2015-01-15 17:25:20 -0600162 * \return{ The route with the lowest cost that has the passed face ID
Vince Lehman4387e782014-06-19 16:57:45 -0500163 * and its child inherit flag set }
164 */
Vince Lehman9dcfc402015-03-26 03:18:54 -0500165 const Route*
Vince Lehman76c751c2014-11-18 17:36:38 -0600166 getRouteWithLowestCostAndChildInheritByFaceId(uint64_t faceId) const;
Vince Lehman4387e782014-06-19 16:57:45 -0500167
Vince12e49462014-06-09 13:29:32 -0500168 const_iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600169 begin() const;
Vince12e49462014-06-09 13:29:32 -0500170
171 const_iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600172 end() const;
Vince12e49462014-06-09 13:29:32 -0500173
174 iterator
175 begin();
176
177 iterator
178 end();
179
180private:
181 void
182 setParent(shared_ptr<RibEntry> parent);
183
184private:
185 Name m_name;
Vince Lehman218be0a2015-01-15 17:25:20 -0600186 std::list<shared_ptr<RibEntry>> m_children;
Vince12e49462014-06-09 13:29:32 -0500187 shared_ptr<RibEntry> m_parent;
Vince Lehman218be0a2015-01-15 17:25:20 -0600188 RouteList m_routes;
189 RouteList m_inheritedRoutes;
Vince Lehman4387e782014-06-19 16:57:45 -0500190
Vince Lehman218be0a2015-01-15 17:25:20 -0600191 /** \brief The number of routes on this namespace with the capture flag set.
Vince Lehman4387e782014-06-19 16:57:45 -0500192 *
Vince Lehman218be0a2015-01-15 17:25:20 -0600193 * This count is used to check if the namespace will block inherited routes.
Junxiao Shi2e526d72016-08-22 16:02:13 +0000194 * If the number is greater than zero, a route on the namespace has its capture
Vince Lehman218be0a2015-01-15 17:25:20 -0600195 * flag set which means the namespace should not inherit any routes.
Vince Lehman4387e782014-06-19 16:57:45 -0500196 */
Vince Lehman218be0a2015-01-15 17:25:20 -0600197 uint64_t m_nRoutesWithCaptureSet;
Vince12e49462014-06-09 13:29:32 -0500198};
199
200inline void
201RibEntry::setName(const Name& prefix)
202{
203 m_name = prefix;
204}
205
206inline const Name&
207RibEntry::getName() const
208{
209 return m_name;
210}
211
212inline void
213RibEntry::setParent(shared_ptr<RibEntry> parent)
214{
215 m_parent = parent;
216}
217
218inline shared_ptr<RibEntry>
219RibEntry::getParent() const
220{
221 return m_parent;
222}
223
Davide Pesaventod396b612017-02-20 22:11:50 -0500224inline const std::list<shared_ptr<RibEntry>>&
Vince Lehman76c751c2014-11-18 17:36:38 -0600225RibEntry::getChildren() const
Vince12e49462014-06-09 13:29:32 -0500226{
227 return m_children;
228}
229
Davide Pesaventod396b612017-02-20 22:11:50 -0500230inline const RibEntry::RouteList&
231RibEntry::getRoutes() const
Vince12e49462014-06-09 13:29:32 -0500232{
Vince Lehman218be0a2015-01-15 17:25:20 -0600233 return m_routes;
Vince12e49462014-06-09 13:29:32 -0500234}
235
Vince Lehman76c751c2014-11-18 17:36:38 -0600236inline const RibEntry::RouteList&
237RibEntry::getInheritedRoutes() const
Vince Lehman4387e782014-06-19 16:57:45 -0500238{
Vince Lehman218be0a2015-01-15 17:25:20 -0600239 return m_inheritedRoutes;
Vince Lehman4387e782014-06-19 16:57:45 -0500240}
241
Vince12e49462014-06-09 13:29:32 -0500242inline RibEntry::const_iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600243RibEntry::begin() const
Vince12e49462014-06-09 13:29:32 -0500244{
Vince Lehman218be0a2015-01-15 17:25:20 -0600245 return m_routes.begin();
Vince12e49462014-06-09 13:29:32 -0500246}
247
248inline RibEntry::const_iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600249RibEntry::end() const
Vince12e49462014-06-09 13:29:32 -0500250{
Vince Lehman218be0a2015-01-15 17:25:20 -0600251 return m_routes.end();
Vince12e49462014-06-09 13:29:32 -0500252}
253
254inline RibEntry::iterator
255RibEntry::begin()
256{
Vince Lehman218be0a2015-01-15 17:25:20 -0600257 return m_routes.begin();
Vince12e49462014-06-09 13:29:32 -0500258}
259
260inline RibEntry::iterator
261RibEntry::end()
262{
Vince Lehman218be0a2015-01-15 17:25:20 -0600263 return m_routes.end();
Vince12e49462014-06-09 13:29:32 -0500264}
265
Vince Lehman4387e782014-06-19 16:57:45 -0500266std::ostream&
267operator<<(std::ostream& os, const RibEntry& entry);
268
Vince12e49462014-06-09 13:29:32 -0500269} // namespace rib
270} // namespace nfd
271
272#endif // NFD_RIB_RIB_ENTRY_HPP