NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
interest.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_INTEREST_HPP
23 #define NDN_INTEREST_HPP
24 
25 #include "common.hpp"
26 
27 #include "name.hpp"
28 #include "selectors.hpp"
29 #include "util/time.hpp"
30 #include "lp/tags.hpp"
31 #include "tag-host.hpp"
32 #include "link.hpp"
33 
34 namespace ndn {
35 
36 class Data;
37 
41 const time::milliseconds DEFAULT_INTEREST_LIFETIME = time::milliseconds(4000);
42 
45 class Interest : public TagHost, public enable_shared_from_this<Interest>
46 {
47 public:
48  class Error : public tlv::Error
49  {
50  public:
51  explicit
52  Error(const std::string& what)
53  : tlv::Error(what)
54  {
55  }
56  };
57 
62  Interest();
63 
70  Interest(const Name& name);
71 
78  Interest(const Name& name, const time::milliseconds& interestLifetime);
79 
84  explicit
85  Interest(const Block& wire);
86 
90  template<encoding::Tag TAG>
91  size_t
92  wireEncode(EncodingImpl<TAG>& encoder) const;
93 
97  const Block&
98  wireEncode() const;
99 
103  void
104  wireDecode(const Block& wire);
105 
109  bool
110  hasWire() const
111  {
112  return m_wire.hasWire();
113  }
114 
121  std::string
122  toUri() const;
123 
124 public: // Link and forwarding hint
125 
130  bool
131  hasLink() const;
132 
139  const Link&
140  getLink() const;
141 
147  void
148  setLink(const Block& link);
149 
154  void
155  unsetLink();
156 
161  bool
162  hasSelectedDelegation() const;
163 
169  Name
170  getSelectedDelegation() const;
171 
178  void
179  setSelectedDelegation(const Name& delegationName);
180 
187  void
188  setSelectedDelegation(size_t delegationIndex);
189 
193  void
195 
196 public: // matching
201  bool
202  matchesName(const Name& name) const;
203 
213  bool
214  matchesData(const Data& data) const;
215 
216 public: // Name and guiders
217  const Name&
218  getName() const
219  {
220  return m_name;
221  }
222 
223  Interest&
224  setName(const Name& name)
225  {
226  m_name = name;
227  m_wire.reset();
228  return *this;
229  }
230 
231  const time::milliseconds&
233  {
234  return m_interestLifetime;
235  }
236 
237  Interest&
238  setInterestLifetime(const time::milliseconds& interestLifetime)
239  {
240  m_interestLifetime = interestLifetime;
241  m_wire.reset();
242  return *this;
243  }
244 
247  bool
248  hasNonce() const
249  {
250  return m_nonce.hasWire();
251  }
252 
257  uint32_t
258  getNonce() const;
259 
265  Interest&
266  setNonce(uint32_t nonce);
267 
275  void
276  refreshNonce();
277 
278 #ifdef NDN_LP_KEEP_LOCAL_CONTROL_HEADER
279 public: // local control header
282  DEPRECATED(
284  getLocalControlHeader());
285 
288  DEPRECATED(
290  getLocalControlHeader() const);
291 
294  DEPRECATED(
295  uint64_t
296  getIncomingFaceId() const);
297 
300  DEPRECATED(
301  Interest&
302  setIncomingFaceId(uint64_t incomingFaceId));
303 
306  DEPRECATED(
307  uint64_t
308  getNextHopFaceId() const);
309 
312  DEPRECATED(
313  Interest&
314  setNextHopFaceId(uint64_t nextHopFaceId));
315 #endif // NDN_LP_KEEP_LOCAL_CONTROL_HEADER
316 
317 public: // Selectors
321  bool
322  hasSelectors() const
323  {
324  return !m_selectors.empty();
325  }
326 
327  const Selectors&
328  getSelectors() const
329  {
330  return m_selectors;
331  }
332 
333  Interest&
334  setSelectors(const Selectors& selectors)
335  {
336  m_selectors = selectors;
337  m_wire.reset();
338  return *this;
339  }
340 
341  int
343  {
344  return m_selectors.getMinSuffixComponents();
345  }
346 
347  Interest&
348  setMinSuffixComponents(int minSuffixComponents)
349  {
350  m_selectors.setMinSuffixComponents(minSuffixComponents);
351  m_wire.reset();
352  return *this;
353  }
354 
355  int
357  {
358  return m_selectors.getMaxSuffixComponents();
359  }
360 
361  Interest&
362  setMaxSuffixComponents(int maxSuffixComponents)
363  {
364  m_selectors.setMaxSuffixComponents(maxSuffixComponents);
365  m_wire.reset();
366  return *this;
367  }
368 
369  const KeyLocator&
371  {
372  return m_selectors.getPublisherPublicKeyLocator();
373  }
374 
375  Interest&
377  {
378  m_selectors.setPublisherPublicKeyLocator(keyLocator);
379  m_wire.reset();
380  return *this;
381  }
382 
383  const Exclude&
384  getExclude() const
385  {
386  return m_selectors.getExclude();
387  }
388 
389  Interest&
390  setExclude(const Exclude& exclude)
391  {
392  m_selectors.setExclude(exclude);
393  m_wire.reset();
394  return *this;
395  }
396 
397  int
399  {
400  return m_selectors.getChildSelector();
401  }
402 
403  Interest&
404  setChildSelector(int childSelector)
405  {
406  m_selectors.setChildSelector(childSelector);
407  m_wire.reset();
408  return *this;
409  }
410 
411  int
413  {
414  return m_selectors.getMustBeFresh();
415  }
416 
417  Interest&
418  setMustBeFresh(bool mustBeFresh)
419  {
420  m_selectors.setMustBeFresh(mustBeFresh);
421  m_wire.reset();
422  return *this;
423  }
424 
425 public: // EqualityComparable concept
426  bool
427  operator==(const Interest& other) const
428  {
429  return wireEncode() == other.wireEncode();
430  }
431 
432  bool
433  operator!=(const Interest& other) const
434  {
435  return !(*this == other);
436  }
437 
438 private:
439  Name m_name;
440  Selectors m_selectors;
441  mutable Block m_nonce;
442  time::milliseconds m_interestLifetime;
443 
444  mutable Block m_link;
445  mutable shared_ptr<Link> m_linkCached;
446  size_t m_selectedDelegationIndex;
447  mutable Block m_wire;
448 };
449 
450 std::ostream&
451 operator<<(std::ostream& os, const Interest& interest);
452 
453 inline std::string
455 {
456  std::ostringstream os;
457  os << *this;
458  return os.str();
459 }
460 
461 } // namespace ndn
462 
463 #endif // NDN_INTEREST_HPP
const Block & wireEncode() const
Encode to a wire format.
Definition: interest.cpp:277
Copyright (c) 2011-2015 Regents of the University of California.
int getChildSelector() const
Definition: interest.hpp:398
bool operator==(const Interest &other) const
Definition: interest.hpp:427
const Selectors & getSelectors() const
Definition: interest.hpp:328
Interest & setMustBeFresh(bool mustBeFresh)
Definition: interest.hpp:418
void setSelectedDelegation(const Name &delegationName)
Set the selected delegation.
Definition: interest.cpp:418
const Link & getLink() const
Get the link object for this interest.
Definition: interest.cpp:370
std::string toUri() const
Encode the name according to the NDN URI Scheme.
Definition: interest.hpp:454
int getMustBeFresh() const
Definition: interest.hpp:412
Base class to store tag information (e.g., inside Interest and Data packets)
Definition: tag-host.hpp:34
void refreshNonce()
Refresh nonce.
Definition: interest.cpp:91
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:320
bool matchesName(const Name &name) const
Check if Interest, including selectors, matches the given name.
Definition: interest.cpp:105
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
represents an Interest packet
Definition: interest.hpp:45
Copyright (c) 2013-2015 Regents of the University of California.
DEPRECATED(lp::LocalControlHeaderFacade getLocalControlHeader())
bool hasNonce() const
Check if Nonce set.
Definition: interest.hpp:248
void unsetSelectedDelegation()
Unset the selected delegation.
Definition: interest.cpp:441
int getMaxSuffixComponents() const
Definition: interest.hpp:356
Name getSelectedDelegation() const
Get the name of the selected delegation.
Definition: interest.cpp:409
const time::milliseconds & getInterestLifetime() const
Definition: interest.hpp:232
Interest()
Create a new Interest with an empty name (ndn:/)
Definition: interest.cpp:36
const KeyLocator & getPublisherPublicKeyLocator() const
Definition: interest.hpp:370
void setLink(const Block &link)
Set the link object for this interest.
Definition: interest.cpp:382
Error(const std::string &what)
Definition: interest.hpp:52
Interest & setExclude(const Exclude &exclude)
Definition: interest.hpp:390
Interest & setChildSelector(int childSelector)
Definition: interest.hpp:404
Interest & setName(const Name &name)
Definition: interest.hpp:224
uint32_t getNonce() const
Get Interest&#39;s nonce.
Definition: interest.cpp:62
Interest & setNonce(uint32_t nonce)
Set Interest&#39;s nonce.
Definition: interest.cpp:76
Interest & setPublisherPublicKeyLocator(const KeyLocator &keyLocator)
Definition: interest.hpp:376
Abstraction implementing Interest selectors.
Definition: selectors.hpp:34
Interest & setMinSuffixComponents(int minSuffixComponents)
Definition: interest.hpp:348
bool operator!=(const Interest &other) const
Definition: interest.hpp:433
bool matchesData(const Data &data) const
Check if Interest can be satisfied by data.
Definition: interest.cpp:132
Interest & setMaxSuffixComponents(int maxSuffixComponents)
Definition: interest.hpp:362
Name abstraction to represent an absolute name.
Definition: name.hpp:46
expose NDNLPv2 tags as LocalControlHeader API
Definition: tags.hpp:64
const Exclude & getExclude() const
Definition: interest.hpp:384
void unsetLink()
Delete the link object for this interest.
Definition: interest.cpp:394
bool hasWire() const
Check if already has wire.
Definition: interest.hpp:110
Interest & setSelectors(const Selectors &selectors)
Definition: interest.hpp:334
void wireDecode(const Block &wire)
Decode from the wire format.
Definition: interest.cpp:295
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Definition: interest.cpp:217
int getMinSuffixComponents() const
Definition: interest.hpp:342
bool hasLink() const
Check whether the Interest contains a Link object.
Definition: interest.cpp:364
const time::milliseconds DEFAULT_INTEREST_LIFETIME
default value for InterestLifetime
Definition: interest.hpp:41
bool hasSelectedDelegation() const
Check whether the Interest includes a selected delegation.
Definition: interest.cpp:403
represents a Data packet
Definition: data.hpp:39
Interest & setInterestLifetime(const time::milliseconds &interestLifetime)
Definition: interest.hpp:238
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
Class to represent Exclude component in NDN interests.
Definition: exclude.hpp:38
bool hasSelectors() const
Definition: interest.hpp:322
const Name & getName() const
Definition: interest.hpp:218