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 "sequencing-manager.hpp"
28 #include "test-access-control.hpp"
30 #include "statistics.hpp"
31 
32 #include <ndn-cxx/security/key-chain.hpp>
33 #include <ndn-cxx/util/signal.hpp>
34 #include <ndn-cxx/util/time.hpp>
35 #include <utility>
36 #include <boost/cstdint.hpp>
37 
38 namespace nlsr {
39 
40 class Nlsr;
41 
42 class Lsdb
43 {
44 public:
45  Lsdb(Nlsr& nlsr, ndn::Scheduler& scheduler);
46 
49  {
50  return m_sync;
51  }
52 
53  bool
54  isLsaNew(const ndn::Name& routerName, const Lsa::Type& lsaType, const uint64_t& sequenceNumber);
55 
56  bool
57  doesLsaExist(const ndn::Name& key, const Lsa::Type& lsType);
58 
62  bool
64 
68  NameLsa*
69  findNameLsa(const ndn::Name& key);
70 
74  bool
75  installNameLsa(NameLsa& nlsa);
76 
84  bool
85  removeNameLsa(const ndn::Name& key);
86 
91  bool
92  isNameLsaNew(const ndn::Name& key, uint64_t seqNo);
93 
94  void
96 
97  const std::list<NameLsa>&
98  getNameLsdb() const;
99 
101  bool
103 
108  findCoordinateLsa(const ndn::Name& key);
109 
113  bool
115 
123  bool
124  removeCoordinateLsa(const ndn::Name& key);
125 
130  bool
131  isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo);
132 
133  void
134  writeCorLsdbLog();
135 
136  const std::list<CoordinateLsa>&
137  getCoordinateLsdb() const;
138 
139  //function related to Adj LSDB
140 
142  void
144 
146  bool
148 
152  bool
153  removeAdjLsa(const ndn::Name& key);
154 
162  bool
163  isAdjLsaNew(const ndn::Name& key, uint64_t seqNo);
164 
168  bool
169  installAdjLsa(AdjLsa& alsa);
170 
174  AdjLsa*
175  findAdjLsa(const ndn::Name& key);
176 
177  const std::list<AdjLsa>&
178  getAdjLsdb() const;
179 
180  void
181  setAdjLsaBuildInterval(uint32_t interval)
182  {
183  m_adjLsaBuildInterval = ndn::time::seconds(interval);
184  }
185 
186  const ndn::time::seconds&
188  {
189  return m_adjLsaBuildInterval;
190  }
191 
194  {
195  return m_sequencingManager;
196  }
197 
198  void
199  writeAdjLsdbLog();
200 
201  void
202  setLsaRefreshTime(const ndn::time::seconds& lsaRefreshTime);
203 
204  void
205  setThisRouterPrefix(std::string trp);
206 
207  void
208  expressInterest(const ndn::Name& interestName, uint32_t timeoutCount,
209  ndn::time::steady_clock::TimePoint deadline = DEFAULT_LSA_RETRIEVAL_DEADLINE);
210 
211  void
212  processInterest(const ndn::Name& name, const ndn::Interest& interest);
213 
214 private:
215  /* \brief Add a name LSA to the LSDB if it isn't already there.
216  \param nlsa The candidade name LSA.
217  */
218  bool
219  addNameLsa(NameLsa& nlsa);
220 
224  bool
225  doesNameLsaExist(const ndn::Name& key);
226 
230  bool
231  addCoordinateLsa(CoordinateLsa& clsa);
232 
236  bool
237  doesCoordinateLsaExist(const ndn::Name& key);
238 
246  void
247  buildAdjLsa();
248 
252  bool
253  addAdjLsa(AdjLsa& alsa);
254 
258  bool
259  doesAdjLsaExist(const ndn::Name& key);
260 
266  ndn::EventId
267  scheduleNameLsaExpiration(const ndn::Name& key, int seqNo,
268  const ndn::time::seconds& expTime);
269 
274  void
275  expireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo);
276 
283  ndn::EventId
284  scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo,
285  const ndn::time::seconds& expTime);
286 
287 private:
288 
289  void
290  expireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo);
291 
292  ndn::EventId
293  scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo,
294  const ndn::time::seconds& expTime);
295 
296  void
297  expireOrRefreshCoordinateLsa(const ndn::Name& lsaKey,
298  uint64_t seqNo);
299 
300 private:
301 
302  void
303  putLsaData(const ndn::Interest& interest, const std::string& content);
304 
305  void
306  processInterestForNameLsa(const ndn::Interest& interest,
307  const ndn::Name& lsaKey,
308  uint64_t seqNo);
309 
310  void
311  processInterestForAdjacencyLsa(const ndn::Interest& interest,
312  const ndn::Name& lsaKey,
313  uint64_t seqNo);
314 
315  void
316  processInterestForCoordinateLsa(const ndn::Interest& interest,
317  const ndn::Name& lsaKey,
318  uint64_t seqNo);
319  void
320  onContentValidated(const std::shared_ptr<const ndn::Data>& data);
321 
322  void
323  processContentNameLsa(const ndn::Name& lsaKey,
324  uint64_t lsSeqNo, std::string& dataContent);
325 
326  void
327  processContentAdjacencyLsa(const ndn::Name& lsaKey,
328  uint64_t lsSeqNo, std::string& dataContent);
329 
330  void
331  processContentCoordinateLsa(const ndn::Name& lsaKey,
332  uint64_t lsSeqNo, std::string& dataContent);
333 
349  void
350  onFetchLsaError(uint32_t errorCode,
351  const std::string& msg,
352  ndn::Name& interestName,
353  uint32_t retransmitNo,
354  const ndn::time::steady_clock::TimePoint& deadline,
355  ndn::Name lsaName,
356  uint64_t seqNo);
357 
364  void
365  afterFetchLsa(const ndn::ConstBufferPtr& data, ndn::Name& interestName);
366 
367 private:
368  ndn::time::system_clock::TimePoint
369  getLsaExpirationTimePoint();
370 
372  void
373  cancelScheduleLsaExpiringEvent(ndn::EventId eid);
374 
375 public:
376  static const ndn::Name::Component NAME_COMPONENT;
377 
378  ndn::util::signal::Signal<Lsdb, Statistics::PacketType> lsaIncrementSignal;
379 
380 private:
381  Nlsr& m_nlsr;
382  ndn::Scheduler& m_scheduler;
383  SyncLogicHandler m_sync;
384 
385  std::list<NameLsa> m_nameLsdb;
386  std::list<AdjLsa> m_adjLsdb;
387  std::list<CoordinateLsa> m_corLsdb;
388 
389  ndn::time::seconds m_lsaRefreshTime;
390  std::string m_thisRouterPrefix;
391 
392  typedef std::map<ndn::Name, uint64_t> SequenceNumberMap;
393 
394  // Maps the name of an LSA to its highest known sequence number from sync;
395  // Used to stop NLSR from trying to fetch outdated LSAs
396  SequenceNumberMap m_highestSeqNo;
397 
398  static const ndn::time::seconds GRACE_PERIOD;
399  static const ndn::time::steady_clock::TimePoint DEFAULT_LSA_RETRIEVAL_DEADLINE;
400 
401  ndn::time::seconds m_adjLsaBuildInterval;
402 
403  SequencingManager m_sequencingManager;
404 
405  ndn::util::signal::ScopedConnection m_onNewLsaConnection;
406 
407 };
408 
409 } // namespace nlsr
410 
411 #endif // NLSR_LSDB_HPP
bool installAdjLsa(AdjLsa &alsa)
Installs an adj. LSA into the LSDB.
Definition: lsdb.cpp:708
const std::list< NameLsa > & getNameLsdb() const
Definition: lsdb.cpp:370
void scheduleAdjLsaBuild()
Schedules a build of this router&#39;s LSA.
Definition: lsdb.cpp:589
bool removeNameLsa(const ndn::Name &key)
Remove a name LSA from the LSDB.
Definition: lsdb.cpp:321
void writeNameLsdbLog()
Definition: lsdb.cpp:360
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
void setAdjLsaBuildInterval(uint32_t interval)
Definition: lsdb.hpp:181
Lsdb(Nlsr &nlsr, ndn::Scheduler &scheduler)
Definition: lsdb.cpp:66
bool isLsaNew(const ndn::Name &routerName, const Lsa::Type &lsaType, const uint64_t &sequenceNumber)
Definition: lsdb.cpp:1313
void writeAdjLsdbLog()
Definition: lsdb.cpp:1287
SyncLogicHandler & getSyncLogicHandler()
Definition: lsdb.hpp:48
void writeCorLsdbLog()
Definition: lsdb.cpp:561
const std::list< CoordinateLsa > & getCoordinateLsdb() const
Definition: lsdb.cpp:571
bool isCoordinateLsaNew(const ndn::Name &key, uint64_t seqNo)
Returns whether a cor. LSA from a router is new or not.
Definition: lsdb.cpp:421
CoordinateLsa * findCoordinateLsa(const ndn::Name &key)
Finds a cor. LSA in the LSDB.
Definition: lsdb.cpp:409
void setLsaRefreshTime(const ndn::time::seconds &lsaRefreshTime)
Definition: lsdb.cpp:815
bool isNameLsaNew(const ndn::Name &key, uint64_t seqNo)
Definition: lsdb.cpp:188
bool installCoordinateLsa(CoordinateLsa &clsa)
Installs a cor. LSA into the LSDB.
Definition: lsdb.cpp:451
SequencingManager & getSequencingManager()
Definition: lsdb.hpp:193
NLSR-to-ChronoSync interaction point.
NameLsa * findNameLsa(const ndn::Name &key)
Returns the name LSA with the given key.
Definition: lsdb.cpp:176
void processInterest(const ndn::Name &name, const ndn::Interest &interest)
Definition: lsdb.cpp:1026
void expressInterest(const ndn::Name &interestName, uint32_t timeoutCount, ndn::time::steady_clock::TimePoint deadline=DEFAULT_LSA_RETRIEVAL_DEADLINE)
Definition: lsdb.cpp:971
bool doesLsaExist(const ndn::Name &key, const Lsa::Type &lsType)
Definition: lsdb.cpp:1298
const ndn::time::seconds & getAdjLsaBuildInterval() const
Definition: lsdb.hpp:187
bool isAdjLsaNew(const ndn::Name &key, uint64_t seqNo)
Returns whether an LSA is new.
Definition: lsdb.cpp:683
bool removeAdjLsa(const ndn::Name &key)
Removes an adj. LSA from the LSDB.
Definition: lsdb.cpp:781
static const ndn::Name::Component NAME_COMPONENT
Definition: lsdb.hpp:376
Copyright (c) 2014-2017, 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:378
void setThisRouterPrefix(std::string trp)
Definition: lsdb.cpp:821
bool installNameLsa(NameLsa &nlsa)
Installs a name LSA into the LSDB.
Definition: lsdb.cpp:213
bool buildAndInstallOwnNameLsa()
Builds a name LSA for this router and then installs it into the LSDB.
Definition: lsdb.cpp:161
bool buildAndInstallOwnCoordinateLsa()
Builds a cor. LSA for this router and installs it into the LSDB.
Definition: lsdb.cpp:388
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:671
bool buildAndInstallOwnAdjLsa()
Wrapper event to build and install an adj. LSA for this router.
Definition: lsdb.cpp:762
bool removeCoordinateLsa(const ndn::Name &key)
Removes a cor. LSA from the LSDB.
Definition: lsdb.cpp:527