Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [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. |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [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/>. |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 24 | */ |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 25 | |
| 26 | #ifndef NFD_RIB_RIB_HPP |
| 27 | #define NFD_RIB_RIB_HPP |
| 28 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 29 | #include "rib-entry.hpp" |
| 30 | #include "fib-update.hpp" |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 31 | #include "common.hpp" |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 32 | #include <ndn-cxx/management/nfd-control-command.hpp> |
Yanbiao Li | b9d439d | 2014-12-11 16:12:32 -0800 | [diff] [blame] | 33 | #include <ndn-cxx/util/signal.hpp> |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 34 | |
| 35 | namespace nfd { |
| 36 | namespace rib { |
| 37 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 38 | /** \brief represents the RIB |
| 39 | */ |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 40 | class Rib : noncopyable |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 41 | { |
| 42 | public: |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 43 | typedef std::list<shared_ptr<RibEntry>> RibEntryList; |
| 44 | typedef std::map<Name, shared_ptr<RibEntry>> RibTable; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 45 | typedef RibTable::const_iterator const_iterator; |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 46 | typedef std::map<uint64_t, std::list<shared_ptr<RibEntry>>> FaceLookupTable; |
| 47 | typedef bool (*RouteComparePredicate)(const Route&, const Route&); |
| 48 | typedef std::set<Route, RouteComparePredicate> RouteSet; |
| 49 | typedef std::list<shared_ptr<const FibUpdate>> FibUpdateList; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 50 | |
| 51 | Rib(); |
| 52 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 53 | const_iterator |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 54 | find(const Name& prefix) const; |
| 55 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 56 | Route* |
| 57 | find(const Name& prefix, const Route& route) const; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 58 | |
| 59 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 60 | insert(const Name& prefix, const Route& route); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 61 | |
| 62 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 63 | erase(const Name& prefix, const Route& route); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 64 | |
| 65 | void |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 66 | erase(const uint64_t faceId); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 67 | |
| 68 | const_iterator |
| 69 | begin() const; |
| 70 | |
| 71 | const_iterator |
| 72 | end() const; |
| 73 | |
| 74 | size_t |
| 75 | size() const; |
| 76 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 77 | bool |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 78 | empty() const; |
| 79 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 80 | shared_ptr<RibEntry> |
| 81 | findParent(const Name& prefix) const; |
| 82 | |
| 83 | /** \brief finds namespaces under the passed prefix |
| 84 | * \return{ a list of entries which are under the passed prefix } |
| 85 | */ |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 86 | std::list<shared_ptr<RibEntry>> |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 87 | findDescendants(const Name& prefix) const; |
| 88 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 89 | const std::list<shared_ptr<const FibUpdate>>& |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 90 | getFibUpdates() const; |
| 91 | |
| 92 | void |
| 93 | clearFibUpdates(); |
| 94 | |
| 95 | private: |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 96 | RibTable::iterator |
| 97 | eraseEntry(RibTable::iterator it); |
| 98 | |
| 99 | void |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 100 | insertFibUpdate(shared_ptr<FibUpdate> update); |
| 101 | |
| 102 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 103 | createFibUpdatesForNewRibEntry(RibEntry& entry, const Route& route); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 104 | |
| 105 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 106 | createFibUpdatesForNewRoute(RibEntry& entry, const Route& route, |
| 107 | const bool captureWasTurnedOn); |
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 | createFibUpdatesForUpdatedRoute(RibEntry& entry, const Route& route, |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 111 | const uint64_t previousFlags, const uint64_t previousCost); |
| 112 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 113 | createFibUpdatesForErasedRoute(RibEntry& entry, const Route& route, |
| 114 | const bool captureWasTurnedOff); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 115 | |
| 116 | void |
| 117 | createFibUpdatesForErasedRibEntry(RibEntry& entry); |
| 118 | |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 119 | RouteSet |
| 120 | getAncestorRoutes(const RibEntry& entry) const; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 121 | |
| 122 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 123 | modifyChildrensInheritedRoutes(RibEntry& entry, const Rib::RouteSet& routesToAdd, |
| 124 | const Rib::RouteSet& routesToRemove); |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 125 | |
| 126 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 127 | traverseSubTree(RibEntry& entry, Rib::RouteSet routesToAdd, |
| 128 | Rib::RouteSet routesToRemove); |
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 Adds passed routes to the entry's inherited routes list |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 131 | */ |
| 132 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 133 | addInheritedRoutesToEntry(RibEntry& entry, const Rib::RouteSet& routesToAdd); |
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 Removes passed routes from the entry's inherited routes list |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 136 | */ |
| 137 | void |
Vince Lehman | 218be0a | 2015-01-15 17:25:20 -0600 | [diff] [blame] | 138 | removeInheritedRoutesFromEntry(RibEntry& entry, const Rib::RouteSet& routesToRemove); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 139 | |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 140 | public: |
Yanbiao Li | b9d439d | 2014-12-11 16:12:32 -0800 | [diff] [blame] | 141 | ndn::util::signal::Signal<Rib, Name> afterInsertEntry; |
| 142 | ndn::util::signal::Signal<Rib, Name> afterEraseEntry; |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 143 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 144 | private: |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 145 | RibTable m_rib; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 146 | FaceLookupTable m_faceMap; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 147 | FibUpdateList m_fibUpdateList; |
| 148 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 149 | size_t m_nItems; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | inline Rib::const_iterator |
| 153 | Rib::begin() const |
| 154 | { |
| 155 | return m_rib.begin(); |
| 156 | } |
| 157 | |
| 158 | inline Rib::const_iterator |
| 159 | Rib::end() const |
| 160 | { |
| 161 | return m_rib.end(); |
| 162 | } |
| 163 | |
| 164 | inline size_t |
| 165 | Rib::size() const |
| 166 | { |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 167 | return m_nItems; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 170 | inline bool |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 171 | Rib::empty() const |
| 172 | { |
| 173 | return m_rib.empty(); |
| 174 | } |
| 175 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 176 | inline const Rib::FibUpdateList& |
| 177 | Rib::getFibUpdates() const |
| 178 | { |
| 179 | return m_fibUpdateList; |
| 180 | } |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 181 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 182 | inline void |
| 183 | Rib::clearFibUpdates() |
| 184 | { |
| 185 | m_fibUpdateList.clear(); |
| 186 | } |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 187 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 188 | std::ostream& |
| 189 | operator<<(std::ostream& os, const Rib& rib); |
| 190 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 191 | } // namespace rib |
| 192 | } // namespace nfd |
| 193 | |
| 194 | #endif // NFD_RIB_RIB_HPP |