blob: 942a5f7a6d22e4621c70fe4bb91546ae28657bf5 [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson47eecfc2013-07-07 22:56:46 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07005 * See COPYING for copyright and distribution information.
Jeff Thompsonb7f95562013-07-03 18:36:42 -07006 */
7
Alexander Afanasyev09c613f2014-01-29 00:23:58 -08008#include "common.hpp"
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08009
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080010#include "interest.hpp"
Alexander Afanasyeve9fdb802014-02-05 17:36:51 -080011#include "util/random.hpp"
Alexander Afanasyev840139f2013-12-28 15:02:50 -080012
Jeff Thompsonb7f95562013-07-03 18:36:42 -070013using namespace std;
14
15namespace ndn {
Alexander Afanasyev84681982014-01-03 13:26:09 -080016
Alexander Afanasyev85480842014-01-06 14:46:54 -080017const uint32_t&
Alexander Afanasyev840139f2013-12-28 15:02:50 -080018Interest::getNonce() const
19{
Alexander Afanasyevc348f832014-02-17 16:35:17 -080020 if (m_nonce == 0)
21 m_nonce = random::generateWord32();
Alexander Afanasyev840139f2013-12-28 15:02:50 -080022
Alexander Afanasyevc348f832014-02-17 16:35:17 -080023 return m_nonce;
Alexander Afanasyev840139f2013-12-28 15:02:50 -080024}
25
26
Alexander Afanasyev84681982014-01-03 13:26:09 -080027bool
28Interest::matchesName(const Name &name) const
Jeff Thompson25b4e612013-10-10 16:03:24 -070029{
Alexander Afanasyevc348f832014-02-17 16:35:17 -080030 if (!m_name.isPrefixOf(name))
Alexander Afanasyev84681982014-01-03 13:26:09 -080031 return false;
32
Alexander Afanasyevc348f832014-02-17 16:35:17 -080033 if (getMinSuffixComponents() >= 0 &&
Alexander Afanasyev84681982014-01-03 13:26:09 -080034 // Add 1 for the implicit digest.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080035 !(name.size() + 1 - m_name.size() >= getMinSuffixComponents()))
Alexander Afanasyev84681982014-01-03 13:26:09 -080036 return false;
37
Alexander Afanasyevc348f832014-02-17 16:35:17 -080038 if (getMaxSuffixComponents() >= 0 &&
Alexander Afanasyev84681982014-01-03 13:26:09 -080039 // Add 1 for the implicit digest.
Alexander Afanasyevc348f832014-02-17 16:35:17 -080040 !(name.size() + 1 - m_name.size() <= getMaxSuffixComponents()))
Alexander Afanasyev84681982014-01-03 13:26:09 -080041 return false;
42
Alexander Afanasyevc348f832014-02-17 16:35:17 -080043 if (!getExclude().empty() && name.size() > m_name.size() &&
44 getExclude().isExcluded(name[m_name.size()]))
Alexander Afanasyev84681982014-01-03 13:26:09 -080045 return false;
46
47 return true;
Jeff Thompson25b4e612013-10-10 16:03:24 -070048}
49
Alexander Afanasyev84681982014-01-03 13:26:09 -080050std::ostream &
51operator << (std::ostream &os, const Interest &interest)
Jeff Thompsonfe556862013-07-09 13:52:55 -070052{
Alexander Afanasyev84681982014-01-03 13:26:09 -080053 os << interest.getName();
Jeff Thompsonfe556862013-07-09 13:52:55 -070054
Alexander Afanasyev84681982014-01-03 13:26:09 -080055 char delim = '?';
56
57 if (interest.getMinSuffixComponents() >= 0) {
58 os << delim << "ndn.MinSuffixComponents=" << interest.getMinSuffixComponents();
59 delim = '&';
Jeff Thompsonfe556862013-07-09 13:52:55 -070060 }
Alexander Afanasyev84681982014-01-03 13:26:09 -080061 if (interest.getMaxSuffixComponents() >= 0) {
62 os << delim << "ndn.MaxSuffixComponents=" << interest.getMaxSuffixComponents();
63 delim = '&';
Jeff Thompson37527d62013-08-21 11:15:54 -070064 }
Alexander Afanasyev84681982014-01-03 13:26:09 -080065 if (interest.getChildSelector() >= 0) {
66 os << delim << "ndn.ChildSelector=" << interest.getChildSelector();
67 delim = '&';
Jeff Thompson13e280b2013-12-03 13:12:23 -080068 }
Alexander Afanasyev84681982014-01-03 13:26:09 -080069 if (interest.getMustBeFresh()) {
70 os << delim << "ndn.MustBeFresh=" << interest.getMustBeFresh();
71 delim = '&';
Jeff Thompson13e280b2013-12-03 13:12:23 -080072 }
Alexander Afanasyev84681982014-01-03 13:26:09 -080073 if (interest.getScope() >= 0) {
74 os << delim << "ndn.Scope=" << interest.getScope();
75 delim = '&';
Jeff Thompson13e280b2013-12-03 13:12:23 -080076 }
Alexander Afanasyev929e86d2014-01-17 16:11:25 -080077 if (interest.getInterestLifetime() >= 0 && interest.getInterestLifetime() != DEFAULT_INTEREST_LIFETIME) {
Alexander Afanasyev84681982014-01-03 13:26:09 -080078 os << delim << "ndn.InterestLifetime=" << interest.getInterestLifetime();
79 delim = '&';
80 }
81
82 if (interest.getNonce() > 0) {
83 os << delim << "ndn.Nonce=" << interest.getNonce();
84 delim = '&';
85 }
86 if (!interest.getExclude().empty()) {
87 os << delim << "ndn.Exclude=" << interest.getExclude();
88 delim = '&';
89 }
90
91 return os;
Jeff Thompson13e280b2013-12-03 13:12:23 -080092}
93
Jeff Thompsonb7f95562013-07-03 18:36:42 -070094}