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 
37 using ndn::nfd::ControlParameters;
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
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:
222  ndn::util::signal::Signal<Rib, Name> afterInsertEntry;
223 
230  ndn::util::signal::Signal<Rib, Name> afterEraseEntry;
231 
234  ndn::util::signal::Signal<Rib, RibRouteRef> afterAddRoute;
235 
238  ndn::util::signal::Signal<Rib, RibRouteRef> beforeRemoveRoute;
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
bool(* RouteComparePredicate)(const Route &, const Route &)
Definition: rib.hpp:63
references a route
Definition: rib.hpp:43
represents the Routing Information Base
Definition: rib.hpp:56
std::set< Route, RouteComparePredicate > RouteSet
Definition: rib.hpp:64
void onFibUpdateFailure(const Rib::UpdateFailureCallback &onFailure, uint32_t code, const std::string &error)
Definition: rib.cpp:444
computes FibUpdates based on updates to the RIB and sends them to NFD
Definition: fib-updater.hpp:41
size_t size() const
Definition: rib.hpp:278
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
std::list< shared_ptr< RibEntry > > findDescendantsForNonInsertedName(const Name &prefix) const
finds namespaces under the passed prefix
Definition: rib.cpp:242
represents a collection of RibUpdates to be applied to a single FaceId
void setFibUpdater(FibUpdater *updater)
Definition: rib.cpp:53
ndn::util::signal::Signal< Rib, Name > afterEraseEntry
signals after a RIB entry is erased
Definition: rib.hpp:230
const_iterator end() const
Definition: rib.hpp:272
ndn::util::signal::Signal< Rib, RibRouteRef > afterAddRoute
signals after a Route is added
Definition: rib.hpp:234
Table::const_iterator iterator
Definition: cs-internal.hpp:41
std::list< RibUpdate > RibUpdateList
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
std::list< shared_ptr< RibEntry > > RibEntryList
Definition: rib.hpp:59
function< void(uint32_t code, const std::string &error)> UpdateFailureCallback
Definition: rib.hpp:113
void insert(const Name &prefix, const Route &route)
Definition: rib.cpp:84
std::list< shared_ptr< RibEntry > > findDescendants(const Name &prefix) const
finds namespaces under the passed prefix
Definition: rib.cpp:220
represents a route for a name prefix
Definition: route.hpp:37
RouteList::const_iterator const_iterator
Definition: rib-entry.hpp:41
RibEntry::const_iterator route
Definition: rib.hpp:46
std::map< Name, shared_ptr< RibEntry > > RibTable
Definition: rib.hpp:60
shared_ptr< RibEntry > entry
Definition: rib.hpp:45
ndn::util::signal::Signal< Rib, RibRouteRef > beforeRemoveRoute
signals before a route is removed
Definition: rib.hpp:238
const_iterator begin() const
Definition: rib.hpp:266
function< void()> UpdateSuccessCallback
Definition: rib.hpp:112
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
void onFibUpdateSuccess(const RibUpdateBatch &batch, const RibUpdateList &inheritedRoutes, const Rib::UpdateSuccessCallback &onSuccess)
Definition: rib.cpp:414
RibTable::const_iterator const_iterator
Definition: rib.hpp:61
represents a RIB entry, which contains one or more Routes with the same prefix
Definition: rib-entry.hpp:36
void beginRemoveFace(uint64_t faceId)
starts the FIB update process when a face has been destroyed
Definition: rib.cpp:356
bool empty() const
Definition: rib.hpp:284
std::map< uint64_t, std::list< shared_ptr< RibEntry > > > FaceLookupTable
Definition: rib.hpp:62
void onRouteExpiration(const Name &prefix, const Route &route)
Definition: rib.cpp:193
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:344
ndn::util::signal::Signal< Rib, Name > afterInsertEntry
signals after a RIB entry is inserted
Definition: rib.hpp:222
shared_ptr< RibEntry > findParent(const Name &prefix) const
Definition: rib.cpp:206