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-2018, 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 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
58  ~Lsa() = default;
59 
60  virtual Type
61  getType() const
62  {
63  return Type::BASE;
64  }
65 
66  void
67  setLsSeqNo(uint32_t lsn)
68  {
69  m_lsSeqNo = lsn;
70  }
71 
72  uint32_t
73  getLsSeqNo() const
74  {
75  return m_lsSeqNo;
76  }
77 
78  const ndn::Name&
79  getOrigRouter() const
80  {
81  return m_origRouter;
82  }
83 
84  void
85  setOrigRouter(const ndn::Name& org)
86  {
87  m_origRouter = org;
88  }
89 
90  const ndn::time::system_clock::TimePoint&
92  {
93  return m_expirationTimePoint;
94  }
95 
96  void
97  setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
98  {
100  }
101 
102  void
103  setExpiringEventId(const ndn::EventId leei)
104  {
105  m_expiringEventId = leei;
106  }
107 
108  ndn::EventId
110  {
111  return m_expiringEventId;
112  }
113 
116  virtual std::string
117  serialize() const = 0;
118 
123  const ndn::Name
124  getKey() const;
125 
131  virtual bool
132  deserialize(const std::string& content) noexcept = 0;
133 
134  virtual void
135  writeLog() const = 0;
136 
137 protected:
143  std::string
144  getData() const;
145 
148  std::string
149  toString() const;
150 
151  bool
152  deserializeCommon(boost::tokenizer<boost::char_separator<char>>::iterator& iterator);
153 
154 protected:
155  ndn::Name m_origRouter;
156  uint32_t m_lsSeqNo;
157  ndn::time::system_clock::TimePoint m_expirationTimePoint;
158  ndn::EventId m_expiringEventId;
159 };
160 
161 class NameLsa : public Lsa
162 {
163 public:
165  {
166  }
167 
168  NameLsa(const ndn::Name& origR, uint32_t lsn,
169  const ndn::time::system_clock::TimePoint& lt,
170  NamePrefixList& npl);
171 
172  Lsa::Type
173  getType() const override
174  {
175  return Lsa::Type::NAME;
176  }
177 
180  {
181  return m_npl;
182  }
183 
184  const NamePrefixList&
185  getNpl() const
186  {
187  return m_npl;
188  }
189 
190  void
191  addName(const ndn::Name& name)
192  {
193  m_npl.insert(name);
194  }
195 
196  void
197  removeName(const ndn::Name& name)
198  {
199  m_npl.remove(name);
200  }
201 
210  bool
211  deserialize(const std::string& content) noexcept override;
212 
213  bool
214  isEqualContent(const NameLsa& other) const;
215 
216  void
217  writeLog() const override;
218 
225  std::string
226  serialize() const override;
227 
228 private:
229  NamePrefixList m_npl;
230 
231  friend std::ostream&
232  operator<<(std::ostream& os, const NameLsa& lsa);
233 };
234 
235 class AdjLsa : public Lsa
236 {
237 public:
239 
241  {
242  }
243 
244  AdjLsa(const ndn::Name& origR, uint32_t lsn,
245  const ndn::time::system_clock::TimePoint& lt,
246  uint32_t nl , AdjacencyList& adl);
247 
248  Lsa::Type
249  getType() const override
250  {
251  return Lsa::Type::ADJACENCY;
252  }
253 
256  {
257  return m_adl;
258  }
259 
260  const AdjacencyList&
261  getAdl() const
262  {
263  return m_adl;
264  }
265 
266  void
268  {
269  m_adl.insert(adj);
270  }
271 
277  bool
278  deserialize(const std::string& content) noexcept override;
279 
280  uint32_t
282  {
283  return m_noLink;
284  }
285 
286  bool
287  isEqualContent(const AdjLsa& alsa) const;
288 
294  void
295  addNptEntries(Nlsr& pnlsr);
296 
297  void
298  removeNptEntries(Nlsr& pnlsr);
299 
300  void
301  writeLog() const override;
302 
303  const_iterator
304  begin() const
305  {
306  return m_adl.begin();
307  }
308 
309  const_iterator
310  end() const
311  {
312  return m_adl.end();
313  }
314 
322  std::string
323  serialize() const override;
324 
325 private:
326  uint32_t m_noLink;
327  AdjacencyList m_adl;
328 
329  friend std::ostream&
330  operator<<(std::ostream& os, const AdjLsa& lsa);
331 };
332 
333 class CoordinateLsa : public Lsa
334 {
335 public:
337  : m_corRad(0)
338  {
339  }
340 
341  CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
342  const ndn::time::system_clock::TimePoint& lt,
343  double r, std::vector<double> theta);
344 
345  Lsa::Type
346  getType() const override
347  {
348  return Lsa::Type::COORDINATE;
349  }
350 
359  bool
360  deserialize(const std::string& content) noexcept override;
361 
362  double
363  getCorRadius() const
364  {
365  return m_corRad;
366  }
367 
368  void
369  setCorRadius(double cr)
370  {
371  m_corRad = cr;
372  }
373 
374  const std::vector<double>
375  getCorTheta() const
376  {
377  return m_angles;
378  }
379 
380  void
381  setCorTheta(std::vector<double> ct)
382  {
383  m_angles = ct;
384  }
385 
386  bool
387  isEqualContent(const CoordinateLsa& clsa) const;
388 
389  void
390  writeLog() const override;
391 
397  std::string
398  serialize() const override;
399 
400 private:
401  double m_corRad;
402  std::vector<double> m_angles;
403 
404  friend std::ostream&
405  operator<<(std::ostream& os, const CoordinateLsa& lsa);
406 };
407 
408 std::ostream&
409 operator<<(std::ostream& os, const AdjLsa& lsa);
410 
411 std::ostream&
412 operator<<(std::ostream& os, const CoordinateLsa& lsa);
413 
414 std::ostream&
415 operator<<(std::ostream& os, const NameLsa& lsa);
416 
417 std::ostream&
418 operator<<(std::ostream& os, const Lsa::Type& type);
419 
420 std::istream&
421 operator>>(std::istream& is, Lsa::Type& type);
422 
423 } // namespace nlsr
424 
425 namespace std {
426  std::string
427  to_string(const nlsr::Lsa::Type& type);
428 } // namespace std
429 
430 #endif // NLSR_LSA_HPP
ndn::time::system_clock::TimePoint m_expirationTimePoint
Definition: lsa.hpp:157
void addAdjacent(Adjacent adj)
Definition: lsa.hpp:267
std::string getData() const
Definition: lsa.cpp:41
AdjacencyList::const_iterator const_iterator
Definition: lsa.hpp:238
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition: adjacent.cpp:83
const ndn::time::system_clock::TimePoint & getExpirationTimePoint() const
Definition: lsa.hpp:91
AdjacencyList & getAdl()
Definition: lsa.hpp:255
void setLsSeqNo(uint32_t lsn)
Definition: lsa.hpp:67
ndn::Name m_origRouter
Definition: lsa.hpp:155
NamePrefixList & getNpl()
Definition: lsa.hpp:179
const_iterator end() const
Definition: lsa.hpp:310
ndn::EventId getExpiringEventId() const
Definition: lsa.hpp:109
Lsa::Type getType() const override
Definition: lsa.hpp:249
Lsa::Type getType() const override
Definition: lsa.hpp:173
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:304
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:97
const ndn::Name & getOrigRouter() const
Definition: lsa.hpp:79
virtual ~Lsa()=default
uint32_t getLsSeqNo() const
Definition: lsa.hpp:73
uint32_t m_lsSeqNo
Definition: lsa.hpp:156
virtual Type getType() const
Definition: lsa.hpp:61
Lsa::Type getType() const override
Definition: lsa.hpp:346
virtual void writeLog() const =0
const AdjacencyList & getAdl() const
Definition: lsa.hpp:261
Lsa()
Definition: lsa.hpp:49
A neighbor reachable over a Face.
Definition: adjacent.hpp:38
void setExpiringEventId(const ndn::EventId leei)
Definition: lsa.hpp:103
void setCorTheta(std::vector< double > ct)
Definition: lsa.hpp:381
void removeName(const ndn::Name &name)
Definition: lsa.hpp:197
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:185
void setCorRadius(double cr)
Definition: lsa.hpp:369
const std::vector< double > getCorTheta() const
Definition: lsa.hpp:375
std::istream & operator>>(std::istream &is, Lsa::Type &type)
Definition: lsa.cpp:345
void setOrigRouter(const ndn::Name &org)
Definition: lsa.hpp:85
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:191
double getCorRadius() const
Definition: lsa.hpp:363
ndn::EventId m_expiringEventId
Definition: lsa.hpp:158
uint32_t getNoLink()
Definition: lsa.hpp:281