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