NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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 "common.hpp"
30 
31 #include "rib-entry.hpp"
32 #include "rib-update-batch.hpp"
33 
34 #include <ndn-cxx/management/nfd-control-parameters.hpp>
35 
36 namespace nfd {
37 namespace rib {
38 
40 
41 class FibUpdater;
42 
45 class Rib : noncopyable
46 {
47 public:
48  typedef std::list<shared_ptr<RibEntry>> RibEntryList;
49  typedef std::map<Name, shared_ptr<RibEntry>> RibTable;
50  typedef RibTable::const_iterator const_iterator;
51  typedef std::map<uint64_t, std::list<shared_ptr<RibEntry>>> FaceLookupTable;
52  typedef bool (*RouteComparePredicate)(const Route&, const Route&);
53  typedef std::set<Route, RouteComparePredicate> RouteSet;
54 
55  Rib();
56 
57  ~Rib();
58 
59  void
60  setFibUpdater(FibUpdater* updater);
61 
62  const_iterator
63  find(const Name& prefix) const;
64 
65  Route*
66  find(const Name& prefix, const Route& route) const;
67 
68  const_iterator
69  begin() const;
70 
71  const_iterator
72  end() const;
73 
74  size_t
75  size() const;
76 
77  bool
78  empty() const;
79 
80  shared_ptr<RibEntry>
81  findParent(const Name& prefix) const;
82 
86  std::list<shared_ptr<RibEntry>>
87  findDescendants(const Name& prefix) const;
88 
97  std::list<shared_ptr<RibEntry>>
98  findDescendantsForNonInsertedName(const Name& prefix) const;
99 
100 public:
101  typedef function<void()> UpdateSuccessCallback;
102  typedef function<void(uint32_t code, const std::string& error)> UpdateFailureCallback;
103 
112  void
113  beginApplyUpdate(const RibUpdate& update,
114  const UpdateSuccessCallback& onSuccess,
115  const UpdateFailureCallback& onFailure);
116 
119  void
120  beginRemoveFace(uint64_t faceId);
121 
122  void
123  onFibUpdateSuccess(const RibUpdateBatch& batch,
124  const RibUpdateList& inheritedRoutes,
125  const Rib::UpdateSuccessCallback& onSuccess);
126 
127  void
129  uint32_t code, const std::string& error);
130 
131  void
132  onRouteExpiration(const Name& prefix, const Route& route);
133 
134 private:
145  void
146  addUpdateToQueue(const RibUpdate& update,
147  const Rib::UpdateSuccessCallback& onSuccess,
148  const Rib::UpdateFailureCallback& onFailure);
149 
157  void
158  sendBatchFromQueue();
159 
161  // Used by RibManager unit-tests to get sent batch to simulate successful FIB update
162  function<void(RibUpdateBatch)> m_onSendBatchFromQueue;
163 
164 public:
165  void
166  insert(const Name& prefix, const Route& route);
167 
169  void
170  erase(const Name& prefix, const Route& route);
171 
172 private:
174  eraseEntry(RibTable::iterator it);
175 
176  void
177  updateRib(const RibUpdateBatch& batch);
178 
183  RouteSet
184  getAncestorRoutes(const RibEntry& entry) const;
185 
192  RouteSet
193  getAncestorRoutes(const Name& name) const;
194 
198  void
199  modifyInheritedRoutes(const RibUpdateList& inheritedRoutes);
200 
202  typedef std::pair<const Name&,const Route&> NameAndRoute;
203 
204  std::list<NameAndRoute>
205  findRoutesWithFaceId(uint64_t faceId);
206 
207 public:
210 
211 private:
212  RibTable m_rib;
213  FaceLookupTable m_faceMap;
214  FibUpdater* m_fibUpdater;
215 
216  size_t m_nItems;
217 
218  friend class FibUpdater;
219 
220 private:
221  struct UpdateQueueItem
222  {
223  RibUpdateBatch batch;
224  const Rib::UpdateSuccessCallback managerSuccessCallback;
225  const Rib::UpdateFailureCallback managerFailureCallback;
226  };
227 
229  typedef std::list<UpdateQueueItem> UpdateQueue;
230  UpdateQueue m_updateBatches;
231 
232 private:
233  bool m_isUpdateInProgress;
234 };
235 
236 inline Rib::const_iterator
237 Rib::begin() const
238 {
239  return m_rib.begin();
240 }
241 
242 inline Rib::const_iterator
243 Rib::end() const
244 {
245  return m_rib.end();
246 }
247 
248 inline size_t
249 Rib::size() const
250 {
251  return m_nItems;
252 }
253 
254 inline bool
255 Rib::empty() const
256 {
257  return m_rib.empty();
258 }
259 
260 std::ostream&
261 operator<<(std::ostream& os, const Rib& rib);
262 
263 } // namespace rib
264 } // namespace nfd
265 
266 #endif // NFD_RIB_RIB_HPP
const_iterator begin() const
Definition: rib.hpp:237
std::list< shared_ptr< RibEntry > > findDescendants(const Name &prefix) const
finds namespaces under the passed prefix
Definition: rib.cpp:214
const_iterator end() const
Definition: rib.hpp:243
represents the RIB
Definition: rib.hpp:45
std::map< uint64_t, std::list< shared_ptr< RibEntry > > > FaceLookupTable
Definition: rib.hpp:51
bool(* RouteComparePredicate)(const Route &, const Route &)
Definition: rib.hpp:52
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:338
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:59
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:408
provides a lightweight signal / event system
function< void(uint32_t code, const std::string &error)> UpdateFailureCallback
Definition: rib.hpp:102
std::set< Route, RouteComparePredicate > RouteSet
Definition: rib.hpp:53
Table::const_iterator iterator
Definition: cs-internal.hpp:41
function< void()> UpdateSuccessCallback
Definition: rib.hpp:101
std::list< shared_ptr< RibEntry > > RibEntryList
Definition: rib.hpp:48
std::list< RibUpdate > RibUpdateList
void insert(const Name &prefix, const Route &route)
Definition: rib.cpp:84
std::map< Name, shared_ptr< RibEntry > > RibTable
Definition: rib.hpp:49
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
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:38
shared_ptr< RibEntry > findParent(const Name &prefix) const
Definition: rib.cpp:200
Name abstraction to represent an absolute name.
Definition: name.hpp:46
RibTable::const_iterator const_iterator
Definition: rib.hpp:50
void beginRemoveFace(uint64_t faceId)
starts the FIB update process when a face has been destroyed
Definition: rib.cpp:350
ndn::util::signal::Signal< Rib, Name > afterInsertEntry
Definition: rib.hpp:208
void onFibUpdateFailure(const Rib::UpdateFailureCallback &onFailure, uint32_t code, const std::string &error)
Definition: rib.cpp:438
bool empty() const
Definition: rib.hpp:255
ndn::util::signal::Signal< Rib, Name > afterEraseEntry
Definition: rib.hpp:209
void onRouteExpiration(const Name &prefix, const Route &route)
Definition: rib.cpp:187
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:39
std::list< shared_ptr< RibEntry > > findDescendantsForNonInsertedName(const Name &prefix) const
finds namespaces under the passed prefix
Definition: rib.cpp:236
void setFibUpdater(FibUpdater *updater)
Definition: rib.cpp:53
size_t size() const
Definition: rib.hpp:249