All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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-2025, 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 
93  void
94  setEntryRefreshTime(int32_t fert)
95  {
96  m_refreshTime = fert;
97  }
98 
119  void
120  registerPrefix(const ndn::Name& namePrefix,
121  const ndn::FaceUri& faceUri,
122  uint64_t faceCost,
123  const ndn::time::milliseconds& timeout,
124  uint64_t flags,
125  uint8_t times);
126 
127  void
128  setStrategy(const ndn::Name& name, const ndn::Name& strategy, uint32_t count);
129 
130  void
131  writeLog();
132 
133 private:
138  bool
139  isNotNeighbor(const ndn::Name& name);
140 
147  void
148  addNextHopsToFibEntryAndNfd(FibEntry& entry, const NextHopsUriSortedSet& hopsToAdd);
149 
150  unsigned int
151  getNumberOfFacesForName(const NexthopList& nextHopList);
152 
156  void
157  unregisterPrefix(const ndn::Name& namePrefix, const ndn::FaceUri& faceUri);
158 
161  void
162  onRegistrationSuccess(const ndn::nfd::ControlParameters& param,
163  const ndn::FaceUri& faceUri);
164 
167  void
168  onRegistrationFailure(const ndn::nfd::ControlResponse& response,
169  const ndn::nfd::ControlParameters& parameters,
170  const ndn::FaceUri& faceUri,
171  uint8_t times);
172 
175  void
176  onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
177 
180  void
181  onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
182  const ndn::nfd::ControlParameters& parameters,
183  uint32_t count);
184 
196  void
197  scheduleEntryRefresh(FibEntry& entry, const AfterRefreshCallback& refreshCb);
198 
199 private:
202  void
203  scheduleLoop(FibEntry& entry);
204 
207  void
208  refreshEntry(const ndn::Name& name, AfterRefreshCallback refreshCb);
209 
210 public:
211  static inline const ndn::Name MULTICAST_STRATEGY{"/localhost/nfd/strategy/multicast"};
212  static inline const ndn::Name BEST_ROUTE_STRATEGY{"/localhost/nfd/strategy/best-route"};
213 
214  ndn::signal::Signal<Fib, ndn::Name> onPrefixRegistrationSuccess;
215 
216 private:
217  ndn::Scheduler& m_scheduler;
218  int32_t m_refreshTime;
219  ndn::nfd::Controller m_controller;
220 
222  std::map<ndn::Name, FibEntry> m_table;
223 
224 private:
225  AdjacencyList& m_adjacencyList;
226  ConfParameter& m_confParameter;
227 
232  static constexpr uint64_t GRACE_PERIOD = 10;
233 };
234 
235 } // namespace nlsr
236 
237 #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:264
void writeLog()
Definition: fib.cpp:338
void remove(const ndn::Name &name)
Completely remove a name prefix from the FIB.
Definition: fib.cpp:48
void update(const ndn::Name &name, const NexthopList &allHops)
Set the nexthop list of a name.
Definition: fib.cpp:86
Fib(ndn::Face &face, ndn::Scheduler &scheduler, AdjacencyList &adjacencyList, ConfParameter &conf, ndn::security::KeyChain &keyChain)
Definition: fib.cpp:37
void setEntryRefreshTime(int32_t fert)
Definition: fib.hpp:94
static const ndn::Name MULTICAST_STRATEGY
Definition: fib.hpp:211
static const ndn::Name BEST_ROUTE_STRATEGY
Definition: fib.hpp:212
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:173
ndn::signal::Signal< Fib, ndn::Name > onPrefixRegistrationSuccess
Definition: fib.hpp:214
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