blob: c9e3904b89bfdc196d26eb331ff97609c94011cc [file] [log] [blame]
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande57a87172020-05-09 19:47:06 -07002/*
Junxiao Shib5734842024-01-09 21:14:53 +00003 * Copyright (c) 2014-2024, The University of Memphis,
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -08004 * 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 Gawande57a87172020-05-09 19:47:06 -070020 */
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080021
22#ifndef NLSR_LSA_COORDINATE_LSA_HPP
23#define NLSR_LSA_COORDINATE_LSA_HPP
24
25#include "lsa.hpp"
Junxiao Shib5734842024-01-09 21:14:53 +000026#include "utility/numeric.hpp"
27
28#include <boost/operators.hpp>
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080029
30namespace nlsr {
31
32/*!
33 \brief Data abstraction for CoordinateLsa
34 CoordinateLsa := COORDINATE-LSA-TYPE TLV-LENGTH
35 Lsa
36 HyperbolicRadius
37 HyperbolicAngle+
38 */
Junxiao Shib5734842024-01-09 21:14:53 +000039class CoordinateLsa : public Lsa, private boost::equality_comparable<CoordinateLsa>
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080040{
41public:
42 CoordinateLsa() = default;
43
Ashlesh Gawande57a87172020-05-09 19:47:06 -070044 CoordinateLsa(const ndn::Name& originRouter, uint64_t seqNo,
Davide Pesavento658fd852023-05-10 22:15:03 -040045 const ndn::time::system_clock::time_point& timepoint,
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080046 double radius, std::vector<double> angles);
47
48 CoordinateLsa(const ndn::Block& block);
49
50 Lsa::Type
51 getType() const override
52 {
Ashlesh Gawande57a87172020-05-09 19:47:06 -070053 return type();
54 }
55
56 static constexpr Lsa::Type
57 type()
58 {
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080059 return Lsa::Type::COORDINATE;
60 }
61
62 double
Junxiao Shib5734842024-01-09 21:14:53 +000063 getRadius() const
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080064 {
65 return m_hyperbolicRadius;
66 }
67
68 void
Junxiao Shib5734842024-01-09 21:14:53 +000069 setRadius(double cr)
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080070 {
71 m_wire.reset();
72 m_hyperbolicRadius = cr;
73 }
74
Junxiao Shib5734842024-01-09 21:14:53 +000075 const std::vector<double>&
76 getTheta() const
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080077 {
78 return m_hyperbolicAngles;
79 }
80
81 void
Junxiao Shib5734842024-01-09 21:14:53 +000082 setTheta(std::vector<double> ct)
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080083 {
84 m_wire.reset();
Junxiao Shib5734842024-01-09 21:14:53 +000085 m_hyperbolicAngles = std::move(ct);
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080086 }
87
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080088 template<ndn::encoding::Tag TAG>
89 size_t
90 wireEncode(ndn::EncodingImpl<TAG>& block) const;
91
92 const ndn::Block&
Ashlesh Gawande57a87172020-05-09 19:47:06 -070093 wireEncode() const override;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -080094
95 void
96 wireDecode(const ndn::Block& wire);
97
Ashlesh Gawande57a87172020-05-09 19:47:06 -070098 std::string
99 toString() const override;
100
Ashlesh Gawande5d93aa52020-06-13 18:57:45 -0700101 std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>>
102 update(const std::shared_ptr<Lsa>& lsa) override;
103
Junxiao Shib5734842024-01-09 21:14:53 +0000104private: // non-member operators
105 // NOTE: the following "hidden friend" operators are available via
106 // argument-dependent lookup only and must be defined inline.
107 // boost::equality_comparable provides != operator.
108
109 friend bool
110 operator==(const CoordinateLsa& lhs, const CoordinateLsa& rhs)
111 {
112 return util::diffInEpsilon(lhs.m_hyperbolicRadius, rhs.m_hyperbolicRadius) &&
113 std::equal(lhs.m_hyperbolicAngles.begin(), lhs.m_hyperbolicAngles.end(),
114 rhs.m_hyperbolicAngles.begin(), rhs.m_hyperbolicAngles.end(),
115 util::diffInEpsilon);
116 }
117
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800118private:
119 double m_hyperbolicRadius = 0.0;
120 std::vector<double> m_hyperbolicAngles;
Ashlesh Gawande0db4d4d2020-02-05 20:30:02 -0800121};
122
123NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(CoordinateLsa);
124
125std::ostream&
126operator<<(std::ostream& os, const CoordinateLsa& lsa);
127
128} // namespace nlsr
129
130#endif // NLSR_LSA_COORDINATE_LSA_HPP