NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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 "name.hpp"
26 #include "selectors.hpp"
27 #include "util/time.hpp"
28 #include "tag-host.hpp"
29 #include "link.hpp"
30 
31 namespace ndn {
32 
33 class Data;
34 
38 const time::milliseconds DEFAULT_INTEREST_LIFETIME = time::milliseconds(4000);
39 
42 class Interest : public TagHost, public enable_shared_from_this<Interest>
43 {
44 public:
45  class Error : public tlv::Error
46  {
47  public:
48  explicit
49  Error(const std::string& what)
50  : tlv::Error(what)
51  {
52  }
53  };
54 
59  Interest();
60 
67  Interest(const Name& name);
68 
75  Interest(const Name& name, const time::milliseconds& interestLifetime);
76 
81  explicit
82  Interest(const Block& wire);
83 
87  template<encoding::Tag TAG>
88  size_t
89  wireEncode(EncodingImpl<TAG>& encoder) const;
90 
94  const Block&
95  wireEncode() const;
96 
100  void
101  wireDecode(const Block& wire);
102 
106  bool
107  hasWire() const
108  {
109  return m_wire.hasWire();
110  }
111 
118  std::string
119  toUri() const;
120 
121 public: // Link and forwarding hint
122 
127  bool
128  hasLink() const;
129 
136  const Link&
137  getLink() const;
138 
144  void
145  setLink(const Block& link);
146 
151  void
152  unsetLink();
153 
158  bool
159  hasSelectedDelegation() const;
160 
166  Name
167  getSelectedDelegation() const;
168 
175  void
176  setSelectedDelegation(const Name& delegationName);
177 
184  void
185  setSelectedDelegation(size_t delegationIndex);
186 
190  void
192 
193 public: // matching
198  bool
199  matchesName(const Name& name) const;
200 
210  bool
211  matchesData(const Data& data) const;
212 
213 public: // Name and guiders
214  const Name&
215  getName() const
216  {
217  return m_name;
218  }
219 
220  Interest&
221  setName(const Name& name)
222  {
223  m_name = name;
224  m_wire.reset();
225  return *this;
226  }
227 
228  const time::milliseconds&
230  {
231  return m_interestLifetime;
232  }
233 
234  Interest&
235  setInterestLifetime(const time::milliseconds& interestLifetime)
236  {
237  m_interestLifetime = interestLifetime;
238  m_wire.reset();
239  return *this;
240  }
241 
244  bool
245  hasNonce() const
246  {
247  return m_nonce.hasWire();
248  }
249 
254  uint32_t
255  getNonce() const;
256 
262  Interest&
263  setNonce(uint32_t nonce);
264 
272  void
273  refreshNonce();
274 
275 public: // Selectors
279  bool
280  hasSelectors() const
281  {
282  return !m_selectors.empty();
283  }
284 
285  const Selectors&
286  getSelectors() const
287  {
288  return m_selectors;
289  }
290 
291  Interest&
292  setSelectors(const Selectors& selectors)
293  {
294  m_selectors = selectors;
295  m_wire.reset();
296  return *this;
297  }
298 
299  int
301  {
302  return m_selectors.getMinSuffixComponents();
303  }
304 
305  Interest&
306  setMinSuffixComponents(int minSuffixComponents)
307  {
308  m_selectors.setMinSuffixComponents(minSuffixComponents);
309  m_wire.reset();
310  return *this;
311  }
312 
313  int
315  {
316  return m_selectors.getMaxSuffixComponents();
317  }
318 
319  Interest&
320  setMaxSuffixComponents(int maxSuffixComponents)
321  {
322  m_selectors.setMaxSuffixComponents(maxSuffixComponents);
323  m_wire.reset();
324  return *this;
325  }
326 
327  const KeyLocator&
329  {
330  return m_selectors.getPublisherPublicKeyLocator();
331  }
332 
333  Interest&
335  {
336  m_selectors.setPublisherPublicKeyLocator(keyLocator);
337  m_wire.reset();
338  return *this;
339  }
340 
341  const Exclude&
342  getExclude() const
343  {
344  return m_selectors.getExclude();
345  }
346 
347  Interest&
348  setExclude(const Exclude& exclude)
349  {
350  m_selectors.setExclude(exclude);
351  m_wire.reset();
352  return *this;
353  }
354 
355  int
357  {
358  return m_selectors.getChildSelector();
359  }
360 
361  Interest&
362  setChildSelector(int childSelector)
363  {
364  m_selectors.setChildSelector(childSelector);
365  m_wire.reset();
366  return *this;
367  }
368 
369  int
371  {
372  return m_selectors.getMustBeFresh();
373  }
374 
375  Interest&
376  setMustBeFresh(bool mustBeFresh)
377  {
378  m_selectors.setMustBeFresh(mustBeFresh);
379  m_wire.reset();
380  return *this;
381  }
382 
383 public: // EqualityComparable concept
384  bool
385  operator==(const Interest& other) const
386  {
387  return wireEncode() == other.wireEncode();
388  }
389 
390  bool
391  operator!=(const Interest& other) const
392  {
393  return !(*this == other);
394  }
395 
396 private:
397  Name m_name;
398  Selectors m_selectors;
399  mutable Block m_nonce;
400  time::milliseconds m_interestLifetime;
401 
402  mutable Block m_link;
403  mutable shared_ptr<Link> m_linkCached;
404  size_t m_selectedDelegationIndex;
405  mutable Block m_wire;
406 };
407 
408 std::ostream&
409 operator<<(std::ostream& os, const Interest& interest);
410 
411 inline std::string
413 {
414  std::ostringstream os;
415  os << *this;
416  return os.str();
417 }
418 
419 } // namespace ndn
420 
421 #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:356
bool operator==(const Interest &other) const
Definition: interest.hpp:385
const Selectors & getSelectors() const
Definition: interest.hpp:286
Interest & setMustBeFresh(bool mustBeFresh)
Definition: interest.hpp:376
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:412
int getMustBeFresh() const
Definition: interest.hpp:370
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:42
bool hasNonce() const
Check if Nonce set.
Definition: interest.hpp:245
void unsetSelectedDelegation()
Unset the selected delegation.
Definition: interest.cpp:441
int getMaxSuffixComponents() const
Definition: interest.hpp:314
Name getSelectedDelegation() const
Get the name of the selected delegation.
Definition: interest.cpp:409
const time::milliseconds & getInterestLifetime() const
Definition: interest.hpp:229
Interest()
Create a new Interest with an empty name (ndn:/)
Definition: interest.cpp:36
const KeyLocator & getPublisherPublicKeyLocator() const
Definition: interest.hpp:328
void setLink(const Block &link)
Set the link object for this interest.
Definition: interest.cpp:382
Error(const std::string &what)
Definition: interest.hpp:49
Interest & setExclude(const Exclude &exclude)
Definition: interest.hpp:348
Interest & setChildSelector(int childSelector)
Definition: interest.hpp:362
Interest & setName(const Name &name)
Definition: interest.hpp:221
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:334
Abstraction implementing Interest selectors.
Definition: selectors.hpp:34
Interest & setMinSuffixComponents(int minSuffixComponents)
Definition: interest.hpp:306
bool operator!=(const Interest &other) const
Definition: interest.hpp:391
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:320
Name abstraction to represent an absolute name.
Definition: name.hpp:46
const Exclude & getExclude() const
Definition: interest.hpp:342
void unsetLink()
Delete the link object for this interest.
Definition: interest.cpp:394
bool hasWire() const
Check if already has wire.
Definition: interest.hpp:107
Interest & setSelectors(const Selectors &selectors)
Definition: interest.hpp:292
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:300
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:38
bool hasSelectedDelegation() const
Check whether the Interest includes a selected delegation.
Definition: interest.cpp:403
represents a Data packet
Definition: data.hpp:37
Interest & setInterestLifetime(const time::milliseconds &interestLifetime)
Definition: interest.hpp:235
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
Represents Exclude selector in NDN Interest.
Definition: exclude.hpp:38
bool hasSelectors() const
Definition: interest.hpp:280
const Name & getName() const
Definition: interest.hpp:215