NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
forwarder-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 
27 
28 namespace ndn {
29 namespace nfd {
30 
31 BOOST_CONCEPT_ASSERT((StatusDatasetItem<ForwarderStatus>));
32 
34  : m_nNameTreeEntries(0)
35  , m_nFibEntries(0)
36  , m_nPitEntries(0)
37  , m_nMeasurementsEntries(0)
38  , m_nCsEntries(0)
39  , m_nInInterests(0)
40  , m_nInData(0)
41  , m_nInNacks(0)
42  , m_nOutInterests(0)
43  , m_nOutData(0)
44  , m_nOutNacks(0)
45  , m_nSatisfiedInterests(0)
46  , m_nUnsatisfiedInterests(0)
47 {
48 }
49 
51 {
52  this->wireDecode(payload);
53 }
54 
55 template<encoding::Tag TAG>
56 size_t
58 {
59  size_t totalLength = 0;
60 
61  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NUnsatisfiedInterests, m_nUnsatisfiedInterests);
62  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NSatisfiedInterests, m_nSatisfiedInterests);
63  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutNacks, m_nOutNacks);
64  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutData, m_nOutData);
65  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NOutInterests, m_nOutInterests);
66  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInNacks, m_nInNacks);
67  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInData, m_nInData);
68  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInInterests, m_nInInterests);
69  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NCsEntries, m_nCsEntries);
70  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NMeasurementsEntries, m_nMeasurementsEntries);
71  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NPitEntries, m_nPitEntries);
72  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NFibEntries, m_nFibEntries);
73  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NNameTreeEntries, m_nNameTreeEntries);
75  time::toUnixTimestamp(m_currentTimestamp).count());
77  time::toUnixTimestamp(m_startTimestamp).count());
78  totalLength += prependStringBlock(encoder, tlv::nfd::NfdVersion, m_nfdVersion);
79 
80  totalLength += encoder.prependVarNumber(totalLength);
81  totalLength += encoder.prependVarNumber(tlv::Content);
82  return totalLength;
83 }
84 
86 
87 const Block&
89 {
90  if (m_wire.hasWire())
91  return m_wire;
92 
93  EncodingEstimator estimator;
94  size_t estimatedSize = wireEncode(estimator);
95 
96  EncodingBuffer buffer(estimatedSize, 0);
97  wireEncode(buffer);
98 
99  m_wire = buffer.block();
100  return m_wire;
101 }
102 
103 void
105 {
106  if (block.type() != tlv::Content) {
107  BOOST_THROW_EXCEPTION(Error("expecting Content block for Status payload"));
108  }
109  m_wire = block;
110  m_wire.parse();
112 
113  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NfdVersion) {
114  m_nfdVersion = readString(*val);
115  ++val;
116  }
117  else {
118  BOOST_THROW_EXCEPTION(Error("missing required NfdVersion field"));
119  }
120 
121  if (val != m_wire.elements_end() && val->type() == tlv::nfd::StartTimestamp) {
122  m_startTimestamp = time::fromUnixTimestamp(time::milliseconds(readNonNegativeInteger(*val)));
123  ++val;
124  }
125  else {
126  BOOST_THROW_EXCEPTION(Error("missing required StartTimestamp field"));
127  }
128 
129  if (val != m_wire.elements_end() && val->type() == tlv::nfd::CurrentTimestamp) {
130  m_currentTimestamp = time::fromUnixTimestamp(time::milliseconds(readNonNegativeInteger(*val)));
131  ++val;
132  }
133  else {
134  BOOST_THROW_EXCEPTION(Error("missing required CurrentTimestamp field"));
135  }
136 
137  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NNameTreeEntries) {
138  m_nNameTreeEntries = readNonNegativeInteger(*val);
139  ++val;
140  }
141  else {
142  BOOST_THROW_EXCEPTION(Error("missing required NNameTreeEntries field"));
143  }
144 
145  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NFibEntries) {
146  m_nFibEntries = readNonNegativeInteger(*val);
147  ++val;
148  }
149  else {
150  BOOST_THROW_EXCEPTION(Error("missing required NFibEntries field"));
151  }
152 
153  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NPitEntries) {
154  m_nPitEntries = readNonNegativeInteger(*val);
155  ++val;
156  }
157  else {
158  BOOST_THROW_EXCEPTION(Error("missing required NPitEntries field"));
159  }
160 
161  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NMeasurementsEntries) {
162  m_nMeasurementsEntries = readNonNegativeInteger(*val);
163  ++val;
164  }
165  else {
166  BOOST_THROW_EXCEPTION(Error("missing required NMeasurementsEntries field"));
167  }
168 
169  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NCsEntries) {
170  m_nCsEntries = readNonNegativeInteger(*val);
171  ++val;
172  }
173  else {
174  BOOST_THROW_EXCEPTION(Error("missing required NCsEntries field"));
175  }
176 
177  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInInterests) {
178  m_nInInterests = readNonNegativeInteger(*val);
179  ++val;
180  }
181  else {
182  BOOST_THROW_EXCEPTION(Error("missing required NInInterests field"));
183  }
184 
185  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInData) {
186  m_nInData = readNonNegativeInteger(*val);
187  ++val;
188  }
189  else {
190  BOOST_THROW_EXCEPTION(Error("missing required NInData field"));
191  }
192 
193  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInNacks) {
194  m_nInNacks = readNonNegativeInteger(*val);
195  ++val;
196  }
197  else {
198  BOOST_THROW_EXCEPTION(Error("missing required NInNacks field"));
199  }
200 
201  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutInterests) {
202  m_nOutInterests = readNonNegativeInteger(*val);
203  ++val;
204  }
205  else {
206  BOOST_THROW_EXCEPTION(Error("missing required NOutInterests field"));
207  }
208 
209  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutData) {
210  m_nOutData = readNonNegativeInteger(*val);
211  ++val;
212  }
213  else {
214  BOOST_THROW_EXCEPTION(Error("missing required NOutData field"));
215  }
216 
217  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutNacks) {
218  m_nOutNacks = readNonNegativeInteger(*val);
219  ++val;
220  }
221  else {
222  BOOST_THROW_EXCEPTION(Error("missing required NOutNacks field"));
223  }
224 
225  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NSatisfiedInterests) {
226  m_nSatisfiedInterests = readNonNegativeInteger(*val);
227  ++val;
228  }
229  else {
230  BOOST_THROW_EXCEPTION(Error("missing required NSatisfiedInterests field"));
231  }
232 
233  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NUnsatisfiedInterests) {
234  m_nUnsatisfiedInterests = readNonNegativeInteger(*val);
235  ++val;
236  }
237  else {
238  BOOST_THROW_EXCEPTION(Error("missing required NUnsatisfiedInterests field"));
239  }
240 }
241 
243 ForwarderStatus::setNfdVersion(const std::string& nfdVersion)
244 {
245  m_wire.reset();
246  m_nfdVersion = nfdVersion;
247  return *this;
248 }
249 
252 {
253  m_wire.reset();
254  m_startTimestamp = startTimestamp;
255  return *this;
256 }
257 
260 {
261  m_wire.reset();
262  m_currentTimestamp = currentTimestamp;
263  return *this;
264 }
265 
267 ForwarderStatus::setNNameTreeEntries(uint64_t nNameTreeEntries)
268 {
269  m_wire.reset();
270  m_nNameTreeEntries = nNameTreeEntries;
271  return *this;
272 }
273 
275 ForwarderStatus::setNFibEntries(uint64_t nFibEntries)
276 {
277  m_wire.reset();
278  m_nFibEntries = nFibEntries;
279  return *this;
280 }
281 
283 ForwarderStatus::setNPitEntries(uint64_t nPitEntries)
284 {
285  m_wire.reset();
286  m_nPitEntries = nPitEntries;
287  return *this;
288 }
289 
291 ForwarderStatus::setNMeasurementsEntries(uint64_t nMeasurementsEntries)
292 {
293  m_wire.reset();
294  m_nMeasurementsEntries = nMeasurementsEntries;
295  return *this;
296 }
297 
299 ForwarderStatus::setNCsEntries(uint64_t nCsEntries)
300 {
301  m_wire.reset();
302  m_nCsEntries = nCsEntries;
303  return *this;
304 }
305 
307 ForwarderStatus::setNInInterests(uint64_t nInInterests)
308 {
309  m_wire.reset();
310  m_nInInterests = nInInterests;
311  return *this;
312 }
313 
316 {
317  m_wire.reset();
318  m_nInData = nInData;
319  return *this;
320 }
321 
324 {
325  m_wire.reset();
326  m_nInNacks = nInNacks;
327  return *this;
328 }
329 
331 ForwarderStatus::setNOutInterests(uint64_t nOutInterests)
332 {
333  m_wire.reset();
334  m_nOutInterests = nOutInterests;
335  return *this;
336 }
337 
340 {
341  m_wire.reset();
342  m_nOutData = nOutData;
343  return *this;
344 }
345 
347 ForwarderStatus::setNOutNacks(uint64_t nOutNacks)
348 {
349  m_wire.reset();
350  m_nOutNacks = nOutNacks;
351  return *this;
352 }
353 
355 ForwarderStatus::setNSatisfiedInterests(uint64_t nSatisfiedInterests)
356 {
357  m_wire.reset();
358  m_nSatisfiedInterests = nSatisfiedInterests;
359  return *this;
360 }
361 
363 ForwarderStatus::setNUnsatisfiedInterests(uint64_t nUnsatisfiedInterests)
364 {
365  m_wire.reset();
366  m_nUnsatisfiedInterests = nUnsatisfiedInterests;
367  return *this;
368 }
369 
370 bool
372 {
373  return a.getNfdVersion() == b.getNfdVersion() &&
377  a.getNFibEntries() == b.getNFibEntries() &&
378  a.getNPitEntries() == b.getNPitEntries() &&
380  a.getNCsEntries() == b.getNCsEntries() &&
381  a.getNInInterests() == b.getNInInterests() &&
382  a.getNInData() == b.getNInData() &&
383  a.getNInNacks() == b.getNInNacks() &&
384  a.getNOutInterests() == b.getNOutInterests() &&
385  a.getNOutData() == b.getNOutData() &&
386  a.getNOutNacks() == b.getNOutNacks() &&
389 }
390 
391 std::ostream&
392 operator<<(std::ostream& os, const ForwarderStatus& status)
393 {
394  os << "GeneralStatus(NfdVersion: " << status.getNfdVersion() << ",\n"
395  << " StartTimestamp: " << status.getStartTimestamp() << ",\n"
396  << " CurrentTimestamp: " << status.getCurrentTimestamp() << ",\n"
397  << " Counters: {NameTreeEntries: " << status.getNNameTreeEntries() << ",\n"
398  << " FibEntries: " << status.getNFibEntries() << ",\n"
399  << " PitEntries: " << status.getNPitEntries() << ",\n"
400  << " MeasurementsEntries: " << status.getNMeasurementsEntries() << ",\n"
401  << " CsEntries: " << status.getNCsEntries() << ",\n"
402  << " Interests: {in: " << status.getNInInterests() << ", "
403  << "out: " << status.getNOutInterests() << "},\n"
404  << " Data: {in: " << status.getNInData() << ", "
405  << "out: " << status.getNOutData() << "},\n"
406  << " Nacks: {in: " << status.getNInNacks() << ", "
407  << "out: " << status.getNOutNacks() << "},\n"
408  << " SatisfiedInterests: " << status.getNSatisfiedInterests() << ",\n"
409  << " UnsatisfiedInterests: " << status.getNUnsatisfiedInterests() << "}\n"
410  << " )";
411 
412  return os;
413 }
414 
415 } // namespace nfd
416 } // namespace ndn
ForwarderStatus & setNFibEntries(uint64_t nFibEntries)
uint64_t getNInInterests() const
uint64_t getNOutInterests() const
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.cpp:249
represents NFD General Status dataset
Copyright (c) 2011-2015 Regents of the University of California.
system_clock::TimePoint fromUnixTimestamp(milliseconds duration)
Convert UNIX timestamp to system_clock::TimePoint.
Definition: time.cpp:119
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
ForwarderStatus & setNOutNacks(uint64_t nOutNacks)
uint64_t getNUnsatisfiedInterests() const
ForwarderStatus & setNInData(uint64_t nInData)
element_container::const_iterator element_const_iterator
Definition: block.hpp:47
ForwarderStatus & setNOutData(uint64_t nOutData)
ForwarderStatus & setNInNacks(uint64_t nInNacks)
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.
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition: block.hpp:369
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
ForwarderStatus & setNSatisfiedInterests(uint64_t nSatisfiedInterests)
const time::system_clock::TimePoint & getStartTimestamp() const
ForwarderStatus & setNInInterests(uint64_t nInInterests)
element_const_iterator elements_end() const
Equivalent to elements().end()
Definition: block.hpp:377
ForwarderStatus & setStartTimestamp(const time::system_clock::TimePoint &startTimestamp)
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
bool operator==(const ChannelStatus &a, const ChannelStatus &b)
uint64_t getNMeasurementsEntries() const
ForwarderStatus & setNfdVersion(const std::string &nfdVersion)
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
ForwarderStatus & setNOutInterests(uint64_t nOutInterests)
ForwarderStatus & setNUnsatisfiedInterests(uint64_t nUnsatisfiedInterests)
void reset()
Reset wire buffer of the element.
Definition: block.cpp:255
ForwarderStatus & setNMeasurementsEntries(uint64_t nMeasurementsEntries)
concept check for an item in a Status Dataset
Definition: concepts.hpp:115
uint64_t getNNameTreeEntries() const
uint64_t getNSatisfiedInterests() const
time_point TimePoint
Definition: time.hpp:195
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
Definition: time.cpp:113
ForwarderStatus & setNPitEntries(uint64_t nPitEntries)
ForwarderStatus & setNCsEntries(uint64_t nCsEntries)
void wireDecode(const Block &wire)
decode ForwarderStatus from a Content block
const time::system_clock::TimePoint & getCurrentTimestamp() const
ForwarderStatus & setNNameTreeEntries(uint64_t nNameTreeEntries)
ForwarderStatus & setCurrentTimestamp(const time::system_clock::TimePoint &currentTimestamp)
const std::string & getNfdVersion() const
EncodingImpl< EncoderTag > EncodingBuffer
uint32_t type() const
Get TLV-TYPE.
Definition: block.hpp:249
EncodingImpl< EstimatorTag > EncodingEstimator
const Block & wireEncode() const
encode ForwarderStatus as a Content block