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