NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
rib.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2018, 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.
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/>.
24  */
25 
26 #ifndef NFD_RIB_RIB_HPP
27 #define NFD_RIB_RIB_HPP
28 
29 #include "rib-entry.hpp"
30 #include "rib-update-batch.hpp"
31 
32 #include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
33 
34 namespace nfd {
35 namespace rib {
36 
38 
39 class FibUpdater;
40 
44 {
45  shared_ptr<RibEntry> entry;
47 };
48 
49 bool
50 operator<(const RibRouteRef& lhs, const RibRouteRef& rhs);
51 
59 class Rib : noncopyable
60 {
61 public:
62  typedef std::list<shared_ptr<RibEntry>> RibEntryList;
63  typedef std::map<Name, shared_ptr<RibEntry>> RibTable;
64  typedef RibTable::const_iterator const_iterator;
65  typedef std::map<uint64_t, std::list<shared_ptr<RibEntry>>> FaceLookupTable;
66  typedef bool (*RouteComparePredicate)(const Route&, const Route&);
67  typedef std::set<Route, RouteComparePredicate> RouteSet;
68 
69  Rib();
70 
71  ~Rib();
72 
73  void
74  setFibUpdater(FibUpdater* updater);
75 
77  find(const Name& prefix) const;
78 
79  Route*
80  find(const Name& prefix, const Route& route) const;
81 
83  begin() const;
84 
86  end() const;
87 
88  size_t
89  size() const;
90 
91  bool
92  empty() const;
93 
94  shared_ptr<RibEntry>
95  findParent(const Name& prefix) const;
96 
100  std::list<shared_ptr<RibEntry>>
101  findDescendants(const Name& prefix) const;
102 
111  std::list<shared_ptr<RibEntry>>
112  findDescendantsForNonInsertedName(const Name& prefix) const;
113 
114 public:
115  using UpdateSuccessCallback = std::function<void()>;
116  using UpdateFailureCallback = std::function<void(uint32_t code, const std::string& error)>;
117 
126  void
127  beginApplyUpdate(const RibUpdate& update,
128  const UpdateSuccessCallback& onSuccess,
129  const UpdateFailureCallback& onFailure);
130 
133  void
134  beginRemoveFace(uint64_t faceId);
135 
136  void
137  onFibUpdateSuccess(const RibUpdateBatch& batch,
138  const RibUpdateList& inheritedRoutes,
139  const Rib::UpdateSuccessCallback& onSuccess);
140 
141  void
143  uint32_t code, const std::string& error);
144 
145  void
146  onRouteExpiration(const Name& prefix, const Route& route);
147 
148  void
149  insert(const Name& prefix, const Route& route);
150 
151 private:
162  void
163  addUpdateToQueue(const RibUpdate& update,
164  const Rib::UpdateSuccessCallback& onSuccess,
165  const Rib::UpdateFailureCallback& onFailure);
166 
174  void
175  sendBatchFromQueue();
176 
178  // Used by RibManager unit-tests to get sent batch to simulate successful FIB update
179  std::function<void(RibUpdateBatch)> m_onSendBatchFromQueue;
180 
181  void
182  erase(const Name& prefix, const Route& route);
183 
184 private:
186  eraseEntry(RibTable::iterator it);
187 
188  void
189  updateRib(const RibUpdateBatch& batch);
190 
195  RouteSet
196  getAncestorRoutes(const RibEntry& entry) const;
197 
204  RouteSet
205  getAncestorRoutes(const Name& name) const;
206 
210  void
211  modifyInheritedRoutes(const RibUpdateList& inheritedRoutes);
212 
214  typedef std::pair<const Name&,const Route&> NameAndRoute;
215 
216  std::list<NameAndRoute>
217  findRoutesWithFaceId(uint64_t faceId);
218 
219 public:
226 
234 
238 
242 
243 private:
244  RibTable m_rib;
245  FaceLookupTable m_faceMap;
246  FibUpdater* m_fibUpdater;
247 
248  size_t m_nItems;
249 
250  friend class FibUpdater;
251 
252 private:
253  struct UpdateQueueItem
254  {
255  RibUpdateBatch batch;
256  const Rib::UpdateSuccessCallback managerSuccessCallback;
257  const Rib::UpdateFailureCallback managerFailureCallback;
258  };
259 
261  typedef std::list<UpdateQueueItem> UpdateQueue;
262  UpdateQueue m_updateBatches;
263 
264 private:
265  bool m_isUpdateInProgress;
266 };
267 
268 inline Rib::const_iterator
269 Rib::begin() const
270 {
271  return m_rib.begin();
272 }
273 
274 inline Rib::const_iterator
275 Rib::end() const
276 {
277  return m_rib.end();
278 }
279 
280 inline size_t
281 Rib::size() const
282 {
283  return m_nItems;
284 }
285 
286 inline bool
287 Rib::empty() const
288 {
289  return m_rib.empty();
290 }
291 
292 std::ostream&
293 operator<<(std::ostream& os, const Rib& rib);
294 
295 } // namespace rib
296 } // namespace nfd
297 
298 #endif // NFD_RIB_RIB_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
const_iterator begin() const
Definition: rib.hpp:269
std::list< shared_ptr< RibEntry > > findDescendants(const Name &prefix) const
finds namespaces under the passed prefix
Definition: rib.cpp:227
const_iterator end() const
Definition: rib.hpp:275
represents the Routing Information Base
Definition: rib.hpp:59
std::map< uint64_t, std::list< shared_ptr< RibEntry > > > FaceLookupTable
Definition: rib.hpp:65
bool(* RouteComparePredicate)(const Route &, const Route &)
Definition: rib.hpp:66
void beginApplyUpdate(const RibUpdate &update, const UpdateSuccessCallback &onSuccess, const UpdateFailureCallback &onFailure)
passes the provided RibUpdateBatch to FibUpdater to calculate and send FibUpdates.
Definition: rib.cpp:351
represents a collection of RibUpdates to be applied to a single FaceId
std::ostream & operator<<(std::ostream &os, const FibUpdate &update)
Definition: fib-update.hpp:74
const_iterator find(const Name &prefix) const
Definition: rib.cpp:66
ndn::util::signal::Signal< Rib, RibRouteRef > afterAddRoute
signals after a Route is added
Definition: rib.hpp:237
computes FibUpdates based on updates to the RIB and sends them to NFD
Definition: fib-updater.hpp:41
void onFibUpdateSuccess(const RibUpdateBatch &batch, const RibUpdateList &inheritedRoutes, const Rib::UpdateSuccessCallback &onSuccess)
Definition: rib.cpp:421
RibEntry::const_iterator route
Definition: rib.hpp:46
provides a lightweight signal / event system
Definition: signal.hpp:50
std::function< void(uint32_t code, const std::string &error)> UpdateFailureCallback
Definition: rib.hpp:116
references a route
Definition: rib.hpp:43
std::set< Route, RouteComparePredicate > RouteSet
Definition: rib.hpp:67
Table::const_iterator iterator
Definition: cs-internal.hpp:41
std::list< shared_ptr< RibEntry > > RibEntryList
Definition: rib.hpp:62
std::list< RibUpdate > RibUpdateList
void insert(const Name &prefix, const Route &route)
Definition: rib.cpp:91
std::map< Name, shared_ptr< RibEntry > > RibTable
Definition: rib.hpp:63
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
shared_ptr< RibEntry > entry
Definition: rib.hpp:45
represents a RIB entry, which contains one or more Routes with the same prefix
Definition: rib-entry.hpp:36
represents a route for a name prefix
Definition: route.hpp:41
shared_ptr< RibEntry > findParent(const Name &prefix) const
Definition: rib.cpp:213
Represents an absolute name.
Definition: name.hpp:42
RibTable::const_iterator const_iterator
Definition: rib.hpp:64
void beginRemoveFace(uint64_t faceId)
starts the FIB update process when a face has been destroyed
Definition: rib.cpp:363
ndn::util::signal::Signal< Rib, Name > afterInsertEntry
signals after a RIB entry is inserted
Definition: rib.hpp:225
void onFibUpdateFailure(const Rib::UpdateFailureCallback &onFailure, uint32_t code, const std::string &error)
Definition: rib.cpp:451
bool empty() const
Definition: rib.hpp:287
ndn::util::signal::Signal< Rib, Name > afterEraseEntry
signals after a RIB entry is erased
Definition: rib.hpp:233
void onRouteExpiration(const Name &prefix, const Route &route)
Definition: rib.cpp:200
RouteList::const_iterator const_iterator
Definition: rib-entry.hpp:41
std::list< shared_ptr< RibEntry > > findDescendantsForNonInsertedName(const Name &prefix) const
finds namespaces under the passed prefix
Definition: rib.cpp:249
bool operator<(const ReadvertisedRoute &lhs, const ReadvertisedRoute &rhs)
std::function< void()> UpdateSuccessCallback
Definition: rib.hpp:115
ndn::util::signal::Signal< Rib, RibRouteRef > beforeRemoveRoute
signals before a route is removed
Definition: rib.hpp:241
void setFibUpdater(FibUpdater *updater)
Definition: rib.cpp:60
size_t size() const
Definition: rib.hpp:281