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