blob: cb85ac246a889d9c3c52ee637bac13e9c37ba05d [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_NAME_LSA_HPP
23#define NLSR_LSA_NAME_LSA_HPP
24
25#include "lsa.hpp"
Junxiao Shi20377642023-08-24 23:55:40 +000026#include "name-prefix-list.hpp"
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080027
28namespace nlsr {
29
30/*!
31 \brief Data abstraction for NameLsa
32 NameLsa := NAME-LSA-TYPE TLV-LENGTH
33 Lsa
34 Name+
35 */
36class NameLsa : public Lsa
37{
38public:
39 NameLsa() = default;
40
Ashlesh Gawande57a87172020-05-09 19:47:06 -070041 NameLsa(const ndn::Name& originRouter, uint64_t seqNo,
Davide Pesavento658fd852023-05-10 22:15:03 -040042 const ndn::time::system_clock::time_point& timepoint,
Ashlesh Gawande57a87172020-05-09 19:47:06 -070043 const NamePrefixList& npl);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080044
45 NameLsa(const ndn::Block& block);
46
47 Lsa::Type
48 getType() const override
49 {
Ashlesh Gawande57a87172020-05-09 19:47:06 -070050 return type();
51 }
52
53 static constexpr Lsa::Type
54 type()
55 {
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080056 return Lsa::Type::NAME;
57 }
58
59 NamePrefixList&
60 getNpl()
61 {
62 return m_npl;
63 }
64
65 const NamePrefixList&
66 getNpl() const
67 {
68 return m_npl;
69 }
70
71 void
72 addName(const ndn::Name& name)
73 {
74 m_wire.reset();
75 m_npl.insert(name);
76 }
77
78 void
79 removeName(const ndn::Name& name)
80 {
81 m_wire.reset();
Junxiao Shi52f16642023-08-15 00:18:35 +000082 m_npl.erase(name);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080083 }
84
85 bool
86 isEqualContent(const NameLsa& other) const;
87
88 template<ndn::encoding::Tag TAG>
89 size_t
90 wireEncode(ndn::EncodingImpl<TAG>& block) const;
91
92 const ndn::Block&
Ashlesh Gawande57a87172020-05-09 19:47:06 -070093 wireEncode() const override;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080094
95 void
96 wireDecode(const ndn::Block& wire);
97
Ashlesh Gawande57a87172020-05-09 19:47:06 -070098 std::string
99 toString() const override;
100
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700101 std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>>
102 update(const std::shared_ptr<Lsa>& lsa) override;
103
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800104private:
105 NamePrefixList m_npl;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800106};
107
108NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NameLsa);
109
110std::ostream&
111operator<<(std::ostream& os, const NameLsa& lsa);
112
113} // namespace nlsr
114
115#endif // NLSR_LSA_NAME_LSA_HPP