NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
nfd-face-query-filter.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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<FaceQueryFilter>));
31 BOOST_CONCEPT_ASSERT((WireEncodable<FaceQueryFilter>));
32 BOOST_CONCEPT_ASSERT((WireDecodable<FaceQueryFilter>));
33 static_assert(std::is_base_of<tlv::Error, FaceQueryFilter::Error>::value,
34  "FaceQueryFilter::Error must inherit from tlv::Error");
35 
37  : m_hasFaceId(false)
38  , m_hasUriScheme(false)
39  , m_hasRemoteUri(false)
40  , m_hasLocalUri(false)
41  , m_hasFaceScope(false)
42  , m_hasFacePersistency(false)
43  , m_hasLinkType(false)
44 {
45 }
46 
48 {
49  this->wireDecode(block);
50 }
51 
52 template<encoding::Tag TAG>
53 size_t
55 {
56  size_t totalLength = 0;
57 
58  if (m_hasLinkType) {
59  totalLength += prependNonNegativeIntegerBlock(encoder,
60  tlv::nfd::LinkType, m_linkType);
61  }
62 
63  if (m_hasFacePersistency) {
64  totalLength += prependNonNegativeIntegerBlock(encoder,
65  tlv::nfd::FacePersistency, m_facePersistency);
66  }
67 
68  if (m_hasFaceScope) {
69  totalLength += prependNonNegativeIntegerBlock(encoder,
70  tlv::nfd::FaceScope, m_faceScope);
71  }
72 
73  if (m_hasLocalUri) {
74  totalLength += encoder.prependByteArrayBlock(tlv::nfd::LocalUri,
75  reinterpret_cast<const uint8_t*>(m_localUri.c_str()), m_localUri.size());
76  }
77 
78  if (m_hasRemoteUri) {
79  totalLength += encoder.prependByteArrayBlock(tlv::nfd::Uri,
80  reinterpret_cast<const uint8_t*>(m_remoteUri.c_str()), m_remoteUri.size());
81  }
82 
83  if (m_hasUriScheme) {
84  totalLength += encoder.prependByteArrayBlock(tlv::nfd::UriScheme,
85  reinterpret_cast<const uint8_t*>(m_uriScheme.c_str()), m_uriScheme.size());
86  }
87 
88  if (m_hasFaceId) {
89  totalLength += prependNonNegativeIntegerBlock(encoder,
90  tlv::nfd::FaceId, m_faceId);
91  }
92 
93  totalLength += encoder.prependVarNumber(totalLength);
94  totalLength += encoder.prependVarNumber(tlv::nfd::FaceQueryFilter);
95  return totalLength;
96 }
97 
98 template size_t
99 FaceQueryFilter::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>&) const;
100 
101 template size_t
102 FaceQueryFilter::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>&) const;
103 
104 const Block&
106 {
107  if (m_wire.hasWire())
108  return m_wire;
109 
110  EncodingEstimator estimator;
111  size_t estimatedSize = wireEncode(estimator);
112 
113  EncodingBuffer buffer(estimatedSize, 0);
114  wireEncode(buffer);
115 
116  m_wire = buffer.block();
117  return m_wire;
118 }
119 
120 void
122 {
123  //all fields are optional
124  if (block.type() != tlv::nfd::FaceQueryFilter) {
125  BOOST_THROW_EXCEPTION(Error("expecting FaceQueryFilter block"));
126  }
127 
128  m_wire = block;
129  m_wire.parse();
131 
132  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) {
133  m_faceId = readNonNegativeInteger(*val);
134  m_hasFaceId = true;
135  ++val;
136  }
137  else {
138  m_hasFaceId = false;
139  }
140 
141  if (val != m_wire.elements_end() && val->type() == tlv::nfd::UriScheme) {
142  m_uriScheme.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
143  m_hasUriScheme = true;
144  ++val;
145  }
146  else {
147  m_hasUriScheme = false;
148  }
149 
150  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Uri) {
151  m_remoteUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
152  m_hasRemoteUri = true;
153  ++val;
154  }
155  else {
156  m_hasRemoteUri = false;
157  }
158 
159  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) {
160  m_localUri.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
161  m_hasLocalUri = true;
162  ++val;
163  }
164  else {
165  m_hasLocalUri = false;
166  }
167 
168  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceScope) {
169  m_faceScope = static_cast<FaceScope>(readNonNegativeInteger(*val));
170  m_hasFaceScope = true;
171  ++val;
172  }
173  else {
174  m_hasFaceScope = false;
175  }
176 
177  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FacePersistency) {
178  m_facePersistency = static_cast<FacePersistency>(readNonNegativeInteger(*val));
179  m_hasFacePersistency = true;
180  ++val;
181  }
182  else {
183  m_hasFacePersistency = false;
184  }
185 
186  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LinkType) {
187  m_linkType = static_cast<LinkType>(readNonNegativeInteger(*val));
188  m_hasLinkType = true;
189  ++val;
190  }
191  else {
192  m_hasLinkType = false;
193  }
194 
195 }
196 
199 {
200  m_wire.reset();
201  m_faceId = faceId;
202  m_hasFaceId = true;
203  return *this;
204 }
205 
208 {
209  m_wire.reset();
210  m_hasFaceId = false;
211  return *this;
212 }
213 
215 FaceQueryFilter::setUriScheme(const std::string& uriScheme)
216 {
217  m_wire.reset();
218  m_uriScheme = uriScheme;
219  m_hasUriScheme = true;
220  return *this;
221 }
222 
225 {
226  m_wire.reset();
227  m_hasUriScheme = false;
228  return *this;
229 }
230 
232 FaceQueryFilter::setRemoteUri(const std::string& remoteUri)
233 {
234  m_wire.reset();
235  m_remoteUri = remoteUri;
236  m_hasRemoteUri = true;
237  return *this;
238 }
239 
242 {
243  m_wire.reset();
244  m_hasRemoteUri = false;
245  return *this;
246 }
247 
249 FaceQueryFilter::setLocalUri(const std::string& localUri)
250 {
251  m_wire.reset();
252  m_localUri = localUri;
253  m_hasLocalUri = true;
254  return *this;
255 }
256 
259 {
260  m_wire.reset();
261  m_hasLocalUri = false;
262  return *this;
263 }
264 
267 {
268  m_wire.reset();
269  m_faceScope = faceScope;
270  m_hasFaceScope = true;
271  return *this;
272 }
273 
276 {
277  m_wire.reset();
278  m_hasFaceScope = false;
279  return *this;
280 }
281 
284 {
285  m_wire.reset();
286  m_facePersistency = facePersistency;
287  m_hasFacePersistency = true;
288  return *this;
289 }
290 
293 {
294  m_wire.reset();
295  m_hasFacePersistency = false;
296  return *this;
297 }
298 
301 {
302  m_wire.reset();
303  m_linkType = linkType;
304  m_hasLinkType = true;
305  return *this;
306 }
307 
310 {
311  m_wire.reset();
312  m_hasLinkType = false;
313  return *this;
314 }
315 
316 std::ostream&
317 operator<<(std::ostream& os, const FaceQueryFilter& filter)
318 {
319  os << "FaceQueryFilter(";
320  if (filter.hasFaceId()) {
321  os << "FaceID: " << filter.getFaceId() << ",\n";
322  }
323 
324  if (filter.hasUriScheme()) {
325  os << "UriScheme: " << filter.getUriScheme() << ",\n";
326  }
327 
328  if (filter.hasRemoteUri()) {
329  os << "RemoteUri: " << filter.getRemoteUri() << ",\n";
330  }
331 
332  if (filter.hasLocalUri()) {
333  os << "LocalUri: " << filter.getLocalUri() << ",\n";
334  }
335 
336  if (filter.hasFaceScope()) {
337  os << "FaceScope: " << filter.getFaceScope() << ",\n";
338  }
339 
340  if (filter.hasFacePersistency()) {
341  os << "FacePersistency: " << filter.getFacePersistency() << ",\n";
342  }
343 
344  if (filter.hasLinkType()) {
345  os << "LinkType: " << filter.getLinkType() << ",\n";
346  }
347  os << ")";
348  return os;
349 }
350 
351 } // namespace nfd
352 } // namespace ndn
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
Copyright (c) 2011-2015 Regents of the University of California.
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Helper to prepend TLV block type type containing non-negative integer value.
const std::string & getLocalUri() const
EncodingImpl< EstimatorTag > EncodingEstimator
element_const_iterator elements_end() const
Definition: block.cpp:595
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
const std::string & getRemoteUri() const
uint64_t readNonNegativeInteger(const Block &block)
Helper to read a non-negative integer from a block.
FaceQueryFilter & setLocalUri(const std::string &localUri)
EncodingImpl< EncoderTag > EncodingBuffer
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
const Block & wireEncode() const
encode FaceQueryFilter
FaceQueryFilter & setFaceScope(FaceScope faceScope)
element_container::const_iterator element_const_iterator
Definition: block.hpp:48
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
void reset()
Reset wire buffer of the element.
Definition: block.cpp:302
FaceQueryFilter & setUriScheme(const std::string &uriScheme)
FaceQueryFilter & unsetFacePersistency()
represents Face Query Filter
FaceQueryFilter & setRemoteUri(const std::string &remoteUri)
FaceQueryFilter & setFaceId(uint64_t faceId)
const std::string & getUriScheme() const
FaceQueryFilter & setLinkType(LinkType linkType)
FaceQueryFilter & setFacePersistency(FacePersistency facePersistency)
FacePersistency getFacePersistency() const
a concept check for TLV abstraction with .wireEncode method
Definition: concepts.hpp:34
void wireDecode(const Block &wire)
decode FaceQueryFilter
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