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>));
33 static_assert(std::is_base_of<tlv::Error, FaceQueryFilter::Error>::value,
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
ndn::nfd::FaceQueryFilter::getFaceId
uint64_t getFaceId() const
Definition: face-query-filter.hpp:79
ndn::tlv::nfd::LinkType
@ LinkType
Definition: tlv-nfd.hpp:69
ndn::nfd::FaceQueryFilter::setLinkType
FaceQueryFilter & setLinkType(LinkType linkType)
Definition: face-query-filter.cpp:277
ndn::tlv::nfd::FaceId
@ FaceId
Definition: tlv-nfd.hpp:36
ndn::nfd::FaceQueryFilter::getUriScheme
const std::string & getUriScheme() const
Definition: face-query-filter.hpp:98
ndn::nfd::operator<<
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
Definition: nfd-constants.cpp:36
ndn::nfd::FaceQueryFilter::wireDecode
void wireDecode(const Block &wire)
decode FaceQueryFilter
Definition: face-query-filter.cpp:105
ndn::nfd::FaceQueryFilter::getFaceScope
FaceScope getFaceScope() const
Definition: face-query-filter.hpp:155
ndn::nfd::FaceQueryFilter::hasFaceScope
bool hasFaceScope() const
Definition: face-query-filter.hpp:149
ndn::Block::elements_begin
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition: block.hpp:399
ndn::nfd::FaceQueryFilter::hasLinkType
bool hasLinkType() const
Definition: face-query-filter.hpp:187
ndn::nfd::FaceQueryFilter::wireEncode
const Block & wireEncode() const
encode FaceQueryFilter
Definition: face-query-filter.cpp:89
ndn::nfd::FaceQueryFilter::unsetFaceId
FaceQueryFilter & unsetFaceId()
Definition: face-query-filter.cpp:195
ndn::nfd::FaceQueryFilter::unsetUriScheme
FaceQueryFilter & unsetUriScheme()
Definition: face-query-filter.cpp:211
ndn::encoding::readString
std::string readString(const Block &block)
Read TLV-VALUE of a TLV element as a string.
Definition: block-helpers.cpp:122
ndn::nfd::LinkType
LinkType
Definition: nfd-constants.hpp:57
face-query-filter.hpp
concepts.hpp
ndn::Block::reset
void reset() noexcept
Reset the Block to a default-constructed state.
Definition: block.cpp:250
ndn::nfd::FaceQueryFilter::setUriScheme
FaceQueryFilter & setUriScheme(const std::string &uriScheme)
Definition: face-query-filter.cpp:203
ndn::nfd::FacePersistency
FacePersistency
Definition: nfd-constants.hpp:45
ndn::nfd::FaceQueryFilter::hasFacePersistency
bool hasFacePersistency() const
Definition: face-query-filter.hpp:168
ndn::WireDecodable
a concept check for TLV abstraction with .wireDecode method and constructible from Block
Definition: concepts.hpp:81
ndn::encoding::EncodingEstimator
EncodingImpl< EstimatorTag > EncodingEstimator
Definition: encoding-buffer-fwd.hpp:39
ndn::encoding::readNonNegativeInteger
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
Definition: block-helpers.cpp:64
ndn::nfd::FaceQueryFilter::setFaceId
FaceQueryFilter & setFaceId(uint64_t faceId)
Definition: face-query-filter.cpp:187
ndn::nfd::FaceQueryFilter::hasLocalUri
bool hasLocalUri() const
Definition: face-query-filter.hpp:130
ndn::nfd::FaceQueryFilter::hasUriScheme
bool hasUriScheme() const
Definition: face-query-filter.hpp:92
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
ndn::Block::type
uint32_t type() const
Return the TLV-TYPE of the Block.
Definition: block.hpp:274
ndn::WireEncodable
a concept check for TLV abstraction with .wireEncode method
Definition: concepts.hpp:45
ndn::nfd::FaceQueryFilter::hasRemoteUri
bool hasRemoteUri() const
Definition: face-query-filter.hpp:111
ndn::nfd::FaceQueryFilter::getLocalUri
const std::string & getLocalUri() const
Definition: face-query-filter.hpp:136
ndn::tlv::nfd::Uri
@ Uri
Definition: tlv-nfd.hpp:37
ndn::tlv::nfd::FaceQueryFilter
@ FaceQueryFilter
Definition: tlv-nfd.hpp:73
ndn::nfd::FaceQueryFilter::setFaceScope
FaceQueryFilter & setFaceScope(FaceScope faceScope)
Definition: face-query-filter.cpp:245
NDN_THROW
#define NDN_THROW(e)
Definition: exception.hpp:61
nonstd::optional_lite::nullopt
const nullopt_t nullopt((nullopt_t::init()))
ndn::nfd::FaceQueryFilter::Error
Definition: face-query-filter.hpp:40
ndn::nfd::FaceQueryFilter::setRemoteUri
FaceQueryFilter & setRemoteUri(const std::string &remoteUri)
Definition: face-query-filter.cpp:217
ndn::nfd::FaceQueryFilter::getLinkType
LinkType getLinkType() const
Definition: face-query-filter.hpp:193
ndn::nfd::FaceQueryFilter::setFacePersistency
FaceQueryFilter & setFacePersistency(FacePersistency facePersistency)
Definition: face-query-filter.cpp:261
ndn::tlv::nfd::UriScheme
@ UriScheme
Definition: tlv-nfd.hpp:66
ndn::nfd::FaceQueryFilter::getFacePersistency
FacePersistency getFacePersistency() const
Definition: face-query-filter.hpp:174
ndn::Block::parse
void parse() const
Parse TLV-VALUE into sub-elements.
Definition: block.cpp:325
ndn::encoding::prependNonNegativeIntegerBlock
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
Definition: block-helpers.cpp:35
ndn::nfd::FaceQueryFilter::getRemoteUri
const std::string & getRemoteUri() const
Definition: face-query-filter.hpp:117
ndn::encoding::EncodingImpl
Definition: encoding-buffer-fwd.hpp:36
tlv-nfd.hpp
block-helpers.hpp
ndn::nfd::FaceQueryFilter::unsetRemoteUri
FaceQueryFilter & unsetRemoteUri()
Definition: face-query-filter.cpp:225
ndn::nfd::FaceQueryFilter::unsetFacePersistency
FaceQueryFilter & unsetFacePersistency()
Definition: face-query-filter.cpp:269
ndn::nfd::FaceQueryFilter::unsetFaceScope
FaceQueryFilter & unsetFaceScope()
Definition: face-query-filter.cpp:253
ndn::nfd::FaceQueryFilter::setLocalUri
FaceQueryFilter & setLocalUri(const std::string &localUri)
Definition: face-query-filter.cpp:231
ndn::tlv::nfd::FacePersistency
@ FacePersistency
Definition: tlv-nfd.hpp:68
ndn::nfd::FaceQueryFilter::FaceQueryFilter
FaceQueryFilter()
ndn::Block
Represents a TLV element of NDN packet format.
Definition: block.hpp:43
ndn::Block::elements_end
element_const_iterator elements_end() const
Equivalent to elements().end()
Definition: block.hpp:407
ndn::Block::hasWire
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Definition: block.hpp:230
ndn::tlv::nfd::LocalUri
@ LocalUri
Definition: tlv-nfd.hpp:64
ndn::tlv::nfd::FaceScope
@ FaceScope
Definition: tlv-nfd.hpp:67
ndn::nfd::operator==
bool operator==(const ChannelStatus &a, const ChannelStatus &b)
Definition: channel-status.cpp:97
ndn::nfd::FaceQueryFilter::empty
bool empty() const
Definition: face-query-filter.cpp:175
ndn::encoding::prependStringBlock
size_t prependStringBlock(EncodingImpl< TAG > &encoder, uint32_t type, const std::string &value)
Prepend a TLV element containing a string.
Definition: block-helpers.cpp:104
ndn::nfd::NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus)
ndn::nfd::FaceScope
FaceScope
Definition: nfd-constants.hpp:34
ndn::nfd::FaceQueryFilter::hasFaceId
bool hasFaceId() const
Definition: face-query-filter.hpp:73
ndn::nfd::FaceQueryFilter
represents Face Query Filter
Definition: face-query-filter.hpp:37
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::encoding::EncodingBuffer
EncodingImpl< EncoderTag > EncodingBuffer
Definition: encoding-buffer-fwd.hpp:38
ndn::nfd::FaceQueryFilter::unsetLocalUri
FaceQueryFilter & unsetLocalUri()
Definition: face-query-filter.cpp:239
ndn::nfd::FaceQueryFilter::unsetLinkType
FaceQueryFilter & unsetLinkType()
Definition: face-query-filter.cpp:285