lsdb.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NLSR_LSDB_HPP
23 #define NLSR_LSDB_HPP
24 
25 #include "conf-parameter.hpp"
26 #include "lsa.hpp"
27 #include "lsa-segment-storage.hpp"
28 #include "sequencing-manager.hpp"
29 #include "test-access-control.hpp"
31 #include "statistics.hpp"
33 
34 #include <ndn-cxx/security/key-chain.hpp>
35 #include <ndn-cxx/util/signal.hpp>
36 #include <ndn-cxx/util/time.hpp>
37 #include <ndn-cxx/util/segment-fetcher.hpp>
38 
39 #include <PSync/segment-publisher.hpp>
40 
41 #include <utility>
42 #include <boost/cstdint.hpp>
43 
44 namespace nlsr {
45 
46 class Lsdb
47 {
48 public:
49  Lsdb(ndn::Face& face, ndn::KeyChain& keyChain,
50  ndn::security::SigningInfo& signingInfo, ConfParameter& confParam,
51  NamePrefixTable& namePrefixTable, RoutingTable& routingTable);
52 
53  ~Lsdb();
54 
57  {
58  return m_sync;
59  }
60 
61  bool
62  isLsaNew(const ndn::Name& routerName, const Lsa::Type& lsaType, const uint64_t& sequenceNumber);
63 
64  bool
65  doesLsaExist(const ndn::Name& key, const Lsa::Type& lsType);
66 
70  bool
72 
76  NameLsa*
77  findNameLsa(const ndn::Name& key);
78 
82  bool
83  installNameLsa(NameLsa& nlsa);
84 
92  bool
93  removeNameLsa(const ndn::Name& key);
94 
99  bool
100  isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
101 
102  void
104 
105  const std::list<NameLsa>&
106  getNameLsdb() const;
107 
109  bool
111 
116  findCoordinateLsa(const ndn::Name& key);
117 
121  bool
123 
131  bool
132  removeCoordinateLsa(const ndn::Name& key);
133 
138  bool
139  isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
140 
141  void
142  writeCorLsdbLog();
143 
144  const std::list<CoordinateLsa>&
145  getCoordinateLsdb() const;
146 
147  //function related to Adj LSDB
148 
150  void
152 
154  bool
156 
160  bool
161  removeAdjLsa(const ndn::Name& key);
162 
170  bool
171  isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
172 
176  bool
177  installAdjLsa(AdjLsa& alsa);
178 
182  AdjLsa*
183  findAdjLsa(const ndn::Name& key);
184 
185  const std::list<AdjLsa>&
186  getAdjLsdb() const;
187 
188  void
189  setAdjLsaBuildInterval(uint32_t interval)
190  {
191  m_adjLsaBuildInterval = ndn::time::seconds(interval);
192  }
193 
194  const ndn::time::seconds&
196  {
197  return m_adjLsaBuildInterval;
198  }
199 
202  {
203  return m_sequencingManager;
204  }
205 
206  void
207  writeAdjLsdbLog();
208 
209  void
210  expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
211  ndn::time::steady_clock::TimePoint deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE);
212 
213  /* \brief Process interest which can be either:
214  * 1) Discovery interest from segment fetcher:
215  * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo>
216  * 2) Interest containing segment number:
217  * /localhop/<network>/nlsr/LSA/<site>/<router>/<lsaType>/<seqNo>/<version>/<segmentNo>
218  */
219  void
220  processInterest(const ndn::Name& name, const ndn::Interest& interest);
221 
222  bool
224  {
225  return m_isBuildAdjLsaSheduled;
226  }
227 
228 private:
229  /* \brief Add a name LSA to the LSDB if it isn't already there.
230  \param nlsa The candidade name LSA.
231  */
232  bool
233  addNameLsa(NameLsa& nlsa);
234 
238  bool
239  doesNameLsaExist(const ndn::Name& key);
240 
244  bool
245  addCoordinateLsa(CoordinateLsa& clsa);
246 
250  bool
251  doesCoordinateLsaExist(const ndn::Name& key);
252 
260  void
261  buildAdjLsa();
262 
266  bool
267  addAdjLsa(AdjLsa& alsa);
268 
272  bool
273  doesAdjLsaExist(const ndn::Name& key);
274 
280  ndn::EventId
281  scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
282  const ndn::time::seconds& expTime);
283 
288  void
289  expireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo);
290 
297  ndn::EventId
298  scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
299  const ndn::time::seconds& expTime);
300 
301 private:
302 
303  void
304  expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
305 
306  ndn::EventId
307  scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
308  const ndn::time::seconds& expTime);
309 
310  void
311  expireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
312  uint64_t seqNo);
313 
314 private:
315 
316  void
317  processInterestForNameLsa(const ndn::Interest& interest,
318  const ndn::Name& lsaKey,
319  uint64_t seqNo);
320 
321  void
322  processInterestForAdjacencyLsa(const ndn::Interest& interest,
323  const ndn::Name& lsaKey,
324  uint64_t seqNo);
325 
326  void
327  processInterestForCoordinateLsa(const ndn::Interest& interest,
328  const ndn::Name& lsaKey,
329  uint64_t seqNo);
330  void
331  onContentValidated(const std::shared_ptr<const ndn::Data>& data);
332 
333  void
334  processContentNameLsa(const ndn::Name& lsaKey,
335  uint64_t lsSeqNo, std::string& dataContent);
336 
337  void
338  processContentAdjacencyLsa(const ndn::Name& lsaKey,
339  uint64_t lsSeqNo, std::string& dataContent);
340 
341  void
342  processContentCoordinateLsa(const ndn::Name& lsaKey,
343  uint64_t lsSeqNo, std::string& dataContent);
344 
360  void
361  onFetchLsaError(uint32_t errorCode,
362  const std::string& msg,
363  const ndn::Name& interestName,
364  uint32_t retransmitNo,
365  const ndn::time::steady_clock::TimePoint& deadline,
366  ndn::Name lsaName,
367  uint64_t seqNo);
368 
375  void
376  afterFetchLsa(const ndn::ConstBufferPtr& data, const ndn::Name& interestName);
377 
378 private:
379  ndn::time::system_clock::TimePoint
380  getLsaExpirationTimePoint();
381 
383  void
384  cancelScheduleLsaExpiringEvent(ndn::EventId eid);
385 
386 public:
387  static const ndn::Name::Component NAME_COMPONENT;
388 
389  ndn::util::signal::Signal<Lsdb, Statistics::PacketType> lsaIncrementSignal;
390  ndn::util::signal::Signal<Lsdb, const ndn::Data&> afterSegmentValidatedSignal;
391 
392 private:
393  ndn::Face& m_face;
394  ndn::Scheduler m_scheduler;
395  ndn::security::SigningInfo& m_signingInfo;
396 
397  ConfParameter& m_confParam;
398  NamePrefixTable& m_namePrefixTable;
399  RoutingTable& m_routingTable;
400  SyncLogicHandler m_sync;
401 
403  LsaSegmentStorage m_lsaStorage;
404 
405 private:
406  std::list<NameLsa> m_nameLsdb;
407  std::list<AdjLsa> m_adjLsdb;
408  std::list<CoordinateLsa> m_corLsdb;
409 
410  ndn::time::seconds m_lsaRefreshTime;
411  std::string m_thisRouterPrefix;
412 
413  typedef std::map<ndn::Name, uint64_t> SequenceNumberMap;
414 
415  // Maps the name of an LSA to its highest known sequence number from sync;
416  // Used to stop NLSR from trying to fetch outdated LSAs
417  SequenceNumberMap m_highestSeqNo;
418 
419  static const ndn::time::seconds GRACE_PERIOD;
420  static const ndn::time::steady_clock::TimePoint DEFAULT_LSA_RETRIEVAL_DEADLINE;
421 
422  ndn::time::seconds m_adjLsaBuildInterval;
423 
424  SequencingManager m_sequencingManager;
425 
426  ndn::util::signal::ScopedConnection m_onNewLsaConnection;
427 
428  std::set<std::shared_ptr<ndn::util::SegmentFetcher>> m_fetchers;
429  psync::SegmentPublisher m_segmentPublisher;
430 
431  bool m_isBuildAdjLsaSheduled;
432  int64_t m_adjBuildCount;
433 };
434 
435 } // namespace nlsr
436 
437 #endif // NLSR_LSDB_HPP
bool installAdjLsa(AdjLsa &alsa)
Installs an adj. LSA into the LSDB.
Definition: lsdb.cpp:707
const std::list< NameLsa > & getNameLsdb() const
Definition: lsdb.cpp:363
A class to house all the configuration parameters for NLSR.
void scheduleAdjLsaBuild()
Schedules a build of this router&#39;s LSA.
Definition: lsdb.cpp:581
bool removeNameLsa(const ndn::Name &key)
Remove a name LSA from the LSDB.
Definition: lsdb.cpp:316
void writeNameLsdbLog()
Definition: lsdb.cpp:354
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
void setAdjLsaBuildInterval(uint32_t interval)
Definition: lsdb.hpp:189
bool isLsaNew(const ndn::Name &routerName, const Lsa::Type &lsaType, const uint64_t &sequenceNumber)
Definition: lsdb.cpp:1324
void writeAdjLsdbLog()
Definition: lsdb.cpp:1299
SyncLogicHandler & getSyncLogicHandler()
Definition: lsdb.hpp:56
void writeCorLsdbLog()
Definition: lsdb.cpp:554
bool getIsBuildAdjLsaSheduled()
Definition: lsdb.hpp:223
const std::list< CoordinateLsa > & getCoordinateLsdb() const
Definition: lsdb.cpp:563
bool isCoordinateLsaNew(const ndn::Name &key, uint64_t seqNo)
Returns whether a cor. LSA from a router is new or not.
Definition: lsdb.cpp:414
CoordinateLsa * findCoordinateLsa(const ndn::Name &key)
Finds a cor. LSA in the LSDB.
Definition: lsdb.cpp:402
ndn::util::signal::Signal< Lsdb, const ndn::Data & > afterSegmentValidatedSignal
Definition: lsdb.hpp:390
bool isNameLsaNew(const ndn::Name &key, uint64_t seqNo)
Definition: lsdb.cpp:180
Lsdb(ndn::Face &face, ndn::KeyChain &keyChain, ndn::security::SigningInfo &signingInfo, ConfParameter &confParam, NamePrefixTable &namePrefixTable, RoutingTable &routingTable)
Definition: lsdb.cpp:40
bool installCoordinateLsa(CoordinateLsa &clsa)
Installs a cor. LSA into the LSDB.
Definition: lsdb.cpp:444
SequencingManager & getSequencingManager()
Definition: lsdb.hpp:201
NLSR-to-ChronoSync interaction point.
NameLsa * findNameLsa(const ndn::Name &key)
Returns the name LSA with the given key.
Definition: lsdb.cpp:168
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
Definition: lsdb.cpp:1032
void expressInterest(const ndn::Name &interestName, uint32_t timeoutCount, ndn::time::steady_clock::TimePoint deadline=DEFAULT_LSA_RETRIEVAL_DEADLINE)
Definition: lsdb.cpp:959
bool doesLsaExist(const ndn::Name &key, const Lsa::Type &lsType)
Definition: lsdb.cpp:1309
const ndn::time::seconds & getAdjLsaBuildInterval() const
Definition: lsdb.hpp:195
bool isAdjLsaNew(const ndn::Name &key, uint64_t seqNo)
Returns whether an LSA is new.
Definition: lsdb.cpp:682
bool removeAdjLsa(const ndn::Name &key)
Removes an adj. LSA from the LSDB.
Definition: lsdb.cpp:779
~Lsdb()
Definition: lsdb.cpp:71
static const ndn::Name::Component NAME_COMPONENT
Definition: lsdb.hpp:387
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
ndn::util::signal::Signal< Lsdb, Statistics::PacketType > lsaIncrementSignal
Definition: lsdb.hpp:389
bool installNameLsa(NameLsa &nlsa)
Installs a name LSA into the LSDB.
Definition: lsdb.cpp:205
bool buildAndInstallOwnNameLsa()
Builds a name LSA for this router and then installs it into the LSDB.
Definition: lsdb.cpp:153
bool buildAndInstallOwnCoordinateLsa()
Builds a cor. LSA for this router and installs it into the LSDB.
Definition: lsdb.cpp:381
const std::list< AdjLsa > & getAdjLsdb() const
Definition: lsdb.cpp:809
AdjLsa * findAdjLsa(const ndn::Name &key)
Finds an adj. LSA in the LSDB.
Definition: lsdb.cpp:670
bool buildAndInstallOwnAdjLsa()
Wrapper event to build and install an adj. LSA for this router.
Definition: lsdb.cpp:760
bool removeCoordinateLsa(const ndn::Name &key)
Removes a cor. LSA from the LSDB.
Definition: lsdb.cpp:520