blob: 44ffa6bcb1eea6a9f6f80479c1f46203f9fdd703 [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
33#include "name-components.h"
34
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 Afanasyevc74a6022011-08-15 20:01:35 -0700128 class 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 *
141 * Sets name of the interest. For example, SetName( Name::Components("prefix")("postfix") );
142 **/
143 void
144 SetName (const Ptr<Name::Components> &name);
145
146 const Name::Components&
147 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 *
164 * For example, SetExclude (Name::Components("exclude1")("exclude2")("exclude3"))
165 **/
166 void
167 SetExclude (const Ptr<Name::Components> &exclude);
168
169 const Name::Components&
170 GetExclude () const;
171
172 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700173 SetChildSelector (bool value);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700174
175 bool
176 IsEnabledChildSelector () const;
177
178 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700179 SetAnswerOriginKind (bool value);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700180
181 bool
182 IsEnabledAnswerOriginKind () const;
183
184 void
185 SetScope (int8_t scope);
186
187 int8_t
188 GetScope () const;
189
190 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700191 SetInterestLifetime (Time time);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700192
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700193 Time
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700194 GetInterestLifetime () const;
195
196 void
197 SetNonce (uint32_t nonce);
198
199 uint32_t
200 GetNonce () const;
201
202 //////////////////////////////////////////////////////////////////
203
204 static TypeId GetTypeId (void);
205 virtual TypeId GetInstanceTypeId (void) const;
206 virtual void Print (std::ostream &os) const;
207 virtual uint32_t GetSerializedSize (void) const;
208 virtual void Serialize (Buffer::Iterator start) const;
209 virtual uint32_t Deserialize (Buffer::Iterator start);
210
211private:
212 Ptr<Name::Components> m_name;
213 int32_t m_minSuffixComponents; ///< minimum suffix components. not used if negative
214 int32_t m_maxSuffixComponents; ///< maximum suffix components. not used if negative
215 Ptr<Name::Components> m_exclude; ///< exclude filter
216 bool m_childSelector;
217 bool m_answerOriginKind;
218 int8_t m_scope; ///< -1 not set, 0 local scope, 1 this host, 2 immediate neighborhood
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700219 Time m_interestLifetime;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700220 uint32_t m_nonce; ///< Nonce. not used if zero
221};
222
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700223} // namespace ns3
224
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700225#endif // _CCNX_INTEREST_HEADER_H_