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-2020, 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 
34 struct FibEntry {
35  ndn::Name name;
36  ndn::scheduler::ScopedEventId refreshEventId;
37  int32_t seqNo = 1;
39 };
40 
41 typedef std::function<void(FibEntry&)> afterRefreshCallback;
42 
43 class AdjacencyList;
44 class ConfParameter;
45 
59 class Fib
60 {
61 public:
62  Fib(ndn::Face& face, ndn::Scheduler& scheduler, AdjacencyList& adjacencyList,
63  ConfParameter& conf, ndn::security::KeyChain& keyChain);
64 
73  void
74  remove(const ndn::Name& name);
75 
87  void
88  update(const ndn::Name& name, const NexthopList& allHops);
89 
98  void
99  clean();
100 
101  void
102  setEntryRefreshTime(int32_t fert)
103  {
104  m_refreshTime = fert;
105  }
106 
127  void
128  registerPrefix(const ndn::Name& namePrefix,
129  const ndn::FaceUri& faceUri,
130  uint64_t faceCost,
131  const ndn::time::milliseconds& timeout,
132  uint64_t flags,
133  uint8_t times);
134 
135  void
136  setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count);
137 
138  void
139  writeLog();
140 
141 private:
146  bool
147  isNotNeighbor(const ndn::Name& name);
148 
155  void
156  addNextHopsToFibEntryAndNfd(FibEntry& entry, const NexthopList& hopsToAdd);
157 
158  unsigned int
159  getNumberOfFacesForName(const NexthopList& nextHopList);
160 
164  void
165  unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
166 
169  void
170  onRegistrationSuccess(const ndn::nfd::ControlParameters& param,
171  const ndn::FaceUri& faceUri);
172 
175  void
176  onRegistrationFailure(const ndn::nfd::ControlResponse& response,
177  const ndn::nfd::ControlParameters& parameters,
178  const ndn::FaceUri& faceUri,
179  uint8_t times);
180 
183  void
184  onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
185 
188  void
189  onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
190  const ndn::nfd::ControlParameters& parameters,
191  uint32_t count);
192 
204  void
205  scheduleEntryRefresh(FibEntry& entry, const afterRefreshCallback& refreshCb);
206 
207 private:
210  void
211  scheduleLoop(FibEntry& entry);
212 
215  void
216  refreshEntry(const ndn::Name& name, afterRefreshCallback refreshCb);
217 
218 public:
219  static const std::string MULTICAST_STRATEGY;
220  static const std::string BEST_ROUTE_V2_STRATEGY;
221  ndn::util::Signal<Fib, const ndn::Name&> onPrefixRegistrationSuccess;
222 
223 private:
224  ndn::Scheduler& m_scheduler;
225  int32_t m_refreshTime;
226  ndn::nfd::Controller m_controller;
227 
229  std::map<ndn::Name, FibEntry> m_table;
230 
231 private:
232  AdjacencyList& m_adjacencyList;
233  ConfParameter& m_confParameter;
234 
239  static constexpr uint64_t GRACE_PERIOD = 10;
240 };
241 
242 } // namespace nlsr
243 
244 #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:60
void writeLog()
Definition: fib.cpp:354
static const std::string MULTICAST_STRATEGY
Definition: fib.hpp:219
void clean()
Remove all entries from the FIB.
Definition: fib.cpp:160
void remove(const ndn::Name &name)
Completely remove a name prefix from the FIB.
Definition: fib.cpp:50
void update(const ndn::Name &name, const NexthopList &allHops)
Set the nexthop list of a name.
Definition: fib.cpp:87
Fib(ndn::Face &face, ndn::Scheduler &scheduler, AdjacencyList &adjacencyList, ConfParameter &conf, ndn::security::KeyChain &keyChain)
Definition: fib.cpp:39
static const std::string BEST_ROUTE_V2_STRATEGY
Definition: fib.hpp:220
void setStrategy(const ndn::Name &name, const std::string &strategy, uint32_t count)
Definition: fib.cpp:279
void setEntryRefreshTime(int32_t fert)
Definition: fib.hpp:102
ndn::util::Signal< Fib, const ndn::Name & > onPrefixRegistrationSuccess
Definition: fib.hpp:221
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:187
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California,...
std::function< void(FibEntry &)> afterRefreshCallback
Definition: fib.hpp:41
Definition: fib.hpp:34
ndn::scheduler::ScopedEventId refreshEventId
Definition: fib.hpp:36
ndn::Name name
Definition: fib.hpp:35
NexthopList nexthopList
Definition: fib.hpp:38
int32_t seqNo
Definition: fib.hpp:37
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE