blob: d4b2f9fd8801b32fd178fe14586862bec739930c [file] [log] [blame]
Alexander Afanasyev6b997c52011-08-08 12:55:25 -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 */
Ilya Moiseenko08a98a42011-08-02 16:06:51 -070020
Alexander Afanasyev404c0792011-08-09 17:09:59 -070021#ifndef _INTEREST_PACKET_H_
22#define _INTEREST_PACKET_H_
Ilya Moiseenko08a98a42011-08-02 16:06:51 -070023
24//#define CCN_INTEREST_LIFETIME_SEC 4
25//#define CCN_INTEREST_LIFETIME_MICROSEC (CCN_INTEREST_LIFETIME_SEC * 1000000)
26
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070027#include <ns3/integer.h>
Alexander Afanasyev404c0792011-08-09 17:09:59 -070028#include <ns3/header.h>
Ilya Moiseenko08a98a42011-08-02 16:06:51 -070029#include <ns3/packet.h>
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070030
Ilya Moiseenko5881eb12011-08-04 19:05:26 -070031#include <string>
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070032#include <vector>
33#include <list>
34
35#include "name-components.h"
Ilya Moiseenko08a98a42011-08-02 16:06:51 -070036
37namespace ns3
38{
Ilya Moiseenko5881eb12011-08-04 19:05:26 -070039namespace NDNabstraction
40{
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -070041
42/**
43 * CCNx XML definition of Interest
44 *
45 * Only few important fields are actually implemented in the simulation
46 *
47 * <xs:element name="Interest" type="InterestType"/>
48 * <xs:complexType name="InterestType">
49 * <xs:sequence>
50 * <xs:element name="Name" type="NameType"/>
51 * <xs:element name="MinSuffixComponents" type="xs:nonNegativeInteger"
52 * minOccurs="0" maxOccurs="1"/>
53 * <xs:element name="MaxSuffixComponents" type="xs:nonNegativeInteger"
54 * minOccurs="0" maxOccurs="1"/>
55 * <xs:choice minOccurs="0" maxOccurs="1">
56 * <xs:element name="PublisherPublicKeyDigest" type="DigestType"/>
57 * <xs:element name="PublisherCertificateDigest" type="DigestType"/>
58 * <xs:element name="PublisherIssuerKeyDigest" type="DigestType"/>
59 * <xs:element name="PublisherIssuerCertificateDigest" type="DigestType"/>
60 * </xs:choice>
61 * <xs:element name="Exclude" type="ExcludeType"
62 * minOccurs="0" maxOccurs="1"/>
63 * <xs:element name="ChildSelector" type="xs:nonNegativeInteger"
64 * minOccurs="0" maxOccurs="1"/>
65 * <xs:element name="AnswerOriginKind" type="xs:nonNegativeInteger"
66 * minOccurs="0" maxOccurs="1"/>
67 * <xs:element name="Scope" type="xs:nonNegativeInteger"
68 * minOccurs="0" maxOccurs="1"/>
69 * <xs:element name="InterestLifetime" type="FinegrainLifetimeType"
70 * minOccurs="0" maxOccurs="1"/>
71 * <xs:element name="Nonce" type="Base64BinaryType"
72 * minOccurs="0" maxOccurs="1"/>
73 * </xs:sequence>
74 * </xs:complexType>
75 *
76 * <xs:complexType name="NameType">
77 * <xs:sequence>
78 * <xs:element name="Component" type="Base64BinaryType"
79 * minOccurs="0" maxOccurs="unbounded"/>
80 * </xs:sequence>
81 * </xs:complexType>
82 *
83 * <xs:complexType name="ExcludeType">
84 * <xs:sequence>
85 * <xs:choice minOccurs="0" maxOccurs="1">
86 * <xs:element name="Any" type="EmptyType"/>
87 * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
88 * </xs:choice>
89 * <xs:sequence minOccurs="0" maxOccurs="unbounded">
90 * <xs:element name="Component" type="Base64BinaryType"/>
91 * <xs:choice minOccurs="0" maxOccurs="1">
92 * <xs:element name="Any" type="EmptyType"/>
93 * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
94 * </xs:choice>
95 * </xs:sequence>
96 * </xs:sequence>
97 * </xs:complexType>
98 *
99 * <!-- Binary representation of time, Unix time epoch, units 2**-12 sec (0.000244140625 sec) -->
100 * <!-- The length limit limit of 6 bytes is not actually to be enforced, but
101 * it will be a loooooooong time before anyone cares. -->
102 *
103 * <!-- Binary representation of relative time, relative to "now" -->
104 * <xs:complexType name="FinegrainLifetimeType">
105 * <xs:simpleContent>
106 * <xs:extension base="BinaryTime12">
107 * <xs:attribute name="ccnbencoding" type="xs:string" fixed="base64Binary"/>
108 * </xs:extension>
109 * </xs:simpleContent>
110 * </xs:complexType>
111 *
112 * <xs:simpleType name="BinaryTime12">
113 * <xs:restriction base="xs:base64Binary">
114 * <xs:length value="6" fixed="true"/>
115 * </xs:restriction>
116 * </xs:simpleType>
117 *
118 **/
119
120 /**
121 NDN InterestPacket and routes to serialize/deserialize
122
123 Simplifications:
124 - Name: binary name components are not supported
125 - MinSuffixComponents and MasSuffixComponents: if value is negative (default), will not be serialized
126 - ChildSelector, AnswerOriginKind: 0 - false, 1 - true, -1 not set
127 - Publisher* elements are not supported
128 - Exclude: only simple name matching is supported (Bloom support has been deprecated in CCNx)
129 - InterestLifetime: not used if negative
130 - Nonce: 32 bit random integer. If value is 0, will not be serialized
131 */
132 class InterestHeader : public Header
133 {
134 public:
135 /**
136 * Constructor
137 *
138 * Creates a null header
139 **/
140 InterestHeader ();
141
142 /**
143 * \brief Set interest name
144 *
145 * Sets name of the interest. For example, SetName( Name::Components("prefix")("postfix") );
146 **/
147 void
148 SetName (const Ptr<Name::Components> &name);
149
150 const Name::Components&
151 GetName () const;
152
153 void
154 SetMinSuffixComponents (int32_t value);
155
156 int32_t
157 GetMinSuffixComponents () const;
158
159 void
160 SetMaxSuffixComponents (int32_t value);
161
162 int32_t
163 GetMaxSuffixComponents () const;
164
165 /**
166 * \brief Set exclude filer
167 *
168 * For example, SetExclude (Name::Components("exclude1")("exclude2")("exclude3"))
169 **/
170 void
171 SetExclude (const Ptr<Name::Components> &exclude);
172
173 const Name::Components&
174 GetExclude () const;
175
176 void
177 EnableChildSelector ();
178
179 bool
180 IsEnabledChildSelector () const;
181
182 void
183 EnableAnswerOriginKind ();
184
185 bool
186 IsEnabledAnswerOriginKind () const;
187
188 void
189 SetScope (int8_t scope);
190
191 int8_t
192 GetScope () const;
193
194 void
195 SetInterestLifetime (intmax_t lifetime);
196
197 intmax_t
198 GetInterestLifetime () const;
199
200 void
201 SetNonce (uint32_t nonce);
202
203 uint32_t
204 GetNonce () const;
205
206 //////////////////////////////////////////////////////////////////
207
208 static TypeId GetTypeId (void);
209 virtual TypeId GetInstanceTypeId (void) const;
210 virtual void Print (std::ostream &os) const;
211 virtual uint32_t GetSerializedSize (void) const;
212 virtual void Serialize (Buffer::Iterator start) const;
213 virtual uint32_t Deserialize (Buffer::Iterator start);
214
215 private:
216 Ptr<Name::Components> m_name;
217 int32_t m_minSuffixComponents; ///< minimum suffix components. not used if negative
218 int32_t m_maxSuffixComponents; ///< maximum suffix components. not used if negative
219 Ptr<Name::Components> m_exclude; ///< exclude filter
220 bool m_childSelector;
221 bool m_answerOriginKind;
222 int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood
223 intmax_t m_interestLifetime; ///< InterestLifetime in 2^{-12} (0.000244140625 sec). not used if negative
224 uint32_t m_nonce; ///< Nonce. not used if zero
225 };
226
227
228 // Not sure that we need a separate NndPacket class. Everything useful will be inside (Interest|ContentObject)Header
229// class NdnPacket : public Packet
230// {
231// public:
232// NdnPacket( )
233 // ;
Alexander Afanasyev404c0792011-08-09 17:09:59 -0700234 // InterestPacket (const unsigned char *name, uint32_t size);
235
236
237 // uint32_t GetName (unsigned char *name);
238
239 // void AddTimeout (uint32_t milliseconds);
240 // uint32_t GetTimeout (void);
241 // void RemoveTimeout (void);
242
243 // void AddNonce (uint32_t nonce);
244 // uint32_t GetNonce (void);
245 // void RemoveNonce (void);
246
247 // uint32_t maxNameLength;
248
Alexander Afanasyev3a6ea5c2011-08-11 18:15:49 -0700249// };
Alexander Afanasyevf583ef22011-08-08 19:05:28 -0700250
Ilya Moiseenko08a98a42011-08-02 16:06:51 -0700251}
Ilya Moiseenko5881eb12011-08-04 19:05:26 -0700252}
Ilya Moiseenko08a98a42011-08-02 16:06:51 -0700253
Alexander Afanasyev404c0792011-08-09 17:09:59 -0700254#endif // _NDN_PACKET_H_