blob: d55d3f1713764288030cfa540e8a622a48417e69 [file] [log] [blame]
Vince12e49462014-06-09 13:29:32 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi2e526d72016-08-22 16:02:13 +00003 * Copyright (c) 2014-2016, 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
31namespace nfd {
32namespace rib {
33
Vince Lehman218be0a2015-01-15 17:25:20 -060034/** \brief represents a RIB entry, which contains one or more Routes with the same prefix
Vince12e49462014-06-09 13:29:32 -050035 */
36class RibEntry : public enable_shared_from_this<RibEntry>
37{
38public:
Vince Lehman218be0a2015-01-15 17:25:20 -060039 typedef std::list<Route> RouteList;
40 typedef RouteList::iterator iterator;
41 typedef RouteList::const_iterator const_iterator;
Vince12e49462014-06-09 13:29:32 -050042
43 RibEntry()
Vince Lehman218be0a2015-01-15 17:25:20 -060044 : m_nRoutesWithCaptureSet(0)
Vince12e49462014-06-09 13:29:32 -050045 {
46 }
47
48 void
49 setName(const Name& prefix);
50
51 const Name&
52 getName() const;
53
54 shared_ptr<RibEntry>
55 getParent() const;
56
57 bool
58 hasParent() const;
59
60 void
61 addChild(shared_ptr<RibEntry> child);
62
63 void
64 removeChild(shared_ptr<RibEntry> child);
65
Vince Lehman76c751c2014-11-18 17:36:38 -060066 const std::list<shared_ptr<RibEntry>>&
67 getChildren() const;
Vince12e49462014-06-09 13:29:32 -050068
69 bool
70 hasChildren() const;
71
Vince Lehman218be0a2015-01-15 17:25:20 -060072 /** \brief inserts a new route into the entry's route list
73 * If another route already exists with the same faceId and origin,
74 * the new route is not inserted.
Nick Gordon89c4cca2016-11-02 15:42:32 +000075 * \return a pair, whose first element is the iterator to the newly
76 * inserted element if the insert succeeds and to the
77 * previously-existing element otherwise, and whose second element
78 * is true if the insert succeeds and false otherwise.
Vince12e49462014-06-09 13:29:32 -050079 */
Nick Gordon89c4cca2016-11-02 15:42:32 +000080 std::pair<RibEntry::iterator, bool>
Vince Lehman218be0a2015-01-15 17:25:20 -060081 insertRoute(const Route& route);
Vince12e49462014-06-09 13:29:32 -050082
Vince Lehman218be0a2015-01-15 17:25:20 -060083 /** \brief erases a Route with the same faceId and origin
Vince12e49462014-06-09 13:29:32 -050084 */
Vince Lehman281ded72014-08-21 12:17:08 -050085 void
Vince Lehman218be0a2015-01-15 17:25:20 -060086 eraseRoute(const Route& route);
Vince12e49462014-06-09 13:29:32 -050087
Vince Lehman218be0a2015-01-15 17:25:20 -060088 /** \brief erases a Route with the passed iterator
Vince12e49462014-06-09 13:29:32 -050089 * \return{ an iterator to the element that followed the erased iterator }
90 */
91 iterator
Vince Lehman218be0a2015-01-15 17:25:20 -060092 eraseRoute(RouteList::iterator route);
Vince12e49462014-06-09 13:29:32 -050093
94 bool
95 hasFaceId(const uint64_t faceId) const;
96
Vince Lehman218be0a2015-01-15 17:25:20 -060097 RouteList&
98 getRoutes();
Vince12e49462014-06-09 13:29:32 -050099
Vince Lehman76c751c2014-11-18 17:36:38 -0600100 size_t
101 getNRoutes() const;
102
Vince12e49462014-06-09 13:29:32 -0500103 iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600104 findRoute(const Route& route);
Vince12e49462014-06-09 13:29:32 -0500105
Vince Lehman76c751c2014-11-18 17:36:38 -0600106 const_iterator
107 findRoute(const Route& route) const;
108
Vince Lehman4387e782014-06-19 16:57:45 -0500109 bool
Vince Lehman218be0a2015-01-15 17:25:20 -0600110 hasRoute(const Route& route);
Vince Lehman4387e782014-06-19 16:57:45 -0500111
112 void
Vince Lehman218be0a2015-01-15 17:25:20 -0600113 addInheritedRoute(const Route& route);
Vince Lehman4387e782014-06-19 16:57:45 -0500114
115 void
Vince Lehman218be0a2015-01-15 17:25:20 -0600116 removeInheritedRoute(const Route& route);
Vince Lehman4387e782014-06-19 16:57:45 -0500117
Vince Lehman218be0a2015-01-15 17:25:20 -0600118 /** \brief Returns the routes this namespace has inherited.
119 * The inherited routes returned represent inherited routes this namespace has in the FIB.
120 * \return{ routes inherited by this namespace }
Vince Lehman4387e782014-06-19 16:57:45 -0500121 */
Vince Lehman76c751c2014-11-18 17:36:38 -0600122 const RouteList&
123 getInheritedRoutes() const;
Vince Lehman4387e782014-06-19 16:57:45 -0500124
Vince Lehman218be0a2015-01-15 17:25:20 -0600125 /** \brief Finds an inherited route with a matching face ID.
126 * \return{ An iterator to the matching route if one is found;
Vince Lehman4387e782014-06-19 16:57:45 -0500127 * otherwise, an iterator to the end of the entry's
Vince Lehman218be0a2015-01-15 17:25:20 -0600128 * inherited route list }
Vince Lehman4387e782014-06-19 16:57:45 -0500129 */
Vince Lehman76c751c2014-11-18 17:36:38 -0600130 RouteList::const_iterator
131 findInheritedRoute(const Route& route) const;
Vince Lehman4387e782014-06-19 16:57:45 -0500132
Vince Lehman218be0a2015-01-15 17:25:20 -0600133 /** \brief Determines if the entry has an inherited route with a matching face ID.
134 * \return{ True, if a matching inherited route is found; otherwise, false. }
Vince Lehman4387e782014-06-19 16:57:45 -0500135 */
136 bool
Vince Lehman76c751c2014-11-18 17:36:38 -0600137 hasInheritedRoute(const Route& route) const;
Vince Lehman4387e782014-06-19 16:57:45 -0500138
139 bool
140 hasCapture() const;
141
Vince Lehman218be0a2015-01-15 17:25:20 -0600142 /** \brief Determines if the entry has an inherited route with the passed
Vince Lehman4387e782014-06-19 16:57:45 -0500143 * face ID and its child inherit flag set.
Vince Lehman218be0a2015-01-15 17:25:20 -0600144 * \return{ True, if a matching inherited route is found; otherwise, false. }
Vince Lehman4387e782014-06-19 16:57:45 -0500145 */
146 bool
147 hasChildInheritOnFaceId(uint64_t faceId) const;
148
Vince Lehman218be0a2015-01-15 17:25:20 -0600149 /** \brief Returns the route with the lowest cost that has the passed face ID.
150 * \return{ The route with the lowest cost that has the passed face ID}
Vince Lehman4387e782014-06-19 16:57:45 -0500151 */
Vince Lehman9dcfc402015-03-26 03:18:54 -0500152 const Route*
Vince Lehman76c751c2014-11-18 17:36:38 -0600153 getRouteWithLowestCostByFaceId(uint64_t faceId) const;
154
Vince Lehman9dcfc402015-03-26 03:18:54 -0500155 const Route*
Vince Lehman76c751c2014-11-18 17:36:38 -0600156 getRouteWithSecondLowestCostByFaceId(uint64_t faceId) const;
Vince Lehman4387e782014-06-19 16:57:45 -0500157
Vince Lehman218be0a2015-01-15 17:25:20 -0600158 /** \brief Returns the route with the lowest cost that has the passed face ID
Vince Lehman4387e782014-06-19 16:57:45 -0500159 * and its child inherit flag set.
Vince Lehman218be0a2015-01-15 17:25:20 -0600160 * \return{ 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 }
162 */
Vince Lehman9dcfc402015-03-26 03:18:54 -0500163 const Route*
Vince Lehman76c751c2014-11-18 17:36:38 -0600164 getRouteWithLowestCostAndChildInheritByFaceId(uint64_t faceId) const;
Vince Lehman4387e782014-06-19 16:57:45 -0500165
Vince12e49462014-06-09 13:29:32 -0500166 const_iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600167 begin() const;
Vince12e49462014-06-09 13:29:32 -0500168
169 const_iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600170 end() const;
Vince12e49462014-06-09 13:29:32 -0500171
172 iterator
173 begin();
174
175 iterator
176 end();
177
178private:
179 void
180 setParent(shared_ptr<RibEntry> parent);
181
182private:
183 Name m_name;
Vince Lehman218be0a2015-01-15 17:25:20 -0600184 std::list<shared_ptr<RibEntry>> m_children;
Vince12e49462014-06-09 13:29:32 -0500185 shared_ptr<RibEntry> m_parent;
Vince Lehman218be0a2015-01-15 17:25:20 -0600186 RouteList m_routes;
187 RouteList m_inheritedRoutes;
Vince Lehman4387e782014-06-19 16:57:45 -0500188
Vince Lehman218be0a2015-01-15 17:25:20 -0600189 /** \brief The number of routes on this namespace with the capture flag set.
Vince Lehman4387e782014-06-19 16:57:45 -0500190 *
Vince Lehman218be0a2015-01-15 17:25:20 -0600191 * This count is used to check if the namespace will block inherited routes.
Junxiao Shi2e526d72016-08-22 16:02:13 +0000192 * If the number is greater than zero, a route on the namespace has its capture
Vince Lehman218be0a2015-01-15 17:25:20 -0600193 * flag set which means the namespace should not inherit any routes.
Vince Lehman4387e782014-06-19 16:57:45 -0500194 */
Vince Lehman218be0a2015-01-15 17:25:20 -0600195 uint64_t m_nRoutesWithCaptureSet;
Vince12e49462014-06-09 13:29:32 -0500196};
197
198inline void
199RibEntry::setName(const Name& prefix)
200{
201 m_name = prefix;
202}
203
204inline const Name&
205RibEntry::getName() const
206{
207 return m_name;
208}
209
210inline void
211RibEntry::setParent(shared_ptr<RibEntry> parent)
212{
213 m_parent = parent;
214}
215
216inline shared_ptr<RibEntry>
217RibEntry::getParent() const
218{
219 return m_parent;
220}
221
Vince Lehman76c751c2014-11-18 17:36:38 -0600222inline const std::list<shared_ptr<RibEntry> >&
223RibEntry::getChildren() const
Vince12e49462014-06-09 13:29:32 -0500224{
225 return m_children;
226}
227
Vince Lehman218be0a2015-01-15 17:25:20 -0600228inline RibEntry::RouteList&
229RibEntry::getRoutes()
Vince12e49462014-06-09 13:29:32 -0500230{
Vince Lehman218be0a2015-01-15 17:25:20 -0600231 return m_routes;
Vince12e49462014-06-09 13:29:32 -0500232}
233
Vince Lehman76c751c2014-11-18 17:36:38 -0600234inline const RibEntry::RouteList&
235RibEntry::getInheritedRoutes() const
Vince Lehman4387e782014-06-19 16:57:45 -0500236{
Vince Lehman218be0a2015-01-15 17:25:20 -0600237 return m_inheritedRoutes;
Vince Lehman4387e782014-06-19 16:57:45 -0500238}
239
Vince12e49462014-06-09 13:29:32 -0500240inline RibEntry::const_iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600241RibEntry::begin() const
Vince12e49462014-06-09 13:29:32 -0500242{
Vince Lehman218be0a2015-01-15 17:25:20 -0600243 return m_routes.begin();
Vince12e49462014-06-09 13:29:32 -0500244}
245
246inline RibEntry::const_iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600247RibEntry::end() const
Vince12e49462014-06-09 13:29:32 -0500248{
Vince Lehman218be0a2015-01-15 17:25:20 -0600249 return m_routes.end();
Vince12e49462014-06-09 13:29:32 -0500250}
251
252inline RibEntry::iterator
253RibEntry::begin()
254{
Vince Lehman218be0a2015-01-15 17:25:20 -0600255 return m_routes.begin();
Vince12e49462014-06-09 13:29:32 -0500256}
257
258inline RibEntry::iterator
259RibEntry::end()
260{
Vince Lehman218be0a2015-01-15 17:25:20 -0600261 return m_routes.end();
Vince12e49462014-06-09 13:29:32 -0500262}
263
Vince Lehman4387e782014-06-19 16:57:45 -0500264std::ostream&
265operator<<(std::ostream& os, const RibEntry& entry);
266
Vince12e49462014-06-09 13:29:32 -0500267} // namespace rib
268} // namespace nfd
269
270#endif // NFD_RIB_RIB_ENTRY_HPP