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 <ndn-cxx/util/scheduler.hpp>
30 #include <ndn-cxx/util/time.hpp>
31 #include <boost/tokenizer.hpp>
32 
33 namespace nlsr {
34 
35 class Lsa
36 {
37 public:
38  enum class Type {
39  ADJACENCY,
40  COORDINATE,
41  NAME,
42  BASE,
43  MOCK
44  };
45 
46  virtual
47  ~Lsa() = default;
48 
49  virtual Type
50  getType() const
51  {
52  return Type::BASE;
53  }
54 
55  void
56  setLsSeqNo(uint32_t lsn)
57  {
58  m_lsSeqNo = lsn;
59  }
60 
61  uint32_t
62  getLsSeqNo() const
63  {
64  return m_lsSeqNo;
65  }
66 
67  const ndn::Name&
68  getOrigRouter() const
69  {
70  return m_origRouter;
71  }
72 
73  void
74  setOrigRouter(const ndn::Name& org)
75  {
76  m_origRouter = org;
77  }
78 
79  const ndn::time::system_clock::TimePoint&
81  {
82  return m_expirationTimePoint;
83  }
84 
85  void
86  setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
87  {
89  }
90 
91  void
92  setExpiringEventId(ndn::scheduler::EventId eid)
93  {
94  m_expiringEventId = std::move(eid);
95  }
96 
97  ndn::scheduler::EventId
99  {
100  return m_expiringEventId;
101  }
102 
105  virtual std::string
106  serialize() const = 0;
107 
112  const ndn::Name
113  getKey() const;
114 
120  virtual bool
121  deserialize(const std::string& content) noexcept = 0;
122 
123  virtual void
124  writeLog() const = 0;
125 
126 protected:
132  std::string
133  getData() const;
134 
137  std::string
138  toString() const;
139 
140  bool
141  deserializeCommon(boost::tokenizer<boost::char_separator<char>>::iterator& iterator);
142 
143 protected:
144  ndn::Name m_origRouter;
145  uint32_t m_lsSeqNo = 0;
146  ndn::time::system_clock::TimePoint m_expirationTimePoint;
147  ndn::scheduler::EventId m_expiringEventId;
148 };
149 
150 class NameLsa : public Lsa
151 {
152 public:
153  NameLsa() = default;
154 
155  NameLsa(const ndn::Name& origR, uint32_t lsn,
156  const ndn::time::system_clock::TimePoint& lt,
157  NamePrefixList& npl);
158 
159  Lsa::Type
160  getType() const override
161  {
162  return Lsa::Type::NAME;
163  }
164 
167  {
168  return m_npl;
169  }
170 
171  const NamePrefixList&
172  getNpl() const
173  {
174  return m_npl;
175  }
176 
177  void
178  addName(const ndn::Name& name)
179  {
180  m_npl.insert(name);
181  }
182 
183  void
184  removeName(const ndn::Name& name)
185  {
186  m_npl.remove(name);
187  }
188 
197  bool
198  deserialize(const std::string& content) noexcept override;
199 
200  bool
201  isEqualContent(const NameLsa& other) const;
202 
203  void
204  writeLog() const override;
205 
212  std::string
213  serialize() const override;
214 
215 private:
216  NamePrefixList m_npl;
217 
218  friend std::ostream&
219  operator<<(std::ostream& os, const NameLsa& lsa);
220 };
221 
222 class AdjLsa : public Lsa
223 {
224 public:
226 
227  AdjLsa() = default;
228 
229  AdjLsa(const ndn::Name& origR, uint32_t lsn,
230  const ndn::time::system_clock::TimePoint& lt,
231  uint32_t nl , AdjacencyList& adl);
232 
233  Lsa::Type
234  getType() const override
235  {
236  return Lsa::Type::ADJACENCY;
237  }
238 
241  {
242  return m_adl;
243  }
244 
245  const AdjacencyList&
246  getAdl() const
247  {
248  return m_adl;
249  }
250 
251  void
253  {
254  m_adl.insert(adj);
255  }
256 
262  bool
263  deserialize(const std::string& content) noexcept override;
264 
265  uint32_t
267  {
268  return m_noLink;
269  }
270 
271  bool
272  isEqualContent(const AdjLsa& alsa) const;
273 
274  void
275  writeLog() const override;
276 
277  const_iterator
278  begin() const
279  {
280  return m_adl.begin();
281  }
282 
283  const_iterator
284  end() const
285  {
286  return m_adl.end();
287  }
288 
296  std::string
297  serialize() const override;
298 
299 private:
300  uint32_t m_noLink;
301  AdjacencyList m_adl;
302 
303  friend std::ostream&
304  operator<<(std::ostream& os, const AdjLsa& lsa);
305 };
306 
307 class CoordinateLsa : public Lsa
308 {
309 public:
310  CoordinateLsa() = default;
311 
312  CoordinateLsa(const ndn::Name& origR, uint32_t lsn,
313  const ndn::time::system_clock::TimePoint& lt,
314  double r, std::vector<double> theta);
315 
316  Lsa::Type
317  getType() const override
318  {
319  return Lsa::Type::COORDINATE;
320  }
321 
330  bool
331  deserialize(const std::string& content) noexcept override;
332 
333  double
334  getCorRadius() const
335  {
336  return m_corRad;
337  }
338 
339  void
340  setCorRadius(double cr)
341  {
342  m_corRad = cr;
343  }
344 
345  const std::vector<double>
346  getCorTheta() const
347  {
348  return m_angles;
349  }
350 
351  void
352  setCorTheta(std::vector<double> ct)
353  {
354  m_angles = ct;
355  }
356 
357  bool
358  isEqualContent(const CoordinateLsa& clsa) const;
359 
360  void
361  writeLog() const override;
362 
368  std::string
369  serialize() const override;
370 
371 private:
372  double m_corRad = 0.0;
373  std::vector<double> m_angles;
374 
375  friend std::ostream&
376  operator<<(std::ostream& os, const CoordinateLsa& lsa);
377 };
378 
379 std::ostream&
380 operator<<(std::ostream& os, const AdjLsa& lsa);
381 
382 std::ostream&
383 operator<<(std::ostream& os, const CoordinateLsa& lsa);
384 
385 std::ostream&
386 operator<<(std::ostream& os, const NameLsa& lsa);
387 
388 std::ostream&
389 operator<<(std::ostream& os, const Lsa::Type& type);
390 
391 std::istream&
392 operator>>(std::istream& is, Lsa::Type& type);
393 
394 } // namespace nlsr
395 
396 namespace std {
397 std::string
398 to_string(const nlsr::Lsa::Type& type);
399 } // namespace std
400 
401 #endif // NLSR_LSA_HPP
ndn::time::system_clock::TimePoint m_expirationTimePoint
Definition: lsa.hpp:146
void addAdjacent(Adjacent adj)
Definition: lsa.hpp:252
std::string getData() const
Definition: lsa.cpp:41
AdjacencyList::const_iterator const_iterator
Definition: lsa.hpp:225
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition: adjacent.cpp:84
const ndn::time::system_clock::TimePoint & getExpirationTimePoint() const
Definition: lsa.hpp:80
AdjacencyList & getAdl()
Definition: lsa.hpp:240
void setLsSeqNo(uint32_t lsn)
Definition: lsa.hpp:56
ndn::Name m_origRouter
Definition: lsa.hpp:144
NamePrefixList & getNpl()
Definition: lsa.hpp:166
const_iterator end() const
Definition: lsa.hpp:284
Lsa::Type getType() const override
Definition: lsa.hpp:234
Lsa::Type getType() const override
Definition: lsa.hpp:160
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:278
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:86
const ndn::Name & getOrigRouter() const
Definition: lsa.hpp:68
virtual ~Lsa()=default
uint32_t getLsSeqNo() const
Definition: lsa.hpp:62
ndn::scheduler::EventId getExpiringEventId() const
Definition: lsa.hpp:98
uint32_t m_lsSeqNo
Definition: lsa.hpp:145
ndn::scheduler::EventId m_expiringEventId
Definition: lsa.hpp:147
virtual Type getType() const
Definition: lsa.hpp:50
Lsa::Type getType() const override
Definition: lsa.hpp:317
virtual void writeLog() const =0
const AdjacencyList & getAdl() const
Definition: lsa.hpp:246
A neighbor reachable over a Face.
Definition: adjacent.hpp:38
void setExpiringEventId(ndn::scheduler::EventId eid)
Definition: lsa.hpp:92
void setCorTheta(std::vector< double > ct)
Definition: lsa.hpp:352
void removeName(const ndn::Name &name)
Definition: lsa.hpp:184
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:172
void setCorRadius(double cr)
Definition: lsa.hpp:340
const std::vector< double > getCorTheta() const
Definition: lsa.hpp:346
std::istream & operator>>(std::istream &is, Lsa::Type &type)
Definition: lsa.cpp:325
void setOrigRouter(const ndn::Name &org)
Definition: lsa.hpp:74
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:178
double getCorRadius() const
Definition: lsa.hpp:334
uint32_t getNoLink()
Definition: lsa.hpp:266