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 | |
| 29 | #include "common.hpp" |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 30 | #include "rib-entry.hpp" |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 31 | #include <ndn-cxx/management/nfd-control-command.hpp> |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
| 34 | namespace rib { |
| 35 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 36 | /** \brief represents the RIB |
| 37 | */ |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 38 | class Rib : noncopyable |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 39 | { |
| 40 | public: |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 41 | typedef std::list<shared_ptr<RibEntry> > RibEntryList; |
| 42 | typedef std::map<Name, shared_ptr<RibEntry> > RibTable; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 43 | typedef RibTable::const_iterator const_iterator; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 44 | typedef std::map<uint64_t, std::list<shared_ptr<RibEntry> > > FaceLookupTable; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 45 | |
| 46 | Rib(); |
| 47 | |
| 48 | ~Rib(); |
| 49 | |
| 50 | const_iterator |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 51 | find(const Name& prefix) const; |
| 52 | |
| 53 | shared_ptr<FaceEntry> |
| 54 | find(const Name& prefix, const FaceEntry& face) const; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 55 | |
| 56 | void |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 57 | insert(const Name& prefix, const FaceEntry& face); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 58 | |
| 59 | void |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 60 | erase(const Name& prefix, const FaceEntry& face); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 61 | |
| 62 | void |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 63 | erase(const uint64_t faceId); |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 64 | |
| 65 | const_iterator |
| 66 | begin() const; |
| 67 | |
| 68 | const_iterator |
| 69 | end() const; |
| 70 | |
| 71 | size_t |
| 72 | size() const; |
| 73 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 74 | bool |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 75 | empty() const; |
| 76 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 77 | |
| 78 | shared_ptr<RibEntry> |
| 79 | findParent(const Name& prefix) const; |
| 80 | |
| 81 | /** \brief finds namespaces under the passed prefix |
| 82 | * \return{ a list of entries which are under the passed prefix } |
| 83 | */ |
| 84 | std::list<shared_ptr<RibEntry> > |
| 85 | findDescendants(const Name& prefix) const; |
| 86 | |
| 87 | RibTable::iterator |
| 88 | eraseEntry(RibTable::iterator it); |
| 89 | |
| 90 | void |
| 91 | eraseEntry(const Name& name); |
| 92 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 93 | private: |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 94 | RibTable m_rib; |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 95 | FaceLookupTable m_faceMap; |
| 96 | size_t m_nItems; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | inline Rib::const_iterator |
| 100 | Rib::begin() const |
| 101 | { |
| 102 | return m_rib.begin(); |
| 103 | } |
| 104 | |
| 105 | inline Rib::const_iterator |
| 106 | Rib::end() const |
| 107 | { |
| 108 | return m_rib.end(); |
| 109 | } |
| 110 | |
| 111 | inline size_t |
| 112 | Rib::size() const |
| 113 | { |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 114 | return m_nItems; |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 117 | inline bool |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 118 | Rib::empty() const |
| 119 | { |
| 120 | return m_rib.empty(); |
| 121 | } |
| 122 | |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 123 | std::ostream& |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 124 | operator<<(std::ostream& os, const FaceEntry& entry); |
| 125 | |
| 126 | std::ostream& |
Alexander Afanasyev | 20d3144 | 2014-04-19 17:00:53 -0700 | [diff] [blame] | 127 | operator<<(std::ostream& os, const RibEntry& entry); |
| 128 | |
Vince | 12e4946 | 2014-06-09 13:29:32 -0500 | [diff] [blame] | 129 | std::ostream& |
| 130 | operator<<(std::ostream& os, const Rib& rib); |
| 131 | |
Alexander Afanasyev | 3ecec50 | 2014-04-16 13:42:44 -0700 | [diff] [blame] | 132 | } // namespace rib |
| 133 | } // namespace nfd |
| 134 | |
| 135 | #endif // NFD_RIB_RIB_HPP |