blob: a44a594c83cf87ebd92d887fe025b3b4fdaa2c5e [file] [log] [blame]
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -08001/* -*- 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
33namespace nlsr {
34
35/*!
36 \brief Data abstraction for Lsa
37 Lsa := LSA-TYPE TLV-LENGTH
38 Name
39 SequenceNumber
40 ExpirationTimePoint
41 */
42class Lsa
43{
44public:
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
62protected:
Ashlesh Gawande57a87172020-05-09 19:47:06 -070063 Lsa(const ndn::Name& originRouter, uint64_t seqNo,
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080064 ndn::time::system_clock::TimePoint expirationTimePoint);
65
66 Lsa() = default;
67
68public:
69 virtual
70 ~Lsa() = default;
71
72 virtual Type
Ashlesh Gawande57a87172020-05-09 19:47:06 -070073 getType() const = 0;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080074
75 void
76 setSeqNo(uint64_t seqNo)
77 {
78 m_seqNo = seqNo;
Ashlesh Gawande57a87172020-05-09 19:47:06 -070079 m_wire.reset();
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080080 }
81
82 uint64_t
83 getSeqNo() const
84 {
85 return m_seqNo;
86 }
87
88 const ndn::Name&
89 getOriginRouter() const
90 {
91 return m_originRouter;
92 }
93
Ashlesh Gawande57a87172020-05-09 19:47:06 -070094 ndn::Name
95 getOriginRouterCopy() const
96 {
97 return m_originRouter;
98 }
99
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800100 const ndn::time::system_clock::TimePoint&
101 getExpirationTimePoint() const
102 {
103 return m_expirationTimePoint;
104 }
105
106 void
107 setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
108 {
109 m_expirationTimePoint = lt;
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700110 m_wire.reset();
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800111 }
112
113 void
114 setExpiringEventId(ndn::scheduler::EventId eid)
115 {
116 m_expiringEventId = std::move(eid);
117 }
118
119 ndn::scheduler::EventId
120 getExpiringEventId() const
121 {
122 return m_expiringEventId;
123 }
124
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800125 /*! Get data common to all LSA types.
126 */
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700127 virtual std::string
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800128 toString() const;
129
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700130 virtual const ndn::Block&
131 wireEncode() const = 0;
132
133protected:
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800134 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
141PUBLIC_WITH_TESTS_ELSE_PROTECTED:
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
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700147 mutable ndn::Block m_wire;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800148};
149
150NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Lsa);
151
152std::ostream&
153operator<<(std::ostream& os, const Lsa::Type& type);
154
155std::istream&
156operator>>(std::istream& is, Lsa::Type& type);
157
158} // namespace nlsr
159
160#endif // NLSR_LSA_LSA_HPP