Loading...
Searching...
No Matches
adjacent.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2022, 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_ADJACENT_HPP
23#define NLSR_ADJACENT_HPP
24
25#include <cmath>
26#include <string>
27
28#include <ndn-cxx/face.hpp>
29#include <ndn-cxx/net/face-uri.hpp>
30
31namespace nlsr {
32
47{
48public:
49 class Error : public ndn::tlv::Error
50 {
51 public:
52 using ndn::tlv::Error::Error;
53 };
54
61
62 Adjacent();
63
64 Adjacent(const ndn::Block& block);
65
66 Adjacent(const ndn::Name& an);
67
68 Adjacent(const ndn::Name& an, const ndn::FaceUri& faceUri, double lc,
69 Status s, uint32_t iton, uint64_t faceId);
70
71 const ndn::Name&
72 getName() const
73 {
74 return m_name;
75 }
76
77 void
78 setName(const ndn::Name& name)
79 {
80 m_wire.reset();
81 m_name = name;
82 }
83
84 const ndn::FaceUri&
85 getFaceUri() const
86 {
87 return m_faceUri;
88 }
89
90 void
91 setFaceUri(const ndn::FaceUri& faceUri)
92 {
93 m_wire.reset();
94 m_faceUri = faceUri;
95 }
96
97 double
99 {
100 return ceil(m_linkCost);
101 }
102
103 void
104 setLinkCost(double lc);
105
106 Status
107 getStatus() const
108 {
109 return m_status;
110 }
111
112 void
114 {
115 m_wire.reset();
116 m_status = s;
117 }
118
119 uint32_t
121 {
122 return m_interestTimedOutNo;
123 }
124
125 void
127 {
128 m_wire.reset();
129 m_interestTimedOutNo = iton;
130 }
131
132 void
133 setFaceId(uint64_t faceId)
134 {
135 m_faceId = faceId;
136 }
137
138 uint64_t
139 getFaceId() const
140 {
141 return m_faceId;
142 }
143
145 bool
146 operator==(const Adjacent& adjacent) const;
147
148 bool
149 operator!=(const Adjacent& adjacent) const
150 {
151 return !(*this == adjacent);
152 }
153
154 bool
155 operator<(const Adjacent& adjacent) const;
156
157 inline bool
158 compare(const ndn::Name& adjacencyName) const
159 {
160 return m_name == adjacencyName;
161 }
162
163 inline bool
164 compareFaceId(const uint64_t faceId) const
165 {
166 return m_faceId == faceId;
167 }
168
169 inline bool
170 compareFaceUri(const ndn::FaceUri& faceUri) const
171 {
172 return m_faceUri == faceUri;
173 }
174
175 template<ndn::encoding::Tag TAG>
176 size_t
177 wireEncode(ndn::EncodingImpl<TAG>& block) const;
178
179 const ndn::Block&
180 wireEncode() const;
181
182 void
183 wireDecode(const ndn::Block& wire);
184
185public:
186 static constexpr double DEFAULT_LINK_COST = 10.0;
187 static constexpr double NON_ADJACENT_COST = -12345.0;
188
189private:
191 ndn::Name m_name;
193 ndn::FaceUri m_faceUri;
195 double m_linkCost;
197 Status m_status = STATUS_UNKNOWN;
199 uint32_t m_interestTimedOutNo = 0;
202 uint64_t m_faceId;
203
204 mutable ndn::Block m_wire;
205
206 friend std::ostream&
207 operator<<(std::ostream& os, const Adjacent& adjacent);
208};
209
211
212std::ostream&
213operator<<(std::ostream& os, const Adjacent& adjacent);
214
215} // namespace nlsr
216
217#endif // NLSR_ADJACENT_HPP
A neighbor reachable over a Face.
Definition adjacent.hpp:47
static constexpr double NON_ADJACENT_COST
Definition adjacent.hpp:187
friend std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition adjacent.cpp:176
static constexpr double DEFAULT_LINK_COST
Definition adjacent.hpp:186
uint32_t getInterestTimedOutNo() const
Definition adjacent.hpp:120
void setStatus(Status s)
Definition adjacent.hpp:113
bool compareFaceUri(const ndn::FaceUri &faceUri) const
Definition adjacent.hpp:170
bool operator!=(const Adjacent &adjacent) const
Definition adjacent.hpp:149
void setFaceId(uint64_t faceId)
Definition adjacent.hpp:133
void setFaceUri(const ndn::FaceUri &faceUri)
Definition adjacent.hpp:91
void wireDecode(const ndn::Block &wire)
Definition adjacent.cpp:118
bool operator<(const Adjacent &adjacent) const
Definition adjacent.cpp:168
bool compare(const ndn::Name &adjacencyName) const
Definition adjacent.hpp:158
void setLinkCost(double lc)
Definition adjacent.cpp:67
const ndn::FaceUri & getFaceUri() const
Definition adjacent.hpp:85
const ndn::Name & getName() const
Definition adjacent.hpp:72
bool compareFaceId(const uint64_t faceId) const
Definition adjacent.hpp:164
const ndn::Block & wireEncode() const
Definition adjacent.cpp:100
void setInterestTimedOutNo(uint32_t iton)
Definition adjacent.hpp:126
bool operator==(const Adjacent &adjacent) const
Equality is when name, Face URI, and link cost are all equal.
Definition adjacent.cpp:160
void setName(const ndn::Name &name)
Definition adjacent.hpp:78
double getLinkCost() const
Definition adjacent.hpp:98
Status getStatus() const
Definition adjacent.hpp:107
uint64_t getFaceId() const
Definition adjacent.hpp:139
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Adjacent)
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition adjacent.cpp:176