NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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; -*- */
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 
76  const_iterator
77  find(const Name& prefix) const;
78 
79  Route*
80  find(const Name& prefix, const Route& route) const;
81 
82  const_iterator
83  begin() const;
84 
85  const_iterator
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  typedef function<void()> UpdateSuccessCallback;
116  typedef function<void(uint32_t code, const std::string& error)> UpdateFailureCallback;
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
142  onFibUpdateFailure(const Rib::UpdateFailureCallback& onFailure,
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  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
represents the Routing Information Base
Definition: rib.hpp:59
std::map< uint64_t, std::list< shared_ptr< RibEntry > > > FaceLookupTable
Definition: rib.hpp:65
Rib
Copyright (c) 2014-2017, Regents of the University of California, Arizona Board of Regents...
Definition: rib.cpp:31
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
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
RibEntry::const_iterator route
Definition: rib.hpp:46
provides a lightweight signal / event system
Definition: signal.hpp:50
references a route
Definition: rib.hpp:43
size_t size() const
Definition: rib.hpp:281
function< void(uint32_t code, const std::string &error)> UpdateFailureCallback
Definition: rib.hpp:116
std::set< Route, RouteComparePredicate > RouteSet
Definition: rib.hpp:67
Table::const_iterator iterator
Definition: cs-internal.hpp:41
function< void()> UpdateSuccessCallback
Definition: rib.hpp:115
std::list< shared_ptr< RibEntry > > RibEntryList
Definition: rib.hpp:62
bool empty() const
Definition: rib.hpp:287
std::list< RibUpdate > RibUpdateList
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:39
Represents an absolute name.
Definition: name.hpp:42
RibTable::const_iterator const_iterator
Definition: rib.hpp:64
ndn::util::signal::Signal< Rib, Name > afterInsertEntry
signals after a RIB entry is inserted
Definition: rib.hpp:225
const_iterator end() const
Definition: rib.hpp:275
ndn::util::signal::Signal< Rib, Name > afterEraseEntry
signals after a RIB entry is erased
Definition: rib.hpp:233
RouteList::const_iterator const_iterator
Definition: rib-entry.hpp:41
const_iterator begin() const
Definition: rib.hpp:269
bool operator<(const ReadvertisedRoute &lhs, const ReadvertisedRoute &rhs)
ndn::util::signal::Signal< Rib, RibRouteRef > beforeRemoveRoute
signals before a route is removed
Definition: rib.hpp:241