Loading...
Searching...
No Matches
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-2025, 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 "name-prefix-list.hpp"
28
29#include <ndn-cxx/util/scheduler.hpp>
30
31#include <list>
32
33
34namespace nlsr {
35
47class Lsa
48{
49public:
50 class Error : public ndn::tlv::Error
51 {
52 public:
53 using ndn::tlv::Error::Error;
54 };
55
56 enum class Type {
59 NAME,
60 BASE
61 };
62
63protected:
64 Lsa() = default;
65
66 Lsa(const ndn::Name& originRouter, uint64_t seqNo,
67 ndn::time::system_clock::time_point expirationTimePoint);
68
69 explicit
70 Lsa(const Lsa& lsa);
71
72public:
73 virtual
74 ~Lsa() = default;
75
76 virtual Type
77 getType() const = 0;
78
79 void
80 setSeqNo(uint64_t seqNo)
81 {
82 m_seqNo = seqNo;
83 m_wire.reset();
84 }
85
86 uint64_t
87 getSeqNo() const
88 {
89 return m_seqNo;
90 }
91
92 const ndn::Name&
94 {
95 return m_originRouter;
96 }
97
98 const ndn::time::system_clock::time_point&
100 {
102 }
103
104 void
105 setExpirationTimePoint(const ndn::time::system_clock::time_point& lt)
106 {
108 m_wire.reset();
109 }
110
111 void
112 setExpiringEventId(ndn::scheduler::EventId eid)
113 {
114 m_expiringEventId = eid;
115 }
116
117 virtual std::tuple<bool, std::list<PrefixInfo>, std::list<PrefixInfo>>
118 update(const std::shared_ptr<Lsa>& lsa) = 0;
119
120 virtual const ndn::Block&
121 wireEncode() const = 0;
122
123protected:
124 template<ndn::encoding::Tag TAG>
125 size_t
126 wireEncode(ndn::EncodingImpl<TAG>& block) const;
127
128 void
129 wireDecode(const ndn::Block& wire);
130
131private:
132 virtual void
133 print(std::ostream& os) const = 0;
134
135 friend std::ostream&
136 operator<<(std::ostream& os, const Lsa& lsa);
137
139 ndn::Name m_originRouter;
140 uint64_t m_seqNo = 0;
141 ndn::time::system_clock::time_point m_expirationTimePoint;
142 ndn::scheduler::ScopedEventId m_expiringEventId;
143
144 mutable ndn::Block m_wire;
145};
146
148
149std::ostream&
150operator<<(std::ostream& os, const Lsa::Type& type);
151
152std::istream&
153operator>>(std::istream& is, Lsa::Type& type);
154
155} // namespace nlsr
156
157#endif // NLSR_LSA_LSA_HPP
Represents a Link State Announcement (LSA).
Definition lsa.hpp:48
virtual Type getType() const =0
Lsa()=default
virtual ~Lsa()=default
void setExpiringEventId(ndn::scheduler::EventId eid)
Definition lsa.hpp:112
uint64_t getSeqNo() const
Definition lsa.hpp:87
virtual std::tuple< bool, std::list< PrefixInfo >, std::list< PrefixInfo > > update(const std::shared_ptr< Lsa > &lsa)=0
uint64_t m_seqNo
Definition lsa.hpp:140
ndn::time::system_clock::time_point m_expirationTimePoint
Definition lsa.hpp:141
void setExpirationTimePoint(const ndn::time::system_clock::time_point &lt)
Definition lsa.hpp:105
ndn::Block m_wire
Definition lsa.hpp:144
ndn::scheduler::ScopedEventId m_expiringEventId
Definition lsa.hpp:142
void setSeqNo(uint64_t seqNo)
Definition lsa.hpp:80
friend std::ostream & operator<<(std::ostream &os, const Lsa &lsa)
Definition lsa.cpp:101
const ndn::time::system_clock::time_point & getExpirationTimePoint() const
Definition lsa.hpp:99
void wireDecode(const ndn::Block &wire)
Definition lsa.cpp:65
virtual const ndn::Block & wireEncode() const =0
ndn::Name m_originRouter
Definition lsa.hpp:139
const ndn::Name & getOriginRouter() const
Definition lsa.hpp:93
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