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-2024, 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 "common.hpp"
26 #include "test-access-control.hpp"
27 
28 #include <ndn-cxx/util/scheduler.hpp>
29 
30 #include <list>
31 
32 namespace nlsr {
33 
45 class Lsa
46 {
47 public:
48  class Error : public ndn::tlv::Error
49  {
50  public:
51  using ndn::tlv::Error::Error;
52  };
53 
54  enum class Type {
55  ADJACENCY,
56  COORDINATE,
57  NAME,
58  BASE
59  };
60 
61 protected:
62  Lsa() = default;
63 
64  Lsa(const ndn::Name& originRouter, uint64_t seqNo,
65  ndn::time::system_clock::time_point expirationTimePoint);
66 
67  explicit
68  Lsa(const Lsa& lsa);
69 
70 public:
71  virtual
72  ~Lsa() = default;
73 
74  virtual Type
75  getType() const = 0;
76 
77  void
78  setSeqNo(uint64_t seqNo)
79  {
80  m_seqNo = seqNo;
81  m_wire.reset();
82  }
83 
84  uint64_t
85  getSeqNo() const
86  {
87  return m_seqNo;
88  }
89 
90  const ndn::Name&
92  {
93  return m_originRouter;
94  }
95 
96  const ndn::time::system_clock::time_point&
98  {
99  return m_expirationTimePoint;
100  }
101 
102  void
103  setExpirationTimePoint(const ndn::time::system_clock::time_point& lt)
104  {
106  m_wire.reset();
107  }
108 
109  void
110  setExpiringEventId(ndn::scheduler::EventId eid)
111  {
112  m_expiringEventId = eid;
113  }
114 
115  virtual std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>>
116  update(const std::shared_ptr<Lsa>& lsa) = 0;
117 
118  virtual const ndn::Block&
119  wireEncode() const = 0;
120 
121 protected:
122  template<ndn::encoding::Tag TAG>
123  size_t
124  wireEncode(ndn::EncodingImpl<TAG>& block) const;
125 
126  void
127  wireDecode(const ndn::Block& wire);
128 
129 private:
130  virtual void
131  print(std::ostream& os) const = 0;
132 
133  friend std::ostream&
134  operator<<(std::ostream& os, const Lsa& lsa);
135 
137  ndn::Name m_originRouter;
138  uint64_t m_seqNo = 0;
139  ndn::time::system_clock::time_point m_expirationTimePoint;
140  ndn::scheduler::ScopedEventId 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
Represents a Link State Announcement (LSA).
Definition: lsa.hpp:46
virtual const ndn::Block & wireEncode() const =0
const ndn::Name & getOriginRouter() const
Definition: lsa.hpp:91
friend std::ostream & operator<<(std::ostream &os, const Lsa &lsa)
Definition: lsa.cpp:101
virtual Type getType() const =0
Lsa()=default
virtual ~Lsa()=default
void setExpiringEventId(ndn::scheduler::EventId eid)
Definition: lsa.hpp:110
uint64_t getSeqNo() const
Definition: lsa.hpp:85
uint64_t m_seqNo
Definition: lsa.hpp:138
ndn::time::system_clock::time_point m_expirationTimePoint
Definition: lsa.hpp:139
virtual std::tuple< bool, std::list< ndn::Name >, std::list< ndn::Name > > update(const std::shared_ptr< Lsa > &lsa)=0
void setExpirationTimePoint(const ndn::time::system_clock::time_point &lt)
Definition: lsa.hpp:103
ndn::Block m_wire
Definition: lsa.hpp:142
ndn::scheduler::ScopedEventId m_expiringEventId
Definition: lsa.hpp:140
void setSeqNo(uint64_t seqNo)
Definition: lsa.hpp:78
void wireDecode(const ndn::Block &wire)
Definition: lsa.cpp:65
ndn::Name m_originRouter
Definition: lsa.hpp:137
const ndn::time::system_clock::time_point & getExpirationTimePoint() const
Definition: lsa.hpp:97
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:134
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition: adjacent.cpp:176
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED