blob: f19dbbe5435c42926d15b945ff9863e392b2df47 [file] [log] [blame]
Alexander Afanasyev5d79e682012-11-19 14:12:23 -08001/* -*- 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
22#ifndef _NDN_CONTENT_OBJECT_HEADER_CCNB_H_
23#define _NDN_CONTENT_OBJECT_HEADER_CCNB_H_
24
25#include "ns3/integer.h"
26#include "ns3/header.h"
27#include "ns3/simple-ref-count.h"
28#include "ns3/trailer.h"
29#include "ns3/nstime.h"
30
31#include <string>
32#include <vector>
33#include <list>
34
35#include "ndn-name-components.h"
36
37namespace ns3 {
38namespace ndn {
39
40/**
41 * Ndn XML definition of ContentObject
42 *
43 * Only few important fields are actually implemented in the simulation
44 *
45 *
46 * ContentObjectHeader serializes/deserializes header up-to and including <Content> tags
47 * Necessary closing tags should be added using ContentObjectTail
48 *
49 * This hacks are necessary to optimize memory use (i.e., virtual payload)
50 *
51 * "<ContentObject><Signature>..</Signature><Name>...</Name><SignedInfo>...</SignedInfo><Content>"
52 *
53 */
54class ContentObjectHeader : public SimpleRefCount<ContentObjectHeader,Header>
55{
56public:
57 ////////////////////////////////////////////////////////////////////////////
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
71 /**
72 * @brief Get digest algorithm
73 */
74 inline const std::string &
75 GetDigestAlgorithm () const;
76
77 /**
78 * @brief Set digest algorithm
79 */
80 inline void
81 SetDigestAlgorithm (const std::string &digestAlgorithm);
82
83 /**
84 * @brief Get signature bits
85 */
86 inline uint32_t
87 GetSignatureBits () const;
88
89 /**
90 * @brief Set signature bits
91 */
92 inline void
93 SetSignatureBits (uint32_t signatureBits);
94
95 /**
96 * @brief Default digest algorithm ("2.16.840.1.101.3.4.2.1")
97 */
98 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
111 /**
112 * @brief Options for the data packet Type
113 */
114 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 NameComponents> 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 NameComponents>
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 NameComponents> m_keyLocator; // support only <KeyName> option for KeyLocator
215 };
216
217 ////////////////////////////////////////////////////////////////////////////
218 ////////////////////////////////////////////////////////////////////////////
219 ////////////////////////////////////////////////////////////////////////////
220 ////////////////////////////////////////////////////////////////////////////
221 ////////////////////////////////////////////////////////////////////////////
222 ////////////////////////////////////////////////////////////////////////////
223
224 /**
225 * Constructor
226 *
227 * Creates a null header
228 **/
229 ContentObjectHeader ();
230
231 /**
232 * \brief Set content object name
233 *
234 * Sets name of the content object. For example, SetName( NameComponents("prefix")("postfix") );
235 **/
236 void
237 SetName (const Ptr<NameComponents> &name);
238
239 /**
240 * @brief Get name of the content object
241 */
242 const NameComponents&
243 GetName () const;
244
245 /**
246 * @brief Get smart pointer to the interest name (to avoid extra memory usage)
247 */
248 Ptr<const NameComponents>
249 GetNamePtr () const;
250
251 /**
252 * @brief Get editable reference to content object's Signature
253 */
254 inline Signature &
255 GetSignature ();
256
257 /**
258 * @brief Get read-only reference to content object's Signature
259 */
260 inline const Signature &
261 GetSignature () const;
262
263 /**
264 * @brief Get editable reference to content object's SignedInfo
265 */
266 inline SignedInfo &
267 GetSignedInfo ();
268
269 /**
270 * @brief Get read-only reference to content object's SignedInfo
271 */
272 inline const SignedInfo &
273 GetSignedInfo () const;
274
275 //////////////////////////////////////////////////////////////////
276
277 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
283
284private:
285 Signature m_signature;
286 Ptr<NameComponents> m_name;
287 SignedInfo m_signedInfo;
288};
289
290/**
291 * ContentObjectTail should always be 2 bytes, representing two closing tags:
292 * "</Content><ContentObject>"
293 */
294class ContentObjectTail : public Trailer
295{
296public:
297 ContentObjectTail ();
298 //////////////////////////////////////////////////////////////////
299
300 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
306};
307
308
309ContentObjectHeader::Signature::Signature ()
310 : m_digestAlgorithm ("99.0")
311 , m_signatureBits (0)
312{
313}
314
315const std::string &
316ContentObjectHeader::Signature::GetDigestAlgorithm () const
317{
318 return m_digestAlgorithm;
319}
320
321void
322ContentObjectHeader::Signature::SetDigestAlgorithm (const std::string &digestAlgorithm)
323{
324 m_digestAlgorithm = digestAlgorithm;
325}
326
327uint32_t
328ContentObjectHeader::Signature::GetSignatureBits () const
329{
330 return m_signatureBits;
331}
332
333inline void
334ContentObjectHeader::Signature::SetSignatureBits (uint32_t signature)
335{
336 m_signatureBits = signature;
337}
338
339
340ContentObjectHeader::Signature &
341ContentObjectHeader::GetSignature ()
342{
343 return m_signature;
344}
345
346const ContentObjectHeader::Signature &
347ContentObjectHeader::GetSignature () const
348{
349 return m_signature;
350}
351
352ContentObjectHeader::SignedInfo &
353ContentObjectHeader::GetSignedInfo ()
354{
355 return m_signedInfo;
356}
357
358const ContentObjectHeader::SignedInfo &
359ContentObjectHeader::GetSignedInfo () const
360{
361 return m_signedInfo;
362}
363
364/**
365 * @ingroup ndn-exceptions
366 * @brief Class for ContentObject parsing exception
367 */
368class ContentObjectHeaderException {};
369
370} // namespace ndn
371} // namespace ns3
372
373#endif // _NDN_CONTENT_OBJECT_HEADER_CCNB_H_