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-2018, 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 "face-map.hpp"
26 #include "fib-entry.hpp"
27 #include "test-access-control.hpp"
28 
29 #include <ndn-cxx/mgmt/nfd/controller.hpp>
30 #include <ndn-cxx/util/time.hpp>
31 
32 namespace nlsr {
33 
34 typedef std::function<void(FibEntry&)> afterRefreshCallback;
35 
36 class AdjacencyList;
37 class ConfParameter;
38 class FibEntry;
39 
53 class Fib
54 {
55 public:
56  Fib(ndn::Face& face, ndn::Scheduler& scheduler, AdjacencyList& adjacencyList, ConfParameter& conf,
57  ndn::security::v2::KeyChain& keyChain)
58  : m_scheduler(scheduler)
59  , m_refreshTime(0)
60  , m_controller(face, keyChain)
61  , m_adjacencyList(adjacencyList)
62  , m_confParameter(conf)
63  {
64  }
65 
67  ~Fib() = default;
68 
78  remove(const ndn::Name& name);
79 
92  update(const ndn::Name& name, NexthopList& allHops);
93 
105  void
106  clean();
107 
108  void
109  setEntryRefreshTime(int32_t fert)
110  {
111  m_refreshTime = fert;
112  }
113 
134  void
135  registerPrefix(const ndn::Name& namePrefix,
136  const ndn::FaceUri& faceUri,
137  uint64_t faceCost,
138  const ndn::time::milliseconds& timeout,
139  uint64_t flags,
140  uint8_t times);
141 
142  void
143  setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count);
144 
145  void
146  writeLog();
147 
148 private:
153  bool
154  isPrefixUpdatable(const ndn::Name& name);
155 
162  void
163  addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& hopsToAdd);
164 
165  unsigned int
166  getNumberOfFacesForName(NexthopList& nextHopList);
167 
171  void
172  unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
173 
176  void
177  onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
178  const std::string& message, const ndn::FaceUri& faceUri);
179 
182  void
183  onRegistrationFailure(const ndn::nfd::ControlResponse& response,
184  const std::string& message,
185  const ndn::nfd::ControlParameters& parameters,
186  const ndn::FaceUri& faceUri,
187  uint8_t times);
188 
191  void
192  onUnregistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
193  const std::string& message);
194 
197  void
198  onUnregistrationFailure(const ndn::nfd::ControlResponse& response,
199  const std::string& message);
200 
203  void
204  onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
205  const std::string& message);
206 
209  void
210  onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
211  const ndn::nfd::ControlParameters& parameters,
212  uint32_t count,
213  const std::string& message);
214 
226  void
227  scheduleEntryRefresh(FibEntry& entry, const afterRefreshCallback& refreshCb);
228 
229 private:
232  void
233  scheduleLoop(FibEntry& entry);
234 
244  void
245  cancelEntryRefresh(const FibEntry& entry);
246 
249  void
250  refreshEntry(const ndn::Name& name, afterRefreshCallback refreshCb);
251 
252 private:
253  ndn::Scheduler& m_scheduler;
254  int32_t m_refreshTime;
255  ndn::nfd::Controller m_controller;
256 
258  FaceMap m_faceMap;
259  std::map<ndn::Name, FibEntry> m_table;
260 
261 private:
262  AdjacencyList& m_adjacencyList;
263  ConfParameter& m_confParameter;
264 
269  static const uint64_t GRACE_PERIOD;
270 };
271 
272 } // namespace nlsr
273 
274 #endif // NLSR_ROUTE_FIB_HPP
void writeLog()
Definition: fib.cpp:398
#define VIRTUAL_WITH_TESTS
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California.
A class to house all the configuration parameters for NLSR.
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
void setStrategy(const ndn::Name &name, const std::string &strategy, uint32_t count)
Definition: fib.cpp:306
Maps names to lists of next hops, and exports this information to NFD.
Definition: fib.hpp:53
void setEntryRefreshTime(int32_t fert)
Definition: fib.hpp:109
void clean()
Remove all entries from the FIB.
Definition: fib.cpp:154
~Fib()=default
Fib(ndn::Face &face, ndn::Scheduler &scheduler, AdjacencyList &adjacencyList, ConfParameter &conf, ndn::security::v2::KeyChain &keyChain)
Definition: fib.hpp:56
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
void update(const ndn::Name &name, NexthopList &allHops)
Set the nexthop list of a name.
Definition: fib.cpp:79
std::function< void(FibEntry &)> afterRefreshCallback
Definition: fib.hpp:34
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:199