blob: c555d21974ef9734c7afefa288ce791da6168202 [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"
Vince12e49462014-06-09 13:29:32 -050032#include "rib-entry.hpp"
Alexander Afanasyev4a771362014-04-24 21:29:33 -070033#include <ndn-cxx/management/nfd-control-command.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
53 ~Rib();
54
55 const_iterator
Vince12e49462014-06-09 13:29:32 -050056 find(const Name& prefix) const;
57
Syed Obaid3313a372014-07-01 01:31:33 -050058 FaceEntry*
Vince12e49462014-06-09 13:29:32 -050059 find(const Name& prefix, const FaceEntry& face) const;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070060
61 void
Vince12e49462014-06-09 13:29:32 -050062 insert(const Name& prefix, const FaceEntry& face);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070063
64 void
Vince12e49462014-06-09 13:29:32 -050065 erase(const Name& prefix, const FaceEntry& face);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070066
67 void
Vince12e49462014-06-09 13:29:32 -050068 erase(const uint64_t faceId);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070069
70 const_iterator
71 begin() const;
72
73 const_iterator
74 end() const;
75
76 size_t
77 size() const;
78
Vince12e49462014-06-09 13:29:32 -050079 bool
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070080 empty() const;
81
Vince12e49462014-06-09 13:29:32 -050082 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 Lehman4387e782014-06-19 16:57:45 -050091 const std::list<shared_ptr<const FibUpdate> >&
92 getFibUpdates() const;
93
94 void
95 clearFibUpdates();
96
97private:
Vince12e49462014-06-09 13:29:32 -050098 RibTable::iterator
99 eraseEntry(RibTable::iterator it);
100
101 void
Vince Lehman4387e782014-06-19 16:57:45 -0500102 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);
Vince12e49462014-06-09 13:29:32 -0500141
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700142private:
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700143 RibTable m_rib;
Vince12e49462014-06-09 13:29:32 -0500144 FaceLookupTable m_faceMap;
Vince Lehman4387e782014-06-19 16:57:45 -0500145 FibUpdateList m_fibUpdateList;
146
Vince12e49462014-06-09 13:29:32 -0500147 size_t m_nItems;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700148};
149
150inline Rib::const_iterator
151Rib::begin() const
152{
153 return m_rib.begin();
154}
155
156inline Rib::const_iterator
157Rib::end() const
158{
159 return m_rib.end();
160}
161
162inline size_t
163Rib::size() const
164{
Vince12e49462014-06-09 13:29:32 -0500165 return m_nItems;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700166}
167
Vince12e49462014-06-09 13:29:32 -0500168inline bool
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700169Rib::empty() const
170{
171 return m_rib.empty();
172}
173
Vince Lehman4387e782014-06-19 16:57:45 -0500174inline const Rib::FibUpdateList&
175Rib::getFibUpdates() const
176{
177 return m_fibUpdateList;
178}
Vince12e49462014-06-09 13:29:32 -0500179
Vince Lehman4387e782014-06-19 16:57:45 -0500180inline void
181Rib::clearFibUpdates()
182{
183 m_fibUpdateList.clear();
184}
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700185
Vince12e49462014-06-09 13:29:32 -0500186std::ostream&
187operator<<(std::ostream& os, const Rib& rib);
188
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700189} // namespace rib
190} // namespace nfd
191
192#endif // NFD_RIB_RIB_HPP