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"
32 
33 #include <ndn-cxx/security/key-chain.hpp>
34 #include <ndn-cxx/util/signal.hpp>
35 #include <ndn-cxx/util/time.hpp>
36 #include <utility>
37 #include <boost/cstdint.hpp>
38 
39 namespace nlsr {
40 
41 class Nlsr;
42 
43 class Lsdb
44 {
45 public:
46  Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler);
47 
50  {
51  return m_sync;
52  }
53 
54  bool
55  isLsaNew(const ndn::Name& routerName, const Lsa::Type& lsaType, const uint64_t& sequenceNumber);
56 
57  bool
58  doesLsaExist(const ndn::Name& key, const Lsa::Type& lsType);
59 
63  bool
65 
69  NameLsa*
70  findNameLsa(const ndn::Name& key);
71 
75  bool
76  installNameLsa(NameLsa& nlsa);
77 
85  bool
86  removeNameLsa(const ndn::Name& key);
87 
92  bool
93  isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
94 
95  void
97 
98  const std::list<NameLsa>&
99  getNameLsdb() const;
100 
102  bool
104 
109  findCoordinateLsa(const ndn::Name& key);
110 
114  bool
116 
124  bool
125  removeCoordinateLsa(const ndn::Name& key);
126 
131  bool
132  isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
133 
134  void
135  writeCorLsdbLog();
136 
137  const std::list<CoordinateLsa>&
138  getCoordinateLsdb() const;
139 
140  //function related to Adj LSDB
141 
143  void
145 
147  bool
149 
153  bool
154  removeAdjLsa(const ndn::Name& key);
155 
163  bool
164  isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
165 
169  bool
170  installAdjLsa(AdjLsa& alsa);
171 
175  AdjLsa*
176  findAdjLsa(const ndn::Name& key);
177 
178  const std::list<AdjLsa>&
179  getAdjLsdb() const;
180 
181  void
182  setAdjLsaBuildInterval(uint32_t interval)
183  {
184  m_adjLsaBuildInterval = ndn::time::seconds(interval);
185  }
186 
187  const ndn::time::seconds&
189  {
190  return m_adjLsaBuildInterval;
191  }
192 
195  {
196  return m_sequencingManager;
197  }
198 
201  {
202  return m_lsaStorage;
203  }
204 
205  void
206  writeAdjLsdbLog();
207 
208  void
209  setLsaRefreshTime(const ndn::time::seconds& lsaRefreshTime);
210 
211  void
212  setThisRouterPrefix(std::string trp);
213 
214  void
215  expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
216  ndn::time::steady_clock::TimePoint deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE);
217 
218  void
219  processInterest(const ndn::Name& name, const ndn::Interest& interest);
220 
221 private:
222  /* \brief Add a name LSA to the LSDB if it isn't already there.
223  \param nlsa The candidade name LSA.
224  */
225  bool
226  addNameLsa(NameLsa& nlsa);
227 
231  bool
232  doesNameLsaExist(const ndn::Name& key);
233 
237  bool
238  addCoordinateLsa(CoordinateLsa& clsa);
239 
243  bool
244  doesCoordinateLsaExist(const ndn::Name& key);
245 
253  void
254  buildAdjLsa();
255 
259  bool
260  addAdjLsa(AdjLsa& alsa);
261 
265  bool
266  doesAdjLsaExist(const ndn::Name& key);
267 
273  ndn::EventId
274  scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
275  const ndn::time::seconds& expTime);
276 
281  void
282  expireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo);
283 
290  ndn::EventId
291  scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
292  const ndn::time::seconds& expTime);
293 
294 private:
295 
296  void
297  expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
298 
299  ndn::EventId
300  scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
301  const ndn::time::seconds& expTime);
302 
303  void
304  expireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
305  uint64_t seqNo);
306 
307 private:
308 
309  void
310  putLsaData(const ndn::Interest& interest, const std::string& content);
311 
312  void
313  processInterestForNameLsa(const ndn::Interest& interest,
314  const ndn::Name& lsaKey,
315  uint64_t seqNo);
316 
317  void
318  processInterestForAdjacencyLsa(const ndn::Interest& interest,
319  const ndn::Name& lsaKey,
320  uint64_t seqNo);
321 
322  void
323  processInterestForCoordinateLsa(const ndn::Interest& interest,
324  const ndn::Name& lsaKey,
325  uint64_t seqNo);
326  void
327  onContentValidated(const std::shared_ptr<const ndn::Data>& data);
328 
329  void
330  processContentNameLsa(const ndn::Name& lsaKey,
331  uint64_t lsSeqNo, std::string& dataContent);
332 
333  void
334  processContentAdjacencyLsa(const ndn::Name& lsaKey,
335  uint64_t lsSeqNo, std::string& dataContent);
336 
337  void
338  processContentCoordinateLsa(const ndn::Name& lsaKey,
339  uint64_t lsSeqNo, std::string& dataContent);
340 
356  void
357  onFetchLsaError(uint32_t errorCode,
358  const std::string& msg,
359  ndn::Name& interestName,
360  uint32_t retransmitNo,
361  const ndn::time::steady_clock::TimePoint& deadline,
362  ndn::Name lsaName,
363  uint64_t seqNo);
364 
371  void
372  afterFetchLsa(const ndn::ConstBufferPtr& data, ndn::Name& interestName);
373 
374 private:
375  ndn::time::system_clock::TimePoint
376  getLsaExpirationTimePoint();
377 
379  void
380  cancelScheduleLsaExpiringEvent(ndn::EventId eid);
381 
382 public:
383  static const ndn::Name::Component NAME_COMPONENT;
384 
385  ndn::util::signal::Signal<Lsdb, Statistics::PacketType> lsaIncrementSignal;
386 
387 private:
388  Nlsr& m_nlsr;
389  ndn::Scheduler& m_scheduler;
390  SyncLogicHandler m_sync;
391  LsaSegmentStorage m_lsaStorage;
392 
393  std::list<NameLsa> m_nameLsdb;
394  std::list<AdjLsa> m_adjLsdb;
395  std::list<CoordinateLsa> m_corLsdb;
396 
397  ndn::time::seconds m_lsaRefreshTime;
398  std::string m_thisRouterPrefix;
399 
400  typedef std::map<ndn::Name, uint64_t> SequenceNumberMap;
401 
402  // Maps the name of an LSA to its highest known sequence number from sync;
403  // Used to stop NLSR from trying to fetch outdated LSAs
404  SequenceNumberMap m_highestSeqNo;
405 
406  static const ndn::time::seconds GRACE_PERIOD;
407  static const ndn::time::steady_clock::TimePoint DEFAULT_LSA_RETRIEVAL_DEADLINE;
408 
409  ndn::time::seconds m_adjLsaBuildInterval;
410 
411  SequencingManager m_sequencingManager;
412 
413  ndn::util::signal::ScopedConnection m_onNewLsaConnection;
414 };
415 
416 } // namespace nlsr
417 
418 #endif // NLSR_LSDB_HPP
bool installAdjLsa(AdjLsa &alsa)
Installs an adj. LSA into the LSDB.
Definition: lsdb.cpp:718
const std::list< NameLsa > & getNameLsdb() const
Definition: lsdb.cpp:380
void scheduleAdjLsaBuild()
Schedules a build of this router&#39;s LSA.
Definition: lsdb.cpp:599
bool removeNameLsa(const ndn::Name &key)
Remove a name LSA from the LSDB.
Definition: lsdb.cpp:331
void writeNameLsdbLog()
Definition: lsdb.cpp:370
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
void setAdjLsaBuildInterval(uint32_t interval)
Definition: lsdb.hpp:182
Lsdb(Nlsr &nlsr, ndn::Scheduler &scheduler)
Definition: lsdb.cpp:67
bool isLsaNew(const ndn::Name &routerName, const Lsa::Type &lsaType, const uint64_t &sequenceNumber)
Definition: lsdb.cpp:1349
void writeAdjLsdbLog()
Definition: lsdb.cpp:1323
SyncLogicHandler & getSyncLogicHandler()
Definition: lsdb.hpp:49
void writeCorLsdbLog()
Definition: lsdb.cpp:571
const std::list< CoordinateLsa > & getCoordinateLsdb() const
Definition: lsdb.cpp:581
bool isCoordinateLsaNew(const ndn::Name &key, uint64_t seqNo)
Returns whether a cor. LSA from a router is new or not.
Definition: lsdb.cpp:431
CoordinateLsa * findCoordinateLsa(const ndn::Name &key)
Finds a cor. LSA in the LSDB.
Definition: lsdb.cpp:419
void setLsaRefreshTime(const ndn::time::seconds &lsaRefreshTime)
Definition: lsdb.cpp:825
bool isNameLsaNew(const ndn::Name &key, uint64_t seqNo)
Definition: lsdb.cpp:191
bool installCoordinateLsa(CoordinateLsa &clsa)
Installs a cor. LSA into the LSDB.
Definition: lsdb.cpp:461
SequencingManager & getSequencingManager()
Definition: lsdb.hpp:194
NLSR-to-ChronoSync interaction point.
NameLsa * findNameLsa(const ndn::Name &key)
Returns the name LSA with the given key.
Definition: lsdb.cpp:179
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
Definition: lsdb.cpp:1041
void expressInterest(const ndn::Name &interestName, uint32_t timeoutCount, ndn::time::steady_clock::TimePoint deadline=DEFAULT_LSA_RETRIEVAL_DEADLINE)
Definition: lsdb.cpp:981
bool doesLsaExist(const ndn::Name &key, const Lsa::Type &lsType)
Definition: lsdb.cpp:1334
const ndn::time::seconds & getAdjLsaBuildInterval() const
Definition: lsdb.hpp:188
bool isAdjLsaNew(const ndn::Name &key, uint64_t seqNo)
Returns whether an LSA is new.
Definition: lsdb.cpp:693
bool removeAdjLsa(const ndn::Name &key)
Removes an adj. LSA from the LSDB.
Definition: lsdb.cpp:791
static const ndn::Name::Component NAME_COMPONENT
Definition: lsdb.hpp:383
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
LsaSegmentStorage & getLsaStorage()
Definition: lsdb.hpp:200
ndn::util::signal::Signal< Lsdb, Statistics::PacketType > lsaIncrementSignal
Definition: lsdb.hpp:385
void setThisRouterPrefix(std::string trp)
Definition: lsdb.cpp:831
bool installNameLsa(NameLsa &nlsa)
Installs a name LSA into the LSDB.
Definition: lsdb.cpp:216
bool buildAndInstallOwnNameLsa()
Builds a name LSA for this router and then installs it into the LSDB.
Definition: lsdb.cpp:164
bool buildAndInstallOwnCoordinateLsa()
Builds a cor. LSA for this router and installs it into the LSDB.
Definition: lsdb.cpp:398
const std::list< AdjLsa > & getAdjLsdb() const
Definition: lsdb.cpp:819
AdjLsa * findAdjLsa(const ndn::Name &key)
Finds an adj. LSA in the LSDB.
Definition: lsdb.cpp:681
bool buildAndInstallOwnAdjLsa()
Wrapper event to build and install an adj. LSA for this router.
Definition: lsdb.cpp:772
bool removeCoordinateLsa(const ndn::Name &key)
Removes a cor. LSA from the LSDB.
Definition: lsdb.cpp:537