blob: ed9ca4e2ccb3d0e33252bcb8fe1a38d173b3fcbe [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>
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070033
34namespace nfd {
35namespace rib {
36
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070037/** \brief represents the RIB
38 */
Alexander Afanasyev20d31442014-04-19 17:00:53 -070039class Rib : noncopyable
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070040{
41public:
Vince12e49462014-06-09 13:29:32 -050042 typedef std::list<shared_ptr<RibEntry> > RibEntryList;
43 typedef std::map<Name, shared_ptr<RibEntry> > RibTable;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070044 typedef RibTable::const_iterator const_iterator;
Vince12e49462014-06-09 13:29:32 -050045 typedef std::map<uint64_t, std::list<shared_ptr<RibEntry> > > FaceLookupTable;
Vince Lehman4387e782014-06-19 16:57:45 -050046 typedef bool (*FaceComparePredicate)(const FaceEntry&, const FaceEntry&);
47 typedef std::set<FaceEntry, FaceComparePredicate> FaceSet;
48 typedef std::list<shared_ptr<const FibUpdate> > FibUpdateList;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070049
50 Rib();
51
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070052 const_iterator
Vince12e49462014-06-09 13:29:32 -050053 find(const Name& prefix) const;
54
Syed Obaid3313a372014-07-01 01:31:33 -050055 FaceEntry*
Vince12e49462014-06-09 13:29:32 -050056 find(const Name& prefix, const FaceEntry& face) const;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070057
58 void
Vince12e49462014-06-09 13:29:32 -050059 insert(const Name& prefix, const FaceEntry& face);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070060
61 void
Vince12e49462014-06-09 13:29:32 -050062 erase(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 uint64_t faceId);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070066
67 const_iterator
68 begin() const;
69
70 const_iterator
71 end() const;
72
73 size_t
74 size() const;
75
Vince12e49462014-06-09 13:29:32 -050076 bool
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070077 empty() const;
78
Vince12e49462014-06-09 13:29:32 -050079 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 Lehman4387e782014-06-19 16:57:45 -050088 const std::list<shared_ptr<const FibUpdate> >&
89 getFibUpdates() const;
90
91 void
92 clearFibUpdates();
93
94private:
Vince12e49462014-06-09 13:29:32 -050095 RibTable::iterator
96 eraseEntry(RibTable::iterator it);
97
98 void
Vince Lehman4387e782014-06-19 16:57:45 -050099 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);
Vince12e49462014-06-09 13:29:32 -0500138
Yanbiao Lic17de832014-11-21 17:51:45 -0800139public:
140 ndn::util::EventEmitter<Name> afterInsertEntry;
141 ndn::util::EventEmitter<Name> afterEraseEntry;
142
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700143private:
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700144 RibTable m_rib;
Vince12e49462014-06-09 13:29:32 -0500145 FaceLookupTable m_faceMap;
Vince Lehman4387e782014-06-19 16:57:45 -0500146 FibUpdateList m_fibUpdateList;
147
Vince12e49462014-06-09 13:29:32 -0500148 size_t m_nItems;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700149};
150
151inline Rib::const_iterator
152Rib::begin() const
153{
154 return m_rib.begin();
155}
156
157inline Rib::const_iterator
158Rib::end() const
159{
160 return m_rib.end();
161}
162
163inline size_t
164Rib::size() const
165{
Vince12e49462014-06-09 13:29:32 -0500166 return m_nItems;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700167}
168
Vince12e49462014-06-09 13:29:32 -0500169inline bool
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700170Rib::empty() const
171{
172 return m_rib.empty();
173}
174
Vince Lehman4387e782014-06-19 16:57:45 -0500175inline const Rib::FibUpdateList&
176Rib::getFibUpdates() const
177{
178 return m_fibUpdateList;
179}
Vince12e49462014-06-09 13:29:32 -0500180
Vince Lehman4387e782014-06-19 16:57:45 -0500181inline void
182Rib::clearFibUpdates()
183{
184 m_fibUpdateList.clear();
185}
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700186
Vince12e49462014-06-09 13:29:32 -0500187std::ostream&
188operator<<(std::ostream& os, const Rib& rib);
189
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700190} // namespace rib
191} // namespace nfd
192
193#endif // NFD_RIB_RIB_HPP