NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
fib-updater.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_FIB_UPDATER_HPP
27 #define NFD_RIB_FIB_UPDATER_HPP
28 
29 #include "core/common.hpp"
30 #include "fib-update.hpp"
31 #include "rib.hpp"
32 #include "rib-update-batch.hpp"
33 
35 
36 namespace nfd {
37 namespace rib {
38 
41 class FibUpdater : noncopyable
42 {
43 public:
44  class Error : public std::runtime_error
45  {
46  public:
47  explicit
48  Error(const std::string& what)
49  : std::runtime_error(what)
50  {
51  }
52  };
53 
54 public:
55  typedef std::list<FibUpdate> FibUpdateList;
56 
57  typedef std::function<void(RibUpdateList inheritedRoutes)> FibUpdateSuccessCallback;
58  typedef std::function<void(uint32_t code, const std::string& error)> FibUpdateFailureCallback;
59 
60  FibUpdater(Rib& rib, ndn::nfd::Controller& controller);
61 
68  void
70  const FibUpdateSuccessCallback& onSuccess,
71  const FibUpdateFailureCallback& onFailure);
72 
77  void
78  computeUpdates(const RibUpdateBatch& batch);
79 
88  void
89  sendUpdates(const FibUpdateList& updates,
90  const FibUpdateSuccessCallback& onSuccess,
91  const FibUpdateFailureCallback& onFailure);
92 
96  void
97  sendUpdatesForBatchFaceId(const FibUpdateSuccessCallback& onSuccess,
98  const FibUpdateFailureCallback& onFailure);
99 
103  void
104  sendUpdatesForNonBatchFaceId(const FibUpdateSuccessCallback& onSuccess,
105  const FibUpdateFailureCallback& onFailure);
106 
112  void
113  sendAddNextHopUpdate(const FibUpdate& update,
114  const FibUpdateSuccessCallback& onSuccess,
115  const FibUpdateFailureCallback& onFailure,
116  uint32_t nTimeouts = 0);
117 
123  void
124  sendRemoveNextHopUpdate(const FibUpdate& update,
125  const FibUpdateSuccessCallback& onSuccess,
126  const FibUpdateFailureCallback& onFailure,
127  uint32_t nTimeouts = 0);
128 
129 private:
132  void
133  computeUpdatesForRegistration(const RibUpdate& update);
134 
137  void
138  computeUpdatesForUnregistration(const RibUpdate& update);
139 
152  void
153  onUpdateSuccess(const FibUpdate update,
154  const FibUpdateSuccessCallback& onSuccess,
155  const FibUpdateFailureCallback& onFailure);
156 
172  void
173  onUpdateError(const FibUpdate update,
174  const FibUpdateSuccessCallback& onSuccess,
175  const FibUpdateFailureCallback& onFailure,
176  const ndn::nfd::ControlResponse& response, uint32_t nTimeouts);
177 
178 private:
186  void
187  addFibUpdate(const FibUpdate update);
188 
191  void
192  addInheritedRoutes(const RibEntry& entry, const Rib::RouteSet& routesToAdd);
193 
197  void
198  addInheritedRoutes(const Name& name, const Rib::RouteSet& routesToAdd, const Route& ignore);
199 
202  void
203  removeInheritedRoutes(const RibEntry& entry, const Rib::RouteSet& routesToRemove);
204 
207  void
208  createFibUpdatesForNewRibEntry(const Name& name, const Route& route,
209  const Rib::RibEntryList& children);
210 
213  void
214  createFibUpdatesForNewRoute(const RibEntry& entry, const Route& route,
215  const bool captureWasTurnedOn);
216 
219  void
220  createFibUpdatesForUpdatedRoute(const RibEntry& entry, const Route& route,
221  const Route& existingRoute);
222 
225  void
226  createFibUpdatesForErasedRoute(const RibEntry& entry, const Route& route,
227  const bool captureWasTurnedOff);
228 
231  void
232  createFibUpdatesForErasedRibEntry(const RibEntry& entry);
233 
236  void
237  modifyChildrensInheritedRoutes(const Rib::RibEntryList& children,
238  const Rib::RouteSet& routesToAdd,
239  const Rib::RouteSet& routesToRemove);
240 
243  void
244  traverseSubTree(const RibEntry& entry, Rib::RouteSet routesToAdd, Rib::RouteSet routesToRemove);
245 
246 private:
249  void
250  addInheritedRoute(const Name& name, const Route& route);
251 
254  void
255  removeInheritedRoute(const Name& name, const Route& route);
256 
257 private:
258  const Rib& m_rib;
259  ndn::nfd::Controller& m_controller;
260  uint64_t m_batchFaceId;
261 
263  FibUpdateList m_updatesForBatchFaceId;
264  FibUpdateList m_updatesForNonBatchFaceId;
265 
269  RibUpdateList m_inheritedRoutes;
270 
271 private:
272  static const unsigned int MAX_NUM_TIMEOUTS;
273  static const uint32_t ERROR_FACE_NOT_FOUND;
274 };
275 
276 } // namespace rib
277 } // namespace nfd
278 
279 #endif // NFD_RIB_FIB_UPDATER_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
FibUpdater(Rib &rib, ndn::nfd::Controller &controller)
Definition: fib-updater.cpp:41
represents the Routing Information Base
Definition: rib.hpp:59
Represents a collection of RibUpdates to be applied to a single FaceId.
computes FibUpdates based on updates to the RIB and sends them to NFD
Definition: fib-updater.hpp:41
std::list< FibUpdate > FibUpdateList
Definition: fib-updater.hpp:55
std::function< void(RibUpdateList inheritedRoutes)> FibUpdateSuccessCallback
Definition: fib-updater.hpp:57
std::function< void(uint32_t code, const std::string &error)> FibUpdateFailureCallback
Definition: fib-updater.hpp:58
std::set< Route, RouteComparePredicate > RouteSet
Definition: rib.hpp:67
represents a FIB update
Definition: fib-update.hpp:37
std::list< shared_ptr< RibEntry > > RibEntryList
Definition: rib.hpp:62
std::list< RibUpdate > RibUpdateList
Error(const std::string &what)
Definition: fib-updater.hpp:48
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:38
represents a route for a name prefix
Definition: route.hpp:43
NFD Management protocol client.
Definition: controller.hpp:51
Represents an absolute name.
Definition: name.hpp:43
ControlCommand response.
void computeAndSendFibUpdates(const RibUpdateBatch &batch, const FibUpdateSuccessCallback &onSuccess, const FibUpdateFailureCallback &onFailure)
computes FibUpdates using the provided RibUpdateBatch and then sends the updates to NFD's FIB
Definition: fib-updater.cpp:49