NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
nfd-forwarder-status.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "nfd-forwarder-status.hpp"
23 #include "encoding/tlv-nfd.hpp"
25 #include "util/concepts.hpp"
26 
27 namespace ndn {
28 namespace nfd {
29 
30 //BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ForwarderStatus>));
31 BOOST_CONCEPT_ASSERT((WireEncodable<ForwarderStatus>));
32 BOOST_CONCEPT_ASSERT((WireDecodable<ForwarderStatus>));
33 static_assert(std::is_base_of<tlv::Error, ForwarderStatus::Error>::value,
34  "ForwarderStatus::Error must inherit from tlv::Error");
35 
37  : m_startTimestamp(time::system_clock::TimePoint::min())
38  , m_currentTimestamp(time::system_clock::TimePoint::min())
39  , m_nNameTreeEntries(0)
40  , m_nFibEntries(0)
41  , m_nPitEntries(0)
42  , m_nMeasurementsEntries(0)
43  , m_nCsEntries(0)
44  , m_nInInterests(0)
45  , m_nInDatas(0)
46  , m_nInNacks(0)
47  , m_nOutInterests(0)
48  , m_nOutDatas(0)
49  , m_nOutNacks(0)
50 {
51 }
52 
54 {
55  this->wireDecode(payload);
56 }
57 
58 template<encoding::Tag TAG>
59 size_t
61 {
62  size_t totalLength = 0;
63 
65  m_nOutNacks);
67  m_nOutDatas);
69  m_nOutInterests);
70  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInNacks,
71  m_nInNacks);
72  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInDatas,
73  m_nInDatas);
75  m_nInInterests);
77  m_nCsEntries);
79  m_nMeasurementsEntries);
81  m_nPitEntries);
83  m_nFibEntries);
85  m_nNameTreeEntries);
87  time::toUnixTimestamp(m_currentTimestamp).count());
89  time::toUnixTimestamp(m_startTimestamp).count());
90  totalLength += encoder.prependByteArrayBlock(tlv::nfd::NfdVersion,
91  reinterpret_cast<const uint8_t*>(m_nfdVersion.c_str()),
92  m_nfdVersion.size());
93 
94  totalLength += encoder.prependVarNumber(totalLength);
95  totalLength += encoder.prependVarNumber(tlv::Content);
96  return totalLength;
97 }
98 
99 template size_t
100 ForwarderStatus::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>&) const;
101 
102 template size_t
103 ForwarderStatus::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>&) const;
104 
105 const Block&
107 {
108  if (m_wire.hasWire())
109  return m_wire;
110 
111  EncodingEstimator estimator;
112  size_t estimatedSize = wireEncode(estimator);
113 
114  EncodingBuffer buffer(estimatedSize, 0);
115  wireEncode(buffer);
116 
117  m_wire = buffer.block();
118  return m_wire;
119 }
120 
121 void
123 {
124  if (block.type() != tlv::Content) {
125  BOOST_THROW_EXCEPTION(Error("expecting Content block for Status payload"));
126  }
127  m_wire = block;
128  m_wire.parse();
130 
131  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NfdVersion) {
132  m_nfdVersion.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
133  ++val;
134  }
135  else {
136  BOOST_THROW_EXCEPTION(Error("missing required NfdVersion field"));
137  }
138 
139  if (val != m_wire.elements_end() && val->type() == tlv::nfd::StartTimestamp) {
140  m_startTimestamp = time::fromUnixTimestamp(time::milliseconds(readNonNegativeInteger(*val)));
141  ++val;
142  }
143  else {
144  BOOST_THROW_EXCEPTION(Error("missing required StartTimestamp field"));
145  }
146 
147  if (val != m_wire.elements_end() && val->type() == tlv::nfd::CurrentTimestamp) {
148  m_currentTimestamp = time::fromUnixTimestamp(time::milliseconds(readNonNegativeInteger(*val)));
149  ++val;
150  }
151  else {
152  BOOST_THROW_EXCEPTION(Error("missing required CurrentTimestamp field"));
153  }
154 
155  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NNameTreeEntries) {
156  m_nNameTreeEntries = static_cast<size_t>(readNonNegativeInteger(*val));
157  ++val;
158  }
159  else {
160  BOOST_THROW_EXCEPTION(Error("missing required NNameTreeEntries field"));
161  }
162 
163  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NFibEntries) {
164  m_nFibEntries = static_cast<size_t>(readNonNegativeInteger(*val));
165  ++val;
166  }
167  else {
168  BOOST_THROW_EXCEPTION(Error("missing required NFibEntries field"));
169  }
170 
171  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NPitEntries) {
172  m_nPitEntries = static_cast<size_t>(readNonNegativeInteger(*val));
173  ++val;
174  }
175  else {
176  BOOST_THROW_EXCEPTION(Error("missing required NPitEntries field"));
177  }
178 
179  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NMeasurementsEntries) {
180  m_nMeasurementsEntries = static_cast<size_t>(readNonNegativeInteger(*val));
181  ++val;
182  }
183  else {
184  BOOST_THROW_EXCEPTION(Error("missing required NMeasurementsEntries field"));
185  }
186 
187  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NCsEntries) {
188  m_nCsEntries = static_cast<size_t>(readNonNegativeInteger(*val));
189  ++val;
190  }
191  else {
192  BOOST_THROW_EXCEPTION(Error("missing required NCsEntries field"));
193  }
194 
195  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInInterests) {
196  m_nInInterests = static_cast<uint64_t>(readNonNegativeInteger(*val));
197  ++val;
198  }
199  else {
200  BOOST_THROW_EXCEPTION(Error("missing required NInInterests field"));
201  }
202 
203  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInDatas) {
204  m_nInDatas = static_cast<uint64_t>(readNonNegativeInteger(*val));
205  ++val;
206  }
207  else {
208  BOOST_THROW_EXCEPTION(Error("missing required NInDatas field"));
209  }
210 
211  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInNacks) {
212  m_nInNacks = static_cast<uint64_t>(readNonNegativeInteger(*val));
213  ++val;
214  }
215  else {
216  BOOST_THROW_EXCEPTION(Error("missing required NInNacks field"));
217  }
218 
219  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutInterests) {
220  m_nOutInterests = static_cast<uint64_t>(readNonNegativeInteger(*val));
221  ++val;
222  }
223  else {
224  BOOST_THROW_EXCEPTION(Error("missing required NOutInterests field"));
225  }
226 
227  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutDatas) {
228  m_nOutDatas = static_cast<uint64_t>(readNonNegativeInteger(*val));
229  ++val;
230  }
231  else {
232  BOOST_THROW_EXCEPTION(Error("missing required NOutDatas field"));
233  }
234 
235  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutNacks) {
236  m_nOutNacks = static_cast<uint64_t>(readNonNegativeInteger(*val));
237  ++val;
238  }
239  else {
240  BOOST_THROW_EXCEPTION(Error("missing required NInNacks field"));
241  }
242 }
243 
245 ForwarderStatus::setNfdVersion(const std::string& nfdVersion)
246 {
247  m_wire.reset();
248  m_nfdVersion = nfdVersion;
249  return *this;
250 }
251 
254 {
255  m_wire.reset();
256  m_startTimestamp = startTimestamp;
257  return *this;
258 }
259 
262 {
263  m_wire.reset();
264  m_currentTimestamp = currentTimestamp;
265  return *this;
266 }
267 
269 ForwarderStatus::setNNameTreeEntries(size_t nNameTreeEntries)
270 {
271  m_wire.reset();
272  m_nNameTreeEntries = nNameTreeEntries;
273  return *this;
274 }
275 
278 {
279  m_wire.reset();
280  m_nFibEntries = nFibEntries;
281  return *this;
282 }
283 
286 {
287  m_wire.reset();
288  m_nPitEntries = nPitEntries;
289  return *this;
290 }
291 
293 ForwarderStatus::setNMeasurementsEntries(size_t nMeasurementsEntries)
294 {
295  m_wire.reset();
296  m_nMeasurementsEntries = nMeasurementsEntries;
297  return *this;
298 }
299 
302 {
303  m_wire.reset();
304  m_nCsEntries = nCsEntries;
305  return *this;
306 }
307 
309 ForwarderStatus::setNInInterests(uint64_t nInInterests)
310 {
311  m_wire.reset();
312  m_nInInterests = nInInterests;
313  return *this;
314 }
315 
318 {
319  m_wire.reset();
320  m_nInDatas = nInDatas;
321  return *this;
322 }
323 
326 {
327  m_wire.reset();
328  m_nInNacks = nInNacks;
329  return *this;
330 }
331 
333 ForwarderStatus::setNOutInterests(uint64_t nOutInterests)
334 {
335  m_wire.reset();
336  m_nOutInterests = nOutInterests;
337  return *this;
338 }
339 
341 ForwarderStatus::setNOutDatas(uint64_t nOutDatas)
342 {
343  m_wire.reset();
344  m_nOutDatas = nOutDatas;
345  return *this;
346 }
347 
349 ForwarderStatus::setNOutNacks(uint64_t nOutNacks)
350 {
351  m_wire.reset();
352  m_nOutNacks = nOutNacks;
353  return *this;
354 }
355 
356 } // namespace nfd
357 } // namespace ndn
ForwarderStatus & setNOutDatas(uint64_t nOutDatas)
element_const_iterator elements_begin() const
Definition: block.cpp:589
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.cpp:471
represents NFD Forwarder Status
Copyright (c) 2011-2015 Regents of the University of California.
ForwarderStatus & setNFibEntries(size_t nFibEntries)
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Helper to prepend TLV block type type containing non-negative integer value.
ForwarderStatus & setNOutNacks(uint64_t nOutNacks)
EncodingImpl< EstimatorTag > EncodingEstimator
element_const_iterator elements_end() const
Definition: block.cpp:595
ForwarderStatus & setNInNacks(uint64_t nInNacks)
void parse() const
Parse wire buffer into subblocks.
Definition: block.cpp:322
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
ForwarderStatus & setNCsEntries(size_t nCsEntries)
uint64_t readNonNegativeInteger(const Block &block)
Helper to read a non-negative integer from a block.
ForwarderStatus & setNNameTreeEntries(size_t nNameTreeEntries)
ForwarderStatus & setNInInterests(uint64_t nInInterests)
EncodingImpl< EncoderTag > EncodingBuffer
ForwarderStatus & setStartTimestamp(const time::system_clock::TimePoint &startTimestamp)
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
element_container::const_iterator element_const_iterator
Definition: block.hpp:48
ForwarderStatus & setNfdVersion(const std::string &nfdVersion)
ForwarderStatus & setNOutInterests(uint64_t nOutInterests)
void reset()
Reset wire buffer of the element.
Definition: block.cpp:302
ForwarderStatus & setNPitEntries(size_t nPitEntries)
time_point TimePoint
Definition: time.hpp:78
system_clock::TimePoint fromUnixTimestamp(const milliseconds &duration)
Convert UNIX timestamp to system_clock::TimePoint.
Definition: time.cpp:124
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
Definition: time.cpp:118
ForwarderStatus & setNInDatas(uint64_t nInDatas)
void wireDecode(const Block &wire)
decode ForwarderStatus from a Content block
a concept check for TLV abstraction with .wireEncode method
Definition: concepts.hpp:34
ForwarderStatus & setNMeasurementsEntries(size_t nMeasurementsEntries)
ForwarderStatus & setCurrentTimestamp(const time::system_clock::TimePoint &currentTimestamp)
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
Definition: concepts.hpp:70
uint32_t type() const
Definition: block.hpp:346
const Block & wireEncode() const
encode ForwarderStatus as a Content block