Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 7c10b3b | 2015-01-20 12:24:27 -0800 | [diff] [blame] | 3 | * 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. |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 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 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 29 | #include "route.hpp" |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
| 32 | namespace rib { |
| 33 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 34 | /** \brief represents a RIB entry, which contains one or more Routes with the same prefix |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 35 | */ |
| 36 | class RibEntry : public enable_shared_from_this<RibEntry> |
| 37 | { |
| 38 | public: |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 39 | typedef std::list<Route> RouteList; |
| 40 | typedef RouteList::iterator iterator; |
| 41 | typedef RouteList::const_iterator const_iterator; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 42 | |
| 43 | RibEntry() |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 44 | : m_nRoutesWithCaptureSet(0) |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 45 | { |
| 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 Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 66 | const std::list<shared_ptr<RibEntry>>& |
| 67 | getChildren() const; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 68 | |
| 69 | bool |
| 70 | hasChildren() const; |
| 71 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 72 | /** \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 } |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 76 | */ |
| 77 | bool |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 78 | insertRoute(const Route& route); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 79 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 80 | /** \brief erases a Route with the same faceId and origin |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 81 | */ |
Vince Lehman | 281ded7 | 2014-08-21 12:17:08 -0500 | [diff] [blame] | 82 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 83 | eraseRoute(const Route& route); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 84 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 85 | /** \brief erases a Route with the passed iterator |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 86 | * \return{ an iterator to the element that followed the erased iterator } |
| 87 | */ |
| 88 | iterator |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 89 | eraseRoute(RouteList::iterator route); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 90 | |
| 91 | bool |
| 92 | hasFaceId(const uint64_t faceId) const; |
| 93 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 94 | RouteList& |
| 95 | getRoutes(); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 96 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 97 | size_t |
| 98 | getNRoutes() const; |
| 99 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 100 | iterator |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 101 | findRoute(const Route& route); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 102 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 103 | const_iterator |
| 104 | findRoute(const Route& route) const; |
| 105 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 106 | bool |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 107 | hasRoute(const Route& route); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 108 | |
| 109 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 110 | addInheritedRoute(const Route& route); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 111 | |
| 112 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 113 | removeInheritedRoute(const Route& route); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 114 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 115 | /** \brief Returns the routes this namespace has inherited. |
| 116 | * The inherited routes returned represent inherited routes this namespace has in the FIB. |
| 117 | * \return{ routes inherited by this namespace } |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 118 | */ |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 119 | const RouteList& |
| 120 | getInheritedRoutes() const; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 121 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 122 | /** \brief Finds an inherited route with a matching face ID. |
| 123 | * \return{ An iterator to the matching route if one is found; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 124 | * otherwise, an iterator to the end of the entry's |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 125 | * inherited route list } |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 126 | */ |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 127 | RouteList::const_iterator |
| 128 | findInheritedRoute(const Route& route) const; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 129 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 130 | /** \brief Determines if the entry has an inherited route with a matching face ID. |
| 131 | * \return{ True, if a matching inherited route is found; otherwise, false. } |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 132 | */ |
| 133 | bool |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 134 | hasInheritedRoute(const Route& route) const; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 135 | |
| 136 | bool |
| 137 | hasCapture() const; |
| 138 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 139 | /** \brief Determines if the entry has an inherited route with the passed |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 140 | * face ID and its child inherit flag set. |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 141 | * \return{ True, if a matching inherited route is found; otherwise, false. } |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 142 | */ |
| 143 | bool |
| 144 | hasChildInheritOnFaceId(uint64_t faceId) const; |
| 145 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 146 | /** \brief Returns the route with the lowest cost that has the passed face ID. |
| 147 | * \return{ The route with the lowest cost that has the passed face ID} |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 148 | */ |
Vince Lehman | 9dcfc40 | 2015-03-26 03:18:54 -0500 | [diff] [blame] | 149 | const Route* |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 150 | getRouteWithLowestCostByFaceId(uint64_t faceId) const; |
| 151 | |
Vince Lehman | 9dcfc40 | 2015-03-26 03:18:54 -0500 | [diff] [blame] | 152 | const Route* |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 153 | getRouteWithSecondLowestCostByFaceId(uint64_t faceId) const; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 154 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 155 | /** \brief Returns the route with the lowest cost that has the passed face ID |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 156 | * and its child inherit flag set. |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 157 | * \return{ The route with the lowest cost that has the passed face ID |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 158 | * and its child inherit flag set } |
| 159 | */ |
Vince Lehman | 9dcfc40 | 2015-03-26 03:18:54 -0500 | [diff] [blame] | 160 | const Route* |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 161 | getRouteWithLowestCostAndChildInheritByFaceId(uint64_t faceId) const; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 162 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 163 | const_iterator |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 164 | begin() const; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 165 | |
| 166 | const_iterator |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 167 | end() const; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 168 | |
| 169 | iterator |
| 170 | begin(); |
| 171 | |
| 172 | iterator |
| 173 | end(); |
| 174 | |
| 175 | private: |
| 176 | void |
| 177 | setParent(shared_ptr<RibEntry> parent); |
| 178 | |
| 179 | private: |
| 180 | Name m_name; |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 181 | std::list<shared_ptr<RibEntry>> m_children; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 182 | shared_ptr<RibEntry> m_parent; |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 183 | RouteList m_routes; |
| 184 | RouteList m_inheritedRoutes; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 185 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 186 | /** \brief The number of routes on this namespace with the capture flag set. |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 187 | * |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 188 | * This count is used to check if the namespace will block inherited routes. |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 189 | * If the number is greater than zero, a route on the namespace has it's capture |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 190 | * flag set which means the namespace should not inherit any routes. |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 191 | */ |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 192 | uint64_t m_nRoutesWithCaptureSet; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | inline void |
| 196 | RibEntry::setName(const Name& prefix) |
| 197 | { |
| 198 | m_name = prefix; |
| 199 | } |
| 200 | |
| 201 | inline const Name& |
| 202 | RibEntry::getName() const |
| 203 | { |
| 204 | return m_name; |
| 205 | } |
| 206 | |
| 207 | inline void |
| 208 | RibEntry::setParent(shared_ptr<RibEntry> parent) |
| 209 | { |
| 210 | m_parent = parent; |
| 211 | } |
| 212 | |
| 213 | inline shared_ptr<RibEntry> |
| 214 | RibEntry::getParent() const |
| 215 | { |
| 216 | return m_parent; |
| 217 | } |
| 218 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 219 | inline const std::list<shared_ptr<RibEntry> >& |
| 220 | RibEntry::getChildren() const |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 221 | { |
| 222 | return m_children; |
| 223 | } |
| 224 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 225 | inline RibEntry::RouteList& |
| 226 | RibEntry::getRoutes() |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 227 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 228 | return m_routes; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 229 | } |
| 230 | |
Vince Lehman | 76c751c | 2014-11-18 17:36:38 -0600 | [diff] [blame] | 231 | inline const RibEntry::RouteList& |
| 232 | RibEntry::getInheritedRoutes() const |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 233 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 234 | return m_inheritedRoutes; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 235 | } |
| 236 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 237 | inline RibEntry::const_iterator |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 238 | RibEntry::begin() const |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 239 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 240 | return m_routes.begin(); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | inline RibEntry::const_iterator |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 244 | RibEntry::end() const |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 245 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 246 | return m_routes.end(); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | inline RibEntry::iterator |
| 250 | RibEntry::begin() |
| 251 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 252 | return m_routes.begin(); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | inline RibEntry::iterator |
| 256 | RibEntry::end() |
| 257 | { |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 258 | return m_routes.end(); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 259 | } |
| 260 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 261 | std::ostream& |
| 262 | operator<<(std::ostream& os, const RibEntry& entry); |
| 263 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 264 | } // namespace rib |
| 265 | } // namespace nfd |
| 266 | |
| 267 | #endif // NFD_RIB_RIB_ENTRY_HPP |