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-2022, 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::rib {
37 
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  using FibUpdateList = std::list<FibUpdate>;
51  using FibUpdateSuccessCallback = std::function<void(RibUpdateList inheritedRoutes)>;
52  using FibUpdateFailureCallback = std::function<void(uint32_t code, const std::string& error)>;
53 
54  FibUpdater(Rib& rib, ndn::nfd::Controller& controller);
55 
56 #ifdef NFD_WITH_TESTS
57  virtual
58  ~FibUpdater() = default;
59 #endif
60 
67  void
69  const FibUpdateSuccessCallback& onSuccess,
70  const FibUpdateFailureCallback& onFailure);
71 
72 private:
77  void
78  computeUpdates(const RibUpdateBatch& batch);
79 
89  void
90  sendUpdates(const FibUpdateList& updates,
91  const FibUpdateSuccessCallback& onSuccess,
92  const FibUpdateFailureCallback& onFailure);
93 
98  void
99  sendUpdatesForBatchFaceId(const FibUpdateSuccessCallback& onSuccess,
100  const FibUpdateFailureCallback& onFailure);
101 
106  void
107  sendUpdatesForNonBatchFaceId(const FibUpdateSuccessCallback& onSuccess,
108  const FibUpdateFailureCallback& onFailure);
109 
117  sendAddNextHopUpdate(const FibUpdate& update,
118  const FibUpdateSuccessCallback& onSuccess,
119  const FibUpdateFailureCallback& onFailure,
120  uint32_t nTimeouts = 0);
121 
128  sendRemoveNextHopUpdate(const FibUpdate& update,
129  const FibUpdateSuccessCallback& onSuccess,
130  const FibUpdateFailureCallback& onFailure,
131  uint32_t nTimeouts = 0);
132 
133 private:
137  void
138  computeUpdatesForRegistration(const RibUpdate& update);
139 
143  void
144  computeUpdatesForUnregistration(const RibUpdate& update);
145 
159  void
160  onUpdateSuccess(const FibUpdate& update,
161  const FibUpdateSuccessCallback& onSuccess,
162  const FibUpdateFailureCallback& onFailure);
163 
180  void
181  onUpdateError(const FibUpdate& update,
182  const FibUpdateSuccessCallback& onSuccess,
183  const FibUpdateFailureCallback& onFailure,
184  const ndn::nfd::ControlResponse& response, uint32_t nTimeouts);
185 
186 private:
195  void
196  addFibUpdate(const FibUpdate& update);
197 
201  void
202  addInheritedRoutes(const RibEntry& entry, const Rib::RouteSet& routesToAdd);
203 
208  void
209  addInheritedRoutes(const Name& name, const Rib::RouteSet& routesToAdd, const Route& ignore);
210 
214  void
215  removeInheritedRoutes(const RibEntry& entry, const Rib::RouteSet& routesToRemove);
216 
220  void
221  createFibUpdatesForNewRibEntry(const Name& name, const Route& route,
222  const Rib::RibEntryList& children);
223 
227  void
228  createFibUpdatesForNewRoute(const RibEntry& entry, const Route& route,
229  bool captureWasTurnedOn);
230 
234  void
235  createFibUpdatesForUpdatedRoute(const RibEntry& entry, const Route& route,
236  const Route& existingRoute);
237 
241  void
242  createFibUpdatesForErasedRoute(const RibEntry& entry, const Route& route,
243  bool captureWasTurnedOff);
244 
248  void
249  createFibUpdatesForErasedRibEntry(const RibEntry& entry);
250 
254  void
255  modifyChildrensInheritedRoutes(const Rib::RibEntryList& children,
256  const Rib::RouteSet& routesToAdd,
257  const Rib::RouteSet& routesToRemove);
258 
262  void
263  traverseSubTree(const RibEntry& entry, Rib::RouteSet routesToAdd, Rib::RouteSet routesToRemove);
264 
268  void
269  addInheritedRoute(const Name& name, const Route& route);
270 
274  void
275  removeInheritedRoute(const Name& name, const Route& route);
276 
277 private:
278  const Rib& m_rib;
279  ndn::nfd::Controller& m_controller;
280  uint64_t m_batchFaceId;
281 
283  FibUpdateList m_updatesForBatchFaceId;
284  FibUpdateList m_updatesForNonBatchFaceId;
285 
290  RibUpdateList m_inheritedRoutes;
291 };
292 
293 } // namespace nfd::rib
294 
295 #endif // NFD_DAEMON_RIB_FIB_UPDATER_HPP
represents a FIB update
Definition: fib-update.hpp:37
Computes FibUpdates based on updates to the RIB and sends them to NFD.
Definition: fib-updater.hpp:42
std::function< void(RibUpdateList inheritedRoutes)> FibUpdateSuccessCallback
Definition: fib-updater.hpp:51
std::list< FibUpdate > FibUpdateList
Definition: fib-updater.hpp:50
FibUpdater(Rib &rib, ndn::nfd::Controller &controller)
Definition: fib-updater.cpp:40
std::function< void(uint32_t code, const std::string &error)> FibUpdateFailureCallback
Definition: fib-updater.hpp:52
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:48
Represents a RIB entry, which contains one or more Routes with the same prefix.
Definition: rib-entry.hpp:39
Represents the Routing Information Base.
Definition: rib.hpp:62
std::list< shared_ptr< RibEntry > > RibEntryList
Definition: rib.hpp:64
Represents a collection of RibUpdates to be applied to a single FaceId.
Represents a route that will be added to or removed from a namespace.
Definition: rib-update.hpp:39
Represents a route for a name prefix.
Definition: route.hpp:43
#define NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
#define NFD_VIRTUAL_WITH_TESTS
Definition: common.hpp:39
#define NFD_PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:42
std::list< RibUpdate > RibUpdateList