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 | |
| 33 | /*! |
| 34 | \brief Data abstraction for AdjLsa |
| 35 | AdjacencyLsa := ADJACENCY-LSA-TYPE TLV-LENGTH |
| 36 | Lsa |
| 37 | Adjacency* |
| 38 | |
| 39 | */ |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 40 | class AdjLsa : public Lsa, private boost::equality_comparable<AdjLsa> |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 41 | { |
| 42 | public: |
| 43 | typedef AdjacencyList::const_iterator const_iterator; |
| 44 | |
| 45 | AdjLsa() = default; |
| 46 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 47 | AdjLsa(const ndn::Name& originR, uint64_t seqNo, |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 48 | const ndn::time::system_clock::time_point& timepoint, AdjacencyList& adl); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 49 | |
| 50 | AdjLsa(const ndn::Block& block); |
| 51 | |
| 52 | Lsa::Type |
| 53 | getType() const override |
| 54 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 55 | return type(); |
| 56 | } |
| 57 | |
| 58 | static constexpr Lsa::Type |
| 59 | type() |
| 60 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 61 | return Lsa::Type::ADJACENCY; |
| 62 | } |
| 63 | |
| 64 | const AdjacencyList& |
| 65 | getAdl() const |
| 66 | { |
| 67 | return m_adl; |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | resetAdl() |
| 72 | { |
| 73 | m_wire.reset(); |
| 74 | m_adl.reset(); |
| 75 | } |
| 76 | |
| 77 | void |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 78 | addAdjacent(const Adjacent& adj) |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 79 | { |
| 80 | m_wire.reset(); |
| 81 | m_adl.insert(adj); |
| 82 | } |
| 83 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 84 | const_iterator |
| 85 | begin() const |
| 86 | { |
| 87 | return m_adl.begin(); |
| 88 | } |
| 89 | |
| 90 | const_iterator |
| 91 | end() const |
| 92 | { |
| 93 | return m_adl.end(); |
| 94 | } |
| 95 | |
| 96 | template<ndn::encoding::Tag TAG> |
| 97 | size_t |
| 98 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 99 | |
| 100 | const ndn::Block& |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 101 | wireEncode() const override; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 102 | |
| 103 | void |
| 104 | wireDecode(const ndn::Block& wire); |
| 105 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 106 | std::string |
| 107 | toString() const override; |
| 108 | |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame] | 109 | std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>> |
| 110 | update(const std::shared_ptr<Lsa>& lsa) override; |
| 111 | |
Junxiao Shi | b875293 | 2024-01-07 15:18:46 +0000 | [diff] [blame] | 112 | private: // non-member operators |
| 113 | // NOTE: the following "hidden friend" operators are available via |
| 114 | // argument-dependent lookup only and must be defined inline. |
| 115 | // boost::equality_comparable provides != operator. |
| 116 | |
| 117 | friend bool |
| 118 | operator==(const AdjLsa& lhs, const AdjLsa& rhs) |
| 119 | { |
| 120 | return lhs.m_adl == rhs.m_adl; |
| 121 | } |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 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 |