Loading...
Searching...
No Matches
coordinate-lsa.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2025, The University of Memphis,
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/>.
20 */
21
22#ifndef NLSR_LSA_COORDINATE_LSA_HPP
23#define NLSR_LSA_COORDINATE_LSA_HPP
24
25#include "lsa.hpp"
26#include "utility/numeric.hpp"
27
28#include <boost/operators.hpp>
29
30namespace nlsr {
31
49class CoordinateLsa : public Lsa, private boost::equality_comparable<CoordinateLsa>
50{
51public:
52 CoordinateLsa() = default;
53
54 CoordinateLsa(const ndn::Name& originRouter, uint64_t seqNo,
55 const ndn::time::system_clock::time_point& timepoint,
56 double radius, std::vector<double> angles);
57
58 explicit
59 CoordinateLsa(const ndn::Block& block);
60
62 getType() const override
63 {
64 return type();
65 }
66
67 static constexpr Lsa::Type
69 {
71 }
72
73 double
74 getRadius() const
75 {
76 return m_hyperbolicRadius;
77 }
78
79 void
80 setRadius(double cr)
81 {
82 m_wire.reset();
83 m_hyperbolicRadius = cr;
84 }
85
86 const std::vector<double>&
87 getTheta() const
88 {
89 return m_hyperbolicAngles;
90 }
91
92 void
93 setTheta(std::vector<double> ct)
94 {
95 m_wire.reset();
96 m_hyperbolicAngles = std::move(ct);
97 }
98
99 template<ndn::encoding::Tag TAG>
100 size_t
101 wireEncode(ndn::EncodingImpl<TAG>& block) const;
102
103 const ndn::Block&
104 wireEncode() const override;
105
106 void
107 wireDecode(const ndn::Block& wire);
108
109 std::tuple<bool, std::list<PrefixInfo>, std::list<PrefixInfo>>
110 update(const std::shared_ptr<Lsa>& lsa) override;
111
112private:
113 void
114 print(std::ostream& os) const override;
115
116private: // 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(),
128 }
129
130private:
131 double m_hyperbolicRadius = 0.0;
132 std::vector<double> m_hyperbolicAngles;
133};
134
136
137} // namespace nlsr
138
139#endif // NLSR_LSA_COORDINATE_LSA_HPP
Represents an LSA of hyperbolic coordinates of the origin router.
const ndn::Block & wireEncode() const override
void wireDecode(const ndn::Block &wire)
const std::vector< double > & getTheta() const
double getRadius() const
Lsa::Type getType() const override
void setTheta(std::vector< double > ct)
CoordinateLsa()=default
void setRadius(double cr)
friend bool operator==(const CoordinateLsa &lhs, const CoordinateLsa &rhs)
static constexpr Lsa::Type type()
Represents a Link State Announcement (LSA).
Definition lsa.hpp:48
ndn::Block m_wire
Definition lsa.hpp:144
bool diffInEpsilon(double lhs, double rhs)
Determine whether the difference between two numbers are within epsilon.
Definition numeric.hpp:36
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Adjacent)