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_ADJ_LSA_HPP |
| 23 | #define NLSR_LSA_ADJ_LSA_HPP |
| 24 | |
| 25 | #include "lsa.hpp" |
Junxiao Shi | 2037764 | 2023-08-24 23:55:40 +0000 | [diff] [blame^] | 26 | #include "adjacent.hpp" |
| 27 | #include "adjacency-list.hpp" |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 28 | |
| 29 | namespace nlsr { |
| 30 | |
| 31 | /*! |
| 32 | \brief Data abstraction for AdjLsa |
| 33 | AdjacencyLsa := ADJACENCY-LSA-TYPE TLV-LENGTH |
| 34 | Lsa |
| 35 | Adjacency* |
| 36 | |
| 37 | */ |
| 38 | class AdjLsa : public Lsa |
| 39 | { |
| 40 | public: |
| 41 | typedef AdjacencyList::const_iterator const_iterator; |
| 42 | |
| 43 | AdjLsa() = default; |
| 44 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 45 | AdjLsa(const ndn::Name& originR, uint64_t seqNo, |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 46 | const ndn::time::system_clock::time_point& timepoint, |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 47 | uint32_t noLink, AdjacencyList& adl); |
| 48 | |
| 49 | AdjLsa(const ndn::Block& block); |
| 50 | |
| 51 | Lsa::Type |
| 52 | getType() const override |
| 53 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 54 | return type(); |
| 55 | } |
| 56 | |
| 57 | static constexpr Lsa::Type |
| 58 | type() |
| 59 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 60 | return Lsa::Type::ADJACENCY; |
| 61 | } |
| 62 | |
| 63 | const AdjacencyList& |
| 64 | getAdl() const |
| 65 | { |
| 66 | return m_adl; |
| 67 | } |
| 68 | |
| 69 | void |
| 70 | resetAdl() |
| 71 | { |
| 72 | m_wire.reset(); |
| 73 | m_adl.reset(); |
| 74 | } |
| 75 | |
| 76 | void |
| 77 | addAdjacent(Adjacent adj) |
| 78 | { |
| 79 | m_wire.reset(); |
| 80 | m_adl.insert(adj); |
| 81 | } |
| 82 | |
| 83 | uint32_t |
| 84 | getNoLink() |
| 85 | { |
| 86 | return m_noLink; |
| 87 | } |
| 88 | |
| 89 | bool |
| 90 | isEqualContent(const AdjLsa& alsa) const; |
| 91 | |
| 92 | const_iterator |
| 93 | begin() const |
| 94 | { |
| 95 | return m_adl.begin(); |
| 96 | } |
| 97 | |
| 98 | const_iterator |
| 99 | end() const |
| 100 | { |
| 101 | return m_adl.end(); |
| 102 | } |
| 103 | |
| 104 | template<ndn::encoding::Tag TAG> |
| 105 | size_t |
| 106 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 107 | |
| 108 | const ndn::Block& |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 109 | wireEncode() const override; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 110 | |
| 111 | void |
| 112 | wireDecode(const ndn::Block& wire); |
| 113 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 114 | std::string |
| 115 | toString() const override; |
| 116 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 117 | std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>> |
| 118 | update(const std::shared_ptr<Lsa>& lsa) override; |
| 119 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 120 | private: |
| 121 | uint32_t m_noLink; |
| 122 | |
| 123 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 124 | AdjacencyList m_adl; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(AdjLsa); |
| 128 | |
| 129 | std::ostream& |
| 130 | operator<<(std::ostream& os, const AdjLsa& lsa); |
| 131 | |
| 132 | } // namespace nlsr |
| 133 | |
| 134 | #endif // NLSR_LSA_ADJ_LSA_HPP |