blob: 9b52ca29f5636ac6bc7c1e33da922ce57ac407fe [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 Afanasyev4aac5572012-08-09 10:49:55 -070022#ifndef _NDN_INTEREST_HEADER_H_
23#define _NDN_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
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070034#include "ndn-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/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070040 * Ndn XML definition of Interest
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070041 *
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/**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700118 * @brief 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
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700125 * - Exclude: only simple name matching is supported (Bloom support has been deprecated in Ndn)
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700126 * - InterestLifetime: ?
127 * - Nonce: 32 bit random integer. If value is 0, will not be serialized
128 **/
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700129class NdnInterestHeader : public SimpleRefCount<NdnInterestHeader,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 Afanasyev4aac5572012-08-09 10:49:55 -0700137 NdnInterestHeader ();
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700138
139 /**
140 * \brief Set interest name
141 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700142 * Sets name of the interest. For example, SetName( ndnNameComponents("prefix")("postfix") );
143 * @param[in] name const pointer to ndnNameComponents object that contains an interest name
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700144 **/
145 void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700146 SetName (const Ptr<NdnNameComponents> &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 **/
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700154 const NdnNameComponents&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700155 GetName () const;
156
Ilya Moiseenko332add02011-12-24 17:21:25 -0800157 /**
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700158 * @brief Get smart pointer to the interest name (to avoid extra memory usage)
159 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700160 Ptr<const NdnNameComponents>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700161 GetNamePtr () const;
162
163 /**
Ilya Moiseenko332add02011-12-24 17:21:25 -0800164 * \brief Set interest MinSuffixComponents
165 *
166 * MinSuffixComponents refer to the number of name components beyond those in the prefix,
167 * and counting the implicit digest, that may occur in the matching ContentObject.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700168 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800169 * @param[in] value minimum length of suffix components
170 **/
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700171 void
172 SetMinSuffixComponents (int32_t value);
173
Ilya Moiseenko332add02011-12-24 17:21:25 -0800174 /**
175 * \brief Get interest MinSuffixComponents
176 *
177 * MinSuffixComponents refer to the number of name components beyond those in the prefix,
178 * and counting the implicit digest, that may occur in the matching ContentObject.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700179 * For more information, see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html
Ilya Moiseenko332add02011-12-24 17:21:25 -0800180 **/
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700181 int32_t
182 GetMinSuffixComponents () const;
183
Ilya Moiseenko332add02011-12-24 17:21:25 -0800184
185 /**
186 * \brief Set interest MaxSuffixComponents
187 *
188 * MaxSuffixComponents refer to the number of name components beyond those in the prefix,
189 * and counting the implicit digest, that may occur in the matching ContentObject.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700190 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800191 * @param[in] value maximum length of suffix components
192 **/
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700193 void
194 SetMaxSuffixComponents (int32_t value);
195
Ilya Moiseenko332add02011-12-24 17:21:25 -0800196 /**
197 * \brief Get interest MaxSuffixComponents
198 *
199 * MaxSuffixComponents refer to the number of name components beyond those in the prefix,
200 * and counting the implicit digest, that may occur in the matching ContentObject.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700201 * For more information, see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html
Ilya Moiseenko332add02011-12-24 17:21:25 -0800202 **/
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700203 int32_t
204 GetMaxSuffixComponents () const;
205
206 /**
207 * \brief Set exclude filer
208 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700209 * For example, SetExclude (ndnNameComponents("exclude1")("exclude2")("exclude3"))
210 * @param[in] exclude const pointer to ndnNameComponents to be excluded
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700211 **/
212 void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700213 SetExclude (const Ptr<NdnNameComponents> &exclude);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700214
Ilya Moiseenko332add02011-12-24 17:21:25 -0800215 /**
216 * \brief Check if interest conatins exclude filter
217 *
218 */
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700219 bool
220 IsEnabledExclude () const;
221
Ilya Moiseenko332add02011-12-24 17:21:25 -0800222 /**
223 * \brief Get exclude filter
224 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700225 const NdnNameComponents&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700226 GetExclude () const;
227
Ilya Moiseenko332add02011-12-24 17:21:25 -0800228 /**
229 * \brief Set ChildSelector
230 * Often a given interest will match more than one ContentObject within a given content store.
231 * The ChildSelector provides a way of expressing a preference for which of these should be returned.
232 * If the value is false, the leftmost child is preferred. If true, the rightmost child is preferred.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700233 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800234 * @param[in] value boolean ChildSelector value
235 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700236 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700237 SetChildSelector (bool value);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700238
Ilya Moiseenko332add02011-12-24 17:21:25 -0800239 /**
240 * \brief Return ChildSelector value
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700241 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800242 *
243 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700244 bool
245 IsEnabledChildSelector () const;
246
Ilya Moiseenko332add02011-12-24 17:21:25 -0800247 /**
248 * \brief Set AnswerOriginKind
249 * Default value for AnswerOriginKind is false.
250 * @param[in] value boolean AnswerOriginKind value
251 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700252 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700253 SetAnswerOriginKind (bool value);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700254
Ilya Moiseenko332add02011-12-24 17:21:25 -0800255 /**
256 * \brief Check the value of AnswerOriginKind
257 *
258 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700259 bool
260 IsEnabledAnswerOriginKind () const;
261
Ilya Moiseenko332add02011-12-24 17:21:25 -0800262 /**
263 * \brief Set Scope
264 * Scope limits where the Interest may propagate.
265 * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host).
266 * Scope 1 limits propagation to the applications on the originating host.
267 * Scope 2 limits propagation to no further than the next host.
268 * Other values are not defined, and will cause the Interest message to be dropped.
269 * Note that this is not a hop count - the value is not decremented as the interest is forwarded.
270 * @param[in] scope interest scope
271 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700272 void
273 SetScope (int8_t scope);
274
Ilya Moiseenko332add02011-12-24 17:21:25 -0800275 /**
276 * \brief Get Scope value
277 * Scope limits where the Interest may propagate.
278 * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host).
279 * Scope 1 limits propagation to the applications on the originating host.
280 * Scope 2 limits propagation to no further than the next host.
281 * Other values are not defined, and will cause the Interest message to be dropped.
282 * Note that this is not a hop count - the value is not decremented as the interest is forwarded.
283 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700284 int8_t
285 GetScope () const;
286
Ilya Moiseenko332add02011-12-24 17:21:25 -0800287 /**
288 * \brief Set InterestLifetime
289 * InterestLifetime indicates the (approximate) time remaining before the interest times out.
290 * The timeout is relative to the arrival time of the interest at the current node.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700291 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800292 * @param[in] time interest lifetime
293 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700294 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700295 SetInterestLifetime (Time time);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700296
Ilya Moiseenko332add02011-12-24 17:21:25 -0800297 /**
298 * \brief Get InterestLifetime value
299 * InterestLifetime indicates the (approximate) time remaining before the interest times out.
300 * The timeout is relative to the arrival time of the interest at the current node.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700301 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800302 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700303 Time
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700304 GetInterestLifetime () const;
305
Ilya Moiseenko332add02011-12-24 17:21:25 -0800306 /**
307 * \brief Set Nonce
308 * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages.
309 * @param[in] nonce Unique packet identification number
310 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700311 void
312 SetNonce (uint32_t nonce);
313
Ilya Moiseenko332add02011-12-24 17:21:25 -0800314 /**
315 * \brief Get Nonce value
316 * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages.
317 *
318 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700319 uint32_t
320 GetNonce () const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800321
322 /**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700323 * @brief NACK Type
324 * Specifies the type of Interest packet
Ilya Moiseenko332add02011-12-24 17:21:25 -0800325 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800326 enum
327 {
328 NORMAL_INTEREST = 0,
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800329 NACK_LOOP = 10,
330 NACK_CONGESTION = 11,
331 NACK_GIVEUP_PIT = 12,
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800332 };
333
Ilya Moiseenko332add02011-12-24 17:21:25 -0800334 /**
335 * \brief Mark the Interest as a Negative Acknowledgement
336 * Three types of NACKs are supported
337 * 1. NACK_LOOP
338 * 2. NACK_CONGESTION
339 * 3. NACK_GIVEUP_PIT
340 * @param[in] nackType NACK_LOOP or NACK_CONGESTION or NACK_GIVEUP_PIT or NORMAL_INTEREST
341 */
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700342 void
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800343 SetNack (uint32_t nackType);
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700344
Ilya Moiseenko332add02011-12-24 17:21:25 -0800345 /**
346 * \brief Get NACK type
347 * Returns NACK_LOOP, NACK_CONGESTION or NACK_GIVEUP_PIT.
348 * Otherwise, in case of normal interest packet, returns NORMAL_INTEREST (equals 0).
349 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800350 uint32_t
351 GetNack () const;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700352
353 //////////////////////////////////////////////////////////////////
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700354
355 static TypeId GetTypeId (void); ///< @brief Get TypeId of the class
356 virtual TypeId GetInstanceTypeId (void) const; ///< @brief Get TypeId of the instance
Ilya Moiseenko332add02011-12-24 17:21:25 -0800357
358 /**
359 * \brief Print Interest packet
360 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700361 virtual void Print (std::ostream &os) const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800362
363 /**
364 * \brief Get the size of Interest packet
365 * Returns the Interest packet size after serialization
366 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700367 virtual uint32_t GetSerializedSize (void) const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800368
369 /**
370 * \brief Serialize Interest packet
371 * Serializes Interest packet into Buffer::Iterator
372 * @param[in] start buffer to contain serialized Interest packet
373 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700374 virtual void Serialize (Buffer::Iterator start) const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800375
376 /**
377 * \brief Deserialize Interest packet
378 * Deserializes Buffer::Iterator into Interest packet
379 * @param[in] start buffer that contains serialized Interest packet
380 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700381 virtual uint32_t Deserialize (Buffer::Iterator start);
382
383private:
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700384 Ptr<NdnNameComponents> m_name; ///< Interest name
Ilya Moiseenko332add02011-12-24 17:21:25 -0800385 int32_t m_minSuffixComponents; ///< Minimum suffix components. not used if negative
386 int32_t m_maxSuffixComponents; ///< Maximum suffix components. not used if negative
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700387 Ptr<NdnNameComponents> m_exclude; ///< Exclude filter
Ilya Moiseenko332add02011-12-24 17:21:25 -0800388 bool m_childSelector; ///< Default value for ChildSelector is false
389 bool m_answerOriginKind; ///< Default value for AnswerOriginKind is false
390 int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood
391 Time m_interestLifetime; ///< InterestLifetime
392 uint32_t m_nonce; ///< Nonce. not used if zero
393 uint32_t m_nackType; ///< Negative Acknowledgement type
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700394};
395
Ilya Moiseenko332add02011-12-24 17:21:25 -0800396/**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700397 * @brief Class for Interest parsing exception
Ilya Moiseenko332add02011-12-24 17:21:25 -0800398 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700399class NdnInterestHeaderException {};
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700400
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700401} // namespace ns3
402
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700403#endif // _NDN_INTEREST_HEADER_H_