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-2019, 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 "fib-entry.hpp"
26 #include "test-access-control.hpp"
27 
28 #include <ndn-cxx/mgmt/nfd/controller.hpp>
29 #include <ndn-cxx/util/time.hpp>
30 
31 namespace nlsr {
32 
33 typedef std::function<void(FibEntry&)> afterRefreshCallback;
34 
35 class AdjacencyList;
36 class ConfParameter;
37 class FibEntry;
38 
52 class Fib
53 {
54 public:
55  Fib(ndn::Face& face, ndn::Scheduler& scheduler, AdjacencyList& adjacencyList,
56  ConfParameter& conf, ndn::security::v2::KeyChain& keyChain);
57 
66  void
67  remove(const ndn::Name& name);
68 
80  void
81  update(const ndn::Name& name, const NexthopList& allHops);
82 
94  void
95  clean();
96 
97  void
98  setEntryRefreshTime(int32_t fert)
99  {
100  m_refreshTime = fert;
101  }
102 
123  void
124  registerPrefix(const ndn::Name& namePrefix,
125  const ndn::FaceUri& faceUri,
126  uint64_t faceCost,
127  const ndn::time::milliseconds& timeout,
128  uint64_t flags,
129  uint8_t times);
130 
131  void
132  setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count);
133 
134  void
135  writeLog();
136 
137 private:
142  bool
143  isNotNeighbor(const ndn::Name& name);
144 
151  void
152  addNextHopsToFibEntryAndNfd(FibEntry& entry, const NexthopList& hopsToAdd);
153 
154  unsigned int
155  getNumberOfFacesForName(const NexthopList& nextHopList);
156 
160  void
161  unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
162 
165  void
166  onRegistrationSuccess(const ndn::nfd::ControlParameters& param,
167  const ndn::FaceUri& faceUri);
168 
171  void
172  onRegistrationFailure(const ndn::nfd::ControlResponse& response,
173  const ndn::nfd::ControlParameters& parameters,
174  const ndn::FaceUri& faceUri,
175  uint8_t times);
176 
179  void
180  onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult);
181 
184  void
185  onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
186  const ndn::nfd::ControlParameters& parameters,
187  uint32_t count);
188 
200  void
201  scheduleEntryRefresh(FibEntry& entry, const afterRefreshCallback& refreshCb);
202 
203 private:
206  void
207  scheduleLoop(FibEntry& entry);
208 
218  void
219  cancelEntryRefresh(const FibEntry& entry);
220 
223  void
224  refreshEntry(const ndn::Name& name, afterRefreshCallback refreshCb);
225 
226 public:
227  static const std::string MULTICAST_STRATEGY;
228  static const std::string BEST_ROUTE_V2_STRATEGY;
229  ndn::util::Signal<Fib, const ndn::Name&> onPrefixRegistrationSuccess;
230 
231 private:
232  ndn::Scheduler& m_scheduler;
233  int32_t m_refreshTime;
234  ndn::nfd::Controller m_controller;
235 
237  std::map<ndn::Name, FibEntry> m_table;
238 
239 private:
240  AdjacencyList& m_adjacencyList;
241  ConfParameter& m_confParameter;
242 
247  static const uint64_t GRACE_PERIOD;
248 };
249 
250 } // namespace nlsr
251 
252 #endif // NLSR_ROUTE_FIB_HPP
void writeLog()
Definition: fib.cpp:376
A class to house all the configuration parameters for NLSR.
void update(const ndn::Name &name, const NexthopList &allHops)
Set the nexthop list of a name.
Definition: fib.cpp:89
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
static const std::string MULTICAST_STRATEGY
Definition: fib.hpp:227
void setStrategy(const ndn::Name &name, const std::string &strategy, uint32_t count)
Definition: fib.cpp:293
static const std::string BEST_ROUTE_V2_STRATEGY
Definition: fib.hpp:228
Maps names to lists of next hops, and exports this information to NFD.
Definition: fib.hpp:52
void setEntryRefreshTime(int32_t fert)
Definition: fib.hpp:98
void clean()
Remove all entries from the FIB.
Definition: fib.cpp:165
Fib(ndn::Face &face, ndn::Scheduler &scheduler, AdjacencyList &adjacencyList, ConfParameter &conf, ndn::security::v2::KeyChain &keyChain)
Definition: fib.cpp:40
Copyright (c) 2014-2019, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
ndn::util::Signal< Fib, const ndn::Name & > onPrefixRegistrationSuccess
Definition: fib.hpp:229
std::function< void(FibEntry &)> afterRefreshCallback
Definition: fib.hpp:33
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:201