All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
nfd-face-status.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
7 #ifndef NDN_MANAGEMENT_NFD_FACE_STATUS_HPP
8 #define NDN_MANAGEMENT_NFD_FACE_STATUS_HPP
9 
10 // This include must be kept as the first one, to ensure nfd-face-flags.hpp compiles on its own.
11 #include "nfd-face-flags.hpp"
12 
13 #include "../encoding/tlv-nfd.hpp"
14 #include "../encoding/encoding-buffer.hpp"
15 
16 namespace ndn {
17 namespace nfd {
18 
22 class FaceStatus : public FaceFlagsTraits<FaceStatus>
23 {
24 public:
25  class Error : public Tlv::Error
26  {
27  public:
28  explicit
29  Error(const std::string& what)
30  : Tlv::Error(what)
31  {
32  }
33  };
34 
35  FaceStatus();
36 
37  explicit
38  FaceStatus(const Block& block)
39  {
40  this->wireDecode(block);
41  }
42 
45  template<bool T>
46  size_t
47  wireEncode(EncodingImpl<T>& encoder) const;
48 
51  const Block&
52  wireEncode() const;
53 
56  void
57  wireDecode(const Block& wire);
58 
59 public: // getters & setters
60  uint64_t
61  getFaceId() const
62  {
63  return m_faceId;
64  }
65 
66  FaceStatus&
67  setFaceId(uint64_t faceId)
68  {
69  m_wire.reset();
70  m_faceId = faceId;
71  return *this;
72  }
73 
74  const std::string&
75  getRemoteUri() const
76  {
77  return m_remoteUri;
78  }
79 
80  FaceStatus&
81  setRemoteUri(const std::string& remoteUri)
82  {
83  m_wire.reset();
84  m_remoteUri = remoteUri;
85  return *this;
86  }
87 
88  const std::string&
89  getLocalUri() const
90  {
91  return m_localUri;
92  }
93 
94  FaceStatus&
95  setLocalUri(const std::string& localUri)
96  {
97  m_wire.reset();
98  m_localUri = localUri;
99  return *this;
100  }
101 
102  uint64_t
103  getFlags() const
104  {
105  return m_flags;
106  }
107 
108  FaceStatus&
109  setFlags(uint64_t flags)
110  {
111  m_wire.reset();
112  m_flags = flags;
113  return *this;
114  }
115 
116  uint64_t
118  {
119  return m_nInInterests;
120  }
121 
122  FaceStatus&
123  setNInInterests(uint64_t nInInterests)
124  {
125  m_wire.reset();
126  m_nInInterests = nInInterests;
127  return *this;
128  }
129 
130  uint64_t
131  getNInDatas() const
132  {
133  return m_nInDatas;
134  }
135 
136  FaceStatus&
137  setNInDatas(uint64_t nInDatas)
138  {
139  m_wire.reset();
140  m_nInDatas = nInDatas;
141  return *this;
142  }
143 
144  uint64_t
146  {
147  return m_nOutInterests;
148  }
149 
150  FaceStatus&
151  setNOutInterests(uint64_t nOutInterests)
152  {
153  m_wire.reset();
154  m_nOutInterests = nOutInterests;
155  return *this;
156  }
157 
158  uint64_t
159  getNOutDatas() const
160  {
161  return m_nOutDatas;
162  }
163 
164  FaceStatus&
165  setNOutDatas(uint64_t nOutDatas)
166  {
167  m_wire.reset();
168  m_nOutDatas = nOutDatas;
169  return *this;
170  }
171 
172 private:
173  uint64_t m_faceId;
174  std::string m_remoteUri;
175  std::string m_localUri;
176  uint64_t m_flags;
177  uint64_t m_nInInterests;
178  uint64_t m_nInDatas;
179  uint64_t m_nOutInterests;
180  uint64_t m_nOutDatas;
181 
182  mutable Block m_wire;
183 };
184 
185 inline
187  : m_faceId(0)
188  , m_flags(0)
189  , m_nInInterests(0)
190  , m_nInDatas(0)
191  , m_nOutInterests(0)
192  , m_nOutDatas(0)
193 {
194 }
195 
196 template<bool T>
197 inline size_t
199 {
200  size_t totalLength = 0;
201 
202  totalLength += prependNonNegativeIntegerBlock(encoder,
203  tlv::nfd::NOutDatas, m_nOutDatas);
204  totalLength += prependNonNegativeIntegerBlock(encoder,
205  tlv::nfd::NOutInterests, m_nOutInterests);
206  totalLength += prependNonNegativeIntegerBlock(encoder,
207  tlv::nfd::NInDatas, m_nInDatas);
208  totalLength += prependNonNegativeIntegerBlock(encoder,
209  tlv::nfd::NInInterests, m_nInInterests);
210  totalLength += prependNonNegativeIntegerBlock(encoder,
211  tlv::nfd::FaceFlags, m_flags);
212  totalLength += prependByteArrayBlock(encoder, tlv::nfd::LocalUri,
213  reinterpret_cast<const uint8_t*>(m_localUri.c_str()), m_localUri.size());
214  totalLength += prependByteArrayBlock(encoder, tlv::nfd::Uri,
215  reinterpret_cast<const uint8_t*>(m_remoteUri.c_str()), m_remoteUri.size());
216  totalLength += prependNonNegativeIntegerBlock(encoder,
217  tlv::nfd::FaceId, m_faceId);
218 
219  totalLength += encoder.prependVarNumber(totalLength);
220  totalLength += encoder.prependVarNumber(tlv::nfd::FaceStatus);
221  return totalLength;
222 }
223 
224 inline const Block&
226 {
227  if (m_wire.hasWire())
228  return m_wire;
229 
230  EncodingEstimator estimator;
231  size_t estimatedSize = wireEncode(estimator);
232 
233  EncodingBuffer buffer(estimatedSize, 0);
234  wireEncode(buffer);
235 
236  m_wire = buffer.block();
237  return m_wire;
238 }
239 
240 inline void
242 {
243  if (block.type() != tlv::nfd::FaceStatus) {
244  throw Error("expecting FaceStatus block");
245  }
246  m_wire = block;
247  m_wire.parse();
249 
250  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) {
251  m_faceId = static_cast<uint64_t>(readNonNegativeInteger(*val));
252  ++val;
253  }
254  else {
255  throw Error("missing required FaceId field");
256  }
257 
258  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Uri) {
259  m_remoteUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
260  ++val;
261  }
262  else {
263  throw Error("missing required Uri field");
264  }
265 
266  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) {
267  m_localUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
268  ++val;
269  }
270  else {
271  throw Error("missing required LocalUri field");
272  }
273 
274  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceFlags) {
275  m_flags = static_cast<uint64_t>(readNonNegativeInteger(*val));
276  ++val;
277  }
278  else {
279  throw Error("missing required FaceFlags field");
280  }
281 
282  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInInterests) {
283  m_nInInterests = static_cast<uint64_t>(readNonNegativeInteger(*val));
284  ++val;
285  }
286  else {
287  throw Error("missing required NInInterests field");
288  }
289 
290  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NInDatas) {
291  m_nInDatas = static_cast<uint64_t>(readNonNegativeInteger(*val));
292  ++val;
293  }
294  else {
295  throw Error("missing required NInDatas field");
296  }
297 
298  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutInterests) {
299  m_nOutInterests = static_cast<uint64_t>(readNonNegativeInteger(*val));
300  ++val;
301  }
302  else {
303  throw Error("missing required NOutInterests field");
304  }
305 
306  if (val != m_wire.elements_end() && val->type() == tlv::nfd::NOutDatas) {
307  m_nOutDatas = static_cast<uint64_t>(readNonNegativeInteger(*val));
308  ++val;
309  }
310  else {
311  throw Error("missing required NOutDatas field");
312  }
313 }
314 
315 inline std::ostream&
316 operator<<(std::ostream& os, const FaceStatus& status)
317 {
318  os << "FaceStatus("
319  << "FaceID: " << status.getFaceId() << ", "
320  << "RemoteUri: " << status.getRemoteUri() << ", "
321  << "LocalUri: " << status.getLocalUri() << ", "
322  << "Flags: " << status.getFlags() << ", "
323  << "Counters: " << status.getNInInterests() << "|" << status.getNInDatas()
324  << "|" << status.getNOutInterests() << "|" << status.getNOutDatas()
325  << ")";
326  return os;
327 }
328 
329 } // namespace nfd
330 } // namespace ndn
331 
332 #endif // NDN_MANAGEMENT_NFD_FACE_STATUS_HPP
std::ostream & operator<<(std::ostream &os, const ControlParameters &parameters)
void wireDecode(const Block &wire)
decode FaceStatus
uint64_t getFaceId() const
FaceStatus & setNOutDatas(uint64_t nOutDatas)
FaceStatus & setNInDatas(uint64_t nInDatas)
const std::string & getRemoteUri() const
FaceStatus & setNOutInterests(uint64_t nOutInterests)
uint64_t getFlags() const
uint64_t getNInDatas() const
implements getters to each face flag
Class representing wire element of the NDN packet.
Definition: block.hpp:26
const std::string & getLocalUri() const
uint64_t readNonNegativeInteger(const Block &block)
element_const_iterator elements_end() const
Definition: block.hpp:476
FaceStatus & setRemoteUri(const std::string &remoteUri)
element_const_iterator elements_begin() const
Definition: block.hpp:470
uint64_t getNInInterests() const
FaceStatus & setNInInterests(uint64_t nInInterests)
represents Face status
element_container::const_iterator element_const_iterator
Definition: block.hpp:31
FaceStatus(const Block &block)
void reset()
Reset wire buffer of the element.
Definition: block.hpp:300
FaceStatus & setLocalUri(const std::string &localUri)
Error(const std::string &what)
void parse() const
Parse wire buffer into subblocks.
Definition: block.cpp:265
uint32_t type() const
Definition: block.hpp:320
uint64_t getNOutInterests() const
FaceStatus & setFaceId(uint64_t faceId)
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.hpp:288
size_t prependNonNegativeIntegerBlock(EncodingImpl< P > &encoder, uint32_t type, uint64_t number)
helper methods
uint64_t getNOutDatas() const
const Block & wireEncode() const
encode FaceStatus
size_t prependByteArrayBlock(EncodingImpl< P > &encoder, uint32_t type, const uint8_t *array, size_t arraySize)
FaceStatus & setFlags(uint64_t flags)
Class representing wire element of the NDN packet.