fib.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
23 #ifndef NLSR_ROUTE_FIB_HPP
24 #define NLSR_ROUTE_FIB_HPP
25 
26 #include "face-map.hpp"
27 #include "fib-entry.hpp"
28 #include "test-access-control.hpp"
29 
30 #include <ndn-cxx/mgmt/nfd/controller.hpp>
31 #include <ndn-cxx/util/time.hpp>
32 
33 namespace nlsr {
34 
35 typedef std::function<void(FibEntry&)> afterRefreshCallback;
36 
37 class AdjacencyList;
38 class ConfParameter;
39 class FibEntry;
40 
54 class Fib
55 {
56 public:
57  Fib(ndn::Face& face, ndn::Scheduler& scheduler, AdjacencyList& adjacencyList, ConfParameter& conf,
58  ndn::security::v2::KeyChain& keyChain)
59  : m_scheduler(scheduler)
60  , m_refreshTime(0)
61  , m_controller(face, keyChain)
62  , m_adjacencyList(adjacencyList)
63  , m_confParameter(conf)
64  {
65  }
66 
76  remove(const ndn::Name& name);
77 
90  update(const ndn::Name& name, NexthopList& allHops);
91 
103  void
104  clean();
105 
106  void
107  setEntryRefreshTime(int32_t fert)
108  {
109  m_refreshTime = fert;
110  }
111 
132  void
133  registerPrefix(const ndn::Name& namePrefix,
134  const ndn::FaceUri& faceUri,
135  uint64_t faceCost,
136  const ndn::time::milliseconds& timeout,
137  uint64_t flags,
138  uint8_t times);
139 
140  void
141  setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count);
142 
143  void
144  writeLog();
145 
146 private:
151  bool
152  isPrefixUpdatable(const ndn::Name& name);
153 
160  void
161  addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& hopsToAdd);
162 
163  unsigned int
164  getNumberOfFacesForName(NexthopList& nextHopList);
165 
169  void
170  unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
171 
174  void
175  onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
176  const std::string& message, const ndn::FaceUri& faceUri);
177 
180  void
181  onRegistrationFailure(const ndn::nfd::ControlResponse& response,
182  const std::string& message,
183  const ndn::nfd::ControlParameters& parameters,
184  const ndn::FaceUri& faceUri,
185  uint8_t times);
186 
189  void
190  onUnregistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
191  const std::string& message);
192 
195  void
196  onUnregistrationFailure(const ndn::nfd::ControlResponse& response,
197  const std::string& message);
198 
201  void
202  onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
203  const std::string& message);
204 
207  void
208  onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
209  const ndn::nfd::ControlParameters& parameters,
210  uint32_t count,
211  const std::string& message);
212 
224  void
225  scheduleEntryRefresh(FibEntry& entry, const afterRefreshCallback& refreshCb);
226 
227 private:
230  void
231  scheduleLoop(FibEntry& entry);
232 
242  void
243  cancelEntryRefresh(const FibEntry& entry);
244 
247  void
248  refreshEntry(const ndn::Name& name, afterRefreshCallback refreshCb);
249 
250 private:
251  ndn::Scheduler& m_scheduler;
252  int32_t m_refreshTime;
253  ndn::nfd::Controller m_controller;
254 
256  FaceMap m_faceMap;
257  std::map<ndn::Name, FibEntry> m_table;
258 
259 private:
260  AdjacencyList& m_adjacencyList;
261  ConfParameter& m_confParameter;
262 
267  static const uint64_t GRACE_PERIOD;
268 };
269 
270 } // namespace nlsr
271 
272 #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:54
void setEntryRefreshTime(int32_t fert)
Definition: fib.hpp:107
void clean()
Remove all entries from the FIB.
Definition: fib.cpp:154
Fib(ndn::Face &face, ndn::Scheduler &scheduler, AdjacencyList &adjacencyList, ConfParameter &conf, ndn::security::v2::KeyChain &keyChain)
Definition: fib.hpp:57
Copyright (c) 2014-2017, 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:35
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