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 
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  void
72  setFibUpdater(FibUpdater* updater);
73 
75  find(const Name& prefix) const;
76 
77  Route*
78  find(const Name& prefix, const Route& route) const;
79 
80  Route*
81  findLongestPrefix(const Name& prefix, const Route& route) const;
82 
84  begin() const;
85 
87  end() const;
88 
89  size_t
90  size() const;
91 
92  bool
93  empty() const;
94 
95  shared_ptr<RibEntry>
96  findParent(const Name& prefix) const;
97 
101  std::list<shared_ptr<RibEntry>>
102  findDescendants(const Name& prefix) const;
103 
112  std::list<shared_ptr<RibEntry>>
113  findDescendantsForNonInsertedName(const Name& prefix) const;
114 
115 public:
116  using UpdateSuccessCallback = std::function<void()>;
117  using UpdateFailureCallback = std::function<void(uint32_t code, const std::string& error)>;
118 
127  void
128  beginApplyUpdate(const RibUpdate& update,
129  const UpdateSuccessCallback& onSuccess,
130  const UpdateFailureCallback& onFailure);
131 
134  void
135  beginRemoveFace(uint64_t faceId);
136 
137  void
138  onFibUpdateSuccess(const RibUpdateBatch& batch,
139  const RibUpdateList& inheritedRoutes,
140  const Rib::UpdateSuccessCallback& onSuccess);
141 
142  void
144  uint32_t code, const std::string& error);
145 
146  void
147  onRouteExpiration(const Name& prefix, const Route& route);
148 
149  void
150  insert(const Name& prefix, const Route& route);
151 
152 private:
163  void
164  addUpdateToQueue(const RibUpdate& update,
165  const Rib::UpdateSuccessCallback& onSuccess,
166  const Rib::UpdateFailureCallback& onFailure);
167 
175  void
176  sendBatchFromQueue();
177 
179 #ifdef WITH_TESTS
180 
185  std::function<bool(const RibUpdateBatch&)> mockFibResponse;
186 
187  bool wantMockFibResponseOnce = false;
188 #endif
189 
190  void
191  erase(const Name& prefix, const Route& route);
192 
193 private:
195  eraseEntry(RibTable::iterator it);
196 
197  void
198  updateRib(const RibUpdateBatch& batch);
199 
204  RouteSet
205  getAncestorRoutes(const RibEntry& entry) const;
206 
213  RouteSet
214  getAncestorRoutes(const Name& name) const;
215 
219  void
220  modifyInheritedRoutes(const RibUpdateList& inheritedRoutes);
221 
223  using NameAndRoute = std::pair<const Name&, const Route&>;
224 
225  std::list<NameAndRoute>
226  findRoutesWithFaceId(uint64_t faceId);
227 
228 public:
235 
243 
247 
251 
252 private:
253  RibTable m_rib;
254  FaceLookupTable m_faceMap;
255  FibUpdater* m_fibUpdater;
256 
257  size_t m_nItems;
258 
259  friend class FibUpdater;
260 
261 private:
262  struct UpdateQueueItem
263  {
264  RibUpdateBatch batch;
265  const Rib::UpdateSuccessCallback managerSuccessCallback;
266  const Rib::UpdateFailureCallback managerFailureCallback;
267  };
268 
270  typedef std::list<UpdateQueueItem> UpdateQueue;
271  UpdateQueue m_updateBatches;
272 
273 private:
274  bool m_isUpdateInProgress;
275 };
276 
277 inline Rib::const_iterator
278 Rib::begin() const
279 {
280  return m_rib.begin();
281 }
282 
283 inline Rib::const_iterator
284 Rib::end() const
285 {
286  return m_rib.end();
287 }
288 
289 inline size_t
290 Rib::size() const
291 {
292  return m_nItems;
293 }
294 
295 inline bool
296 Rib::empty() const
297 {
298  return m_rib.empty();
299 }
300 
301 std::ostream&
302 operator<<(std::ostream& os, const Rib& rib);
303 
304 } // namespace rib
305 } // namespace nfd
306 
307 #endif // NFD_RIB_RIB_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
const_iterator begin() const
Definition: rib.hpp:278
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:284
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:350
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
Route * findLongestPrefix(const Name &prefix, const Route &route) const
Definition: rib.cpp:84
const_iterator find(const Name &prefix) const
Definition: rib.cpp:61
ndn::util::signal::Signal< Rib, RibRouteRef > afterAddRoute
signals after a Route is added
Definition: rib.hpp:246
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:429
RibEntry::const_iterator route
Definition: rib.hpp:46
provides a lightweight signal / event system
Definition: signal.hpp:51
std::function< void(uint32_t code, const std::string &error)> UpdateFailureCallback
Definition: rib.hpp:117
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:98
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:38
represents a route for a name prefix
Definition: route.hpp:43
shared_ptr< RibEntry > findParent(const Name &prefix) const
Definition: rib.cpp:214
Represents an absolute name.
Definition: name.hpp:43
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:362
ndn::util::signal::Signal< Rib, Name > afterInsertEntry
signals after a RIB entry is inserted
Definition: rib.hpp:234
void onFibUpdateFailure(const Rib::UpdateFailureCallback &onFailure, uint32_t code, const std::string &error)
Definition: rib.cpp:459
bool empty() const
Definition: rib.hpp:296
ndn::util::signal::Signal< Rib, Name > afterEraseEntry
signals after a RIB entry is erased
Definition: rib.hpp:242
void onRouteExpiration(const Name &prefix, const Route &route)
Definition: rib.cpp:201
RouteList::const_iterator const_iterator
Definition: rib-entry.hpp:43
std::list< shared_ptr< RibEntry > > findDescendantsForNonInsertedName(const Name &prefix) const
finds namespaces under the passed prefix
Definition: rib.cpp:248
bool operator<(const ReadvertisedRoute &lhs, const ReadvertisedRoute &rhs)
std::function< void()> UpdateSuccessCallback
Definition: rib.hpp:116
ndn::util::signal::Signal< Rib, RibRouteRef > beforeRemoveRoute
signals before a route is removed
Definition: rib.hpp:250
void setFibUpdater(FibUpdater *updater)
Definition: rib.cpp:55
size_t size() const
Definition: rib.hpp:290