Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 2 | /* |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2014-2024, The University of Memphis, |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 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 Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 20 | */ |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 21 | |
| 22 | #ifndef NLSR_LSA_NAME_LSA_HPP |
| 23 | #define NLSR_LSA_NAME_LSA_HPP |
| 24 | |
| 25 | #include "lsa.hpp" |
Junxiao Shi | 2037764 | 2023-08-24 23:55:40 +0000 | [diff] [blame] | 26 | #include "name-prefix-list.hpp" |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 27 | |
Junxiao Shi | 2ecb059 | 2023-08-14 11:35:05 +0000 | [diff] [blame] | 28 | #include <boost/operators.hpp> |
| 29 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 30 | namespace nlsr { |
| 31 | |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame^] | 32 | /** |
| 33 | * @brief Represents an LSA of name prefixes announced by the origin router. |
| 34 | * |
| 35 | * NameLsa is encoded as: |
| 36 | * @code{.abnf} |
| 37 | * NameLsa = NAME-LSA-TYPE TLV-LENGTH |
| 38 | * Lsa |
| 39 | * 1*Name |
| 40 | * @endcode |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 41 | */ |
Junxiao Shi | 2ecb059 | 2023-08-14 11:35:05 +0000 | [diff] [blame] | 42 | class NameLsa : public Lsa, private boost::equality_comparable<NameLsa> |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 43 | { |
| 44 | public: |
| 45 | NameLsa() = default; |
| 46 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 47 | NameLsa(const ndn::Name& originRouter, uint64_t seqNo, |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 48 | const ndn::time::system_clock::time_point& timepoint, |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 49 | const NamePrefixList& npl); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 50 | |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame^] | 51 | explicit |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 52 | NameLsa(const ndn::Block& block); |
| 53 | |
| 54 | Lsa::Type |
| 55 | getType() const override |
| 56 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 57 | return type(); |
| 58 | } |
| 59 | |
| 60 | static constexpr Lsa::Type |
| 61 | type() |
| 62 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 63 | return Lsa::Type::NAME; |
| 64 | } |
| 65 | |
| 66 | NamePrefixList& |
| 67 | getNpl() |
| 68 | { |
| 69 | return m_npl; |
| 70 | } |
| 71 | |
| 72 | const NamePrefixList& |
| 73 | getNpl() const |
| 74 | { |
| 75 | return m_npl; |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | addName(const ndn::Name& name) |
| 80 | { |
| 81 | m_wire.reset(); |
| 82 | m_npl.insert(name); |
| 83 | } |
| 84 | |
| 85 | void |
| 86 | removeName(const ndn::Name& name) |
| 87 | { |
| 88 | m_wire.reset(); |
Junxiao Shi | 52f1664 | 2023-08-15 00:18:35 +0000 | [diff] [blame] | 89 | m_npl.erase(name); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 92 | template<ndn::encoding::Tag TAG> |
| 93 | size_t |
| 94 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 95 | |
| 96 | const ndn::Block& |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 97 | wireEncode() const override; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 98 | |
| 99 | void |
| 100 | wireDecode(const ndn::Block& wire); |
| 101 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 102 | std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>> |
| 103 | update(const std::shared_ptr<Lsa>& lsa) override; |
| 104 | |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame^] | 105 | private: |
| 106 | void |
| 107 | print(std::ostream& os) const override; |
| 108 | |
Junxiao Shi | 2ecb059 | 2023-08-14 11:35:05 +0000 | [diff] [blame] | 109 | private: // non-member operators |
| 110 | // NOTE: the following "hidden friend" operators are available via |
| 111 | // argument-dependent lookup only and must be defined inline. |
| 112 | // boost::equality_comparable provides != operator. |
| 113 | |
| 114 | friend bool |
| 115 | operator==(const NameLsa& lhs, const NameLsa& rhs) |
| 116 | { |
| 117 | return lhs.m_npl == rhs.m_npl; |
| 118 | } |
| 119 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 120 | private: |
| 121 | NamePrefixList m_npl; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NameLsa); |
| 125 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 126 | } // namespace nlsr |
| 127 | |
| 128 | #endif // NLSR_LSA_NAME_LSA_HPP |