NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
face-query-filter.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2019 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 
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>));
34  "FaceQueryFilter::Error must inherit from tlv::Error");
35 
37 
39 {
40  this->wireDecode(block);
41 }
42 
43 template<encoding::Tag TAG>
44 size_t
46 {
47  size_t totalLength = 0;
48 
49  if (m_linkType) {
50  totalLength += prependNonNegativeIntegerBlock(encoder,
51  tlv::nfd::LinkType, *m_linkType);
52  }
53 
54  if (m_facePersistency) {
55  totalLength += prependNonNegativeIntegerBlock(encoder,
56  tlv::nfd::FacePersistency, *m_facePersistency);
57  }
58 
59  if (m_faceScope) {
60  totalLength += prependNonNegativeIntegerBlock(encoder,
61  tlv::nfd::FaceScope, *m_faceScope);
62  }
63 
64  if (hasLocalUri()) {
65  totalLength += prependStringBlock(encoder, tlv::nfd::LocalUri, m_localUri);
66  }
67 
68  if (hasRemoteUri()) {
69  totalLength += prependStringBlock(encoder, tlv::nfd::Uri, m_remoteUri);
70  }
71 
72  if (hasUriScheme()) {
73  totalLength += prependStringBlock(encoder, tlv::nfd::UriScheme, m_uriScheme);
74  }
75 
76  if (m_faceId) {
77  totalLength += prependNonNegativeIntegerBlock(encoder,
78  tlv::nfd::FaceId, *m_faceId);
79  }
80 
81  totalLength += encoder.prependVarNumber(totalLength);
82  totalLength += encoder.prependVarNumber(tlv::nfd::FaceQueryFilter);
83  return totalLength;
84 }
85 
87 
88 const Block&
90 {
91  if (m_wire.hasWire())
92  return m_wire;
93 
94  EncodingEstimator estimator;
95  size_t estimatedSize = wireEncode(estimator);
96 
97  EncodingBuffer buffer(estimatedSize, 0);
98  wireEncode(buffer);
99 
100  m_wire = buffer.block();
101  return m_wire;
102 }
103 
104 void
106 {
107  if (block.type() != tlv::nfd::FaceQueryFilter) {
108  NDN_THROW(Error("FaceQueryFilter", block.type()));
109  }
110 
111  m_wire = block;
112  m_wire.parse();
113  auto val = m_wire.elements_begin();
114 
115  // all fields are optional
116 
117  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) {
118  m_faceId = readNonNegativeInteger(*val);
119  ++val;
120  }
121  else {
122  m_faceId = nullopt;
123  }
124 
125  if (val != m_wire.elements_end() && val->type() == tlv::nfd::UriScheme) {
126  m_uriScheme = readString(*val);
127  ++val;
128  }
129  else {
130  m_uriScheme.clear();
131  }
132 
133  if (val != m_wire.elements_end() && val->type() == tlv::nfd::Uri) {
134  m_remoteUri = readString(*val);
135  ++val;
136  }
137  else {
138  m_remoteUri.clear();
139  }
140 
141  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) {
142  m_localUri = readString(*val);
143  ++val;
144  }
145  else {
146  m_localUri.clear();
147  }
148 
149  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceScope) {
150  m_faceScope = readNonNegativeIntegerAs<FaceScope>(*val);
151  ++val;
152  }
153  else {
154  m_faceScope = nullopt;
155  }
156 
157  if (val != m_wire.elements_end() && val->type() == tlv::nfd::FacePersistency) {
158  m_facePersistency = readNonNegativeIntegerAs<FacePersistency>(*val);
159  ++val;
160  }
161  else {
162  m_facePersistency = nullopt;
163  }
164 
165  if (val != m_wire.elements_end() && val->type() == tlv::nfd::LinkType) {
166  m_linkType = readNonNegativeIntegerAs<LinkType>(*val);
167  ++val;
168  }
169  else {
170  m_linkType = nullopt;
171  }
172 }
173 
174 bool
176 {
177  return !this->hasFaceId() &&
178  !this->hasUriScheme() &&
179  !this->hasRemoteUri() &&
180  !this->hasLocalUri() &&
181  !this->hasFaceScope() &&
182  !this->hasFacePersistency() &&
183  !this->hasLinkType();
184 }
185 
188 {
189  m_wire.reset();
190  m_faceId = faceId;
191  return *this;
192 }
193 
196 {
197  m_wire.reset();
198  m_faceId = nullopt;
199  return *this;
200 }
201 
203 FaceQueryFilter::setUriScheme(const std::string& uriScheme)
204 {
205  m_wire.reset();
206  m_uriScheme = uriScheme;
207  return *this;
208 }
209 
212 {
213  return this->setUriScheme("");
214 }
215 
217 FaceQueryFilter::setRemoteUri(const std::string& remoteUri)
218 {
219  m_wire.reset();
220  m_remoteUri = remoteUri;
221  return *this;
222 }
223 
226 {
227  return this->setRemoteUri("");
228 }
229 
231 FaceQueryFilter::setLocalUri(const std::string& localUri)
232 {
233  m_wire.reset();
234  m_localUri = localUri;
235  return *this;
236 }
237 
240 {
241  return this->setLocalUri("");
242 }
243 
246 {
247  m_wire.reset();
248  m_faceScope = faceScope;
249  return *this;
250 }
251 
254 {
255  m_wire.reset();
256  m_faceScope = nullopt;
257  return *this;
258 }
259 
262 {
263  m_wire.reset();
264  m_facePersistency = facePersistency;
265  return *this;
266 }
267 
270 {
271  m_wire.reset();
272  m_facePersistency = nullopt;
273  return *this;
274 }
275 
278 {
279  m_wire.reset();
280  m_linkType = linkType;
281  return *this;
282 }
283 
286 {
287  m_wire.reset();
288  m_linkType = nullopt;
289  return *this;
290 }
291 
292 bool
294 {
295  return a.hasFaceId() == b.hasFaceId() &&
296  (!a.hasFaceId() || a.getFaceId() == b.getFaceId()) &&
297  a.hasUriScheme() == b.hasUriScheme() &&
298  (!a.hasUriScheme() || a.getUriScheme() == b.getUriScheme()) &&
299  a.hasRemoteUri() == b.hasRemoteUri() &&
300  (!a.hasRemoteUri() || a.getRemoteUri() == b.getRemoteUri()) &&
301  a.hasLocalUri() == b.hasLocalUri() &&
302  (!a.hasLocalUri() || a.getLocalUri() == b.getLocalUri()) &&
303  a.hasFaceScope() == b.hasFaceScope() &&
304  (!a.hasFaceScope() || a.getFaceScope() == b.getFaceScope()) &&
307  a.hasLinkType() == b.hasLinkType() &&
308  (!a.hasLinkType() || a.getLinkType() == b.getLinkType());
309 }
310 
311 std::ostream&
312 operator<<(std::ostream& os, const FaceQueryFilter& filter)
313 {
314  os << "FaceQueryFilter(";
315  if (filter.hasFaceId()) {
316  os << "FaceID: " << filter.getFaceId() << ",\n";
317  }
318 
319  if (filter.hasUriScheme()) {
320  os << "UriScheme: " << filter.getUriScheme() << ",\n";
321  }
322 
323  if (filter.hasRemoteUri()) {
324  os << "RemoteUri: " << filter.getRemoteUri() << ",\n";
325  }
326 
327  if (filter.hasLocalUri()) {
328  os << "LocalUri: " << filter.getLocalUri() << ",\n";
329  }
330 
331  if (filter.hasFaceScope()) {
332  os << "FaceScope: " << filter.getFaceScope() << ",\n";
333  }
334 
335  if (filter.hasFacePersistency()) {
336  os << "FacePersistency: " << filter.getFacePersistency() << ",\n";
337  }
338 
339  if (filter.hasLinkType()) {
340  os << "LinkType: " << filter.getLinkType() << ",\n";
341  }
342  os << ")";
343  return os;
344 }
345 
346 } // namespace nfd
347 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
FaceQueryFilter & unsetLocalUri()
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
const std::string & getLocalUri() const
void parse() const
Parse TLV-VALUE into sub-elements.
Definition: block.cpp:324
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus)
Represents a TLV element of the NDN packet format.
Definition: block.hpp:44
const std::string & getRemoteUri() const
size_t prependStringBlock(EncodingImpl< TAG > &encoder, uint32_t type, const std::string &value)
Prepend a TLV element containing a string.
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Definition: block.hpp:221
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:433
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
#define NDN_THROW(e)
Definition: exception.hpp:61
FaceQueryFilter & unsetFaceScope()
FaceQueryFilter & setLocalUri(const std::string &localUri)
element_const_iterator elements_end() const
Equivalent to elements().end()
Definition: block.hpp:441
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
void reset() noexcept
Reset the Block to a default-constructed state.
Definition: block.cpp:254
bool operator==(const ChannelStatus &a, const ChannelStatus &b)
const Block & wireEncode() const
encode FaceQueryFilter
FaceQueryFilter & setFaceScope(FaceScope faceScope)
FaceQueryFilter & unsetFaceId()
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
FaceQueryFilter & setUriScheme(const std::string &uriScheme)
FaceQueryFilter & unsetFacePersistency()
represents Face Query Filter
FaceQueryFilter & unsetUriScheme()
FaceQueryFilter & unsetRemoteUri()
FaceQueryFilter & setRemoteUri(const std::string &remoteUri)
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
Definition: block.hpp:277
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:44
void wireDecode(const Block &wire)
decode FaceQueryFilter
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
Definition: concepts.hpp:80
EncodingImpl< EncoderTag > EncodingBuffer
const nullopt_t nullopt((nullopt_t::init()))
EncodingImpl< EstimatorTag > EncodingEstimator
FaceQueryFilter & unsetLinkType()