blob: 979dfddacb32f141706e38ff99a512f9aa70ce47 [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/**
117 NDN InterestHeader and routines to serialize/deserialize
118
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 /**
132 * Constructor
133 *
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") );
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700142 **/
143 void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700144 SetName (const Ptr<CcnxNameComponents> &name);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700145
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700146 const CcnxNameComponents&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700147 GetName () const;
148
149 void
150 SetMinSuffixComponents (int32_t value);
151
152 int32_t
153 GetMinSuffixComponents () const;
154
155 void
156 SetMaxSuffixComponents (int32_t value);
157
158 int32_t
159 GetMaxSuffixComponents () const;
160
161 /**
162 * \brief Set exclude filer
163 *
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700164 * For example, SetExclude (CcnxNameComponents("exclude1")("exclude2")("exclude3"))
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700165 **/
166 void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700167 SetExclude (const Ptr<CcnxNameComponents> &exclude);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700168
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700169 bool
170 IsEnabledExclude () const;
171
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700172 const CcnxNameComponents&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700173 GetExclude () const;
174
175 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700176 SetChildSelector (bool value);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700177
178 bool
179 IsEnabledChildSelector () const;
180
181 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700182 SetAnswerOriginKind (bool value);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700183
184 bool
185 IsEnabledAnswerOriginKind () const;
186
187 void
188 SetScope (int8_t scope);
189
190 int8_t
191 GetScope () const;
192
193 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700194 SetInterestLifetime (Time time);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700195
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700196 Time
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700197 GetInterestLifetime () const;
198
199 void
200 SetNonce (uint32_t nonce);
201
202 uint32_t
203 GetNonce () const;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700204
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800205 enum
206 {
207 NORMAL_INTEREST = 0,
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800208 NACK_LOOP = 10,
209 NACK_CONGESTION = 11,
210 NACK_GIVEUP_PIT = 12,
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800211 };
212
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700213 void
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800214 SetNack (uint32_t nackType);
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700215
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800216 uint32_t
217 GetNack () const;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700218
219 //////////////////////////////////////////////////////////////////
220
221 static TypeId GetTypeId (void);
222 virtual TypeId GetInstanceTypeId (void) const;
223 virtual void Print (std::ostream &os) const;
224 virtual uint32_t GetSerializedSize (void) const;
225 virtual void Serialize (Buffer::Iterator start) const;
226 virtual uint32_t Deserialize (Buffer::Iterator start);
227
228private:
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700229 Ptr<CcnxNameComponents> m_name;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700230 int32_t m_minSuffixComponents; ///< minimum suffix components. not used if negative
231 int32_t m_maxSuffixComponents; ///< maximum suffix components. not used if negative
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700232 Ptr<CcnxNameComponents> m_exclude; ///< exclude filter
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700233 bool m_childSelector;
234 bool m_answerOriginKind;
235 int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700236 Time m_interestLifetime;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700237 uint32_t m_nonce; ///< Nonce. not used if zero
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800238 uint32_t m_nackType;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700239};
240
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700241class CcnxInterestHeaderException {};
242
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700243} // namespace ns3
244
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700245#endif // _CCNX_INTEREST_HEADER_H_