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  using FibUpdateList = std::list<FibUpdate>;
52  using FibUpdateSuccessCallback = std::function<void(RibUpdateList inheritedRoutes)>;
53  using FibUpdateFailureCallback = std::function<void(uint32_t code, const std::string& error)>;
54 
55  FibUpdater(Rib& rib, ndn::nfd::Controller& controller);
56 
58  ~FibUpdater() = default;
59 
66  void
68  const FibUpdateSuccessCallback& onSuccess,
69  const FibUpdateFailureCallback& onFailure);
70 
71 private:
75  void
76  computeUpdates(const RibUpdateBatch& batch);
77 
86  void
87  sendUpdates(const FibUpdateList& updates,
88  const FibUpdateSuccessCallback& onSuccess,
89  const FibUpdateFailureCallback& onFailure);
90 
94  void
95  sendUpdatesForBatchFaceId(const FibUpdateSuccessCallback& onSuccess,
96  const FibUpdateFailureCallback& onFailure);
97 
101  void
102  sendUpdatesForNonBatchFaceId(const FibUpdateSuccessCallback& onSuccess,
103  const FibUpdateFailureCallback& onFailure);
104 
111  VIRTUAL_WITH_TESTS void
112  sendAddNextHopUpdate(const FibUpdate& update,
113  const FibUpdateSuccessCallback& onSuccess,
114  const FibUpdateFailureCallback& onFailure,
115  uint32_t nTimeouts = 0);
116 
122  VIRTUAL_WITH_TESTS void
123  sendRemoveNextHopUpdate(const FibUpdate& update,
124  const FibUpdateSuccessCallback& onSuccess,
125  const FibUpdateFailureCallback& onFailure,
126  uint32_t nTimeouts = 0);
127 
128 private:
131  void
132  computeUpdatesForRegistration(const RibUpdate& update);
133 
136  void
137  computeUpdatesForUnregistration(const RibUpdate& update);
138 
151  void
152  onUpdateSuccess(const FibUpdate update,
153  const FibUpdateSuccessCallback& onSuccess,
154  const FibUpdateFailureCallback& onFailure);
155 
171  void
172  onUpdateError(const FibUpdate update,
173  const FibUpdateSuccessCallback& onSuccess,
174  const FibUpdateFailureCallback& onFailure,
175  const ndn::nfd::ControlResponse& response, uint32_t nTimeouts);
176 
177 private:
185  void
186  addFibUpdate(const FibUpdate update);
187 
190  void
191  addInheritedRoutes(const RibEntry& entry, const Rib::RouteSet& routesToAdd);
192 
196  void
197  addInheritedRoutes(const Name& name, const Rib::RouteSet& routesToAdd, const Route& ignore);
198 
201  void
202  removeInheritedRoutes(const RibEntry& entry, const Rib::RouteSet& routesToRemove);
203 
206  void
207  createFibUpdatesForNewRibEntry(const Name& name, const Route& route,
208  const Rib::RibEntryList& children);
209 
212  void
213  createFibUpdatesForNewRoute(const RibEntry& entry, const Route& route,
214  const bool captureWasTurnedOn);
215 
218  void
219  createFibUpdatesForUpdatedRoute(const RibEntry& entry, const Route& route,
220  const Route& existingRoute);
221 
224  void
225  createFibUpdatesForErasedRoute(const RibEntry& entry, const Route& route,
226  const bool captureWasTurnedOff);
227 
230  void
231  createFibUpdatesForErasedRibEntry(const RibEntry& entry);
232 
235  void
236  modifyChildrensInheritedRoutes(const Rib::RibEntryList& children,
237  const Rib::RouteSet& routesToAdd,
238  const Rib::RouteSet& routesToRemove);
239 
242  void
243  traverseSubTree(const RibEntry& entry, Rib::RouteSet routesToAdd, Rib::RouteSet routesToRemove);
244 
247  void
248  addInheritedRoute(const Name& name, const Route& route);
249 
252  void
253  removeInheritedRoute(const Name& name, const Route& route);
254 
255 private:
256  const Rib& m_rib;
257  ndn::nfd::Controller& m_controller;
258  uint64_t m_batchFaceId;
259 
261  FibUpdateList m_updatesForBatchFaceId;
262  FibUpdateList m_updatesForNonBatchFaceId;
263 
267  RibUpdateList m_inheritedRoutes;
268 };
269 
270 } // namespace rib
271 } // namespace nfd
272 
273 #endif // NFD_DAEMON_RIB_FIB_UPDATER_HPP
represents the Routing Information Base
Definition: rib.hpp:59
std::function< void(RibUpdateList inheritedRoutes)> FibUpdateSuccessCallback
Definition: fib-updater.hpp:52
computes FibUpdates based on updates to the RIB and sends them to NFD
Definition: fib-updater.hpp:41
std::function< void(uint32_t code, const std::string &error)> FibUpdateFailureCallback
Definition: fib-updater.hpp:53
Represents a collection of RibUpdates to be applied to a single FaceId.
std::list< shared_ptr< RibEntry > > RibEntryList
Definition: rib.hpp:62
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
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:42
std::list< RibUpdate > RibUpdateList
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
represents a route for a name prefix
Definition: route.hpp:43
std::list< FibUpdate > FibUpdateList
Definition: fib-updater.hpp:51
FibUpdater(Rib &rib, ndn::nfd::Controller &controller)
Definition: fib-updater.cpp:41
#define VIRTUAL_WITH_TESTS
Definition: common.hpp:39
#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