Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 1 | /* -*- 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 | |
| 31 | namespace nfd { |
| 32 | namespace rib { |
| 33 | |
| 34 | /** \class RibEntry |
| 35 | * \brief represents a namespace |
| 36 | */ |
| 37 | class RibEntry : public enable_shared_from_this<RibEntry> |
| 38 | { |
| 39 | public: |
| 40 | typedef std::list<FaceEntry> FaceList; |
| 41 | typedef FaceList::iterator iterator; |
| 42 | typedef FaceList::const_iterator const_iterator; |
| 43 | |
| 44 | RibEntry() |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 45 | : m_nFacesWithCaptureSet(0) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 46 | { |
| 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 |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 82 | */ |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 83 | void |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 84 | 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 Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 101 | 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 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 155 | const_iterator |
| 156 | cbegin() const; |
| 157 | |
| 158 | const_iterator |
| 159 | cend() const; |
| 160 | |
| 161 | iterator |
| 162 | begin(); |
| 163 | |
| 164 | iterator |
| 165 | end(); |
| 166 | |
| 167 | private: |
| 168 | void |
| 169 | setParent(shared_ptr<RibEntry> parent); |
| 170 | |
| 171 | private: |
| 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 Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 177 | |
| 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; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | inline void |
| 188 | RibEntry::setName(const Name& prefix) |
| 189 | { |
| 190 | m_name = prefix; |
| 191 | } |
| 192 | |
| 193 | inline const Name& |
| 194 | RibEntry::getName() const |
| 195 | { |
| 196 | return m_name; |
| 197 | } |
| 198 | |
| 199 | inline void |
| 200 | RibEntry::setParent(shared_ptr<RibEntry> parent) |
| 201 | { |
| 202 | m_parent = parent; |
| 203 | } |
| 204 | |
| 205 | inline shared_ptr<RibEntry> |
| 206 | RibEntry::getParent() const |
| 207 | { |
| 208 | return m_parent; |
| 209 | } |
| 210 | |
| 211 | inline std::list<shared_ptr<RibEntry> >& |
| 212 | RibEntry::getChildren() |
| 213 | { |
| 214 | return m_children; |
| 215 | } |
| 216 | |
| 217 | inline RibEntry::FaceList& |
| 218 | RibEntry::getFaces() |
| 219 | { |
| 220 | return m_faces; |
| 221 | } |
| 222 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 223 | inline RibEntry::FaceList& |
| 224 | RibEntry::getInheritedFaces() |
| 225 | { |
| 226 | return m_inheritedFaces; |
| 227 | } |
| 228 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 229 | inline RibEntry::const_iterator |
| 230 | RibEntry::cbegin() const |
| 231 | { |
| 232 | return m_faces.begin(); |
| 233 | } |
| 234 | |
| 235 | inline RibEntry::const_iterator |
| 236 | RibEntry::cend() const |
| 237 | { |
| 238 | return m_faces.end(); |
| 239 | } |
| 240 | |
| 241 | inline RibEntry::iterator |
| 242 | RibEntry::begin() |
| 243 | { |
| 244 | return m_faces.begin(); |
| 245 | } |
| 246 | |
| 247 | inline RibEntry::iterator |
| 248 | RibEntry::end() |
| 249 | { |
| 250 | return m_faces.end(); |
| 251 | } |
| 252 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 253 | std::ostream& |
| 254 | operator<<(std::ostream& os, const RibEntry& entry); |
| 255 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 256 | } // namespace rib |
| 257 | } // namespace nfd |
| 258 | |
| 259 | #endif // NFD_RIB_RIB_ENTRY_HPP |