blob: 5e9c8d5c9d7ee6c7819e802d5c0f8a52dc25f28f [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/*
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -08003 * 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/>.
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"
26
27namespace nlsr {
28
29/*!
30 \brief Data abstraction for NameLsa
31 NameLsa := NAME-LSA-TYPE TLV-LENGTH
32 Lsa
33 Name+
34 */
35class NameLsa : public Lsa
36{
37public:
38 NameLsa() = default;
39
Ashlesh Gawande57a87172020-05-09 19:47:06 -070040 NameLsa(const ndn::Name& originRouter, uint64_t seqNo,
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080041 const ndn::time::system_clock::TimePoint& timepoint,
Ashlesh Gawande57a87172020-05-09 19:47:06 -070042 const NamePrefixList& npl);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080043
44 NameLsa(const ndn::Block& block);
45
46 Lsa::Type
47 getType() const override
48 {
Ashlesh Gawande57a87172020-05-09 19:47:06 -070049 return type();
50 }
51
52 static constexpr Lsa::Type
53 type()
54 {
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080055 return Lsa::Type::NAME;
56 }
57
58 NamePrefixList&
59 getNpl()
60 {
61 return m_npl;
62 }
63
64 const NamePrefixList&
65 getNpl() const
66 {
67 return m_npl;
68 }
69
70 void
71 addName(const ndn::Name& name)
72 {
73 m_wire.reset();
74 m_npl.insert(name);
75 }
76
77 void
78 removeName(const ndn::Name& name)
79 {
80 m_wire.reset();
81 m_npl.remove(name);
82 }
83
84 bool
85 isEqualContent(const NameLsa& other) const;
86
87 template<ndn::encoding::Tag TAG>
88 size_t
89 wireEncode(ndn::EncodingImpl<TAG>& block) const;
90
91 const ndn::Block&
Ashlesh Gawande57a87172020-05-09 19:47:06 -070092 wireEncode() const override;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080093
94 void
95 wireDecode(const ndn::Block& wire);
96
Ashlesh Gawande57a87172020-05-09 19:47:06 -070097 std::string
98 toString() const override;
99
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800100private:
101 NamePrefixList m_npl;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800102};
103
104NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NameLsa);
105
106std::ostream&
107operator<<(std::ostream& os, const NameLsa& lsa);
108
109} // namespace nlsr
110
111#endif // NLSR_LSA_NAME_LSA_HPP