blob: fc7862466d479474d0c0d33be92a6f50b2034975 [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
82 * \return{ true if the face is removed, false otherwise }
83 */
84 bool
85 eraseFace(const FaceEntry& face);
86
87 /** \brief erases a FaceEntry with the passed iterator
88 * \return{ an iterator to the element that followed the erased iterator }
89 */
90 iterator
91 eraseFace(FaceList::iterator face);
92
93 bool
94 hasFaceId(const uint64_t faceId) const;
95
96 FaceList&
97 getFaces();
98
99 iterator
100 findFace(const FaceEntry& face);
101
Vince Lehman4387e782014-06-19 16:57:45 -0500102 bool
103 hasFace(const FaceEntry& face);
104
105 void
106 addInheritedFace(const FaceEntry& face);
107
108 void
109 removeInheritedFace(const FaceEntry& face);
110
111 /** \brief Returns the faces this namespace has inherited.
112 * The inherited faces returned represent inherited entries this namespace has in the FIB.
113 * \return{ faces inherited by this namespace }
114 */
115 FaceList&
116 getInheritedFaces();
117
118 /** \brief Finds an inherited face with a matching face ID.
119 * \return{ An iterator to the matching face if one is found;
120 * otherwise, an iterator to the end of the entry's
121 * inherited face list }
122 */
123 FaceList::iterator
124 findInheritedFace(const FaceEntry& face);
125
126 /** \brief Determines if the entry has an inherited face with a matching face ID.
127 * \return{ True, if a matching inherited face is found; otherwise, false. }
128 */
129 bool
130 hasInheritedFace(const FaceEntry& face);
131
132 bool
133 hasCapture() const;
134
135 /** \brief Determines if the entry has an inherited face with the passed
136 * face ID and its child inherit flag set.
137 * \return{ True, if a matching inherited face is found; otherwise, false. }
138 */
139 bool
140 hasChildInheritOnFaceId(uint64_t faceId) const;
141
142 /** \brief Returns the face with the lowest cost that has the passed face ID.
143 * \return{ The face with with the lowest cost that has the passed face ID}
144 */
145 shared_ptr<FaceEntry>
146 getFaceWithLowestCostByFaceId(uint64_t faceId);
147
148 /** \brief Returns the face with the lowest cost that has the passed face ID
149 * and its child inherit flag set.
150 * \return{ The face with with the lowest cost that has the passed face ID
151 * and its child inherit flag set }
152 */
153 shared_ptr<FaceEntry>
154 getFaceWithLowestCostAndChildInheritByFaceId(uint64_t faceId);
155
Vince12e49462014-06-09 13:29:32 -0500156 const_iterator
157 cbegin() const;
158
159 const_iterator
160 cend() const;
161
162 iterator
163 begin();
164
165 iterator
166 end();
167
168private:
169 void
170 setParent(shared_ptr<RibEntry> parent);
171
172private:
173 Name m_name;
174 std::list<shared_ptr<RibEntry> > m_children;
175 shared_ptr<RibEntry> m_parent;
176 FaceList m_faces;
177 FaceList m_inheritedFaces;
Vince Lehman4387e782014-06-19 16:57:45 -0500178
179 /** \brief The number of faces on this namespace with the capture flag set.
180 *
181 * This count is used to check if the namespace will block inherited faces.
182 * If the number is greater than zero, a route on the namespace has it's capture
183 * flag set which means the namespace should not inherit any faces.
184 */
185 uint64_t m_nFacesWithCaptureSet;
Vince12e49462014-06-09 13:29:32 -0500186};
187
188inline void
189RibEntry::setName(const Name& prefix)
190{
191 m_name = prefix;
192}
193
194inline const Name&
195RibEntry::getName() const
196{
197 return m_name;
198}
199
200inline void
201RibEntry::setParent(shared_ptr<RibEntry> parent)
202{
203 m_parent = parent;
204}
205
206inline shared_ptr<RibEntry>
207RibEntry::getParent() const
208{
209 return m_parent;
210}
211
212inline std::list<shared_ptr<RibEntry> >&
213RibEntry::getChildren()
214{
215 return m_children;
216}
217
218inline RibEntry::FaceList&
219RibEntry::getFaces()
220{
221 return m_faces;
222}
223
Vince Lehman4387e782014-06-19 16:57:45 -0500224inline RibEntry::FaceList&
225RibEntry::getInheritedFaces()
226{
227 return m_inheritedFaces;
228}
229
Vince12e49462014-06-09 13:29:32 -0500230inline RibEntry::const_iterator
231RibEntry::cbegin() const
232{
233 return m_faces.begin();
234}
235
236inline RibEntry::const_iterator
237RibEntry::cend() const
238{
239 return m_faces.end();
240}
241
242inline RibEntry::iterator
243RibEntry::begin()
244{
245 return m_faces.begin();
246}
247
248inline RibEntry::iterator
249RibEntry::end()
250{
251 return m_faces.end();
252}
253
Vince Lehman4387e782014-06-19 16:57:45 -0500254std::ostream&
255operator<<(std::ostream& os, const RibEntry& entry);
256
Vince12e49462014-06-09 13:29:32 -0500257} // namespace rib
258} // namespace nfd
259
260#endif // NFD_RIB_RIB_ENTRY_HPP