blob: 3e4654154cb597f3d04034f12b9cd3b1e80c0c33 [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 Afanasyeve275cf82012-04-18 14:25:02 -070027#include "ns3/simple-ref-count.h"
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070028#include "ns3/nstime.h"
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070029
30#include <string>
31#include <vector>
32#include <list>
33
Ilya Moiseenkod26e6822011-08-23 17:48:38 -070034#include "ccnx-name-components.h"
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070035
36namespace ns3
37{
Alexander Afanasyev2536e202011-08-12 14:13:10 -070038
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070039/**
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/**
Ilya Moiseenko332add02011-12-24 17:21:25 -0800118 * NDN InterestHeader and routines to serialize/deserialize
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700119
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)
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700126 - InterestLifetime: ?
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700127 - Nonce: 32 bit random integer. If value is 0, will not be serialized
128 */
Alexander Afanasyeve275cf82012-04-18 14:25:02 -0700129class CcnxInterestHeader : public SimpleRefCount<CcnxInterestHeader,Header>
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700130{
131public:
132 /**
Ilya Moiseenko332add02011-12-24 17:21:25 -0800133 * \brief Constructor
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700134 *
135 * Creates a null header
136 **/
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700137 CcnxInterestHeader ();
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700138
139 /**
140 * \brief Set interest name
141 *
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700142 * Sets name of the interest. For example, SetName( CcnxNameComponents("prefix")("postfix") );
Ilya Moiseenko332add02011-12-24 17:21:25 -0800143 * @param[in] name const pointer to CcnxNameComponents object that contains an interest name
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700144 **/
145 void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700146 SetName (const Ptr<CcnxNameComponents> &name);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700147
Ilya Moiseenko332add02011-12-24 17:21:25 -0800148
149 /**
150 * \brief Get interest name
151 *
152 * Gets name of the interest.
153 **/
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700154 const CcnxNameComponents&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700155 GetName () const;
156
Ilya Moiseenko332add02011-12-24 17:21:25 -0800157 /**
158 * \brief Set interest MinSuffixComponents
159 *
160 * MinSuffixComponents refer to the number of name components beyond those in the prefix,
161 * and counting the implicit digest, that may occur in the matching ContentObject.
162 * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
163 * @param[in] value minimum length of suffix components
164 **/
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700165 void
166 SetMinSuffixComponents (int32_t value);
167
Ilya Moiseenko332add02011-12-24 17:21:25 -0800168 /**
169 * \brief Get interest MinSuffixComponents
170 *
171 * MinSuffixComponents refer to the number of name components beyond those in the prefix,
172 * and counting the implicit digest, that may occur in the matching ContentObject.
173 * For more information, see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html
174 **/
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700175 int32_t
176 GetMinSuffixComponents () const;
177
Ilya Moiseenko332add02011-12-24 17:21:25 -0800178
179 /**
180 * \brief Set interest MaxSuffixComponents
181 *
182 * MaxSuffixComponents refer to the number of name components beyond those in the prefix,
183 * and counting the implicit digest, that may occur in the matching ContentObject.
184 * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
185 * @param[in] value maximum length of suffix components
186 **/
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700187 void
188 SetMaxSuffixComponents (int32_t value);
189
Ilya Moiseenko332add02011-12-24 17:21:25 -0800190 /**
191 * \brief Get interest MaxSuffixComponents
192 *
193 * MaxSuffixComponents refer to the number of name components beyond those in the prefix,
194 * and counting the implicit digest, that may occur in the matching ContentObject.
195 * For more information, see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html
196 **/
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700197 int32_t
198 GetMaxSuffixComponents () const;
199
200 /**
201 * \brief Set exclude filer
202 *
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700203 * For example, SetExclude (CcnxNameComponents("exclude1")("exclude2")("exclude3"))
Ilya Moiseenko332add02011-12-24 17:21:25 -0800204 * @param[in] exclude const pointer to CcnxNameComponents to be excluded
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700205 **/
206 void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700207 SetExclude (const Ptr<CcnxNameComponents> &exclude);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700208
Ilya Moiseenko332add02011-12-24 17:21:25 -0800209 /**
210 * \brief Check if interest conatins exclude filter
211 *
212 */
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700213 bool
214 IsEnabledExclude () const;
215
Ilya Moiseenko332add02011-12-24 17:21:25 -0800216 /**
217 * \brief Get exclude filter
218 */
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700219 const CcnxNameComponents&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700220 GetExclude () const;
221
Ilya Moiseenko332add02011-12-24 17:21:25 -0800222 /**
223 * \brief Set ChildSelector
224 * Often a given interest will match more than one ContentObject within a given content store.
225 * The ChildSelector provides a way of expressing a preference for which of these should be returned.
226 * If the value is false, the leftmost child is preferred. If true, the rightmost child is preferred.
227 * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
228 * @param[in] value boolean ChildSelector value
229 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700230 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700231 SetChildSelector (bool value);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700232
Ilya Moiseenko332add02011-12-24 17:21:25 -0800233 /**
234 * \brief Return ChildSelector value
235 * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
236 *
237 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700238 bool
239 IsEnabledChildSelector () const;
240
Ilya Moiseenko332add02011-12-24 17:21:25 -0800241 /**
242 * \brief Set AnswerOriginKind
243 * Default value for AnswerOriginKind is false.
244 * @param[in] value boolean AnswerOriginKind value
245 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700246 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700247 SetAnswerOriginKind (bool value);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700248
Ilya Moiseenko332add02011-12-24 17:21:25 -0800249 /**
250 * \brief Check the value of AnswerOriginKind
251 *
252 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700253 bool
254 IsEnabledAnswerOriginKind () const;
255
Ilya Moiseenko332add02011-12-24 17:21:25 -0800256 /**
257 * \brief Set Scope
258 * Scope limits where the Interest may propagate.
259 * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host).
260 * Scope 1 limits propagation to the applications on the originating host.
261 * Scope 2 limits propagation to no further than the next host.
262 * Other values are not defined, and will cause the Interest message to be dropped.
263 * Note that this is not a hop count - the value is not decremented as the interest is forwarded.
264 * @param[in] scope interest scope
265 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700266 void
267 SetScope (int8_t scope);
268
Ilya Moiseenko332add02011-12-24 17:21:25 -0800269 /**
270 * \brief Get Scope value
271 * Scope limits where the Interest may propagate.
272 * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host).
273 * Scope 1 limits propagation to the applications on the originating host.
274 * Scope 2 limits propagation to no further than the next host.
275 * Other values are not defined, and will cause the Interest message to be dropped.
276 * Note that this is not a hop count - the value is not decremented as the interest is forwarded.
277 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700278 int8_t
279 GetScope () const;
280
Ilya Moiseenko332add02011-12-24 17:21:25 -0800281 /**
282 * \brief Set InterestLifetime
283 * InterestLifetime indicates the (approximate) time remaining before the interest times out.
284 * The timeout is relative to the arrival time of the interest at the current node.
285 * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
286 * @param[in] time interest lifetime
287 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700288 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700289 SetInterestLifetime (Time time);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700290
Ilya Moiseenko332add02011-12-24 17:21:25 -0800291 /**
292 * \brief Get InterestLifetime value
293 * InterestLifetime indicates the (approximate) time remaining before the interest times out.
294 * The timeout is relative to the arrival time of the interest at the current node.
295 * \see http://www.ccnx.org/releases/latest/doc/technical/InterestMessage.html for more information.
296 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700297 Time
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700298 GetInterestLifetime () const;
299
Ilya Moiseenko332add02011-12-24 17:21:25 -0800300 /**
301 * \brief Set Nonce
302 * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages.
303 * @param[in] nonce Unique packet identification number
304 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700305 void
306 SetNonce (uint32_t nonce);
307
Ilya Moiseenko332add02011-12-24 17:21:25 -0800308 /**
309 * \brief Get Nonce value
310 * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages.
311 *
312 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700313 uint32_t
314 GetNonce () const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800315
316 /**
317 * \enum NACK Type
318 * \brief Specifies the type of Interest packet
319 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800320 enum
321 {
322 NORMAL_INTEREST = 0,
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800323 NACK_LOOP = 10,
324 NACK_CONGESTION = 11,
325 NACK_GIVEUP_PIT = 12,
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800326 };
327
Ilya Moiseenko332add02011-12-24 17:21:25 -0800328 /**
329 * \brief Mark the Interest as a Negative Acknowledgement
330 * Three types of NACKs are supported
331 * 1. NACK_LOOP
332 * 2. NACK_CONGESTION
333 * 3. NACK_GIVEUP_PIT
334 * @param[in] nackType NACK_LOOP or NACK_CONGESTION or NACK_GIVEUP_PIT or NORMAL_INTEREST
335 */
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700336 void
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800337 SetNack (uint32_t nackType);
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700338
Ilya Moiseenko332add02011-12-24 17:21:25 -0800339 /**
340 * \brief Get NACK type
341 * Returns NACK_LOOP, NACK_CONGESTION or NACK_GIVEUP_PIT.
342 * Otherwise, in case of normal interest packet, returns NORMAL_INTEREST (equals 0).
343 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800344 uint32_t
345 GetNack () const;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700346
347 //////////////////////////////////////////////////////////////////
348
349 static TypeId GetTypeId (void);
350 virtual TypeId GetInstanceTypeId (void) const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800351
352 /**
353 * \brief Print Interest packet
354 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700355 virtual void Print (std::ostream &os) const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800356
357 /**
358 * \brief Get the size of Interest packet
359 * Returns the Interest packet size after serialization
360 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700361 virtual uint32_t GetSerializedSize (void) const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800362
363 /**
364 * \brief Serialize Interest packet
365 * Serializes Interest packet into Buffer::Iterator
366 * @param[in] start buffer to contain serialized Interest packet
367 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700368 virtual void Serialize (Buffer::Iterator start) const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800369
370 /**
371 * \brief Deserialize Interest packet
372 * Deserializes Buffer::Iterator into Interest packet
373 * @param[in] start buffer that contains serialized Interest packet
374 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700375 virtual uint32_t Deserialize (Buffer::Iterator start);
376
377private:
Ilya Moiseenko332add02011-12-24 17:21:25 -0800378 Ptr<CcnxNameComponents> m_name; ///< Interest name
379 int32_t m_minSuffixComponents; ///< Minimum suffix components. not used if negative
380 int32_t m_maxSuffixComponents; ///< Maximum suffix components. not used if negative
381 Ptr<CcnxNameComponents> m_exclude; ///< Exclude filter
382 bool m_childSelector; ///< Default value for ChildSelector is false
383 bool m_answerOriginKind; ///< Default value for AnswerOriginKind is false
384 int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood
385 Time m_interestLifetime; ///< InterestLifetime
386 uint32_t m_nonce; ///< Nonce. not used if zero
387 uint32_t m_nackType; ///< Negative Acknowledgement type
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700388};
389
Ilya Moiseenko332add02011-12-24 17:21:25 -0800390/**
391 * \brief Exception class for CcnxInterestHeader
392 */
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700393class CcnxInterestHeaderException {};
394
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700395} // namespace ns3
396
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700397#endif // _CCNX_INTEREST_HEADER_H_