33 , m_linkCost(DEFAULT_LINK_COST)
34 , m_status(STATUS_INACTIVE)
35 , m_interestTimedOutNo(0)
48 , m_linkCost(DEFAULT_LINK_COST)
49 , m_status(STATUS_INACTIVE)
50 , m_interestTimedOutNo(0)
56 Status s, uint32_t iton, uint64_t faceId)
60 , m_interestTimedOutNo(iton)
73 NDN_THROW(ndn::tlv::Error(
"Neighbor's link-cost cannot be negative"));
81 template<ndn::encoding::Tag TAG>
85 size_t totalLength = 0;
87 totalLength += prependDoubleBlock(encoder,
nlsr::tlv::Cost, m_linkCost);
89 totalLength += prependStringBlock(encoder,
nlsr::tlv::Uri, m_faceUri.toString());
91 totalLength += m_name.wireEncode(encoder);
93 totalLength += encoder.prependVarNumber(totalLength);
102 if (m_wire.hasWire()) {
106 ndn::EncodingEstimator estimator;
109 ndn::EncodingBuffer buffer(estimatedSize, 0);
112 m_wire = buffer.block();
121 m_faceUri = ndn::FaceUri();
127 NDN_THROW(
Error(
"Adjacency", m_wire.type()));
132 auto val = m_wire.elements_begin();
134 if (val != m_wire.elements_end() && val->type() == ndn::tlv::Name) {
135 m_name.wireDecode(*val);
139 NDN_THROW(
Error(
"Missing required Name field"));
142 if (val != m_wire.elements_end() && val->type() ==
nlsr::tlv::Uri) {
143 m_faceUri = ndn::FaceUri(readString(*val));
147 NDN_THROW(
Error(
"Missing required Uri field"));
151 m_linkCost = ndn::encoding::readDouble(*val);
155 NDN_THROW(
Error(
"Missing required Cost field"));
162 return m_name == adjacent.
getName() &&
171 return std::tie(m_name, m_linkCost) <
172 std::tie(adjacent.
getName(), linkCost);
178 os <<
"Adjacent: " << adjacent.m_name
179 <<
"\n\t\tConnecting FaceUri: " << adjacent.m_faceUri
180 <<
"\n\t\tLink cost: " << adjacent.m_linkCost
181 <<
"\n\t\tStatus: " << adjacent.m_status
182 <<
"\n\t\tInterest Timed Out: " << adjacent.m_interestTimedOutNo << std::endl;
A neighbor reachable over a Face.
static constexpr double NON_ADJACENT_COST
const ndn::FaceUri & getFaceUri() const
void wireDecode(const ndn::Block &wire)
bool operator<(const Adjacent &adjacent) const
void setLinkCost(double lc)
const ndn::Block & wireEncode() const
const ndn::Name & getName() const
bool operator==(const Adjacent &adjacent) const
Equality is when name, Face URI, and link cost are all equal.
double getLinkCost() const
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define INIT_LOGGER(name)
#define NLSR_LOG_ERROR(x)
bool diffInEpsilon(double lhs, double rhs)
Determine whether the difference between two numbers are within epsilon.
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Adjacent)