blob: 1bd438210e1995bb23569a49be594ad012f63fc7 [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:
63 Lsa(const ndn::Name& originRouter, uint32_t seqNo,
64 ndn::time::system_clock::TimePoint expirationTimePoint);
65
66 Lsa() = default;
67
68public:
69 virtual
70 ~Lsa() = default;
71
72 virtual Type
73 getType() const
74 {
75 return Type::BASE;
76 }
77
78 void
79 setSeqNo(uint64_t seqNo)
80 {
81 m_seqNo = seqNo;
82 m_baseWire.reset();
83 }
84
85 uint64_t
86 getSeqNo() const
87 {
88 return m_seqNo;
89 }
90
91 const ndn::Name&
92 getOriginRouter() const
93 {
94 return m_originRouter;
95 }
96
97 const ndn::time::system_clock::TimePoint&
98 getExpirationTimePoint() const
99 {
100 return m_expirationTimePoint;
101 }
102
103 void
104 setExpirationTimePoint(const ndn::time::system_clock::TimePoint& lt)
105 {
106 m_expirationTimePoint = lt;
107 m_baseWire.reset();
108 }
109
110 void
111 setExpiringEventId(ndn::scheduler::EventId eid)
112 {
113 m_expiringEventId = std::move(eid);
114 }
115
116 ndn::scheduler::EventId
117 getExpiringEventId() const
118 {
119 return m_expiringEventId;
120 }
121
122 /*! \brief Gets the key for this LSA.
123
124 Format is: \<router name\>/\<LSA type>\
125 */
126 ndn::Name
127 getKey() const;
128
129 /*! Get data common to all LSA types.
130 */
131 std::string
132 toString() const;
133
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
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
147 mutable ndn::Block m_baseWire;
148};
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