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 | b875293 | 2024-01-07 15:18:46 +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_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 | |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 29 | #include <boost/operators.hpp> |
| 30 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 31 | namespace nlsr { |
| 32 | |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame^] | 33 | /** |
| 34 | * @brief Represents an LSA of adjacencies of the origin router in link-state mode. |
| 35 | * |
| 36 | * AdjLsa is encoded as: |
| 37 | * @code{.abnf} |
| 38 | * AdjLsa = ADJACENCY-LSA-TYPE TLV-LENGTH |
| 39 | * Lsa |
| 40 | * *Adjacency |
| 41 | * @endcode |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 42 | */ |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 43 | class AdjLsa : public Lsa, private boost::equality_comparable<AdjLsa> |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 44 | { |
| 45 | public: |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame^] | 46 | using const_iterator = AdjacencyList::const_iterator; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 47 | |
| 48 | AdjLsa() = default; |
| 49 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 50 | AdjLsa(const ndn::Name& originR, uint64_t seqNo, |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 51 | const ndn::time::system_clock::time_point& timepoint, AdjacencyList& adl); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 52 | |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame^] | 53 | explicit |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 54 | AdjLsa(const ndn::Block& block); |
| 55 | |
| 56 | Lsa::Type |
| 57 | getType() const override |
| 58 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 59 | return type(); |
| 60 | } |
| 61 | |
| 62 | static constexpr Lsa::Type |
| 63 | type() |
| 64 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 65 | return Lsa::Type::ADJACENCY; |
| 66 | } |
| 67 | |
| 68 | const AdjacencyList& |
| 69 | getAdl() const |
| 70 | { |
| 71 | return m_adl; |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | resetAdl() |
| 76 | { |
| 77 | m_wire.reset(); |
| 78 | m_adl.reset(); |
| 79 | } |
| 80 | |
| 81 | void |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 82 | addAdjacent(const Adjacent& adj) |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 83 | { |
| 84 | m_wire.reset(); |
| 85 | m_adl.insert(adj); |
| 86 | } |
| 87 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 88 | const_iterator |
| 89 | begin() const |
| 90 | { |
| 91 | return m_adl.begin(); |
| 92 | } |
| 93 | |
| 94 | const_iterator |
| 95 | end() const |
| 96 | { |
| 97 | return m_adl.end(); |
| 98 | } |
| 99 | |
| 100 | template<ndn::encoding::Tag TAG> |
| 101 | size_t |
| 102 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 103 | |
| 104 | const ndn::Block& |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 105 | wireEncode() const override; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 106 | |
| 107 | void |
| 108 | wireDecode(const ndn::Block& wire); |
| 109 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 110 | std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>> |
| 111 | update(const std::shared_ptr<Lsa>& lsa) override; |
| 112 | |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame^] | 113 | private: |
| 114 | void |
| 115 | print(std::ostream& os) const override; |
| 116 | |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 117 | private: // non-member operators |
| 118 | // NOTE: the following "hidden friend" operators are available via |
| 119 | // argument-dependent lookup only and must be defined inline. |
| 120 | // boost::equality_comparable provides != operator. |
| 121 | |
| 122 | friend bool |
| 123 | operator==(const AdjLsa& lhs, const AdjLsa& rhs) |
| 124 | { |
| 125 | return lhs.m_adl == rhs.m_adl; |
| 126 | } |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 127 | |
| 128 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 129 | AdjacencyList m_adl; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(AdjLsa); |
| 133 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 134 | } // namespace nlsr |
| 135 | |
| 136 | #endif // NLSR_LSA_ADJ_LSA_HPP |