blob: c563f70eb94c94db4e91e9a5b82d7d103a173e01 [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_CONTENT_OBJECT_HEADER_H_
23#define _CCNX_CONTENT_OBJECT_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 Afanasyev070aa482011-08-20 00:38:25 -070028#include "ns3/trailer.h"
Alexander Afanasyev9568f952012-04-05 16:09:14 -070029#include "ns3/nstime.h"
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070030
31#include <string>
32#include <vector>
33#include <list>
34
Ilya Moiseenkod26e6822011-08-23 17:48:38 -070035#include "ccnx-name-components.h"
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070036
37namespace ns3
38{
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070039
40/**
41 * CCNx XML definition of ContentObject
42 *
43 * Only few important fields are actually implemented in the simulation
44 *
45 *
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070046 * ContentObjectHeader serializes/deserializes header up-to and including <Content> tags
47 * Necessary closing tags should be added using ContentObjectTail
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070048 *
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070049 * This hacks are necessary to optimize memory use (i.e., virtual payload)
50 *
51 * "<ContentObject><Signature>..</Signature><Name>...</Name><SignedInfo>...</SignedInfo><Content>"
52 *
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070053 */
Alexander Afanasyeve275cf82012-04-18 14:25:02 -070054class CcnxContentObjectHeader : public SimpleRefCount<CcnxContentObjectHeader,Header>
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070055{
56public:
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070057 ////////////////////////////////////////////////////////////////////////////
58 ////////////////////////////////////////////////////////////////////////////
59 ////////////////////////////////////////////////////////////////////////////
60 /**
61 * @brief Class representing Signature section of the content object
62 */
63 class Signature
64 {
65 public:
66 /**
67 * @brief Default constructor. Creates a fake-type signature
68 */
69 inline Signature ();
70
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070071 /**
72 * @brief Get digest algorithm
73 */
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070074 inline const std::string &
75 GetDigestAlgorithm () const;
76
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070077 /**
78 * @brief Set digest algorithm
79 */
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070080 inline void
81 SetDigestAlgorithm (const std::string &digestAlgorithm);
82
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070083 /**
84 * @brief Get signature bits
85 */
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070086 inline uint32_t
87 GetSignatureBits () const;
88
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070089 /**
90 * @brief Set signature bits
91 */
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070092 inline void
93 SetSignatureBits (uint32_t signatureBits);
94
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070095 /**
96 * @brief Default digest algorithm ("2.16.840.1.101.3.4.2.1")
97 */
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070098 static const std::string DefaultDigestAlgorithm; // = "2.16.840.1.101.3.4.2.1";
99
100 private:
101 std::string m_digestAlgorithm; // if value is `2.16.840.1.101.3.4.2.1`, then SHA-256 (not supported)
102 // in NS-3 value `99.0` represents a fake digest
103 // Witness // not used in NS-3
104 uint32_t m_signatureBits; // in NS-3 a fake signature is a just 32-bits
105 };
106
107 ////////////////////////////////////////////////////////////////////////////
108 ////////////////////////////////////////////////////////////////////////////
109 ////////////////////////////////////////////////////////////////////////////
110
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700111 /**
112 * @brief Options for the data packet Type
113 */
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700114 enum ContentType
115 {
116 DATA = 0x0C04C0, // default value. If ContentObject is type of DATA, then ContentType tag will be omitted
117 ENCR = 0x10D091,
118 GONE = 0x18E344,
119 KEY = 0x28463F,
120 LINK = 0x2C834A,
121 NACK = 0x34008A
122 };
123
124 ////////////////////////////////////////////////////////////////////////////
125 ////////////////////////////////////////////////////////////////////////////
126 ////////////////////////////////////////////////////////////////////////////
127
128 /**
129 * @brief Class representing SignedInfo section of the content object
130 */
131 class SignedInfo
132 {
133 public:
134 /**
135 * @brief Default constructor
136 */
137 SignedInfo ();
138
139 /**
140 * @brief Set PublisherPublicKey digest
141 * @param digest a fake 32-bit digest is supported
142 */
143 void
144 SetPublisherPublicKeyDigest (uint32_t digest);
145
146 /**
147 * @brief Get PublisherPublicKey digest
148 */
149 uint32_t
150 GetPublisherPublicKeyDigest () const;
151
152 /**
153 * @brief Set content object timestamp
154 * @param timestamp timestamp
155 */
156 void
157 SetTimestamp (const Time &timestamp);
158
159 /**
160 * @brief Get timestamp of the content object
161 */
162 Time
163 GetTimestamp () const;
164
165 /**
166 * @brief Set ContentObject type
167 * @param type type of the content object
168 */
169 void
170 SetContentType (ContentType type);
171
172 /**
173 * @brief Get ContentObject type
174 */
175 ContentType
176 GetContentType () const;
177
178 /**
179 * @brief Set freshness of the content object
180 * @param freshness Freshness, 0s means infinity
181 */
182 void
183 SetFreshness (const Time &freshness);
184
185 /**
186 * @brief Get freshness of the content object
187 */
188 Time
189 GetFreshness () const;
190
191 /**
192 * @brief Set key locator
193 * @param keyLocator name of the key
194 *
195 * Note that only <KeyName> option for the key locator is supported
196 */
197 void
198 SetKeyLocator (Ptr<const CcnxNameComponents> keyLocator);
199
200 /**
201 * @brief Get key locator
202 *
203 * Note that only <KeyName> option for the key locator is supported
204 */
205 Ptr<const CcnxNameComponents>
206 GetKeyLocator () const;
207
208 private:
209 uint32_t m_publisherPublicKeyDigest; // fake publisher key digest
210 Time m_timestamp;
211 ContentType m_type;
212 Time m_freshness;
213 // FinalBlockID
214 Ptr<const CcnxNameComponents> m_keyLocator; // support only <KeyName> option for KeyLocator
215 };
216
217 ////////////////////////////////////////////////////////////////////////////
218 ////////////////////////////////////////////////////////////////////////////
219 ////////////////////////////////////////////////////////////////////////////
220 ////////////////////////////////////////////////////////////////////////////
221 ////////////////////////////////////////////////////////////////////////////
222 ////////////////////////////////////////////////////////////////////////////
223
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700224 /**
225 * Constructor
226 *
227 * Creates a null header
228 **/
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700229 CcnxContentObjectHeader ();
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700230
231 /**
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700232 * \brief Set content object name
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700233 *
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700234 * Sets name of the content object. For example, SetName( CcnxNameComponents("prefix")("postfix") );
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700235 **/
236 void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700237 SetName (const Ptr<CcnxNameComponents> &name);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700238
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700239 /**
240 * @brief Get name of the content object
241 */
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700242 const CcnxNameComponents&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700243 GetName () const;
244
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700245 /**
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700246 * @brief Get smart pointer to the interest name (to avoid extra memory usage)
247 */
248 Ptr<const CcnxNameComponents>
249 GetNamePtr () const;
250
251 /**
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700252 * @brief Get editable reference to content object's Signature
253 */
254 inline Signature &
255 GetSignature ();
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700256
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700257 /**
258 * @brief Get read-only reference to content object's Signature
259 */
260 inline const Signature &
261 GetSignature () const;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700262
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700263 /**
264 * @brief Get editable reference to content object's SignedInfo
265 */
266 inline SignedInfo &
267 GetSignedInfo ();
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700268
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700269 /**
270 * @brief Get read-only reference to content object's SignedInfo
271 */
272 inline const SignedInfo &
273 GetSignedInfo () const;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700274
275 //////////////////////////////////////////////////////////////////
276
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700277 static TypeId GetTypeId (void); ///< @brief Get TypeId
278 virtual TypeId GetInstanceTypeId (void) const; ///< @brief Get TypeId of the instance
279 virtual void Print (std::ostream &os) const; ///< @brief Print out information about the Header into the stream
280 virtual uint32_t GetSerializedSize (void) const; ///< @brief Get size necessary to serialize the Header
281 virtual void Serialize (Buffer::Iterator start) const; ///< @brief Serialize the Header
282 virtual uint32_t Deserialize (Buffer::Iterator start); ///< @brief Deserialize the Header
Alexander Afanasyev9568f952012-04-05 16:09:14 -0700283
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700284private:
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700285 Signature m_signature;
Alexander Afanasyev9568f952012-04-05 16:09:14 -0700286 Ptr<CcnxNameComponents> m_name;
287 SignedInfo m_signedInfo;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700288};
289
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700290/**
291 * ContentObjectTail should always be 2 bytes, representing two closing tags:
292 * "</Content><ContentObject>"
293 */
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700294class CcnxContentObjectTail : public Trailer
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700295{
296public:
297 CcnxContentObjectTail ();
298 //////////////////////////////////////////////////////////////////
299
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700300 static TypeId GetTypeId (void); ///< @brief Get TypeId
301 virtual TypeId GetInstanceTypeId (void) const; ///< @brief Get TypeId of the instance
302 virtual void Print (std::ostream &os) const; ///< @brief Print out information about Tail into the stream
303 virtual uint32_t GetSerializedSize (void) const; ///< @brief Get size necessary to serialize the Tail
304 virtual void Serialize (Buffer::Iterator start) const; ///< @brief Serialize the Tail
305 virtual uint32_t Deserialize (Buffer::Iterator start); ///< @brief Deserialize the Tail
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700306};
307
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700308
309CcnxContentObjectHeader::Signature::Signature ()
310 : m_digestAlgorithm ("99.0")
311 , m_signatureBits (0)
312{
313}
314
315const std::string &
316CcnxContentObjectHeader::Signature::GetDigestAlgorithm () const
317{
318 return m_digestAlgorithm;
319}
320
321void
322CcnxContentObjectHeader::Signature::SetDigestAlgorithm (const std::string &digestAlgorithm)
323{
324 m_digestAlgorithm = digestAlgorithm;
325}
326
327uint32_t
328CcnxContentObjectHeader::Signature::GetSignatureBits () const
329{
330 return m_signatureBits;
331}
332
333inline void
334CcnxContentObjectHeader::Signature::SetSignatureBits (uint32_t signature)
335{
336 m_signatureBits = signature;
337}
338
339
340CcnxContentObjectHeader::Signature &
341CcnxContentObjectHeader::GetSignature ()
342{
343 return m_signature;
344}
345
346const CcnxContentObjectHeader::Signature &
347CcnxContentObjectHeader::GetSignature () const
348{
349 return m_signature;
350}
351
352CcnxContentObjectHeader::SignedInfo &
353CcnxContentObjectHeader::GetSignedInfo ()
354{
355 return m_signedInfo;
356}
357
358const CcnxContentObjectHeader::SignedInfo &
359CcnxContentObjectHeader::GetSignedInfo () const
360{
361 return m_signedInfo;
362}
363
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700364/**
365 * @brief Class for ContentObject parsing exception
366 */
Alexander Afanasyeve91ab752011-08-31 19:13:40 -0700367class CcnxContentObjectHeaderException {};
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700368
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700369} // namespace ns3
370
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700371#endif // _CCNX_CONTENT_OBJECT_HEADER_H_