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 |
| 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 Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 102 | 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 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 156 | const_iterator |
| 157 | cbegin() const; |
| 158 | |
| 159 | const_iterator |
| 160 | cend() const; |
| 161 | |
| 162 | iterator |
| 163 | begin(); |
| 164 | |
| 165 | iterator |
| 166 | end(); |
| 167 | |
| 168 | private: |
| 169 | void |
| 170 | setParent(shared_ptr<RibEntry> parent); |
| 171 | |
| 172 | private: |
| 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 Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 178 | |
| 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; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | inline void |
| 189 | RibEntry::setName(const Name& prefix) |
| 190 | { |
| 191 | m_name = prefix; |
| 192 | } |
| 193 | |
| 194 | inline const Name& |
| 195 | RibEntry::getName() const |
| 196 | { |
| 197 | return m_name; |
| 198 | } |
| 199 | |
| 200 | inline void |
| 201 | RibEntry::setParent(shared_ptr<RibEntry> parent) |
| 202 | { |
| 203 | m_parent = parent; |
| 204 | } |
| 205 | |
| 206 | inline shared_ptr<RibEntry> |
| 207 | RibEntry::getParent() const |
| 208 | { |
| 209 | return m_parent; |
| 210 | } |
| 211 | |
| 212 | inline std::list<shared_ptr<RibEntry> >& |
| 213 | RibEntry::getChildren() |
| 214 | { |
| 215 | return m_children; |
| 216 | } |
| 217 | |
| 218 | inline RibEntry::FaceList& |
| 219 | RibEntry::getFaces() |
| 220 | { |
| 221 | return m_faces; |
| 222 | } |
| 223 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 224 | inline RibEntry::FaceList& |
| 225 | RibEntry::getInheritedFaces() |
| 226 | { |
| 227 | return m_inheritedFaces; |
| 228 | } |
| 229 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 230 | inline RibEntry::const_iterator |
| 231 | RibEntry::cbegin() const |
| 232 | { |
| 233 | return m_faces.begin(); |
| 234 | } |
| 235 | |
| 236 | inline RibEntry::const_iterator |
| 237 | RibEntry::cend() const |
| 238 | { |
| 239 | return m_faces.end(); |
| 240 | } |
| 241 | |
| 242 | inline RibEntry::iterator |
| 243 | RibEntry::begin() |
| 244 | { |
| 245 | return m_faces.begin(); |
| 246 | } |
| 247 | |
| 248 | inline RibEntry::iterator |
| 249 | RibEntry::end() |
| 250 | { |
| 251 | return m_faces.end(); |
| 252 | } |
| 253 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 254 | std::ostream& |
| 255 | operator<<(std::ostream& os, const RibEntry& entry); |
| 256 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 257 | } // namespace rib |
| 258 | } // namespace nfd |
| 259 | |
| 260 | #endif // NFD_RIB_RIB_ENTRY_HPP |