blob: 2568b1a19878f7e8cb849cfcab0c6d9d6e2fb181 [file] [log] [blame]
Alexander Afanasyev3ecec502014-04-16 13:42:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Vince12e49462014-06-09 13:29:32 -05003 * 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 Afanasyev3ecec502014-04-16 13:42:44 -070010 *
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/>.
Vince12e49462014-06-09 13:29:32 -050024 */
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070025
26#ifndef NFD_RIB_RIB_HPP
27#define NFD_RIB_RIB_HPP
28
Vince Lehman4387e782014-06-19 16:57:45 -050029#include "rib-entry.hpp"
30#include "fib-update.hpp"
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070031#include "common.hpp"
Alexander Afanasyev4a771362014-04-24 21:29:33 -070032#include <ndn-cxx/management/nfd-control-command.hpp>
Yanbiao Lib9d439d2014-12-11 16:12:32 -080033#include <ndn-cxx/util/signal.hpp>
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070034
35namespace nfd {
36namespace rib {
37
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070038/** \brief represents the RIB
39 */
Alexander Afanasyev20d31442014-04-19 17:00:53 -070040class Rib : noncopyable
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070041{
42public:
Vince12e49462014-06-09 13:29:32 -050043 typedef std::list<shared_ptr<RibEntry> > RibEntryList;
44 typedef std::map<Name, shared_ptr<RibEntry> > RibTable;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070045 typedef RibTable::const_iterator const_iterator;
Vince12e49462014-06-09 13:29:32 -050046 typedef std::map<uint64_t, std::list<shared_ptr<RibEntry> > > FaceLookupTable;
Vince Lehman4387e782014-06-19 16:57:45 -050047 typedef bool (*FaceComparePredicate)(const FaceEntry&, const FaceEntry&);
48 typedef std::set<FaceEntry, FaceComparePredicate> FaceSet;
49 typedef std::list<shared_ptr<const FibUpdate> > FibUpdateList;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070050
51 Rib();
52
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070053 const_iterator
Vince12e49462014-06-09 13:29:32 -050054 find(const Name& prefix) const;
55
Syed Obaid3313a372014-07-01 01:31:33 -050056 FaceEntry*
Vince12e49462014-06-09 13:29:32 -050057 find(const Name& prefix, const FaceEntry& face) const;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070058
59 void
Vince12e49462014-06-09 13:29:32 -050060 insert(const Name& prefix, const FaceEntry& face);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070061
62 void
Vince12e49462014-06-09 13:29:32 -050063 erase(const Name& prefix, const FaceEntry& face);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070064
65 void
Vince12e49462014-06-09 13:29:32 -050066 erase(const uint64_t faceId);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070067
68 const_iterator
69 begin() const;
70
71 const_iterator
72 end() const;
73
74 size_t
75 size() const;
76
Vince12e49462014-06-09 13:29:32 -050077 bool
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070078 empty() const;
79
Vince12e49462014-06-09 13:29:32 -050080 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 */
86 std::list<shared_ptr<RibEntry> >
87 findDescendants(const Name& prefix) const;
88
Vince Lehman4387e782014-06-19 16:57:45 -050089 const std::list<shared_ptr<const FibUpdate> >&
90 getFibUpdates() const;
91
92 void
93 clearFibUpdates();
94
95private:
Vince12e49462014-06-09 13:29:32 -050096 RibTable::iterator
97 eraseEntry(RibTable::iterator it);
98
99 void
Vince Lehman4387e782014-06-19 16:57:45 -0500100 insertFibUpdate(shared_ptr<FibUpdate> update);
101
102 void
103 createFibUpdatesForNewRibEntry(RibEntry& entry, const FaceEntry& face);
104
105 void
106 createFibUpdatesForNewFaceEntry(RibEntry& entry, const FaceEntry& face,
107 const bool captureWasTurnedOn);
108
109 void
110 createFibUpdatesForUpdatedEntry(RibEntry& entry, const FaceEntry& face,
111 const uint64_t previousFlags, const uint64_t previousCost);
112 void
113 createFibUpdatesForErasedFaceEntry(RibEntry& entry, const FaceEntry& face,
114 const bool captureWasTurnedOff);
115
116 void
117 createFibUpdatesForErasedRibEntry(RibEntry& entry);
118
119 FaceSet
120 getAncestorFaces(const RibEntry& entry) const;
121
122 void
123 modifyChildrensInheritedFaces(RibEntry& entry, const Rib::FaceSet& facesToAdd,
124 const Rib::FaceSet& facesToRemove);
125
126 void
127 traverseSubTree(RibEntry& entry, Rib::FaceSet facesToAdd,
128 Rib::FaceSet facesToRemove);
129
130 /** \brief Adds passed faces to the entry's inherited faces list
131 */
132 void
133 addInheritedFacesToEntry(RibEntry& entry, const Rib::FaceSet& facesToAdd);
134
135 /** \brief Removes passed faces from the entry's inherited faces list
136 */
137 void
138 removeInheritedFacesFromEntry(RibEntry& entry, const Rib::FaceSet& facesToRemove);
Vince12e49462014-06-09 13:29:32 -0500139
Yanbiao Lic17de832014-11-21 17:51:45 -0800140public:
Yanbiao Lib9d439d2014-12-11 16:12:32 -0800141 ndn::util::signal::Signal<Rib, Name> afterInsertEntry;
142 ndn::util::signal::Signal<Rib, Name> afterEraseEntry;
Yanbiao Lic17de832014-11-21 17:51:45 -0800143
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700144private:
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700145 RibTable m_rib;
Vince12e49462014-06-09 13:29:32 -0500146 FaceLookupTable m_faceMap;
Vince Lehman4387e782014-06-19 16:57:45 -0500147 FibUpdateList m_fibUpdateList;
148
Vince12e49462014-06-09 13:29:32 -0500149 size_t m_nItems;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700150};
151
152inline Rib::const_iterator
153Rib::begin() const
154{
155 return m_rib.begin();
156}
157
158inline Rib::const_iterator
159Rib::end() const
160{
161 return m_rib.end();
162}
163
164inline size_t
165Rib::size() const
166{
Vince12e49462014-06-09 13:29:32 -0500167 return m_nItems;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700168}
169
Vince12e49462014-06-09 13:29:32 -0500170inline bool
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700171Rib::empty() const
172{
173 return m_rib.empty();
174}
175
Vince Lehman4387e782014-06-19 16:57:45 -0500176inline const Rib::FibUpdateList&
177Rib::getFibUpdates() const
178{
179 return m_fibUpdateList;
180}
Vince12e49462014-06-09 13:29:32 -0500181
Vince Lehman4387e782014-06-19 16:57:45 -0500182inline void
183Rib::clearFibUpdates()
184{
185 m_fibUpdateList.clear();
186}
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700187
Vince12e49462014-06-09 13:29:32 -0500188std::ostream&
189operator<<(std::ostream& os, const Rib& rib);
190
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700191} // namespace rib
192} // namespace nfd
193
194#endif // NFD_RIB_RIB_HPP