lsa.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2019, The University of Memphis,
4  * Regents of the University of California,
5  * Arizona Board of Regents.
6  *
7  * This file is part of NLSR (Named-data Link State Routing).
8  * See AUTHORS.md for complete list of NLSR authors and contributors.
9  *
10  * NLSR is free software: you can redistribute it and/or modify it under the terms
11  * of the GNU General Public License as published by the Free Software Foundation,
12  * either version 3 of the License, or (at your option) any later version.
13  *
14  * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16  * PURPOSE. See the GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along with
19  * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
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 Lsa
37 {
38 public:
39  enum class Type {
40  ADJACENCY,
41  COORDINATE,
42  NAME,
43  BASE,
44  MOCK
45  };
46 
47  Lsa()
48  : m_origRouter()
49  , m_lsSeqNo()
52  {
53  }
54 
55  virtual
56  ~Lsa() = default;
57 
58  virtual Type
59  getType() const
60  {
61  return Type::BASE;
62  }
63 
64  void
65  setLsSeqNo(uint32_t lsn)
66  {
67  m_lsSeqNo = lsn;
68  }
69 
70  uint32_t
71  getLsSeqNo() const
72  {
73  return m_lsSeqNo;
74  }
75 
76  const ndn::Name&
77  getOrigRouter() const
78  {
79  return m_origRouter;
80  }
81 
82  void
83  setOrigRouter(const ndn::Name& org)
84  {
85  m_origRouter = org;
86  }
87 
88  const ndn::time::system_clock::TimePoint&
90  {
91  return m_expirationTimePoint;
92  }
93 
94  void
95  setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
96  {
98  }
99 
100  void
101  setExpiringEventId(const ndn::EventId leei)
102  {
103  m_expiringEventId = leei;
104  }
105 
106  ndn::EventId
108  {
109  return m_expiringEventId;
110  }
111 
114  virtual std::string
115  serialize() const = 0;
116 
121  const ndn::Name
122  getKey() const;
123 
129  virtual bool
130  deserialize(const std::string& content) noexcept = 0;
131 
132  virtual void
133  writeLog() const = 0;
134 
135 protected:
141  std::string
142  getData() const;
143 
146  std::string
147  toString() const;
148 
149  bool
150  deserializeCommon(boost::tokenizer<boost::char_separator<char>>::iterator& iterator);
151 
152 protected:
153  ndn::Name m_origRouter;
154  uint32_t m_lsSeqNo;
155  ndn::time::system_clock::TimePoint m_expirationTimePoint;
156  ndn::EventId m_expiringEventId;
157 };
158 
159 class NameLsa : public Lsa
160 {
161 public:
163  {
164  }
165 
166  NameLsa(const ndn::Name& origR, uint32_t lsn,
167  const ndn::time::system_clock::TimePoint& lt,
168  NamePrefixList& npl);
169 
170  Lsa::Type
171  getType() const override
172  {
173  return Lsa::Type::NAME;
174  }
175 
178  {
179  return m_npl;
180  }
181 
182  const NamePrefixList&
183  getNpl() const
184  {
185  return m_npl;
186  }
187 
188  void
189  addName(const ndn::Name& name)
190  {
191  m_npl.insert(name);
192  }
193 
194  void
195  removeName(const ndn::Name& name)
196  {
197  m_npl.remove(name);
198  }
199 
208  bool
209  deserialize(const std::string& content) noexcept override;
210 
211  bool
212  isEqualContent(const NameLsa& other) const;
213 
214  void
215  writeLog() const override;
216 
223  std::string
224  serialize() const override;
225 
226 private:
227  NamePrefixList m_npl;
228 
229  friend std::ostream&
230  operator<<(std::ostream& os, const NameLsa& lsa);
231 };
232 
233 class AdjLsa : public Lsa
234 {
235 public:
237 
239  {
240  }
241 
242  AdjLsa(const ndn::Name& origR, uint32_t lsn,
243  const ndn::time::system_clock::TimePoint& lt,
244  uint32_t nl , AdjacencyList& adl);
245 
246  Lsa::Type
247  getType() const override
248  {
249  return Lsa::Type::ADJACENCY;
250  }
251 
254  {
255  return m_adl;
256  }
257 
258  const AdjacencyList&
259  getAdl() const
260  {
261  return m_adl;
262  }
263 
264  void
266  {
267  m_adl.insert(adj);
268  }
269 
275  bool
276  deserialize(const std::string& content) noexcept override;
277 
278  uint32_t
280  {
281  return m_noLink;
282  }
283 
284  bool
285  isEqualContent(const AdjLsa& alsa) const;
286 
287  void
288  writeLog() const override;
289 
290  const_iterator
291  begin() const
292  {
293  return m_adl.begin();
294  }
295 
296  const_iterator
297  end() const
298  {
299  return m_adl.end();
300  }
301 
309  std::string
310  serialize() const override;
311 
312 private:
313  uint32_t m_noLink;
314  AdjacencyList m_adl;
315 
316  friend std::ostream&
317  operator<<(std::ostream& os, const AdjLsa& lsa);
318 };
319 
320 class CoordinateLsa : public Lsa
321 {
322 public:
324  : m_corRad(0)
325  {
326  }
327 
328  CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
329  const ndn::time::system_clock::TimePoint& lt,
330  double r, std::vector<double> theta);
331 
332  Lsa::Type
333  getType() const override
334  {
335  return Lsa::Type::COORDINATE;
336  }
337 
346  bool
347  deserialize(const std::string& content) noexcept override;
348 
349  double
350  getCorRadius() const
351  {
352  return m_corRad;
353  }
354 
355  void
356  setCorRadius(double cr)
357  {
358  m_corRad = cr;
359  }
360 
361  const std::vector<double>
362  getCorTheta() const
363  {
364  return m_angles;
365  }
366 
367  void
368  setCorTheta(std::vector<double> ct)
369  {
370  m_angles = ct;
371  }
372 
373  bool
374  isEqualContent(const CoordinateLsa& clsa) const;
375 
376  void
377  writeLog() const override;
378 
384  std::string
385  serialize() const override;
386 
387 private:
388  double m_corRad;
389  std::vector<double> m_angles;
390 
391  friend std::ostream&
392  operator<<(std::ostream& os, const CoordinateLsa& lsa);
393 };
394 
395 std::ostream&
396 operator<<(std::ostream& os, const AdjLsa& lsa);
397 
398 std::ostream&
399 operator<<(std::ostream& os, const CoordinateLsa& lsa);
400 
401 std::ostream&
402 operator<<(std::ostream& os, const NameLsa& lsa);
403 
404 std::ostream&
405 operator<<(std::ostream& os, const Lsa::Type& type);
406 
407 std::istream&
408 operator>>(std::istream& is, Lsa::Type& type);
409 
410 } // namespace nlsr
411 
412 namespace std {
413  std::string
414  to_string(const nlsr::Lsa::Type& type);
415 } // namespace std
416 
417 #endif // NLSR_LSA_HPP
ndn::time::system_clock::TimePoint m_expirationTimePoint
Definition: lsa.hpp:155
void addAdjacent(Adjacent adj)
Definition: lsa.hpp:265
std::string getData() const
Definition: lsa.cpp:41
AdjacencyList::const_iterator const_iterator
Definition: lsa.hpp:236
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition: adjacent.cpp:84
const ndn::time::system_clock::TimePoint & getExpirationTimePoint() const
Definition: lsa.hpp:89
AdjacencyList & getAdl()
Definition: lsa.hpp:253
void setLsSeqNo(uint32_t lsn)
Definition: lsa.hpp:65
ndn::Name m_origRouter
Definition: lsa.hpp:153
NamePrefixList & getNpl()
Definition: lsa.hpp:177
const_iterator end() const
Definition: lsa.hpp:297
ndn::EventId getExpiringEventId() const
Definition: lsa.hpp:107
Lsa::Type getType() const override
Definition: lsa.hpp:247
Lsa::Type getType() const override
Definition: lsa.hpp:171
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:291
std::list< Adjacent >::const_iterator const_iterator
std::string toString() const
Definition: lsa.cpp:345
void setExpirationTimePoint(const ndn::time::system_clock::TimePoint &lt)
Definition: lsa.hpp:95
const ndn::Name & getOrigRouter() const
Definition: lsa.hpp:77
virtual ~Lsa()=default
uint32_t getLsSeqNo() const
Definition: lsa.hpp:71
uint32_t m_lsSeqNo
Definition: lsa.hpp:154
virtual Type getType() const
Definition: lsa.hpp:59
Lsa::Type getType() const override
Definition: lsa.hpp:333
virtual void writeLog() const =0
const AdjacencyList & getAdl() const
Definition: lsa.hpp:259
Lsa()
Definition: lsa.hpp:47
A neighbor reachable over a Face.
Definition: adjacent.hpp:38
void setExpiringEventId(const ndn::EventId leei)
Definition: lsa.hpp:101
void setCorTheta(std::vector< double > ct)
Definition: lsa.hpp:368
void removeName(const ndn::Name &name)
Definition: lsa.hpp:195
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:183
void setCorRadius(double cr)
Definition: lsa.hpp:356
const std::vector< double > getCorTheta() const
Definition: lsa.hpp:362
std::istream & operator>>(std::istream &is, Lsa::Type &type)
Definition: lsa.cpp:325
void setOrigRouter(const ndn::Name &org)
Definition: lsa.hpp:83
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:189
double getCorRadius() const
Definition: lsa.hpp:350
ndn::EventId m_expiringEventId
Definition: lsa.hpp:156
uint32_t getNoLink()
Definition: lsa.hpp:279