Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 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 |
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" |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 32 | #include "rib-entry.hpp" |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 33 | #include <ndn-cxx/management/nfd-control-command.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 | 12e4946 | 2014-06-09 13:29:32 -0500 | [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 | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 46 | typedef std::map<uint64_t, std::list<shared_ptr<RibEntry> > > FaceLookupTable; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 47 | typedef bool (*FaceComparePredicate)(const FaceEntry&, const FaceEntry&); |
| 48 | typedef std::set<FaceEntry, FaceComparePredicate> FaceSet; |
| 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 | |
| 53 | ~Rib(); |
| 54 | |
| 55 | const_iterator |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 56 | find(const Name& prefix) const; |
| 57 | |
Syed Obaid | 3313a37 | 2014-07-01 01:31:33 -0500 | [diff] [blame^] | 58 | FaceEntry* |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 59 | find(const Name& prefix, const FaceEntry& face) const; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 60 | |
| 61 | void |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 62 | insert(const Name& prefix, const FaceEntry& face); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 63 | |
| 64 | void |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 65 | erase(const Name& prefix, const FaceEntry& face); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 66 | |
| 67 | void |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 68 | erase(const uint64_t faceId); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 69 | |
| 70 | const_iterator |
| 71 | begin() const; |
| 72 | |
| 73 | const_iterator |
| 74 | end() const; |
| 75 | |
| 76 | size_t |
| 77 | size() const; |
| 78 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 79 | bool |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 80 | empty() const; |
| 81 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 82 | shared_ptr<RibEntry> |
| 83 | findParent(const Name& prefix) const; |
| 84 | |
| 85 | /** \brief finds namespaces under the passed prefix |
| 86 | * \return{ a list of entries which are under the passed prefix } |
| 87 | */ |
| 88 | std::list<shared_ptr<RibEntry> > |
| 89 | findDescendants(const Name& prefix) const; |
| 90 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 91 | const std::list<shared_ptr<const FibUpdate> >& |
| 92 | getFibUpdates() const; |
| 93 | |
| 94 | void |
| 95 | clearFibUpdates(); |
| 96 | |
| 97 | private: |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 98 | RibTable::iterator |
| 99 | eraseEntry(RibTable::iterator it); |
| 100 | |
| 101 | void |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 102 | insertFibUpdate(shared_ptr<FibUpdate> update); |
| 103 | |
| 104 | void |
| 105 | createFibUpdatesForNewRibEntry(RibEntry& entry, const FaceEntry& face); |
| 106 | |
| 107 | void |
| 108 | createFibUpdatesForNewFaceEntry(RibEntry& entry, const FaceEntry& face, |
| 109 | const bool captureWasTurnedOn); |
| 110 | |
| 111 | void |
| 112 | createFibUpdatesForUpdatedEntry(RibEntry& entry, const FaceEntry& face, |
| 113 | const uint64_t previousFlags, const uint64_t previousCost); |
| 114 | void |
| 115 | createFibUpdatesForErasedFaceEntry(RibEntry& entry, const FaceEntry& face, |
| 116 | const bool captureWasTurnedOff); |
| 117 | |
| 118 | void |
| 119 | createFibUpdatesForErasedRibEntry(RibEntry& entry); |
| 120 | |
| 121 | FaceSet |
| 122 | getAncestorFaces(const RibEntry& entry) const; |
| 123 | |
| 124 | void |
| 125 | modifyChildrensInheritedFaces(RibEntry& entry, const Rib::FaceSet& facesToAdd, |
| 126 | const Rib::FaceSet& facesToRemove); |
| 127 | |
| 128 | void |
| 129 | traverseSubTree(RibEntry& entry, Rib::FaceSet facesToAdd, |
| 130 | Rib::FaceSet facesToRemove); |
| 131 | |
| 132 | /** \brief Adds passed faces to the entry's inherited faces list |
| 133 | */ |
| 134 | void |
| 135 | addInheritedFacesToEntry(RibEntry& entry, const Rib::FaceSet& facesToAdd); |
| 136 | |
| 137 | /** \brief Removes passed faces from the entry's inherited faces list |
| 138 | */ |
| 139 | void |
| 140 | removeInheritedFacesFromEntry(RibEntry& entry, const Rib::FaceSet& facesToRemove); |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 141 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 142 | private: |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 143 | RibTable m_rib; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 144 | FaceLookupTable m_faceMap; |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 145 | FibUpdateList m_fibUpdateList; |
| 146 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 147 | size_t m_nItems; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | inline Rib::const_iterator |
| 151 | Rib::begin() const |
| 152 | { |
| 153 | return m_rib.begin(); |
| 154 | } |
| 155 | |
| 156 | inline Rib::const_iterator |
| 157 | Rib::end() const |
| 158 | { |
| 159 | return m_rib.end(); |
| 160 | } |
| 161 | |
| 162 | inline size_t |
| 163 | Rib::size() const |
| 164 | { |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 165 | return m_nItems; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 168 | inline bool |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 169 | Rib::empty() const |
| 170 | { |
| 171 | return m_rib.empty(); |
| 172 | } |
| 173 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 174 | inline const Rib::FibUpdateList& |
| 175 | Rib::getFibUpdates() const |
| 176 | { |
| 177 | return m_fibUpdateList; |
| 178 | } |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 179 | |
Vince Lehman | 4387e78 | 2014-06-19 16:57:45 -0500 | [diff] [blame] | 180 | inline void |
| 181 | Rib::clearFibUpdates() |
| 182 | { |
| 183 | m_fibUpdateList.clear(); |
| 184 | } |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 185 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 186 | std::ostream& |
| 187 | operator<<(std::ostream& os, const Rib& rib); |
| 188 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 189 | } // namespace rib |
| 190 | } // namespace nfd |
| 191 | |
| 192 | #endif // NFD_RIB_RIB_HPP |