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"
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 
138  Link
139  getLink() const;
140 
146  void
147  setLink(const Block& link);
148 
152  void
153  unsetLink();
154 
159  bool
160  hasSelectedDelegation() const;
161 
167  Name
168  getSelectedDelegation() const;
169 
176  void
177  setSelectedDelegation(const Name& delegationName);
178 
185  void
186  setSelectedDelegation(size_t delegationIndex);
187 
191  void
193 
194 public: // matching
199  bool
200  matchesName(const Name& name) const;
201 
211  bool
212  matchesData(const Data& data) const;
213 
214 public: // Name and guiders
215  const Name&
216  getName() const
217  {
218  return m_name;
219  }
220 
221  Interest&
222  setName(const Name& name)
223  {
224  m_name = name;
225  m_wire.reset();
226  return *this;
227  }
228 
229  const time::milliseconds&
231  {
232  return m_interestLifetime;
233  }
234 
235  Interest&
236  setInterestLifetime(const time::milliseconds& interestLifetime)
237  {
238  m_interestLifetime = interestLifetime;
239  m_wire.reset();
240  return *this;
241  }
242 
245  bool
246  hasNonce() const
247  {
248  return m_nonce.hasWire();
249  }
250 
255  uint32_t
256  getNonce() const;
257 
263  Interest&
264  setNonce(uint32_t nonce);
265 
273  void
274  refreshNonce();
275 
276 public: // local control header
279  {
280  return m_localControlHeader;
281  }
282 
285  {
286  return m_localControlHeader;
287  }
288 
289  uint64_t
291  {
293  }
294 
295  Interest&
296  setIncomingFaceId(uint64_t incomingFaceId)
297  {
298  getLocalControlHeader().setIncomingFaceId(incomingFaceId);
299  // ! do not reset Interest's wire !
300  return *this;
301  }
302 
303  uint64_t
305  {
307  }
308 
309  Interest&
310  setNextHopFaceId(uint64_t nextHopFaceId)
311  {
312  getLocalControlHeader().setNextHopFaceId(nextHopFaceId);
313  // ! do not reset Interest's wire !
314  return *this;
315  }
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  size_t m_selectedDelegationIndex;
446  mutable Block m_wire;
447 
448  nfd::LocalControlHeader m_localControlHeader;
450 };
451 
452 std::ostream&
453 operator<<(std::ostream& os, const Interest& interest);
454 
455 inline std::string
457 {
458  std::ostringstream os;
459  os << *this;
460  return os.str();
461 }
462 
463 } // namespace ndn
464 
465 #endif // NDN_INTEREST_HPP
int getMinSuffixComponents() const
Definition: interest.hpp:342
bool hasSelectedDelegation() const
Check whether the Interest includes a selected delegation.
Definition: interest.cpp:398
int getMaxSuffixComponents() const
Definition: interest.hpp:356
const nfd::LocalControlHeader & getLocalControlHeader() const
Definition: interest.hpp:284
const Name & getName() const
Definition: interest.hpp:216
Copyright (c) 2011-2015 Regents of the University of California.
bool operator==(const Interest &other) const
Definition: interest.hpp:427
bool matchesName(const Name &name) const
Check if Interest, including selectors, matches the given name.
Definition: interest.cpp:105
Link getLink() const
Get the link object for this interest.
Definition: interest.cpp:369
Interest & setMustBeFresh(bool mustBeFresh)
Definition: interest.hpp:418
void setSelectedDelegation(const Name &delegationName)
Set the selected delegation.
Definition: interest.cpp:417
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:340
bool hasWire() const
Check if already has wire.
Definition: interest.hpp:110
bool hasSelectors() const
Definition: interest.hpp:322
const Block & wireEncode() const
Encode to a wire format.
Definition: interest.cpp:277
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-2014 Regents of the University of California.
std::string toUri() const
Encode the name according to the NDN URI Scheme.
Definition: interest.hpp:456
const time::milliseconds & getInterestLifetime() const
Definition: interest.hpp:230
int getChildSelector() const
Definition: interest.hpp:398
Name getSelectedDelegation() const
Get the name of the selected delegation.
Definition: interest.cpp:408
uint32_t getNonce() const
Get Interest&#39;s nonce.
Definition: interest.cpp:62
void unsetSelectedDelegation()
Unset the selected delegation.
Definition: interest.cpp:440
uint64_t getNextHopFaceId() const
Definition: interest.hpp:304
Interest()
Create a new Interest with an empty name (ndn:/)
Definition: interest.cpp:36
void setLink(const Block &link)
Set the link object for this interest.
Definition: interest.cpp:379
const Selectors & getSelectors() const
Definition: interest.hpp:328
int getMustBeFresh() const
Definition: interest.hpp:412
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:222
Interest & setNonce(uint32_t nonce)
Set Interest&#39;s nonce.
Definition: interest.cpp:76
Interest & setPublisherPublicKeyLocator(const KeyLocator &keyLocator)
Definition: interest.hpp:376
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Definition: interest.cpp:217
const Exclude & getExclude() const
Definition: interest.hpp:384
Abstraction implementing Interest selectors.
Definition: selectors.hpp:34
Class to handle work with LocalControlHeader.
Interest & setMinSuffixComponents(int minSuffixComponents)
Definition: interest.hpp:348
uint64_t getIncomingFaceId() const
Definition: interest.hpp:290
Interest & setMaxSuffixComponents(int maxSuffixComponents)
Definition: interest.hpp:362
Name abstraction to represent an absolute name.
Definition: name.hpp:46
bool matchesData(const Data &data) const
Check if Interest can be satisfied by data.
Definition: interest.cpp:132
void unsetLink()
Reset the wire format of the given interest and the contained link.
Definition: interest.cpp:390
Interest & setSelectors(const Selectors &selectors)
Definition: interest.hpp:334
Interest & setNextHopFaceId(uint64_t nextHopFaceId)
Definition: interest.hpp:310
void wireDecode(const Block &wire)
Decode from the wire format.
Definition: interest.cpp:295
Interest & setIncomingFaceId(uint64_t incomingFaceId)
Definition: interest.hpp:296
bool hasLink() const
Check whether the Interest contains a Link object.
Definition: interest.cpp:361
bool operator!=(const Interest &other) const
Definition: interest.hpp:433
const KeyLocator & getPublisherPublicKeyLocator() const
Definition: interest.hpp:370
const time::milliseconds DEFAULT_INTEREST_LIFETIME
default value for InterestLifetime
Definition: interest.hpp:41
void setIncomingFaceId(uint64_t incomingFaceId)
represents a Data packet
Definition: data.hpp:39
Interest & setInterestLifetime(const time::milliseconds &interestLifetime)
Definition: interest.hpp:236
void setNextHopFaceId(uint64_t nextHopFaceId)
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
Class to represent Exclude component in NDN interests.
Definition: exclude.hpp:38
nfd::LocalControlHeader & getLocalControlHeader()
Definition: interest.hpp:278
bool hasNonce() const
Check if Nonce set.
Definition: interest.hpp:246