blob: dabf69f7c2e74e62b05ba572137df34b0f3b2f4e [file] [log] [blame]
Alexander Afanasyev3ecec502014-04-16 13:42:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev7c10b3b2015-01-20 12:24:27 -08003 * Copyright (c) 2014-2015, 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:
Vince Lehman218be0a2015-01-15 17:25:20 -060043 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;
Vince Lehman218be0a2015-01-15 17:25:20 -060046 typedef std::map<uint64_t, std::list<shared_ptr<RibEntry>>> FaceLookupTable;
47 typedef bool (*RouteComparePredicate)(const Route&, const Route&);
48 typedef std::set<Route, RouteComparePredicate> RouteSet;
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
Vince Lehman218be0a2015-01-15 17:25:20 -060056 Route*
57 find(const Name& prefix, const Route& route) const;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070058
59 void
Vince Lehman218be0a2015-01-15 17:25:20 -060060 insert(const Name& prefix, const Route& route);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070061
62 void
Vince Lehman218be0a2015-01-15 17:25:20 -060063 erase(const Name& prefix, const Route& route);
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 */
Vince Lehman218be0a2015-01-15 17:25:20 -060086 std::list<shared_ptr<RibEntry>>
Vince12e49462014-06-09 13:29:32 -050087 findDescendants(const Name& prefix) const;
88
Vince Lehman218be0a2015-01-15 17:25:20 -060089 const std::list<shared_ptr<const FibUpdate>>&
Vince Lehman4387e782014-06-19 16:57:45 -050090 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
Vince Lehman218be0a2015-01-15 17:25:20 -0600103 createFibUpdatesForNewRibEntry(RibEntry& entry, const Route& route);
Vince Lehman4387e782014-06-19 16:57:45 -0500104
105 void
Vince Lehman218be0a2015-01-15 17:25:20 -0600106 createFibUpdatesForNewRoute(RibEntry& entry, const Route& route,
107 const bool captureWasTurnedOn);
Vince Lehman4387e782014-06-19 16:57:45 -0500108
109 void
Vince Lehman218be0a2015-01-15 17:25:20 -0600110 createFibUpdatesForUpdatedRoute(RibEntry& entry, const Route& route,
Vince Lehman4387e782014-06-19 16:57:45 -0500111 const uint64_t previousFlags, const uint64_t previousCost);
112 void
Vince Lehman218be0a2015-01-15 17:25:20 -0600113 createFibUpdatesForErasedRoute(RibEntry& entry, const Route& route,
114 const bool captureWasTurnedOff);
Vince Lehman4387e782014-06-19 16:57:45 -0500115
116 void
117 createFibUpdatesForErasedRibEntry(RibEntry& entry);
118
Vince Lehman218be0a2015-01-15 17:25:20 -0600119 RouteSet
120 getAncestorRoutes(const RibEntry& entry) const;
Vince Lehman4387e782014-06-19 16:57:45 -0500121
122 void
Vince Lehman218be0a2015-01-15 17:25:20 -0600123 modifyChildrensInheritedRoutes(RibEntry& entry, const Rib::RouteSet& routesToAdd,
124 const Rib::RouteSet& routesToRemove);
Vince Lehman4387e782014-06-19 16:57:45 -0500125
126 void
Vince Lehman218be0a2015-01-15 17:25:20 -0600127 traverseSubTree(RibEntry& entry, Rib::RouteSet routesToAdd,
128 Rib::RouteSet routesToRemove);
Vince Lehman4387e782014-06-19 16:57:45 -0500129
Vince Lehman218be0a2015-01-15 17:25:20 -0600130 /** \brief Adds passed routes to the entry's inherited routes list
Vince Lehman4387e782014-06-19 16:57:45 -0500131 */
132 void
Vince Lehman218be0a2015-01-15 17:25:20 -0600133 addInheritedRoutesToEntry(RibEntry& entry, const Rib::RouteSet& routesToAdd);
Vince Lehman4387e782014-06-19 16:57:45 -0500134
Vince Lehman218be0a2015-01-15 17:25:20 -0600135 /** \brief Removes passed routes from the entry's inherited routes list
Vince Lehman4387e782014-06-19 16:57:45 -0500136 */
137 void
Vince Lehman218be0a2015-01-15 17:25:20 -0600138 removeInheritedRoutesFromEntry(RibEntry& entry, const Rib::RouteSet& routesToRemove);
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