NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
face-status.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2018 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
28 
29 namespace ndn {
30 namespace nfd {
31 
32 BOOST_CONCEPT_ASSERT((StatusDatasetItem<FaceStatus>));
33 
35  : m_nInInterests(0)
36  , m_nInData(0)
37  , m_nInNacks(0)
38  , m_nOutInterests(0)
39  , m_nOutData(0)
40  , m_nOutNacks(0)
41  , m_nInBytes(0)
42  , m_nOutBytes(0)
43 {
44 }
45 
47 {
48  this->wireDecode(block);
49 }
50 
51 template<encoding::Tag TAG>
52 size_t
54 {
55  size_t totalLength = 0;
56 
57  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Flags, m_flags);
58  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutBytes, m_nOutBytes);
59  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInBytes, m_nInBytes);
60  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutNacks, m_nOutNacks);
61  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutData, m_nOutData);
62  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutInterests, m_nOutInterests);
63  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInNacks, m_nInNacks);
64  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInData, m_nInData);
65  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInInterests, m_nInInterests);
66  if (m_mtu) {
67  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Mtu, *m_mtu);
68  }
69  if (m_defaultCongestionThreshold) {
71  *m_defaultCongestionThreshold);
72  }
73  if (m_baseCongestionMarkingInterval) {
75  m_baseCongestionMarkingInterval->count());
76  }
80  if (m_expirationPeriod) {
82  m_expirationPeriod->count());
83  }
84  totalLength += prependStringBlock(encoder, tlv::nfd::LocalUri, m_localUri);
85  totalLength += prependStringBlock(encoder, tlv::nfd::Uri, m_remoteUri);
87 
88  totalLength += encoder.prependVarNumber(totalLength);
89  totalLength += encoder.prependVarNumber(tlv::nfd::FaceStatus);
90  return totalLength;
91 }
92 
94 
95 const Block&
97 {
98  if (m_wire.hasWire())
99  return m_wire;
100 
101  EncodingEstimator estimator;
102  size_t estimatedSize = wireEncode(estimator);
103 
104  EncodingBuffer buffer(estimatedSize, 0);
105  wireEncode(buffer);
106 
107  m_wire = buffer.block();
108  return m_wire;
109 }
110 
111 void
113 {
114  if (block.type() != tlv::nfd::FaceStatus) {
115  BOOST_THROW_EXCEPTION(Error("expecting FaceStatus block"));
116  }
117  m_wire = block;
118  m_wire.parse();
120 
121  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) {
123  ++val;
124  }
125  else {
126  BOOST_THROW_EXCEPTION(Error("missing required FaceId field"));
127  }
128 
129  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Uri) {
130  m_remoteUri = readString(*val);
131  ++val;
132  }
133  else {
134  BOOST_THROW_EXCEPTION(Error("missing required Uri field"));
135  }
136 
137  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) {
138  m_localUri = readString(*val);
139  ++val;
140  }
141  else {
142  BOOST_THROW_EXCEPTION(Error("missing required LocalUri field"));
143  }
144 
145  if (val != m_wire.elements_end() && val->type() == tlv::nfd::ExpirationPeriod) {
146  m_expirationPeriod.emplace(readNonNegativeInteger(*val));
147  ++val;
148  }
149  else {
150  m_expirationPeriod = nullopt;
151  }
152 
153  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceScope) {
154  m_faceScope = readNonNegativeIntegerAs<FaceScope>(*val);
155  ++val;
156  }
157  else {
158  BOOST_THROW_EXCEPTION(Error("missing required FaceScope field"));
159  }
160 
161  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FacePersistency) {
162  m_facePersistency = readNonNegativeIntegerAs<FacePersistency>(*val);
163  ++val;
164  }
165  else {
166  BOOST_THROW_EXCEPTION(Error("missing required FacePersistency field"));
167  }
168 
169  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LinkType) {
170  m_linkType = readNonNegativeIntegerAs<LinkType>(*val);
171  ++val;
172  }
173  else {
174  BOOST_THROW_EXCEPTION(Error("missing required LinkType field"));
175  }
176 
177  if (val != m_wire.elements_end() && val->type() == tlv::nfd::BaseCongestionMarkingInterval) {
178  m_baseCongestionMarkingInterval.emplace(readNonNegativeInteger(*val));
179  ++val;
180  }
181  else {
182  m_baseCongestionMarkingInterval = nullopt;
183  }
184 
185  if (val != m_wire.elements_end() && val->type() == tlv::nfd::DefaultCongestionThreshold) {
186  m_defaultCongestionThreshold = readNonNegativeInteger(*val);
187  ++val;
188  }
189  else {
190  m_defaultCongestionThreshold = nullopt;
191  }
192 
193  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Mtu) {
194  m_mtu = readNonNegativeInteger(*val);
195  ++val;
196  }
197  else {
198  m_mtu = nullopt;
199  }
200 
201  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInInterests) {
202  m_nInInterests = readNonNegativeInteger(*val);
203  ++val;
204  }
205  else {
206  BOOST_THROW_EXCEPTION(Error("missing required NInInterests field"));
207  }
208 
209  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInData) {
210  m_nInData = readNonNegativeInteger(*val);
211  ++val;
212  }
213  else {
214  BOOST_THROW_EXCEPTION(Error("missing required NInData field"));
215  }
216 
217  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInNacks) {
218  m_nInNacks = readNonNegativeInteger(*val);
219  ++val;
220  }
221  else {
222  BOOST_THROW_EXCEPTION(Error("missing required NInNacks field"));
223  }
224 
225  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutInterests) {
226  m_nOutInterests = readNonNegativeInteger(*val);
227  ++val;
228  }
229  else {
230  BOOST_THROW_EXCEPTION(Error("missing required NOutInterests field"));
231  }
232 
233  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutData) {
234  m_nOutData = readNonNegativeInteger(*val);
235  ++val;
236  }
237  else {
238  BOOST_THROW_EXCEPTION(Error("missing required NOutData field"));
239  }
240 
241  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutNacks) {
242  m_nOutNacks = readNonNegativeInteger(*val);
243  ++val;
244  }
245  else {
246  BOOST_THROW_EXCEPTION(Error("missing required NOutNacks field"));
247  }
248 
249  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInBytes) {
250  m_nInBytes = readNonNegativeInteger(*val);
251  ++val;
252  }
253  else {
254  BOOST_THROW_EXCEPTION(Error("missing required NInBytes field"));
255  }
256 
257  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutBytes) {
258  m_nOutBytes = readNonNegativeInteger(*val);
259  ++val;
260  }
261  else {
262  BOOST_THROW_EXCEPTION(Error("missing required NOutBytes field"));
263  }
264 
265  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Flags) {
267  ++val;
268  }
269  else {
270  BOOST_THROW_EXCEPTION(Error("missing required Flags field"));
271  }
272 }
273 
274 FaceStatus&
275 FaceStatus::setExpirationPeriod(time::milliseconds expirationPeriod)
276 {
277  m_wire.reset();
278  m_expirationPeriod = expirationPeriod;
279  return *this;
280 }
281 
282 FaceStatus&
284 {
285  m_wire.reset();
286  m_expirationPeriod = nullopt;
287  return *this;
288 }
289 
290 FaceStatus&
292 {
293  m_wire.reset();
294  m_baseCongestionMarkingInterval = interval;
295  return *this;
296 }
297 
298 FaceStatus&
300 {
301  m_wire.reset();
302  m_baseCongestionMarkingInterval = nullopt;
303  return *this;
304 }
305 
306 FaceStatus&
308 {
309  m_wire.reset();
310  m_defaultCongestionThreshold = threshold;
311  return *this;
312 }
313 
314 FaceStatus&
316 {
317  m_wire.reset();
318  m_defaultCongestionThreshold = nullopt;
319  return *this;
320 }
321 
322 FaceStatus&
323 FaceStatus::setMtu(uint64_t mtu)
324 {
325  m_wire.reset();
326  m_mtu = mtu;
327  return *this;
328 }
329 
330 FaceStatus&
332 {
333  m_wire.reset();
334  m_mtu = nullopt;
335  return *this;
336 }
337 
338 FaceStatus&
339 FaceStatus::setNInInterests(uint64_t nInInterests)
340 {
341  m_wire.reset();
342  m_nInInterests = nInInterests;
343  return *this;
344 }
345 
346 FaceStatus&
347 FaceStatus::setNInData(uint64_t nInData)
348 {
349  m_wire.reset();
350  m_nInData = nInData;
351  return *this;
352 }
353 
354 FaceStatus&
355 FaceStatus::setNInNacks(uint64_t nInNacks)
356 {
357  m_wire.reset();
358  m_nInNacks = nInNacks;
359  return *this;
360 }
361 
362 FaceStatus&
363 FaceStatus::setNOutInterests(uint64_t nOutInterests)
364 {
365  m_wire.reset();
366  m_nOutInterests = nOutInterests;
367  return *this;
368 }
369 
370 FaceStatus&
371 FaceStatus::setNOutData(uint64_t nOutData)
372 {
373  m_wire.reset();
374  m_nOutData = nOutData;
375  return *this;
376 }
377 
378 FaceStatus&
379 FaceStatus::setNOutNacks(uint64_t nOutNacks)
380 {
381  m_wire.reset();
382  m_nOutNacks = nOutNacks;
383  return *this;
384 }
385 
386 FaceStatus&
387 FaceStatus::setNInBytes(uint64_t nInBytes)
388 {
389  m_wire.reset();
390  m_nInBytes = nInBytes;
391  return *this;
392 }
393 
394 FaceStatus&
395 FaceStatus::setNOutBytes(uint64_t nOutBytes)
396 {
397  m_wire.reset();
398  m_nOutBytes = nOutBytes;
399  return *this;
400 }
401 
402 bool
403 operator==(const FaceStatus& a, const FaceStatus& b)
404 {
405  return a.getFaceId() == b.getFaceId() &&
406  a.getRemoteUri() == b.getRemoteUri() &&
407  a.getLocalUri() == b.getLocalUri() &&
408  a.getFaceScope() == b.getFaceScope() &&
410  a.getLinkType() == b.getLinkType() &&
411  a.getFlags() == b.getFlags() &&
420  a.hasMtu() == b.hasMtu() &&
421  (!a.hasMtu() || a.getMtu() == b.getMtu()) &&
422  a.getNInInterests() == b.getNInInterests() &&
423  a.getNInData() == b.getNInData() &&
424  a.getNInNacks() == b.getNInNacks() &&
425  a.getNOutInterests() == b.getNOutInterests() &&
426  a.getNOutData() == b.getNOutData() &&
427  a.getNOutNacks() == b.getNOutNacks() &&
428  a.getNInBytes() == b.getNInBytes() &&
429  a.getNOutBytes() == b.getNOutBytes();
430 }
431 
432 std::ostream&
433 operator<<(std::ostream& os, const FaceStatus& status)
434 {
435  os << "Face(FaceId: " << status.getFaceId() << ",\n"
436  << " RemoteUri: " << status.getRemoteUri() << ",\n"
437  << " LocalUri: " << status.getLocalUri() << ",\n";
438 
439  if (status.hasExpirationPeriod()) {
440  os << " ExpirationPeriod: " << status.getExpirationPeriod() << ",\n";
441  }
442  else {
443  os << " ExpirationPeriod: infinite,\n";
444  }
445 
446  os << " FaceScope: " << status.getFaceScope() << ",\n"
447  << " FacePersistency: " << status.getFacePersistency() << ",\n"
448  << " LinkType: " << status.getLinkType() << ",\n";
449 
450  if (status.hasBaseCongestionMarkingInterval()) {
451  os << " BaseCongestionMarkingInterval: " << status.getBaseCongestionMarkingInterval() << ",\n";
452  }
453 
454  if (status.hasDefaultCongestionThreshold()) {
455  os << " DefaultCongestionThreshold: " << status.getDefaultCongestionThreshold() << " bytes,\n";
456  }
457 
458  if (status.hasMtu()) {
459  os << " Mtu: " << status.getMtu() << " bytes,\n";
460  }
461 
462  os << " Flags: " << AsHex{status.getFlags()} << ",\n"
463  << " Counters: {Interests: {in: " << status.getNInInterests() << ", "
464  << "out: " << status.getNOutInterests() << "},\n"
465  << " Data: {in: " << status.getNInData() << ", "
466  << "out: " << status.getNOutData() << "},\n"
467  << " Nacks: {in: " << status.getNInNacks() << ", "
468  << "out: " << status.getNOutNacks() << "},\n"
469  << " bytes: {in: " << status.getNInBytes() << ", "
470  << "out: " << status.getNOutBytes() << "}}\n";
471 
472  return os << " )";
473 }
474 
475 } // namespace nfd
476 } // namespace ndn
const std::string & getLocalUri() const
Definition: face-traits.hpp:75
void wireDecode(const Block &wire)
decode FaceStatus
uint64_t getNOutInterests() const
time::milliseconds getExpirationPeriod() const
Definition: face-status.hpp:68
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.cpp:249
Copyright (c) 2011-2015 Regents of the University of California.
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
FacePersistency getFacePersistency() const
bool hasExpirationPeriod() const
Definition: face-status.hpp:62
uint64_t getNOutNacks() const
bool hasBaseCongestionMarkingInterval() const
Definition: face-status.hpp:81
element_container::const_iterator element_const_iterator
Definition: block.hpp:47
uint64_t getNOutBytes() const
uint64_t getNInInterests() const
Helper class to convert a number to hexadecimal format, for use with stream insertion operators.
FaceStatus & unsetDefaultCongestionThreshold()
void parse() const
Parse TLV-VALUE into sub elements.
Definition: block.cpp:333
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus)
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
size_t prependStringBlock(EncodingImpl< TAG > &encoder, uint32_t type, const std::string &value)
Prepend a TLV element containing a string.
std::string readString(const Block &block)
Read TLV-VALUE of a TLV element as a string.
FaceScope getFaceScope() const
Definition: face-traits.hpp:89
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition: block.hpp:369
FaceStatus & setNOutBytes(uint64_t nOutBytes)
FaceStatus & setNOutInterests(uint64_t nOutInterests)
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
const std::string & getRemoteUri() const
Definition: face-traits.hpp:61
uint64_t getNOutData() const
FaceStatus & setExpirationPeriod(time::milliseconds expirationPeriod)
FaceStatus & setNInInterests(uint64_t nInInterests)
uint64_t getNInBytes() const
FaceStatus & setNInBytes(uint64_t nInBytes)
FaceStatus & unsetBaseCongestionMarkingInterval()
element_const_iterator elements_end() const
Equivalent to elements().end()
Definition: block.hpp:377
FaceStatus & unsetExpirationPeriod()
FaceStatus & setNInNacks(uint64_t nInNacks)
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
FaceStatus & setNOutData(uint64_t nOutData)
bool operator==(const ChannelStatus &a, const ChannelStatus &b)
represents an item in NFD Face dataset
Definition: face-status.hpp:36
time::nanoseconds getBaseCongestionMarkingInterval() const
Definition: face-status.hpp:87
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
FaceStatus & setMtu(uint64_t mtu)
set MTU (measured in bytes)
void reset()
Reset wire buffer of the element.
Definition: block.cpp:255
uint64_t getDefaultCongestionThreshold() const
get default congestion threshold (measured in bytes)
concept check for an item in a Status Dataset
Definition: concepts.hpp:115
FaceStatus & setBaseCongestionMarkingInterval(time::nanoseconds interval)
uint64_t getFlags() const
uint64_t getNInData() const
FaceStatus & setNOutNacks(uint64_t nOutNacks)
uint64_t getMtu() const
get MTU (measured in bytes)
const Block & wireEncode() const
encode FaceStatus
Definition: face-status.cpp:96
FaceStatus & setNInData(uint64_t nInData)
FaceStatus & unsetMtu()
uint64_t getFaceId() const
Definition: face-traits.hpp:47
bool hasDefaultCongestionThreshold() const
EncodingImpl< EncoderTag > EncodingBuffer
const nullopt_t nullopt((nullopt_t::init()))
uint32_t type() const
Get TLV-TYPE.
Definition: block.hpp:249
LinkType getLinkType() const
EncodingImpl< EstimatorTag > EncodingEstimator
FaceStatus & setDefaultCongestionThreshold(uint64_t threshold)
set default congestion threshold (measured in bytes)
uint64_t getNInNacks() const