blob: 259e156d2884572204379e56497b76570211f1a3 [file] [log] [blame]
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -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 * 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 Afanasyev8a677dd2011-08-12 13:08:15 -070027
28#include <string>
29#include <vector>
30#include <list>
31
32#include "name-components.h"
33
34namespace ns3
35{
Alexander Afanasyev2536e202011-08-12 14:13:10 -070036
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070037/**
38 * CCNx XML definition of Interest
39 *
40 * Only few important fields are actually implemented in the simulation
41 *
42 * <xs:element name="Interest" type="InterestType"/>
43 * <xs:complexType name="InterestType">
44 * <xs:sequence>
45 * <xs:element name="Name" type="NameType"/>
46 * <xs:element name="MinSuffixComponents" type="xs:nonNegativeInteger"
47 * minOccurs="0" maxOccurs="1"/>
48 * <xs:element name="MaxSuffixComponents" type="xs:nonNegativeInteger"
49 * minOccurs="0" maxOccurs="1"/>
50 * <xs:choice minOccurs="0" maxOccurs="1">
51 * <xs:element name="PublisherPublicKeyDigest" type="DigestType"/>
52 * <xs:element name="PublisherCertificateDigest" type="DigestType"/>
53 * <xs:element name="PublisherIssuerKeyDigest" type="DigestType"/>
54 * <xs:element name="PublisherIssuerCertificateDigest" type="DigestType"/>
55 * </xs:choice>
56 * <xs:element name="Exclude" type="ExcludeType"
57 * minOccurs="0" maxOccurs="1"/>
58 * <xs:element name="ChildSelector" type="xs:nonNegativeInteger"
59 * minOccurs="0" maxOccurs="1"/>
60 * <xs:element name="AnswerOriginKind" type="xs:nonNegativeInteger"
61 * minOccurs="0" maxOccurs="1"/>
62 * <xs:element name="Scope" type="xs:nonNegativeInteger"
63 * minOccurs="0" maxOccurs="1"/>
64 * <xs:element name="InterestLifetime" type="FinegrainLifetimeType"
65 * minOccurs="0" maxOccurs="1"/>
66 * <xs:element name="Nonce" type="Base64BinaryType"
67 * minOccurs="0" maxOccurs="1"/>
68 * </xs:sequence>
69 * </xs:complexType>
70 *
71 * <xs:complexType name="NameType">
72 * <xs:sequence>
73 * <xs:element name="Component" type="Base64BinaryType"
74 * minOccurs="0" maxOccurs="unbounded"/>
75 * </xs:sequence>
76 * </xs:complexType>
77 *
78 * <xs:complexType name="ExcludeType">
79 * <xs:sequence>
80 * <xs:choice minOccurs="0" maxOccurs="1">
81 * <xs:element name="Any" type="EmptyType"/>
82 * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
83 * </xs:choice>
84 * <xs:sequence minOccurs="0" maxOccurs="unbounded">
85 * <xs:element name="Component" type="Base64BinaryType"/>
86 * <xs:choice minOccurs="0" maxOccurs="1">
87 * <xs:element name="Any" type="EmptyType"/>
88 * <xs:element name="Bloom" type="Base64BinaryType"/> <!-- Bloom is deprecated --!>
89 * </xs:choice>
90 * </xs:sequence>
91 * </xs:sequence>
92 * </xs:complexType>
93 *
94 * <!-- Binary representation of time, Unix time epoch, units 2**-12 sec (0.000244140625 sec) -->
95 * <!-- The length limit limit of 6 bytes is not actually to be enforced, but
96 * it will be a loooooooong time before anyone cares. -->
97 *
98 * <!-- Binary representation of relative time, relative to "now" -->
99 * <xs:complexType name="FinegrainLifetimeType">
100 * <xs:simpleContent>
101 * <xs:extension base="BinaryTime12">
102 * <xs:attribute name="ccnbencoding" type="xs:string" fixed="base64Binary"/>
103 * </xs:extension>
104 * </xs:simpleContent>
105 * </xs:complexType>
106 *
107 * <xs:simpleType name="BinaryTime12">
108 * <xs:restriction base="xs:base64Binary">
109 * <xs:length value="6" fixed="true"/>
110 * </xs:restriction>
111 * </xs:simpleType>
112 *
113 **/
114
115/**
116 NDN InterestHeader and routines to serialize/deserialize
117
118 Simplifications:
119 - Name: binary name components are not supported
120 - MinSuffixComponents and MasSuffixComponents: if value is negative (default), will not be serialized
121 - ChildSelector, AnswerOriginKind: 0 - false, 1 - true, -1 not set
122 - Publisher* elements are not supported
123 - Exclude: only simple name matching is supported (Bloom support has been deprecated in CCNx)
124 - InterestLifetime: not used if negative
125 - Nonce: 32 bit random integer. If value is 0, will not be serialized
126 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700127class CcnxInterestHeader : public Header
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700128{
129public:
130 /**
131 * Constructor
132 *
133 * Creates a null header
134 **/
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700135 CcnxInterestHeader ();
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700136
137 /**
138 * \brief Set interest name
139 *
140 * Sets name of the interest. For example, SetName( Name::Components("prefix")("postfix") );
141 **/
142 void
143 SetName (const Ptr<Name::Components> &name);
144
145 const Name::Components&
146 GetName () const;
147
148 void
149 SetMinSuffixComponents (int32_t value);
150
151 int32_t
152 GetMinSuffixComponents () const;
153
154 void
155 SetMaxSuffixComponents (int32_t value);
156
157 int32_t
158 GetMaxSuffixComponents () const;
159
160 /**
161 * \brief Set exclude filer
162 *
163 * For example, SetExclude (Name::Components("exclude1")("exclude2")("exclude3"))
164 **/
165 void
166 SetExclude (const Ptr<Name::Components> &exclude);
167
168 const Name::Components&
169 GetExclude () const;
170
171 void
172 EnableChildSelector ();
173
174 bool
175 IsEnabledChildSelector () const;
176
177 void
178 EnableAnswerOriginKind ();
179
180 bool
181 IsEnabledAnswerOriginKind () const;
182
183 void
184 SetScope (int8_t scope);
185
186 int8_t
187 GetScope () const;
188
189 void
190 SetInterestLifetime (intmax_t lifetime);
191
192 intmax_t
193 GetInterestLifetime () const;
194
195 void
196 SetNonce (uint32_t nonce);
197
198 uint32_t
199 GetNonce () const;
200
201 //////////////////////////////////////////////////////////////////
202
203 static TypeId GetTypeId (void);
204 virtual TypeId GetInstanceTypeId (void) const;
205 virtual void Print (std::ostream &os) const;
206 virtual uint32_t GetSerializedSize (void) const;
207 virtual void Serialize (Buffer::Iterator start) const;
208 virtual uint32_t Deserialize (Buffer::Iterator start);
209
210private:
211 Ptr<Name::Components> m_name;
212 int32_t m_minSuffixComponents; ///< minimum suffix components. not used if negative
213 int32_t m_maxSuffixComponents; ///< maximum suffix components. not used if negative
214 Ptr<Name::Components> m_exclude; ///< exclude filter
215 bool m_childSelector;
216 bool m_answerOriginKind;
217 int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood
218 intmax_t m_interestLifetime; ///< InterestLifetime in 2^{-12} (0.000244140625 sec). not used if negative
219 uint32_t m_nonce; ///< Nonce. not used if zero
220};
221
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700222} // namespace ns3
223
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700224#endif // _CCNX_INTEREST_HEADER_H_