fib.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2023, The University of Memphis,
4  * Regents of the University of California,
5  * Arizona Board of Regents.
6  *
7  * This file is part of NLSR (Named-data Link State Routing).
8  * See AUTHORS.md for complete list of NLSR authors and contributors.
9  *
10  * NLSR is free software: you can redistribute it and/or modify it under the terms
11  * of the GNU General Public License as published by the Free Software Foundation,
12  * either version 3 of the License, or (at your option) any later version.
13  *
14  * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16  * PURPOSE. See the GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along with
19  * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef NLSR_ROUTE_FIB_HPP
23 #define NLSR_ROUTE_FIB_HPP
24 
25 #include "test-access-control.hpp"
26 #include "nexthop-list.hpp"
27 
28 #include <ndn-cxx/mgmt/nfd/controller.hpp>
29 #include <ndn-cxx/util/scheduler.hpp>
30 #include <ndn-cxx/util/time.hpp>
31 
32 namespace nlsr {
33 
35 
36 struct FibEntry
37 {
38  ndn::Name name;
39  ndn::scheduler::ScopedEventId refreshEventId;
40  int32_t seqNo = 1;
42 };
43 
44 using AfterRefreshCallback = std::function<void(FibEntry&)>;
45 
46 class AdjacencyList;
47 class ConfParameter;
48 
62 class Fib
63 {
64 public:
65  Fib(ndn::Face& face, ndn::Scheduler& scheduler, AdjacencyList& adjacencyList,
66  ConfParameter& conf, ndn::security::KeyChain& keyChain);
67 
76  void
77  remove(const ndn::Name& name);
78 
90  void
91  update(const ndn::Name& name, const NexthopList& allHops);
92 
101  void
102  clean();
103 
104  void
105  setEntryRefreshTime(int32_t fert)
106  {
107  m_refreshTime = fert;
108  }
109 
130  void
131  registerPrefix(const ndn::Name& namePrefix,
132  const ndn::FaceUri& faceUri,
133  uint64_t faceCost,
134  const ndn::time::milliseconds& timeout,
135  uint64_t flags,
136  uint8_t times);
137 
138  void
139  setStrategy(const ndn::Name& name, const ndn::Name& strategy, uint32_t count);
140 
141  void
142  writeLog();
143 
144 private:
149  bool
150  isNotNeighbor(const ndn::Name& name);
151 
158  void
159  addNextHopsToFibEntryAndNfd(FibEntry& entry, const NextHopsUriSortedSet& hopsToAdd);
160 
161  unsigned int
162  getNumberOfFacesForName(const NexthopList& nextHopList);
163 
167  void
168  unregisterPrefix(const ndn::Name& namePrefix, const ndn::FaceUri& faceUri);
169 
172  void
173  onRegistrationSuccess(const ndn::nfd::ControlParameters& param,
174  const ndn::FaceUri& faceUri);
175 
178  void
179  onRegistrationFailure(const ndn::nfd::ControlResponse& response,
180  const ndn::nfd::ControlParameters& parameters,
181  const ndn::FaceUri& faceUri,
182  uint8_t times);
183 
186  void
187  onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
188 
191  void
192  onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
193  const ndn::nfd::ControlParameters& parameters,
194  uint32_t count);
195 
207  void
208  scheduleEntryRefresh(FibEntry& entry, const AfterRefreshCallback& refreshCb);
209 
210 private:
213  void
214  scheduleLoop(FibEntry& entry);
215 
218  void
219  refreshEntry(const ndn::Name& name, AfterRefreshCallback refreshCb);
220 
221 public:
222  static inline const ndn::Name MULTICAST_STRATEGY{"/localhost/nfd/strategy/multicast"};
223  static inline const ndn::Name BEST_ROUTE_STRATEGY{"/localhost/nfd/strategy/best-route"};
224 
225  ndn::signal::Signal<Fib, ndn::Name> onPrefixRegistrationSuccess;
226 
227 private:
228  ndn::Scheduler& m_scheduler;
229  int32_t m_refreshTime;
230  ndn::nfd::Controller m_controller;
231 
233  std::map<ndn::Name, FibEntry> m_table;
234 
235 private:
236  AdjacencyList& m_adjacencyList;
237  ConfParameter& m_confParameter;
238 
243  static constexpr uint64_t GRACE_PERIOD = 10;
244 };
245 
246 } // namespace nlsr
247 
248 #endif // NLSR_ROUTE_FIB_HPP
A class to house all the configuration parameters for NLSR.
Maps names to lists of next hops, and exports this information to NFD.
Definition: fib.hpp:63
void setStrategy(const ndn::Name &name, const ndn::Name &strategy, uint32_t count)
Definition: fib.cpp:274
void writeLog()
Definition: fib.cpp:349
void clean()
Remove all entries from the FIB.
Definition: fib.cpp:155
void remove(const ndn::Name &name)
Completely remove a name prefix from the FIB.
Definition: fib.cpp:46
void update(const ndn::Name &name, const NexthopList &allHops)
Set the nexthop list of a name.
Definition: fib.cpp:84
Fib(ndn::Face &face, ndn::Scheduler &scheduler, AdjacencyList &adjacencyList, ConfParameter &conf, ndn::security::KeyChain &keyChain)
Definition: fib.cpp:35
void setEntryRefreshTime(int32_t fert)
Definition: fib.hpp:105
static const ndn::Name MULTICAST_STRATEGY
Definition: fib.hpp:222
static const ndn::Name BEST_ROUTE_STRATEGY
Definition: fib.hpp:223
void registerPrefix(const ndn::Name &namePrefix, const ndn::FaceUri &faceUri, uint64_t faceCost, const ndn::time::milliseconds &timeout, uint64_t flags, uint8_t times)
Inform NFD of a next-hop.
Definition: fib.cpp:182
ndn::signal::Signal< Fib, ndn::Name > onPrefixRegistrationSuccess
Definition: fib.hpp:225
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
std::function< void(FibEntry &)> AfterRefreshCallback
Definition: fib.hpp:44
Definition: fib.hpp:37
ndn::scheduler::ScopedEventId refreshEventId
Definition: fib.hpp:39
ndn::Name name
Definition: fib.hpp:38
NextHopsUriSortedSet nexthopSet
Definition: fib.hpp:41
int32_t seqNo
Definition: fib.hpp:40
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE