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