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 
56 class Rib : noncopyable
57 {
58 public:
59  typedef std::list<shared_ptr<RibEntry>> RibEntryList;
60  typedef std::map<Name, shared_ptr<RibEntry>> RibTable;
61  typedef RibTable::const_iterator const_iterator;
62  typedef std::map<uint64_t, std::list<shared_ptr<RibEntry>>> FaceLookupTable;
63  typedef bool (*RouteComparePredicate)(const Route&, const Route&);
64  typedef std::set<Route, RouteComparePredicate> RouteSet;
65 
66  Rib();
67 
68  ~Rib();
69 
70  void
71  setFibUpdater(FibUpdater* updater);
72 
73  const_iterator
74  find(const Name& prefix) const;
75 
76  Route*
77  find(const Name& prefix, const Route& route) const;
78 
79  const_iterator
80  begin() const;
81 
82  const_iterator
83  end() const;
84 
85  size_t
86  size() const;
87 
88  bool
89  empty() const;
90 
91  shared_ptr<RibEntry>
92  findParent(const Name& prefix) const;
93 
97  std::list<shared_ptr<RibEntry>>
98  findDescendants(const Name& prefix) const;
99 
108  std::list<shared_ptr<RibEntry>>
109  findDescendantsForNonInsertedName(const Name& prefix) const;
110 
111 public:
112  typedef function<void()> UpdateSuccessCallback;
113  typedef function<void(uint32_t code, const std::string& error)> UpdateFailureCallback;
114 
123  void
124  beginApplyUpdate(const RibUpdate& update,
125  const UpdateSuccessCallback& onSuccess,
126  const UpdateFailureCallback& onFailure);
127 
130  void
131  beginRemoveFace(uint64_t faceId);
132 
133  void
134  onFibUpdateSuccess(const RibUpdateBatch& batch,
135  const RibUpdateList& inheritedRoutes,
136  const Rib::UpdateSuccessCallback& onSuccess);
137 
138  void
139  onFibUpdateFailure(const Rib::UpdateFailureCallback& onFailure,
140  uint32_t code, const std::string& error);
141 
142  void
143  onRouteExpiration(const Name& prefix, const Route& route);
144 
145  void
146  insert(const Name& prefix, const Route& route);
147 
148 private:
159  void
160  addUpdateToQueue(const RibUpdate& update,
161  const Rib::UpdateSuccessCallback& onSuccess,
162  const Rib::UpdateFailureCallback& onFailure);
163 
171  void
172  sendBatchFromQueue();
173 
175  // Used by RibManager unit-tests to get sent batch to simulate successful FIB update
176  function<void(RibUpdateBatch)> m_onSendBatchFromQueue;
177 
178  void
179  erase(const Name& prefix, const Route& route);
180 
181 private:
183  eraseEntry(RibTable::iterator it);
184 
185  void
186  updateRib(const RibUpdateBatch& batch);
187 
192  RouteSet
193  getAncestorRoutes(const RibEntry& entry) const;
194 
201  RouteSet
202  getAncestorRoutes(const Name& name) const;
203 
207  void
208  modifyInheritedRoutes(const RibUpdateList& inheritedRoutes);
209 
211  typedef std::pair<const Name&,const Route&> NameAndRoute;
212 
213  std::list<NameAndRoute>
214  findRoutesWithFaceId(uint64_t faceId);
215 
216 public:
223 
231 
235 
239 
240 private:
241  RibTable m_rib;
242  FaceLookupTable m_faceMap;
243  FibUpdater* m_fibUpdater;
244 
245  size_t m_nItems;
246 
247  friend class FibUpdater;
248 
249 private:
250  struct UpdateQueueItem
251  {
252  RibUpdateBatch batch;
253  const Rib::UpdateSuccessCallback managerSuccessCallback;
254  const Rib::UpdateFailureCallback managerFailureCallback;
255  };
256 
258  typedef std::list<UpdateQueueItem> UpdateQueue;
259  UpdateQueue m_updateBatches;
260 
261 private:
262  bool m_isUpdateInProgress;
263 };
264 
265 inline Rib::const_iterator
266 Rib::begin() const
267 {
268  return m_rib.begin();
269 }
270 
271 inline Rib::const_iterator
272 Rib::end() const
273 {
274  return m_rib.end();
275 }
276 
277 inline size_t
278 Rib::size() const
279 {
280  return m_nItems;
281 }
282 
283 inline bool
284 Rib::empty() const
285 {
286  return m_rib.empty();
287 }
288 
289 std::ostream&
290 operator<<(std::ostream& os, const Rib& rib);
291 
292 } // namespace rib
293 } // namespace nfd
294 
295 #endif // NFD_RIB_RIB_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
const_iterator begin() const
Definition: rib.hpp:266
const_iterator end() const
Definition: rib.hpp:272
represents the Routing Information Base
Definition: rib.hpp:56
std::map< uint64_t, std::list< shared_ptr< RibEntry > > > FaceLookupTable
Definition: rib.hpp:62
Rib
Copyright (c) 2014-2016, 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:234
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
references a route
Definition: rib.hpp:43
function< void(uint32_t code, const std::string &error)> UpdateFailureCallback
Definition: rib.hpp:113
std::set< Route, RouteComparePredicate > RouteSet
Definition: rib.hpp:64
Table::const_iterator iterator
Definition: cs-internal.hpp:41
function< void()> UpdateSuccessCallback
Definition: rib.hpp:112
std::list< shared_ptr< RibEntry > > RibEntryList
Definition: rib.hpp:59
std::list< RibUpdate > RibUpdateList
std::map< Name, shared_ptr< RibEntry > > RibTable
Definition: rib.hpp:60
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:37
Name abstraction to represent an absolute name.
Definition: name.hpp:46
RibTable::const_iterator const_iterator
Definition: rib.hpp:61
ndn::util::signal::Signal< Rib, Name > afterInsertEntry
signals after a RIB entry is inserted
Definition: rib.hpp:222
bool empty() const
Definition: rib.hpp:284
ndn::util::signal::Signal< Rib, Name > afterEraseEntry
signals after a RIB entry is erased
Definition: rib.hpp:230
RouteList::const_iterator const_iterator
Definition: rib-entry.hpp:41
ndn::util::signal::Signal< Rib, RibRouteRef > beforeRemoveRoute
signals before a route is removed
Definition: rib.hpp:238
size_t size() const
Definition: rib.hpp:278