blob: b17085a459e365e0419b2d09d75dfd9325f703a3 [file] [log] [blame]
Vince12e49462014-06-09 13:29:32 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, 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_RIB_RIB_ENTRY_HPP
27#define NFD_RIB_RIB_ENTRY_HPP
28
29#include "face-entry.hpp"
30
31namespace nfd {
32namespace rib {
33
34/** \class RibEntry
35 * \brief represents a namespace
36 */
37class RibEntry : public enable_shared_from_this<RibEntry>
38{
39public:
40 typedef std::list<FaceEntry> FaceList;
41 typedef FaceList::iterator iterator;
42 typedef FaceList::const_iterator const_iterator;
43
44 RibEntry()
Vince Lehman4387e782014-06-19 16:57:45 -050045 : m_nFacesWithCaptureSet(0)
Vince12e49462014-06-09 13:29:32 -050046 {
47 }
48
49 void
50 setName(const Name& prefix);
51
52 const Name&
53 getName() const;
54
55 shared_ptr<RibEntry>
56 getParent() const;
57
58 bool
59 hasParent() const;
60
61 void
62 addChild(shared_ptr<RibEntry> child);
63
64 void
65 removeChild(shared_ptr<RibEntry> child);
66
67 std::list<shared_ptr<RibEntry> >&
68 getChildren();
69
70 bool
71 hasChildren() const;
72
73 /** \brief inserts a new face into the entry's face list
74 * If another entry already exists with the same faceId and origin,
75 * the new face is not inserted.
76 * \return{ true if the face is inserted, false otherwise }
77 */
78 bool
79 insertFace(const FaceEntry& face);
80
81 /** \brief erases a FaceEntry with the same faceId and origin
Vince12e49462014-06-09 13:29:32 -050082 */
Vince Lehman281ded72014-08-21 12:17:08 -050083 void
Vince12e49462014-06-09 13:29:32 -050084 eraseFace(const FaceEntry& face);
85
86 /** \brief erases a FaceEntry with the passed iterator
87 * \return{ an iterator to the element that followed the erased iterator }
88 */
89 iterator
90 eraseFace(FaceList::iterator face);
91
92 bool
93 hasFaceId(const uint64_t faceId) const;
94
95 FaceList&
96 getFaces();
97
98 iterator
99 findFace(const FaceEntry& face);
100
Vince Lehman4387e782014-06-19 16:57:45 -0500101 bool
102 hasFace(const FaceEntry& face);
103
104 void
105 addInheritedFace(const FaceEntry& face);
106
107 void
108 removeInheritedFace(const FaceEntry& face);
109
110 /** \brief Returns the faces this namespace has inherited.
111 * The inherited faces returned represent inherited entries this namespace has in the FIB.
112 * \return{ faces inherited by this namespace }
113 */
114 FaceList&
115 getInheritedFaces();
116
117 /** \brief Finds an inherited face with a matching face ID.
118 * \return{ An iterator to the matching face if one is found;
119 * otherwise, an iterator to the end of the entry's
120 * inherited face list }
121 */
122 FaceList::iterator
123 findInheritedFace(const FaceEntry& face);
124
125 /** \brief Determines if the entry has an inherited face with a matching face ID.
126 * \return{ True, if a matching inherited face is found; otherwise, false. }
127 */
128 bool
129 hasInheritedFace(const FaceEntry& face);
130
131 bool
132 hasCapture() const;
133
134 /** \brief Determines if the entry has an inherited face with the passed
135 * face ID and its child inherit flag set.
136 * \return{ True, if a matching inherited face is found; otherwise, false. }
137 */
138 bool
139 hasChildInheritOnFaceId(uint64_t faceId) const;
140
141 /** \brief Returns the face with the lowest cost that has the passed face ID.
142 * \return{ The face with with the lowest cost that has the passed face ID}
143 */
144 shared_ptr<FaceEntry>
145 getFaceWithLowestCostByFaceId(uint64_t faceId);
146
147 /** \brief Returns the face with the lowest cost that has the passed face ID
148 * and its child inherit flag set.
149 * \return{ The face with with the lowest cost that has the passed face ID
150 * and its child inherit flag set }
151 */
152 shared_ptr<FaceEntry>
153 getFaceWithLowestCostAndChildInheritByFaceId(uint64_t faceId);
154
Vince12e49462014-06-09 13:29:32 -0500155 const_iterator
156 cbegin() const;
157
158 const_iterator
159 cend() const;
160
161 iterator
162 begin();
163
164 iterator
165 end();
166
167private:
168 void
169 setParent(shared_ptr<RibEntry> parent);
170
171private:
172 Name m_name;
173 std::list<shared_ptr<RibEntry> > m_children;
174 shared_ptr<RibEntry> m_parent;
175 FaceList m_faces;
176 FaceList m_inheritedFaces;
Vince Lehman4387e782014-06-19 16:57:45 -0500177
178 /** \brief The number of faces on this namespace with the capture flag set.
179 *
180 * This count is used to check if the namespace will block inherited faces.
181 * If the number is greater than zero, a route on the namespace has it's capture
182 * flag set which means the namespace should not inherit any faces.
183 */
184 uint64_t m_nFacesWithCaptureSet;
Vince12e49462014-06-09 13:29:32 -0500185};
186
187inline void
188RibEntry::setName(const Name& prefix)
189{
190 m_name = prefix;
191}
192
193inline const Name&
194RibEntry::getName() const
195{
196 return m_name;
197}
198
199inline void
200RibEntry::setParent(shared_ptr<RibEntry> parent)
201{
202 m_parent = parent;
203}
204
205inline shared_ptr<RibEntry>
206RibEntry::getParent() const
207{
208 return m_parent;
209}
210
211inline std::list<shared_ptr<RibEntry> >&
212RibEntry::getChildren()
213{
214 return m_children;
215}
216
217inline RibEntry::FaceList&
218RibEntry::getFaces()
219{
220 return m_faces;
221}
222
Vince Lehman4387e782014-06-19 16:57:45 -0500223inline RibEntry::FaceList&
224RibEntry::getInheritedFaces()
225{
226 return m_inheritedFaces;
227}
228
Vince12e49462014-06-09 13:29:32 -0500229inline RibEntry::const_iterator
230RibEntry::cbegin() const
231{
232 return m_faces.begin();
233}
234
235inline RibEntry::const_iterator
236RibEntry::cend() const
237{
238 return m_faces.end();
239}
240
241inline RibEntry::iterator
242RibEntry::begin()
243{
244 return m_faces.begin();
245}
246
247inline RibEntry::iterator
248RibEntry::end()
249{
250 return m_faces.end();
251}
252
Vince Lehman4387e782014-06-19 16:57:45 -0500253std::ostream&
254operator<<(std::ostream& os, const RibEntry& entry);
255
Vince12e49462014-06-09 13:29:32 -0500256} // namespace rib
257} // namespace nfd
258
259#endif // NFD_RIB_RIB_ENTRY_HPP