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-2019, 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_DAEMON_RIB_FIB_UPDATER_HPP
27 #define NFD_DAEMON_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 
34 #include <ndn-cxx/mgmt/nfd/controller.hpp>
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  using std::runtime_error::runtime_error;
48  };
49 
50 public:
51  typedef std::list<FibUpdate> FibUpdateList;
52 
53  typedef std::function<void(RibUpdateList inheritedRoutes)> FibUpdateSuccessCallback;
54  typedef std::function<void(uint32_t code, const std::string& error)> FibUpdateFailureCallback;
55 
56  FibUpdater(Rib& rib, ndn::nfd::Controller& controller);
57 
64  void
66  const FibUpdateSuccessCallback& onSuccess,
67  const FibUpdateFailureCallback& onFailure);
68 
73  void
74  computeUpdates(const RibUpdateBatch& batch);
75 
84  void
85  sendUpdates(const FibUpdateList& updates,
86  const FibUpdateSuccessCallback& onSuccess,
87  const FibUpdateFailureCallback& onFailure);
88 
92  void
93  sendUpdatesForBatchFaceId(const FibUpdateSuccessCallback& onSuccess,
94  const FibUpdateFailureCallback& onFailure);
95 
99  void
100  sendUpdatesForNonBatchFaceId(const FibUpdateSuccessCallback& onSuccess,
101  const FibUpdateFailureCallback& onFailure);
102 
108  void
109  sendAddNextHopUpdate(const FibUpdate& update,
110  const FibUpdateSuccessCallback& onSuccess,
111  const FibUpdateFailureCallback& onFailure,
112  uint32_t nTimeouts = 0);
113 
119  void
120  sendRemoveNextHopUpdate(const FibUpdate& update,
121  const FibUpdateSuccessCallback& onSuccess,
122  const FibUpdateFailureCallback& onFailure,
123  uint32_t nTimeouts = 0);
124 
125 private:
128  void
129  computeUpdatesForRegistration(const RibUpdate& update);
130 
133  void
134  computeUpdatesForUnregistration(const RibUpdate& update);
135 
148  void
149  onUpdateSuccess(const FibUpdate update,
150  const FibUpdateSuccessCallback& onSuccess,
151  const FibUpdateFailureCallback& onFailure);
152 
168  void
169  onUpdateError(const FibUpdate update,
170  const FibUpdateSuccessCallback& onSuccess,
171  const FibUpdateFailureCallback& onFailure,
172  const ndn::nfd::ControlResponse& response, uint32_t nTimeouts);
173 
174 private:
182  void
183  addFibUpdate(const FibUpdate update);
184 
187  void
188  addInheritedRoutes(const RibEntry& entry, const Rib::RouteSet& routesToAdd);
189 
193  void
194  addInheritedRoutes(const Name& name, const Rib::RouteSet& routesToAdd, const Route& ignore);
195 
198  void
199  removeInheritedRoutes(const RibEntry& entry, const Rib::RouteSet& routesToRemove);
200 
203  void
204  createFibUpdatesForNewRibEntry(const Name& name, const Route& route,
205  const Rib::RibEntryList& children);
206 
209  void
210  createFibUpdatesForNewRoute(const RibEntry& entry, const Route& route,
211  const bool captureWasTurnedOn);
212 
215  void
216  createFibUpdatesForUpdatedRoute(const RibEntry& entry, const Route& route,
217  const Route& existingRoute);
218 
221  void
222  createFibUpdatesForErasedRoute(const RibEntry& entry, const Route& route,
223  const bool captureWasTurnedOff);
224 
227  void
228  createFibUpdatesForErasedRibEntry(const RibEntry& entry);
229 
232  void
233  modifyChildrensInheritedRoutes(const Rib::RibEntryList& children,
234  const Rib::RouteSet& routesToAdd,
235  const Rib::RouteSet& routesToRemove);
236 
239  void
240  traverseSubTree(const RibEntry& entry, Rib::RouteSet routesToAdd, Rib::RouteSet routesToRemove);
241 
242 private:
245  void
246  addInheritedRoute(const Name& name, const Route& route);
247 
250  void
251  removeInheritedRoute(const Name& name, const Route& route);
252 
253 private:
254  const Rib& m_rib;
255  ndn::nfd::Controller& m_controller;
256  uint64_t m_batchFaceId;
257 
259  FibUpdateList m_updatesForBatchFaceId;
260  FibUpdateList m_updatesForNonBatchFaceId;
261 
265  RibUpdateList m_inheritedRoutes;
266 
267 private:
268  static const unsigned int MAX_NUM_TIMEOUTS;
269  static const uint32_t ERROR_FACE_NOT_FOUND;
270 };
271 
272 } // namespace rib
273 } // namespace nfd
274 
275 #endif // NFD_DAEMON_RIB_FIB_UPDATER_HPP
std::list< FibUpdate > FibUpdateList
Definition: fib-updater.hpp:51
represents the Routing Information Base
Definition: rib.hpp:59
std::set< Route, RouteComparePredicate > RouteSet
Definition: rib.hpp:67
computes FibUpdates based on updates to the RIB and sends them to NFD
Definition: fib-updater.hpp:41
std::function< void(RibUpdateList inheritedRoutes)> FibUpdateSuccessCallback
Definition: fib-updater.hpp:53
Represents a collection of RibUpdates to be applied to a single FaceId.
void computeAndSendFibUpdates(const RibUpdateBatch &batch, const FibUpdateSuccessCallback &onSuccess, const FibUpdateFailureCallback &onFailure)
computes FibUpdates using the provided RibUpdateBatch and then sends the updates to NFD&#39;s FIB ...
Definition: fib-updater.cpp:49
std::list< RibUpdate > RibUpdateList
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
std::list< shared_ptr< RibEntry > > RibEntryList
Definition: rib.hpp:62
represents a route for a name prefix
Definition: route.hpp:43
FibUpdater(Rib &rib, ndn::nfd::Controller &controller)
Definition: fib-updater.cpp:41
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
represents a FIB update
Definition: fib-update.hpp:37
Represents a RIB entry, which contains one or more Routes with the same prefix.
Definition: rib-entry.hpp:38
std::function< void(uint32_t code, const std::string &error)> FibUpdateFailureCallback
Definition: fib-updater.hpp:54