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,
57  ConfParameter& conf, ndn::security::v2::KeyChain& keyChain);
58 
67  void
68  remove(const ndn::Name& name);
69 
81  void
82  update(const ndn::Name& name, const NexthopList& allHops);
83 
95  void
96  clean();
97 
98  void
99  setEntryRefreshTime(int32_t fert)
100  {
101  m_refreshTime = fert;
102  }
103 
124  void
125  registerPrefix(const ndn::Name& namePrefix,
126  const ndn::FaceUri& faceUri,
127  uint64_t faceCost,
128  const ndn::time::milliseconds& timeout,
129  uint64_t flags,
130  uint8_t times);
131 
132  void
133  setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count);
134 
135  void
136  writeLog();
137 
138 private:
143  bool
144  isNotNeighbor(const ndn::Name& name);
145 
152  void
153  addNextHopsToFibEntryAndNfd(FibEntry& entry, const NexthopList& hopsToAdd);
154 
155  unsigned int
156  getNumberOfFacesForName(const NexthopList& nextHopList);
157 
161  void
162  unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
163 
166  void
167  onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
168  const std::string& message, const ndn::FaceUri& faceUri);
169 
172  void
173  onRegistrationFailure(const ndn::nfd::ControlResponse& response,
174  const std::string& message,
175  const ndn::nfd::ControlParameters& parameters,
176  const ndn::FaceUri& faceUri,
177  uint8_t times);
178 
181  void
182  onUnregistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
183  const std::string& message);
184 
187  void
188  onUnregistrationFailure(const ndn::nfd::ControlResponse& response,
189  const std::string& message);
190 
193  void
194  onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
195  const std::string& message);
196 
199  void
200  onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
201  const ndn::nfd::ControlParameters& parameters,
202  uint32_t count,
203  const std::string& message);
204 
216  void
217  scheduleEntryRefresh(FibEntry& entry, const afterRefreshCallback& refreshCb);
218 
219 private:
222  void
223  scheduleLoop(FibEntry& entry);
224 
234  void
235  cancelEntryRefresh(const FibEntry& entry);
236 
239  void
240  refreshEntry(const ndn::Name& name, afterRefreshCallback refreshCb);
241 
242 private:
243  ndn::Scheduler& m_scheduler;
244  int32_t m_refreshTime;
245  ndn::nfd::Controller m_controller;
246 
248  FaceMap m_faceMap;
249  std::map<ndn::Name, FibEntry> m_table;
250 
251 private:
252  AdjacencyList& m_adjacencyList;
253  ConfParameter& m_confParameter;
254 
259  static const uint64_t GRACE_PERIOD;
260 };
261 
262 } // namespace nlsr
263 
264 #endif // NLSR_ROUTE_FIB_HPP
void writeLog()
Definition: fib.cpp:397
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:87
#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:99
void clean()
Remove all entries from the FIB.
Definition: fib.cpp:164
Fib(ndn::Face &face, ndn::Scheduler &scheduler, AdjacencyList &adjacencyList, ConfParameter &conf, ndn::security::v2::KeyChain &keyChain)
Definition: fib.cpp:38
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
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:200