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-2020, 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_LSA_HPP
23 #define NLSR_LSA_LSA_HPP
24 
25 #include "name-prefix-list.hpp"
26 #include "adjacent.hpp"
27 #include "adjacency-list.hpp"
28 #include "test-access-control.hpp"
29 
30 #include <ndn-cxx/util/scheduler.hpp>
31 #include <ndn-cxx/util/time.hpp>
32 
33 namespace nlsr {
34 
42 class Lsa
43 {
44 public:
45  class Error : public ndn::tlv::Error
46  {
47  public:
48  explicit
49  Error(const std::string& what)
50  : ndn::tlv::Error(what)
51  {
52  }
53  };
54 
55  enum class Type {
56  ADJACENCY,
57  COORDINATE,
58  NAME,
59  BASE
60  };
61 
62 protected:
63  Lsa(const ndn::Name& originRouter, uint64_t seqNo,
64  ndn::time::system_clock::TimePoint expirationTimePoint);
65 
66  Lsa() = default;
67 
68 public:
69  virtual
70  ~Lsa() = default;
71 
72  virtual Type
73  getType() const = 0;
74 
75  void
76  setSeqNo(uint64_t seqNo)
77  {
78  m_seqNo = seqNo;
79  m_wire.reset();
80  }
81 
82  uint64_t
83  getSeqNo() const
84  {
85  return m_seqNo;
86  }
87 
88  const ndn::Name&
90  {
91  return m_originRouter;
92  }
93 
94  ndn::Name
96  {
97  return m_originRouter;
98  }
99 
100  const ndn::time::system_clock::TimePoint&
102  {
103  return m_expirationTimePoint;
104  }
105 
106  void
107  setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
108  {
110  m_wire.reset();
111  }
112 
113  void
114  setExpiringEventId(ndn::scheduler::EventId eid)
115  {
116  m_expiringEventId = std::move(eid);
117  }
118 
119  ndn::scheduler::EventId
121  {
122  return m_expiringEventId;
123  }
124 
127  virtual std::string
128  toString() const;
129 
130  virtual const ndn::Block&
131  wireEncode() const = 0;
132 
133 protected:
134  template<ndn::encoding::Tag TAG>
135  size_t
136  wireEncode(ndn::EncodingImpl<TAG>& block) const;
137 
138  void
139  wireDecode(const ndn::Block& wire);
140 
142  ndn::Name m_originRouter;
143  uint64_t m_seqNo = 0;
144  ndn::time::system_clock::TimePoint m_expirationTimePoint;
145  ndn::scheduler::EventId m_expiringEventId;
146 
147  mutable ndn::Block m_wire;
148 };
149 
151 
152 std::ostream&
153 operator<<(std::ostream& os, const Lsa::Type& type);
154 
155 std::istream&
156 operator>>(std::istream& is, Lsa::Type& type);
157 
158 } // namespace nlsr
159 
160 #endif // NLSR_LSA_LSA_HPP
ndn::time::system_clock::TimePoint m_expirationTimePoint
Definition: lsa.hpp:144
Data abstraction for Lsa Lsa := LSA-TYPE TLV-LENGTH Name SequenceNumber ExpirationTimePoint.
Definition: lsa.hpp:42
Definition: tlv-nlsr.hpp:25
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition: adjacent.cpp:181
const ndn::time::system_clock::TimePoint & getExpirationTimePoint() const
Definition: lsa.hpp:101
void setSeqNo(uint64_t seqNo)
Definition: lsa.hpp:76
uint64_t getSeqNo() const
Definition: lsa.hpp:83
void setExpirationTimePoint(const ndn::time::system_clock::TimePoint &lt)
Definition: lsa.hpp:107
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Adjacent)
virtual ~Lsa()=default
ndn::Block m_wire
Definition: lsa.hpp:147
virtual Type getType() const =0
ndn::scheduler::EventId m_expiringEventId
Definition: lsa.hpp:145
ndn::Name m_originRouter
Definition: lsa.hpp:142
ndn::Name getOriginRouterCopy() const
Definition: lsa.hpp:95
virtual std::string toString() const
Definition: lsa.cpp:141
void setExpiringEventId(ndn::scheduler::EventId eid)
Definition: lsa.hpp:114
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
uint64_t m_seqNo
Definition: lsa.hpp:143
std::istream & operator>>(std::istream &is, Lsa::Type &type)
Definition: lsa.cpp:121
const ndn::Name & getOriginRouter() const
Definition: lsa.hpp:89
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED
ndn::scheduler::EventId getExpiringEventId() const
Definition: lsa.hpp:120
Error(const std::string &what)
Definition: lsa.hpp:49
virtual const ndn::Block & wireEncode() const =0
Lsa()=default
void wireDecode(const ndn::Block &wire)
Definition: lsa.cpp:62