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 | b573484 | 2024-01-09 21:14:53 +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_COORDINATE_LSA_HPP |
| 23 | #define NLSR_LSA_COORDINATE_LSA_HPP |
| 24 | |
| 25 | #include "lsa.hpp" |
Junxiao Shi | b573484 | 2024-01-09 21:14:53 +0000 | [diff] [blame] | 26 | #include "utility/numeric.hpp" |
| 27 | |
| 28 | #include <boost/operators.hpp> |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 29 | |
| 30 | namespace nlsr { |
| 31 | |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame] | 32 | /** |
| 33 | * @brief Represents an LSA of hyperbolic coordinates of the origin router. |
| 34 | * |
| 35 | * CoordinateLsa is encoded as: |
| 36 | * @code{.abnf} |
| 37 | * CoordinateLsa = COORDINATE-LSA-TYPE TLV-LENGTH |
| 38 | * Lsa |
| 39 | * HyperbolicRadius |
| 40 | * 1*HyperbolicAngle ; theta |
| 41 | * |
| 42 | * HyperbolicRadius = HYPERBOLIC-RADIUS-TYPE TLV-LENGTH |
| 43 | * Double ; IEEE754 double precision |
| 44 | * |
| 45 | * HyperbolicAngle = HYPERBOLIC-ANGLE-TYPE TLV-LENGTH |
| 46 | * Double ; IEEE754 double precision |
| 47 | * @endcode |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 48 | */ |
Junxiao Shi | b573484 | 2024-01-09 21:14:53 +0000 | [diff] [blame] | 49 | class CoordinateLsa : public Lsa, private boost::equality_comparable<CoordinateLsa> |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 50 | { |
| 51 | public: |
| 52 | CoordinateLsa() = default; |
| 53 | |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 54 | CoordinateLsa(const ndn::Name& originRouter, uint64_t seqNo, |
Davide Pesavento | 658fd85 | 2023-05-10 22:15:03 -0400 | [diff] [blame] | 55 | const ndn::time::system_clock::time_point& timepoint, |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 56 | double radius, std::vector<double> angles); |
| 57 | |
Junxiao Shi | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame] | 58 | explicit |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 59 | CoordinateLsa(const ndn::Block& block); |
| 60 | |
| 61 | Lsa::Type |
| 62 | getType() const override |
| 63 | { |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 64 | return type(); |
| 65 | } |
| 66 | |
| 67 | static constexpr Lsa::Type |
| 68 | type() |
| 69 | { |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 70 | return Lsa::Type::COORDINATE; |
| 71 | } |
| 72 | |
| 73 | double |
Junxiao Shi | b573484 | 2024-01-09 21:14:53 +0000 | [diff] [blame] | 74 | getRadius() const |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 75 | { |
| 76 | return m_hyperbolicRadius; |
| 77 | } |
| 78 | |
| 79 | void |
Junxiao Shi | b573484 | 2024-01-09 21:14:53 +0000 | [diff] [blame] | 80 | setRadius(double cr) |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 81 | { |
| 82 | m_wire.reset(); |
| 83 | m_hyperbolicRadius = cr; |
| 84 | } |
| 85 | |
Junxiao Shi | b573484 | 2024-01-09 21:14:53 +0000 | [diff] [blame] | 86 | const std::vector<double>& |
| 87 | getTheta() const |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 88 | { |
| 89 | return m_hyperbolicAngles; |
| 90 | } |
| 91 | |
| 92 | void |
Junxiao Shi | b573484 | 2024-01-09 21:14:53 +0000 | [diff] [blame] | 93 | setTheta(std::vector<double> ct) |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 94 | { |
| 95 | m_wire.reset(); |
Junxiao Shi | b573484 | 2024-01-09 21:14:53 +0000 | [diff] [blame] | 96 | m_hyperbolicAngles = std::move(ct); |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 99 | template<ndn::encoding::Tag TAG> |
| 100 | size_t |
| 101 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 102 | |
| 103 | const ndn::Block& |
Ashlesh Gawande | 57a8717 | 2020-05-09 19:47:06 -0700 | [diff] [blame] | 104 | wireEncode() const override; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 105 | |
| 106 | void |
| 107 | wireDecode(const ndn::Block& wire); |
| 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 | 153fbc1 | 2024-01-09 23:37:23 +0000 | [diff] [blame] | 112 | private: |
| 113 | void |
| 114 | print(std::ostream& os) const override; |
| 115 | |
Junxiao Shi | b573484 | 2024-01-09 21:14:53 +0000 | [diff] [blame] | 116 | private: // non-member operators |
| 117 | // NOTE: the following "hidden friend" operators are available via |
| 118 | // argument-dependent lookup only and must be defined inline. |
| 119 | // boost::equality_comparable provides != operator. |
| 120 | |
| 121 | friend bool |
| 122 | operator==(const CoordinateLsa& lhs, const CoordinateLsa& rhs) |
| 123 | { |
| 124 | return util::diffInEpsilon(lhs.m_hyperbolicRadius, rhs.m_hyperbolicRadius) && |
| 125 | std::equal(lhs.m_hyperbolicAngles.begin(), lhs.m_hyperbolicAngles.end(), |
| 126 | rhs.m_hyperbolicAngles.begin(), rhs.m_hyperbolicAngles.end(), |
| 127 | util::diffInEpsilon); |
| 128 | } |
| 129 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 130 | private: |
| 131 | double m_hyperbolicRadius = 0.0; |
| 132 | std::vector<double> m_hyperbolicAngles; |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(CoordinateLsa); |
| 136 | |
Ashlesh Gawande | 0db4d4d | 2020-02-05 20:30:02 -0800 | [diff] [blame] | 137 | } // namespace nlsr |
| 138 | |
| 139 | #endif // NLSR_LSA_COORDINATE_LSA_HPP |