lsa.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NLSR_LSA_HPP
23 #define NLSR_LSA_HPP
24 
25 #include "name-prefix-list.hpp"
26 #include "adjacent.hpp"
27 #include "adjacency-list.hpp"
28 
29 #include <boost/cstdint.hpp>
30 #include <ndn-cxx/util/scheduler.hpp>
31 #include <ndn-cxx/util/time.hpp>
32 #include <boost/tokenizer.hpp>
33 
34 namespace nlsr {
35 
36 class Nlsr;
37 
38 class Lsa
39 {
40 public:
41  enum class Type {
42  ADJACENCY,
43  COORDINATE,
44  NAME,
45  BASE,
46  MOCK
47  };
48 
49  Lsa()
50  : m_origRouter()
51  , m_lsSeqNo()
54  {
55  }
56 
57  virtual Type
58  getType() const
59  {
60  return Type::BASE;
61  }
62 
63  void
64  setLsSeqNo(uint32_t lsn)
65  {
66  m_lsSeqNo = lsn;
67  }
68 
69  uint32_t
70  getLsSeqNo() const
71  {
72  return m_lsSeqNo;
73  }
74 
75  const ndn::Name&
76  getOrigRouter() const
77  {
78  return m_origRouter;
79  }
80 
81  void
82  setOrigRouter(const ndn::Name& org)
83  {
84  m_origRouter = org;
85  }
86 
87  const ndn::time::system_clock::TimePoint&
89  {
90  return m_expirationTimePoint;
91  }
92 
93  void
94  setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
95  {
97  }
98 
99  void
100  setExpiringEventId(const ndn::EventId leei)
101  {
102  m_expiringEventId = leei;
103  }
104 
105  ndn::EventId
107  {
108  return m_expiringEventId;
109  }
110 
113  virtual std::string
114  serialize() const = 0;
115 
120  const ndn::Name
121  getKey() const;
122 
128  virtual bool
129  deserialize(const std::string& content) noexcept = 0;
130 
131  virtual void
132  writeLog() const = 0;
133 
134 protected:
140  std::string
141  getData() const;
142 
145  std::string
146  toString() const;
147 
148  bool
149  deserializeCommon(boost::tokenizer<boost::char_separator<char>>::iterator& iterator);
150 
151 protected:
152  ndn::Name m_origRouter;
153  uint32_t m_lsSeqNo;
154  ndn::time::system_clock::TimePoint m_expirationTimePoint;
155  ndn::EventId m_expiringEventId;
156 };
157 
158 class NameLsa: public Lsa
159 {
160 public:
162  {
163  }
164 
165  NameLsa(const ndn::Name& origR, uint32_t lsn,
166  const ndn::time::system_clock::TimePoint& lt,
167  NamePrefixList& npl);
168 
169  Lsa::Type
170  getType() const override
171  {
172  return Lsa::Type::NAME;
173  }
174 
177  {
178  return m_npl;
179  }
180 
181  const NamePrefixList&
182  getNpl() const
183  {
184  return m_npl;
185  }
186 
187  void
188  addName(const ndn::Name& name)
189  {
190  m_npl.insert(name);
191  }
192 
193  void
194  removeName(const ndn::Name& name)
195  {
196  m_npl.remove(name);
197  }
198 
207  bool
208  deserialize(const std::string& content) noexcept override;
209 
210  bool
211  isEqualContent(const NameLsa& other) const;
212 
213  void
214  writeLog() const override;
215 
222  std::string
223  serialize() const override;
224 
225 private:
226  NamePrefixList m_npl;
227 
228  friend std::ostream&
229  operator<<(std::ostream& os, const NameLsa& lsa);
230 };
231 
232 class AdjLsa: public Lsa
233 {
234 public:
236 
238  {
239  }
240 
241  AdjLsa(const ndn::Name& origR, uint32_t lsn,
242  const ndn::time::system_clock::TimePoint& lt,
243  uint32_t nl , AdjacencyList& adl);
244 
245  Lsa::Type
246  getType() const override
247  {
248  return Lsa::Type::ADJACENCY;
249  }
250 
253  {
254  return m_adl;
255  }
256 
257  const AdjacencyList&
258  getAdl() const
259  {
260  return m_adl;
261  }
262 
263  void
265  {
266  m_adl.insert(adj);
267  }
268 
274  bool
275  deserialize(const std::string& content) noexcept override;
276 
277  uint32_t
279  {
280  return m_noLink;
281  }
282 
283  bool
284  isEqualContent(AdjLsa& alsa);
285 
291  void
292  addNptEntries(Nlsr& pnlsr);
293 
294  void
295  removeNptEntries(Nlsr& pnlsr);
296 
297  void
298  writeLog() const override;
299 
300  const_iterator
301  begin() const
302  {
303  return m_adl.begin();
304  }
305 
306  const_iterator
307  end() const
308  {
309  return m_adl.end();
310  }
311 
319  std::string
320  serialize() const override;
321 
322 private:
323  uint32_t m_noLink;
324  AdjacencyList m_adl;
325 
326  friend std::ostream&
327  operator<<(std::ostream& os, const AdjLsa& lsa);
328 };
329 
330 class CoordinateLsa: public Lsa
331 {
332 public:
334  : m_corRad(0)
335  {
336  }
337 
338  CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
339  const ndn::time::system_clock::TimePoint& lt,
340  double r, std::vector<double> theta);
341 
342  Lsa::Type
343  getType() const override
344  {
345  return Lsa::Type::COORDINATE;
346  }
347 
356  bool
357  deserialize(const std::string& content) noexcept override;
358 
359  double
360  getCorRadius() const
361  {
362  return m_corRad;
363  }
364 
365  void
366  setCorRadius(double cr)
367  {
368  m_corRad = cr;
369  }
370 
371  const std::vector<double>
372  getCorTheta() const
373  {
374  return m_angles;
375  }
376 
377  void
378  setCorTheta(std::vector<double> ct)
379  {
380  m_angles = ct;
381  }
382 
383  bool
384  isEqualContent(const CoordinateLsa& clsa);
385 
386  void
387  writeLog() const override;
388 
394  std::string
395  serialize() const override;
396 
397 private:
398  double m_corRad;
399  std::vector<double> m_angles;
400 
401  friend std::ostream&
402  operator<<(std::ostream& os, const CoordinateLsa& lsa);
403 };
404 
405 std::ostream&
406 operator<<(std::ostream& os, const AdjLsa& lsa);
407 
408 std::ostream&
409 operator<<(std::ostream& os, const CoordinateLsa& lsa);
410 
411 std::ostream&
412 operator<<(std::ostream& os, const NameLsa& lsa);
413 
414 std::ostream&
415 operator<<(std::ostream& os, const Lsa::Type& type);
416 
417 std::istream&
418 operator>>(std::istream& is, Lsa::Type& type);
419 
420 } // namespace nlsr
421 
422 namespace std {
423  std::string
424  to_string(const nlsr::Lsa::Type& type);
425 } // namespace std
426 
427 #endif // NLSR_LSA_HPP
ndn::time::system_clock::TimePoint m_expirationTimePoint
Definition: lsa.hpp:154
void addAdjacent(Adjacent adj)
Definition: lsa.hpp:264
std::string getData() const
Definition: lsa.cpp:41
AdjacencyList::const_iterator const_iterator
Definition: lsa.hpp:235
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition: adjacent.cpp:83
const ndn::time::system_clock::TimePoint & getExpirationTimePoint() const
Definition: lsa.hpp:88
AdjacencyList & getAdl()
Definition: lsa.hpp:252
void setLsSeqNo(uint32_t lsn)
Definition: lsa.hpp:64
ndn::Name m_origRouter
Definition: lsa.hpp:152
NamePrefixList & getNpl()
Definition: lsa.hpp:176
const_iterator end() const
Definition: lsa.hpp:307
ndn::EventId getExpiringEventId() const
Definition: lsa.hpp:106
Lsa::Type getType() const override
Definition: lsa.hpp:246
Lsa::Type getType() const override
Definition: lsa.hpp:170
bool deserializeCommon(boost::tokenizer< boost::char_separator< char >>::iterator &iterator)
Definition: lsa.cpp:56
STL namespace.
virtual bool deserialize(const std::string &content) noexcept=0
Populate this LSA with content from the string "content".
const_iterator begin() const
Definition: lsa.hpp:301
std::list< Adjacent >::const_iterator const_iterator
std::string toString() const
Definition: lsa.cpp:365
void setExpirationTimePoint(const ndn::time::system_clock::TimePoint &lt)
Definition: lsa.hpp:94
const ndn::Name & getOrigRouter() const
Definition: lsa.hpp:76
uint32_t getLsSeqNo() const
Definition: lsa.hpp:70
uint32_t m_lsSeqNo
Definition: lsa.hpp:153
virtual Type getType() const
Definition: lsa.hpp:58
Lsa::Type getType() const override
Definition: lsa.hpp:343
virtual void writeLog() const =0
const AdjacencyList & getAdl() const
Definition: lsa.hpp:258
Lsa()
Definition: lsa.hpp:49
A neighbor reachable over a Face.
Definition: adjacent.hpp:38
void setExpiringEventId(const ndn::EventId leei)
Definition: lsa.hpp:100
void setCorTheta(std::vector< double > ct)
Definition: lsa.hpp:378
void removeName(const ndn::Name &name)
Definition: lsa.hpp:194
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
const NamePrefixList & getNpl() const
Definition: lsa.hpp:182
void setCorRadius(double cr)
Definition: lsa.hpp:366
const std::vector< double > getCorTheta() const
Definition: lsa.hpp:372
std::istream & operator>>(std::istream &is, Lsa::Type &type)
Definition: lsa.cpp:345
void setOrigRouter(const ndn::Name &org)
Definition: lsa.hpp:82
virtual std::string serialize() const =0
Return the data that this LSA represents.
const ndn::Name getKey() const
Gets the key for this LSA.
Definition: lsa.cpp:50
void addName(const ndn::Name &name)
Definition: lsa.hpp:188
double getCorRadius() const
Definition: lsa.hpp:360
ndn::EventId m_expiringEventId
Definition: lsa.hpp:155
uint32_t getNoLink()
Definition: lsa.hpp:278