blob: dcfd983fc46b289b0864110e30d144815586ecae [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -07002/*
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
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070022#ifndef _CCNX_INTEREST_HEADER_H_
23#define _CCNX_INTEREST_HEADER_H_
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070024
Alexander Afanasyev2536e202011-08-12 14:13:10 -070025#include "ns3/integer.h"
26#include "ns3/header.h"
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070027#include "ns3/nstime.h"
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070028
29#include <string>
30#include <vector>
31#include <list>
32
Ilya Moiseenkod26e6822011-08-23 17:48:38 -070033#include "ccnx-name-components.h"
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070034
35namespace ns3
36{
Alexander Afanasyev2536e202011-08-12 14:13:10 -070037
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070038/**
39 * CCNx XML definition of Interest
40 *
41 * Only few important fields are actually implemented in the simulation
42 *
43 * <xs:element name="Interest" type="InterestType"/>
44 * <xs:complexType name="InterestType">
45 * <xs:sequence>
46 * <xs:element name="Name" type="NameType"/>
47 * <xs:element name="MinSuffixComponents" type="xs:nonNegativeInteger"
48 * minOccurs="0" maxOccurs="1"/>
49 * <xs:element name="MaxSuffixComponents" type="xs:nonNegativeInteger"
50 * minOccurs="0" maxOccurs="1"/>
51 * <xs:choice minOccurs="0" maxOccurs="1">
52 * <xs:element name="PublisherPublicKeyDigest" type="DigestType"/>
53 * <xs:element name="PublisherCertificateDigest" type="DigestType"/>
54 * <xs:element name="PublisherIssuerKeyDigest" type="DigestType"/>
55 * <xs:element name="PublisherIssuerCertificateDigest" type="DigestType"/>
56 * </xs:choice>
57 * <xs:element name="Exclude" type="ExcludeType"
58 * minOccurs="0" maxOccurs="1"/>
59 * <xs:element name="ChildSelector" type="xs:nonNegativeInteger"
60 * minOccurs="0" maxOccurs="1"/>
61 * <xs:element name="AnswerOriginKind" type="xs:nonNegativeInteger"
62 * minOccurs="0" maxOccurs="1"/>
63 * <xs:element name="Scope" type="xs:nonNegativeInteger"
64 * minOccurs="0" maxOccurs="1"/>
65 * <xs:element name="InterestLifetime" type="FinegrainLifetimeType"
66 * minOccurs="0" maxOccurs="1"/>
67 * <xs:element name="Nonce" type="Base64BinaryType"
68 * minOccurs="0" maxOccurs="1"/>
69 * </xs:sequence>
70 * </xs:complexType>
71 *
72 * <xs:complexType name="NameType">
73 * <xs:sequence>
74 * <xs:element name="Component" type="Base64BinaryType"
75 * minOccurs="0" maxOccurs="unbounded"/>
76 * </xs:sequence>
77 * </xs:complexType>
78 *
79 * <xs:complexType name="ExcludeType">
80 * <xs:sequence>
81 * <xs:choice minOccurs="0" maxOccurs="1">
82 * <xs:element name="Any" type="EmptyType"/>
83 * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
84 * </xs:choice>
85 * <xs:sequence minOccurs="0" maxOccurs="unbounded">
86 * <xs:element name="Component" type="Base64BinaryType"/>
87 * <xs:choice minOccurs="0" maxOccurs="1">
88 * <xs:element name="Any" type="EmptyType"/>
89 * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
90 * </xs:choice>
91 * </xs:sequence>
92 * </xs:sequence>
93 * </xs:complexType>
94 *
95 * <!-- Binary representation of time, Unix time epoch, units 2**-12 sec (0.000244140625 sec) -->
96 * <!-- The length limit limit of 6 bytes is not actually to be enforced, but
97 * it will be a loooooooong time before anyone cares. -->
98 *
99 * <!-- Binary representation of relative time, relative to "now" -->
100 * <xs:complexType name="FinegrainLifetimeType">
101 * <xs:simpleContent>
102 * <xs:extension base="BinaryTime12">
103 * <xs:attribute name="ccnbencoding" type="xs:string" fixed="base64Binary"/>
104 * </xs:extension>
105 * </xs:simpleContent>
106 * </xs:complexType>
107 *
108 * <xs:simpleType name="BinaryTime12">
109 * <xs:restriction base="xs:base64Binary">
110 * <xs:length value="6" fixed="true"/>
111 * </xs:restriction>
112 * </xs:simpleType>
113 *
114 **/
115
116/**
Ilya Moiseenko332add02011-12-24 17:21:25 -0800117 * NDN InterestHeader and routines to serialize/deserialize
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700118
119 Simplifications:
120 - Name: binary name components are not supported
121 - MinSuffixComponents and MasSuffixComponents: if value is negative (default), will not be serialized
122 - ChildSelector, AnswerOriginKind: 0 - false, 1 - true, -1 not set
123 - Publisher* elements are not supported
124 - Exclude: only simple name matching is supported (Bloom support has been deprecated in CCNx)
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700125 - InterestLifetime: ?
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700126 - Nonce: 32 bit random integer. If value is 0, will not be serialized
127 */
Alexander Afanasyevfccdb9e2011-08-22 19:27:14 -0700128class CcnxInterestHeader : public Header
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700129{
130public:
131 /**
Ilya Moiseenko332add02011-12-24 17:21:25 -0800132 * \brief Constructor
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700133 *
134 * Creates a null header
135 **/
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700136 CcnxInterestHeader ();
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700137
138 /**
139 * \brief Set interest name
140 *
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700141 * Sets name of the interest. For example, SetName( CcnxNameComponents("prefix")("postfix") );
Ilya Moiseenko332add02011-12-24 17:21:25 -0800142 * @param[in] name const pointer to CcnxNameComponents object that contains an interest name
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700143 **/
144 void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700145 SetName (const Ptr<CcnxNameComponents> &name);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700146
Ilya Moiseenko332add02011-12-24 17:21:25 -0800147
148 /**
149 * \brief Get interest name
150 *
151 * Gets name of the interest.
152 **/
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700153 const CcnxNameComponents&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700154 GetName () const;
155
Ilya Moiseenko332add02011-12-24 17:21:25 -0800156 /**
157 * \brief Set interest MinSuffixComponents
158 *
159 * MinSuffixComponents refer to the number of name components beyond those in the prefix,
160 * and counting the implicit digest, that may occur in the matching ContentObject.
161 * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
162 * @param[in] value minimum length of suffix components
163 **/
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700164 void
165 SetMinSuffixComponents (int32_t value);
166
Ilya Moiseenko332add02011-12-24 17:21:25 -0800167 /**
168 * \brief Get interest MinSuffixComponents
169 *
170 * MinSuffixComponents refer to the number of name components beyond those in the prefix,
171 * and counting the implicit digest, that may occur in the matching ContentObject.
172 * For more information, see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html
173 **/
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700174 int32_t
175 GetMinSuffixComponents () const;
176
Ilya Moiseenko332add02011-12-24 17:21:25 -0800177
178 /**
179 * \brief Set interest MaxSuffixComponents
180 *
181 * MaxSuffixComponents refer to the number of name components beyond those in the prefix,
182 * and counting the implicit digest, that may occur in the matching ContentObject.
183 * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
184 * @param[in] value maximum length of suffix components
185 **/
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700186 void
187 SetMaxSuffixComponents (int32_t value);
188
Ilya Moiseenko332add02011-12-24 17:21:25 -0800189 /**
190 * \brief Get interest MaxSuffixComponents
191 *
192 * MaxSuffixComponents refer to the number of name components beyond those in the prefix,
193 * and counting the implicit digest, that may occur in the matching ContentObject.
194 * For more information, see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html
195 **/
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700196 int32_t
197 GetMaxSuffixComponents () const;
198
199 /**
200 * \brief Set exclude filer
201 *
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700202 * For example, SetExclude (CcnxNameComponents("exclude1")("exclude2")("exclude3"))
Ilya Moiseenko332add02011-12-24 17:21:25 -0800203 * @param[in] exclude const pointer to CcnxNameComponents to be excluded
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700204 **/
205 void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700206 SetExclude (const Ptr<CcnxNameComponents> &exclude);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700207
Ilya Moiseenko332add02011-12-24 17:21:25 -0800208 /**
209 * \brief Check if interest conatins exclude filter
210 *
211 */
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700212 bool
213 IsEnabledExclude () const;
214
Ilya Moiseenko332add02011-12-24 17:21:25 -0800215 /**
216 * \brief Get exclude filter
217 */
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700218 const CcnxNameComponents&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700219 GetExclude () const;
220
Ilya Moiseenko332add02011-12-24 17:21:25 -0800221 /**
222 * \brief Set ChildSelector
223 * Often a given interest will match more than one ContentObject within a given content store.
224 * The ChildSelector provides a way of expressing a preference for which of these should be returned.
225 * If the value is false, the leftmost child is preferred. If true, the rightmost child is preferred.
226 * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
227 * @param[in] value boolean ChildSelector value
228 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700229 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700230 SetChildSelector (bool value);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700231
Ilya Moiseenko332add02011-12-24 17:21:25 -0800232 /**
233 * \brief Return ChildSelector value
234 * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
235 *
236 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700237 bool
238 IsEnabledChildSelector () const;
239
Ilya Moiseenko332add02011-12-24 17:21:25 -0800240 /**
241 * \brief Set AnswerOriginKind
242 * Default value for AnswerOriginKind is false.
243 * @param[in] value boolean AnswerOriginKind value
244 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700245 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700246 SetAnswerOriginKind (bool value);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700247
Ilya Moiseenko332add02011-12-24 17:21:25 -0800248 /**
249 * \brief Check the value of AnswerOriginKind
250 *
251 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700252 bool
253 IsEnabledAnswerOriginKind () const;
254
Ilya Moiseenko332add02011-12-24 17:21:25 -0800255 /**
256 * \brief Set Scope
257 * Scope limits where the Interest may propagate.
258 * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host).
259 * Scope 1 limits propagation to the applications on the originating host.
260 * Scope 2 limits propagation to no further than the next host.
261 * Other values are not defined, and will cause the Interest message to be dropped.
262 * Note that this is not a hop count - the value is not decremented as the interest is forwarded.
263 * @param[in] scope interest scope
264 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700265 void
266 SetScope (int8_t scope);
267
Ilya Moiseenko332add02011-12-24 17:21:25 -0800268 /**
269 * \brief Get Scope value
270 * Scope limits where the Interest may propagate.
271 * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host).
272 * Scope 1 limits propagation to the applications on the originating host.
273 * Scope 2 limits propagation to no further than the next host.
274 * Other values are not defined, and will cause the Interest message to be dropped.
275 * Note that this is not a hop count - the value is not decremented as the interest is forwarded.
276 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700277 int8_t
278 GetScope () const;
279
Ilya Moiseenko332add02011-12-24 17:21:25 -0800280 /**
281 * \brief Set InterestLifetime
282 * InterestLifetime indicates the (approximate) time remaining before the interest times out.
283 * The timeout is relative to the arrival time of the interest at the current node.
284 * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
285 * @param[in] time interest lifetime
286 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700287 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700288 SetInterestLifetime (Time time);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700289
Ilya Moiseenko332add02011-12-24 17:21:25 -0800290 /**
291 * \brief Get InterestLifetime value
292 * InterestLifetime indicates the (approximate) time remaining before the interest times out.
293 * The timeout is relative to the arrival time of the interest at the current node.
294 * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
295 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700296 Time
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700297 GetInterestLifetime () const;
298
Ilya Moiseenko332add02011-12-24 17:21:25 -0800299 /**
300 * \brief Set Nonce
301 * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages.
302 * @param[in] nonce Unique packet identification number
303 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700304 void
305 SetNonce (uint32_t nonce);
306
Ilya Moiseenko332add02011-12-24 17:21:25 -0800307 /**
308 * \brief Get Nonce value
309 * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages.
310 *
311 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700312 uint32_t
313 GetNonce () const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800314
315 /**
316 * \enum NACK Type
317 * \brief Specifies the type of Interest packet
318 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800319 enum
320 {
321 NORMAL_INTEREST = 0,
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800322 NACK_LOOP = 10,
323 NACK_CONGESTION = 11,
324 NACK_GIVEUP_PIT = 12,
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800325 };
326
Ilya Moiseenko332add02011-12-24 17:21:25 -0800327 /**
328 * \brief Mark the Interest as a Negative Acknowledgement
329 * Three types of NACKs are supported
330 * 1. NACK_LOOP
331 * 2. NACK_CONGESTION
332 * 3. NACK_GIVEUP_PIT
333 * @param[in] nackType NACK_LOOP or NACK_CONGESTION or NACK_GIVEUP_PIT or NORMAL_INTEREST
334 */
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700335 void
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800336 SetNack (uint32_t nackType);
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700337
Ilya Moiseenko332add02011-12-24 17:21:25 -0800338 /**
339 * \brief Get NACK type
340 * Returns NACK_LOOP, NACK_CONGESTION or NACK_GIVEUP_PIT.
341 * Otherwise, in case of normal interest packet, returns NORMAL_INTEREST (equals 0).
342 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800343 uint32_t
344 GetNack () const;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700345
346 //////////////////////////////////////////////////////////////////
347
348 static TypeId GetTypeId (void);
349 virtual TypeId GetInstanceTypeId (void) const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800350
351 /**
352 * \brief Print Interest packet
353 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700354 virtual void Print (std::ostream &os) const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800355
356 /**
357 * \brief Get the size of Interest packet
358 * Returns the Interest packet size after serialization
359 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700360 virtual uint32_t GetSerializedSize (void) const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800361
362 /**
363 * \brief Serialize Interest packet
364 * Serializes Interest packet into Buffer::Iterator
365 * @param[in] start buffer to contain serialized Interest packet
366 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700367 virtual void Serialize (Buffer::Iterator start) const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800368
369 /**
370 * \brief Deserialize Interest packet
371 * Deserializes Buffer::Iterator into Interest packet
372 * @param[in] start buffer that contains serialized Interest packet
373 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700374 virtual uint32_t Deserialize (Buffer::Iterator start);
375
376private:
Ilya Moiseenko332add02011-12-24 17:21:25 -0800377 Ptr<CcnxNameComponents> m_name; ///< Interest name
378 int32_t m_minSuffixComponents; ///< Minimum suffix components. not used if negative
379 int32_t m_maxSuffixComponents; ///< Maximum suffix components. not used if negative
380 Ptr<CcnxNameComponents> m_exclude; ///< Exclude filter
381 bool m_childSelector; ///< Default value for ChildSelector is false
382 bool m_answerOriginKind; ///< Default value for AnswerOriginKind is false
383 int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood
384 Time m_interestLifetime; ///< InterestLifetime
385 uint32_t m_nonce; ///< Nonce. not used if zero
386 uint32_t m_nackType; ///< Negative Acknowledgement type
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700387};
388
Ilya Moiseenko332add02011-12-24 17:21:25 -0800389/**
390 * \brief Exception class for CcnxInterestHeader
391 */
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700392class CcnxInterestHeaderException {};
393
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700394} // namespace ns3
395
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700396#endif // _CCNX_INTEREST_HEADER_H_