blob: 52adfd94c1446ac660d8aafd34b9db86a5a50769 [file] [log] [blame]
Vince12e49462014-06-09 13:29:32 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev7c10b3b2015-01-20 12:24:27 -08003 * Copyright (c) 2014-2015, 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.
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 Lehman218be0a2015-01-15 17:25:20 -060066 std::list<shared_ptr<RibEntry>>&
Vince12e49462014-06-09 13:29:32 -050067 getChildren();
68
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.
75 * \return{ true if the route is inserted, false otherwise }
Vince12e49462014-06-09 13:29:32 -050076 */
77 bool
Vince Lehman218be0a2015-01-15 17:25:20 -060078 insertRoute(const Route& route);
Vince12e49462014-06-09 13:29:32 -050079
Vince Lehman218be0a2015-01-15 17:25:20 -060080 /** \brief erases a Route with the same faceId and origin
Vince12e49462014-06-09 13:29:32 -050081 */
Vince Lehman281ded72014-08-21 12:17:08 -050082 void
Vince Lehman218be0a2015-01-15 17:25:20 -060083 eraseRoute(const Route& route);
Vince12e49462014-06-09 13:29:32 -050084
Vince Lehman218be0a2015-01-15 17:25:20 -060085 /** \brief erases a Route with the passed iterator
Vince12e49462014-06-09 13:29:32 -050086 * \return{ an iterator to the element that followed the erased iterator }
87 */
88 iterator
Vince Lehman218be0a2015-01-15 17:25:20 -060089 eraseRoute(RouteList::iterator route);
Vince12e49462014-06-09 13:29:32 -050090
91 bool
92 hasFaceId(const uint64_t faceId) const;
93
Vince Lehman218be0a2015-01-15 17:25:20 -060094 RouteList&
95 getRoutes();
Vince12e49462014-06-09 13:29:32 -050096
97 iterator
Vince Lehman218be0a2015-01-15 17:25:20 -060098 findRoute(const Route& route);
Vince12e49462014-06-09 13:29:32 -050099
Vince Lehman4387e782014-06-19 16:57:45 -0500100 bool
Vince Lehman218be0a2015-01-15 17:25:20 -0600101 hasRoute(const Route& route);
Vince Lehman4387e782014-06-19 16:57:45 -0500102
103 void
Vince Lehman218be0a2015-01-15 17:25:20 -0600104 addInheritedRoute(const Route& route);
Vince Lehman4387e782014-06-19 16:57:45 -0500105
106 void
Vince Lehman218be0a2015-01-15 17:25:20 -0600107 removeInheritedRoute(const Route& route);
Vince Lehman4387e782014-06-19 16:57:45 -0500108
Vince Lehman218be0a2015-01-15 17:25:20 -0600109 /** \brief Returns the routes this namespace has inherited.
110 * The inherited routes returned represent inherited routes this namespace has in the FIB.
111 * \return{ routes inherited by this namespace }
Vince Lehman4387e782014-06-19 16:57:45 -0500112 */
Vince Lehman218be0a2015-01-15 17:25:20 -0600113 RouteList&
114 getInheritedRoutes();
Vince Lehman4387e782014-06-19 16:57:45 -0500115
Vince Lehman218be0a2015-01-15 17:25:20 -0600116 /** \brief Finds an inherited route with a matching face ID.
117 * \return{ An iterator to the matching route if one is found;
Vince Lehman4387e782014-06-19 16:57:45 -0500118 * otherwise, an iterator to the end of the entry's
Vince Lehman218be0a2015-01-15 17:25:20 -0600119 * inherited route list }
Vince Lehman4387e782014-06-19 16:57:45 -0500120 */
Vince Lehman218be0a2015-01-15 17:25:20 -0600121 RouteList::iterator
122 findInheritedRoute(const Route& route);
Vince Lehman4387e782014-06-19 16:57:45 -0500123
Vince Lehman218be0a2015-01-15 17:25:20 -0600124 /** \brief Determines if the entry has an inherited route with a matching face ID.
125 * \return{ True, if a matching inherited route is found; otherwise, false. }
Vince Lehman4387e782014-06-19 16:57:45 -0500126 */
127 bool
Vince Lehman218be0a2015-01-15 17:25:20 -0600128 hasInheritedRoute(const Route& route);
Vince Lehman4387e782014-06-19 16:57:45 -0500129
130 bool
131 hasCapture() const;
132
Vince Lehman218be0a2015-01-15 17:25:20 -0600133 /** \brief Determines if the entry has an inherited route with the passed
Vince Lehman4387e782014-06-19 16:57:45 -0500134 * face ID and its child inherit flag set.
Vince Lehman218be0a2015-01-15 17:25:20 -0600135 * \return{ True, if a matching inherited route is found; otherwise, false. }
Vince Lehman4387e782014-06-19 16:57:45 -0500136 */
137 bool
138 hasChildInheritOnFaceId(uint64_t faceId) const;
139
Vince Lehman218be0a2015-01-15 17:25:20 -0600140 /** \brief Returns the route with the lowest cost that has the passed face ID.
141 * \return{ The route with the lowest cost that has the passed face ID}
Vince Lehman4387e782014-06-19 16:57:45 -0500142 */
Vince Lehman218be0a2015-01-15 17:25:20 -0600143 shared_ptr<Route>
144 getRouteWithLowestCostByFaceId(uint64_t faceId);
Vince Lehman4387e782014-06-19 16:57:45 -0500145
Vince Lehman218be0a2015-01-15 17:25:20 -0600146 /** \brief Returns the route with the lowest cost that has the passed face ID
Vince Lehman4387e782014-06-19 16:57:45 -0500147 * and its child inherit flag set.
Vince Lehman218be0a2015-01-15 17:25:20 -0600148 * \return{ The route with the lowest cost that has the passed face ID
Vince Lehman4387e782014-06-19 16:57:45 -0500149 * and its child inherit flag set }
150 */
Vince Lehman218be0a2015-01-15 17:25:20 -0600151 shared_ptr<Route>
152 getRouteWithLowestCostAndChildInheritByFaceId(uint64_t faceId);
Vince Lehman4387e782014-06-19 16:57:45 -0500153
Vince12e49462014-06-09 13:29:32 -0500154 const_iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600155 begin() const;
Vince12e49462014-06-09 13:29:32 -0500156
157 const_iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600158 end() const;
Vince12e49462014-06-09 13:29:32 -0500159
160 iterator
161 begin();
162
163 iterator
164 end();
165
166private:
167 void
168 setParent(shared_ptr<RibEntry> parent);
169
170private:
171 Name m_name;
Vince Lehman218be0a2015-01-15 17:25:20 -0600172 std::list<shared_ptr<RibEntry>> m_children;
Vince12e49462014-06-09 13:29:32 -0500173 shared_ptr<RibEntry> m_parent;
Vince Lehman218be0a2015-01-15 17:25:20 -0600174 RouteList m_routes;
175 RouteList m_inheritedRoutes;
Vince Lehman4387e782014-06-19 16:57:45 -0500176
Vince Lehman218be0a2015-01-15 17:25:20 -0600177 /** \brief The number of routes on this namespace with the capture flag set.
Vince Lehman4387e782014-06-19 16:57:45 -0500178 *
Vince Lehman218be0a2015-01-15 17:25:20 -0600179 * This count is used to check if the namespace will block inherited routes.
Vince Lehman4387e782014-06-19 16:57:45 -0500180 * If the number is greater than zero, a route on the namespace has it's capture
Vince Lehman218be0a2015-01-15 17:25:20 -0600181 * flag set which means the namespace should not inherit any routes.
Vince Lehman4387e782014-06-19 16:57:45 -0500182 */
Vince Lehman218be0a2015-01-15 17:25:20 -0600183 uint64_t m_nRoutesWithCaptureSet;
Vince12e49462014-06-09 13:29:32 -0500184};
185
186inline void
187RibEntry::setName(const Name& prefix)
188{
189 m_name = prefix;
190}
191
192inline const Name&
193RibEntry::getName() const
194{
195 return m_name;
196}
197
198inline void
199RibEntry::setParent(shared_ptr<RibEntry> parent)
200{
201 m_parent = parent;
202}
203
204inline shared_ptr<RibEntry>
205RibEntry::getParent() const
206{
207 return m_parent;
208}
209
Vince Lehman218be0a2015-01-15 17:25:20 -0600210inline std::list<shared_ptr<RibEntry>>&
Vince12e49462014-06-09 13:29:32 -0500211RibEntry::getChildren()
212{
213 return m_children;
214}
215
Vince Lehman218be0a2015-01-15 17:25:20 -0600216inline RibEntry::RouteList&
217RibEntry::getRoutes()
Vince12e49462014-06-09 13:29:32 -0500218{
Vince Lehman218be0a2015-01-15 17:25:20 -0600219 return m_routes;
Vince12e49462014-06-09 13:29:32 -0500220}
221
Vince Lehman218be0a2015-01-15 17:25:20 -0600222inline RibEntry::RouteList&
223RibEntry::getInheritedRoutes()
Vince Lehman4387e782014-06-19 16:57:45 -0500224{
Vince Lehman218be0a2015-01-15 17:25:20 -0600225 return m_inheritedRoutes;
Vince Lehman4387e782014-06-19 16:57:45 -0500226}
227
Vince12e49462014-06-09 13:29:32 -0500228inline RibEntry::const_iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600229RibEntry::begin() const
Vince12e49462014-06-09 13:29:32 -0500230{
Vince Lehman218be0a2015-01-15 17:25:20 -0600231 return m_routes.begin();
Vince12e49462014-06-09 13:29:32 -0500232}
233
234inline RibEntry::const_iterator
Vince Lehman218be0a2015-01-15 17:25:20 -0600235RibEntry::end() const
Vince12e49462014-06-09 13:29:32 -0500236{
Vince Lehman218be0a2015-01-15 17:25:20 -0600237 return m_routes.end();
Vince12e49462014-06-09 13:29:32 -0500238}
239
240inline RibEntry::iterator
241RibEntry::begin()
242{
Vince Lehman218be0a2015-01-15 17:25:20 -0600243 return m_routes.begin();
Vince12e49462014-06-09 13:29:32 -0500244}
245
246inline RibEntry::iterator
247RibEntry::end()
248{
Vince Lehman218be0a2015-01-15 17:25:20 -0600249 return m_routes.end();
Vince12e49462014-06-09 13:29:32 -0500250}
251
Vince Lehman4387e782014-06-19 16:57:45 -0500252std::ostream&
253operator<<(std::ostream& os, const RibEntry& entry);
254
Vince12e49462014-06-09 13:29:32 -0500255} // namespace rib
256} // namespace nfd
257
258#endif // NFD_RIB_RIB_ENTRY_HPP