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_nOutInterests(0)
47  , m_nOutDatas(0)
48 {
49 }
50 
52 {
53  this->wireDecode(payload);
54 }
55 
56 template<encoding::Tag TAG>
57 size_t
58 ForwarderStatus::wireEncode(EncodingImpl<TAG>& encoder) const
59 {
60  size_t totalLength = 0;
61 
63  m_nOutDatas);
65  m_nOutInterests);
66  totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NInDatas,
67  m_nInDatas);
69  m_nInInterests);
71  m_nCsEntries);
73  m_nMeasurementsEntries);
75  m_nPitEntries);
77  m_nFibEntries);
79  m_nNameTreeEntries);
81  time::toUnixTimestamp(m_currentTimestamp).count());
83  time::toUnixTimestamp(m_startTimestamp).count());
84  totalLength += encoder.prependByteArrayBlock(tlv::nfd::NfdVersion,
85  reinterpret_cast<const uint8_t*>(m_nfdVersion.c_str()),
86  m_nfdVersion.size());
87 
88  totalLength += encoder.prependVarNumber(totalLength);
89  totalLength += encoder.prependVarNumber(tlv::Content);
90  return totalLength;
91 }
92 
93 template size_t
94 ForwarderStatus::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>&) const;
95 
96 template size_t
97 ForwarderStatus::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>&) const;
98 
99 const Block&
101 {
102  if (m_wire.hasWire())
103  return m_wire;
104 
105  EncodingEstimator estimator;
106  size_t estimatedSize = wireEncode(estimator);
107 
108  EncodingBuffer buffer(estimatedSize, 0);
109  wireEncode(buffer);
110 
111  m_wire = buffer.block();
112  return m_wire;
113 }
114 
115 void
117 {
118  if (block.type() != tlv::Content) {
119  BOOST_THROW_EXCEPTION(Error("expecting Content block for Status payload"));
120  }
121  m_wire = block;
122  m_wire.parse();
124 
125  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NfdVersion) {
126  m_nfdVersion.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
127  ++val;
128  }
129  else {
130  BOOST_THROW_EXCEPTION(Error("missing required NfdVersion field"));
131  }
132 
133  if (val != m_wire.elements_end() && val->type() == tlv::nfd::StartTimestamp) {
134  m_startTimestamp = time::fromUnixTimestamp(time::milliseconds(readNonNegativeInteger(*val)));
135  ++val;
136  }
137  else {
138  BOOST_THROW_EXCEPTION(Error("missing required StartTimestamp field"));
139  }
140 
141  if (val != m_wire.elements_end() && val->type() == tlv::nfd::CurrentTimestamp) {
142  m_currentTimestamp = time::fromUnixTimestamp(time::milliseconds(readNonNegativeInteger(*val)));
143  ++val;
144  }
145  else {
146  BOOST_THROW_EXCEPTION(Error("missing required CurrentTimestamp field"));
147  }
148 
149  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NNameTreeEntries) {
150  m_nNameTreeEntries = static_cast<size_t>(readNonNegativeInteger(*val));
151  ++val;
152  }
153  else {
154  BOOST_THROW_EXCEPTION(Error("missing required NNameTreeEntries field"));
155  }
156 
157  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NFibEntries) {
158  m_nFibEntries = static_cast<size_t>(readNonNegativeInteger(*val));
159  ++val;
160  }
161  else {
162  BOOST_THROW_EXCEPTION(Error("missing required NFibEntries field"));
163  }
164 
165  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NPitEntries) {
166  m_nPitEntries = static_cast<size_t>(readNonNegativeInteger(*val));
167  ++val;
168  }
169  else {
170  BOOST_THROW_EXCEPTION(Error("missing required NPitEntries field"));
171  }
172 
173  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NMeasurementsEntries) {
174  m_nMeasurementsEntries = static_cast<size_t>(readNonNegativeInteger(*val));
175  ++val;
176  }
177  else {
178  BOOST_THROW_EXCEPTION(Error("missing required NMeasurementsEntries field"));
179  }
180 
181  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NCsEntries) {
182  m_nCsEntries = static_cast<size_t>(readNonNegativeInteger(*val));
183  ++val;
184  }
185  else {
186  BOOST_THROW_EXCEPTION(Error("missing required NCsEntries field"));
187  }
188 
189  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInInterests) {
190  m_nInInterests = static_cast<uint64_t>(readNonNegativeInteger(*val));
191  ++val;
192  }
193  else {
194  BOOST_THROW_EXCEPTION(Error("missing required NInInterests field"));
195  }
196 
197  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInDatas) {
198  m_nInDatas = static_cast<uint64_t>(readNonNegativeInteger(*val));
199  ++val;
200  }
201  else {
202  BOOST_THROW_EXCEPTION(Error("missing required NInDatas field"));
203  }
204 
205  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutInterests) {
206  m_nOutInterests = static_cast<uint64_t>(readNonNegativeInteger(*val));
207  ++val;
208  }
209  else {
210  BOOST_THROW_EXCEPTION(Error("missing required NOutInterests field"));
211  }
212 
213  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutDatas) {
214  m_nOutDatas = static_cast<uint64_t>(readNonNegativeInteger(*val));
215  ++val;
216  }
217  else {
218  BOOST_THROW_EXCEPTION(Error("missing required NOutDatas field"));
219  }
220 }
221 
223 ForwarderStatus::setNfdVersion(const std::string& nfdVersion)
224 {
225  m_wire.reset();
226  m_nfdVersion = nfdVersion;
227  return *this;
228 }
229 
232 {
233  m_wire.reset();
234  m_startTimestamp = startTimestamp;
235  return *this;
236 }
237 
240 {
241  m_wire.reset();
242  m_currentTimestamp = currentTimestamp;
243  return *this;
244 }
245 
247 ForwarderStatus::setNNameTreeEntries(size_t nNameTreeEntries)
248 {
249  m_wire.reset();
250  m_nNameTreeEntries = nNameTreeEntries;
251  return *this;
252 }
253 
256 {
257  m_wire.reset();
258  m_nFibEntries = nFibEntries;
259  return *this;
260 }
261 
264 {
265  m_wire.reset();
266  m_nPitEntries = nPitEntries;
267  return *this;
268 }
269 
271 ForwarderStatus::setNMeasurementsEntries(size_t nMeasurementsEntries)
272 {
273  m_wire.reset();
274  m_nMeasurementsEntries = nMeasurementsEntries;
275  return *this;
276 }
277 
280 {
281  m_wire.reset();
282  m_nCsEntries = nCsEntries;
283  return *this;
284 }
285 
287 ForwarderStatus::setNInInterests(uint64_t nInInterests)
288 {
289  m_wire.reset();
290  m_nInInterests = nInInterests;
291  return *this;
292 }
293 
296 {
297  m_wire.reset();
298  m_nInDatas = nInDatas;
299  return *this;
300 }
301 
303 ForwarderStatus::setNOutInterests(uint64_t nOutInterests)
304 {
305  m_wire.reset();
306  m_nOutInterests = nOutInterests;
307  return *this;
308 }
309 
311 ForwarderStatus::setNOutDatas(uint64_t nOutDatas)
312 {
313  m_wire.reset();
314  m_nOutDatas = nOutDatas;
315  return *this;
316 }
317 
318 } // namespace nfd
319 } // namespace ndn
ForwarderStatus & setNOutDatas(uint64_t nOutDatas)
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.
EncodingImpl< EstimatorTag > EncodingEstimator
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.
element_const_iterator elements_end() const
Definition: block.cpp:595
ForwarderStatus & setNNameTreeEntries(size_t nNameTreeEntries)
element_const_iterator elements_begin() const
Definition: block.cpp:589
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:38
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)
const Block & wireEncode() const
encode ForwarderStatus as a Content block
void parse() const
Parse wire buffer into subblocks.
Definition: block.cpp:322
uint32_t type() const
Definition: block.hpp:346
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
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.cpp:471
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