blob: 4f2b94882f1b82e180558687317922769bf14191 [file] [log] [blame]
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
20 */
21
22#ifndef _INTEREST_HEADER_H_
23#define _INTEREST_HEADER_H_
24
25#include <ns3/integer.h>
26#include <ns3/header.h>
27
28#include <string>
29#include <vector>
30#include <list>
31
32#include "name-components.h"
33
34namespace ns3
35{
36namespace NDNabstraction
37{
38
39/**
40 * CCNx XML definition of Interest
41 *
42 * Only few important fields are actually implemented in the simulation
43 *
44 * <xs:element name="Interest" type="InterestType"/>
45 * <xs:complexType name="InterestType">
46 * <xs:sequence>
47 * <xs:element name="Name" type="NameType"/>
48 * <xs:element name="MinSuffixComponents" type="xs:nonNegativeInteger"
49 * minOccurs="0" maxOccurs="1"/>
50 * <xs:element name="MaxSuffixComponents" type="xs:nonNegativeInteger"
51 * minOccurs="0" maxOccurs="1"/>
52 * <xs:choice minOccurs="0" maxOccurs="1">
53 * <xs:element name="PublisherPublicKeyDigest" type="DigestType"/>
54 * <xs:element name="PublisherCertificateDigest" type="DigestType"/>
55 * <xs:element name="PublisherIssuerKeyDigest" type="DigestType"/>
56 * <xs:element name="PublisherIssuerCertificateDigest" type="DigestType"/>
57 * </xs:choice>
58 * <xs:element name="Exclude" type="ExcludeType"
59 * minOccurs="0" maxOccurs="1"/>
60 * <xs:element name="ChildSelector" type="xs:nonNegativeInteger"
61 * minOccurs="0" maxOccurs="1"/>
62 * <xs:element name="AnswerOriginKind" type="xs:nonNegativeInteger"
63 * minOccurs="0" maxOccurs="1"/>
64 * <xs:element name="Scope" type="xs:nonNegativeInteger"
65 * minOccurs="0" maxOccurs="1"/>
66 * <xs:element name="InterestLifetime" type="FinegrainLifetimeType"
67 * minOccurs="0" maxOccurs="1"/>
68 * <xs:element name="Nonce" type="Base64BinaryType"
69 * minOccurs="0" maxOccurs="1"/>
70 * </xs:sequence>
71 * </xs:complexType>
72 *
73 * <xs:complexType name="NameType">
74 * <xs:sequence>
75 * <xs:element name="Component" type="Base64BinaryType"
76 * minOccurs="0" maxOccurs="unbounded"/>
77 * </xs:sequence>
78 * </xs:complexType>
79 *
80 * <xs:complexType name="ExcludeType">
81 * <xs:sequence>
82 * <xs:choice minOccurs="0" maxOccurs="1">
83 * <xs:element name="Any" type="EmptyType"/>
84 * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
85 * </xs:choice>
86 * <xs:sequence minOccurs="0" maxOccurs="unbounded">
87 * <xs:element name="Component" type="Base64BinaryType"/>
88 * <xs:choice minOccurs="0" maxOccurs="1">
89 * <xs:element name="Any" type="EmptyType"/>
90 * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
91 * </xs:choice>
92 * </xs:sequence>
93 * </xs:sequence>
94 * </xs:complexType>
95 *
96 * <!-- Binary representation of time, Unix time epoch, units 2**-12 sec (0.000244140625 sec) -->
97 * <!-- The length limit limit of 6 bytes is not actually to be enforced, but
98 * it will be a loooooooong time before anyone cares. -->
99 *
100 * <!-- Binary representation of relative time, relative to "now" -->
101 * <xs:complexType name="FinegrainLifetimeType">
102 * <xs:simpleContent>
103 * <xs:extension base="BinaryTime12">
104 * <xs:attribute name="ccnbencoding" type="xs:string" fixed="base64Binary"/>
105 * </xs:extension>
106 * </xs:simpleContent>
107 * </xs:complexType>
108 *
109 * <xs:simpleType name="BinaryTime12">
110 * <xs:restriction base="xs:base64Binary">
111 * <xs:length value="6" fixed="true"/>
112 * </xs:restriction>
113 * </xs:simpleType>
114 *
115 **/
116
117/**
118 NDN InterestHeader and routines to serialize/deserialize
119
120 Simplifications:
121 - Name: binary name components are not supported
122 - MinSuffixComponents and MasSuffixComponents: if value is negative (default), will not be serialized
123 - ChildSelector, AnswerOriginKind: 0 - false, 1 - true, -1 not set
124 - Publisher* elements are not supported
125 - Exclude: only simple name matching is supported (Bloom support has been deprecated in CCNx)
126 - InterestLifetime: not used if negative
127 - Nonce: 32 bit random integer. If value is 0, will not be serialized
128 */
129class InterestHeader : public Header
130{
131public:
132 /**
133 * Constructor
134 *
135 * Creates a null header
136 **/
137 InterestHeader ();
138
139 /**
140 * \brief Set interest name
141 *
142 * Sets name of the interest. For example, SetName( Name::Components("prefix")("postfix") );
143 **/
144 void
145 SetName (const Ptr<Name::Components> &name);
146
147 const Name::Components&
148 GetName () const;
149
150 void
151 SetMinSuffixComponents (int32_t value);
152
153 int32_t
154 GetMinSuffixComponents () const;
155
156 void
157 SetMaxSuffixComponents (int32_t value);
158
159 int32_t
160 GetMaxSuffixComponents () const;
161
162 /**
163 * \brief Set exclude filer
164 *
165 * For example, SetExclude (Name::Components("exclude1")("exclude2")("exclude3"))
166 **/
167 void
168 SetExclude (const Ptr<Name::Components> &exclude);
169
170 const Name::Components&
171 GetExclude () const;
172
173 void
174 EnableChildSelector ();
175
176 bool
177 IsEnabledChildSelector () const;
178
179 void
180 EnableAnswerOriginKind ();
181
182 bool
183 IsEnabledAnswerOriginKind () const;
184
185 void
186 SetScope (int8_t scope);
187
188 int8_t
189 GetScope () const;
190
191 void
192 SetInterestLifetime (intmax_t lifetime);
193
194 intmax_t
195 GetInterestLifetime () const;
196
197 void
198 SetNonce (uint32_t nonce);
199
200 uint32_t
201 GetNonce () const;
202
203 //////////////////////////////////////////////////////////////////
204
205 static TypeId GetTypeId (void);
206 virtual TypeId GetInstanceTypeId (void) const;
207 virtual void Print (std::ostream &os) const;
208 virtual uint32_t GetSerializedSize (void) const;
209 virtual void Serialize (Buffer::Iterator start) const;
210 virtual uint32_t Deserialize (Buffer::Iterator start);
211
212private:
213 Ptr<Name::Components> m_name;
214 int32_t m_minSuffixComponents; ///< minimum suffix components. not used if negative
215 int32_t m_maxSuffixComponents; ///< maximum suffix components. not used if negative
216 Ptr<Name::Components> m_exclude; ///< exclude filter
217 bool m_childSelector;
218 bool m_answerOriginKind;
219 int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood
220 intmax_t m_interestLifetime; ///< InterestLifetime in 2^{-12} (0.000244140625 sec). not used if negative
221 uint32_t m_nonce; ///< Nonce. not used if zero
222};
223
224} // namespace NDNabstraction
225} // namespace ns3
226
227#endif // _INTEREST_HEADER_H_