blob: 0c784b939d55d07ab1ad98a2a3454b3995890ffe [file] [log] [blame]
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande57a87172020-05-09 19:47:06 -07002/*
Davide Pesavento658fd852023-05-10 22:15:03 -04003 * Copyright (c) 2014-2023, The University of Memphis,
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -08004 * 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/>.
Ashlesh Gawande57a87172020-05-09 19:47:06 -070020 */
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080021
22#ifndef NLSR_LSA_ADJ_LSA_HPP
23#define NLSR_LSA_ADJ_LSA_HPP
24
25#include "lsa.hpp"
26#include "test-access-control.hpp"
27
28namespace nlsr {
29
30/*!
31 \brief Data abstraction for AdjLsa
32 AdjacencyLsa := ADJACENCY-LSA-TYPE TLV-LENGTH
33 Lsa
34 Adjacency*
35
36 */
37class AdjLsa : public Lsa
38{
39public:
40 typedef AdjacencyList::const_iterator const_iterator;
41
42 AdjLsa() = default;
43
Ashlesh Gawande57a87172020-05-09 19:47:06 -070044 AdjLsa(const ndn::Name& originR, uint64_t seqNo,
Davide Pesavento658fd852023-05-10 22:15:03 -040045 const ndn::time::system_clock::time_point& timepoint,
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080046 uint32_t noLink, AdjacencyList& adl);
47
48 AdjLsa(const ndn::Block& block);
49
50 Lsa::Type
51 getType() const override
52 {
Ashlesh Gawande57a87172020-05-09 19:47:06 -070053 return type();
54 }
55
56 static constexpr Lsa::Type
57 type()
58 {
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080059 return Lsa::Type::ADJACENCY;
60 }
61
62 const AdjacencyList&
63 getAdl() const
64 {
65 return m_adl;
66 }
67
68 void
69 resetAdl()
70 {
71 m_wire.reset();
72 m_adl.reset();
73 }
74
75 void
76 addAdjacent(Adjacent adj)
77 {
78 m_wire.reset();
79 m_adl.insert(adj);
80 }
81
82 uint32_t
83 getNoLink()
84 {
85 return m_noLink;
86 }
87
88 bool
89 isEqualContent(const AdjLsa& alsa) const;
90
91 const_iterator
92 begin() const
93 {
94 return m_adl.begin();
95 }
96
97 const_iterator
98 end() const
99 {
100 return m_adl.end();
101 }
102
103 template<ndn::encoding::Tag TAG>
104 size_t
105 wireEncode(ndn::EncodingImpl<TAG>& block) const;
106
107 const ndn::Block&
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700108 wireEncode() const override;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800109
110 void
111 wireDecode(const ndn::Block& wire);
112
Ashlesh Gawande57a87172020-05-09 19:47:06 -0700113 std::string
114 toString() const override;
115
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700116 std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>>
117 update(const std::shared_ptr<Lsa>& lsa) override;
118
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800119private:
120 uint32_t m_noLink;
121
122PUBLIC_WITH_TESTS_ELSE_PRIVATE:
123 AdjacencyList m_adl;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800124};
125
126NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(AdjLsa);
127
128std::ostream&
129operator<<(std::ostream& os, const AdjLsa& lsa);
130
131} // namespace nlsr
132
133#endif // NLSR_LSA_ADJ_LSA_HPP