blob: a7bad0155d8238c48f2d809019da4bd62ab59f38 [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
71 inline const std::string &
72 GetDigestAlgorithm () const;
73
74 inline void
75 SetDigestAlgorithm (const std::string &digestAlgorithm);
76
77 inline uint32_t
78 GetSignatureBits () const;
79
80 inline void
81 SetSignatureBits (uint32_t signatureBits);
82
83 static const std::string DefaultDigestAlgorithm; // = "2.16.840.1.101.3.4.2.1";
84
85 private:
86 std::string m_digestAlgorithm; // if value is `2.16.840.1.101.3.4.2.1`, then SHA-256 (not supported)
87 // in NS-3 value `99.0` represents a fake digest
88 // Witness // not used in NS-3
89 uint32_t m_signatureBits; // in NS-3 a fake signature is a just 32-bits
90 };
91
92 ////////////////////////////////////////////////////////////////////////////
93 ////////////////////////////////////////////////////////////////////////////
94 ////////////////////////////////////////////////////////////////////////////
95
96 enum ContentType
97 {
98 DATA = 0x0C04C0, // default value. If ContentObject is type of DATA, then ContentType tag will be omitted
99 ENCR = 0x10D091,
100 GONE = 0x18E344,
101 KEY = 0x28463F,
102 LINK = 0x2C834A,
103 NACK = 0x34008A
104 };
105
106 ////////////////////////////////////////////////////////////////////////////
107 ////////////////////////////////////////////////////////////////////////////
108 ////////////////////////////////////////////////////////////////////////////
109
110 /**
111 * @brief Class representing SignedInfo section of the content object
112 */
113 class SignedInfo
114 {
115 public:
116 /**
117 * @brief Default constructor
118 */
119 SignedInfo ();
120
121 /**
122 * @brief Set PublisherPublicKey digest
123 * @param digest a fake 32-bit digest is supported
124 */
125 void
126 SetPublisherPublicKeyDigest (uint32_t digest);
127
128 /**
129 * @brief Get PublisherPublicKey digest
130 */
131 uint32_t
132 GetPublisherPublicKeyDigest () const;
133
134 /**
135 * @brief Set content object timestamp
136 * @param timestamp timestamp
137 */
138 void
139 SetTimestamp (const Time &timestamp);
140
141 /**
142 * @brief Get timestamp of the content object
143 */
144 Time
145 GetTimestamp () const;
146
147 /**
148 * @brief Set ContentObject type
149 * @param type type of the content object
150 */
151 void
152 SetContentType (ContentType type);
153
154 /**
155 * @brief Get ContentObject type
156 */
157 ContentType
158 GetContentType () const;
159
160 /**
161 * @brief Set freshness of the content object
162 * @param freshness Freshness, 0s means infinity
163 */
164 void
165 SetFreshness (const Time &freshness);
166
167 /**
168 * @brief Get freshness of the content object
169 */
170 Time
171 GetFreshness () const;
172
173 /**
174 * @brief Set key locator
175 * @param keyLocator name of the key
176 *
177 * Note that only <KeyName> option for the key locator is supported
178 */
179 void
180 SetKeyLocator (Ptr<const CcnxNameComponents> keyLocator);
181
182 /**
183 * @brief Get key locator
184 *
185 * Note that only <KeyName> option for the key locator is supported
186 */
187 Ptr<const CcnxNameComponents>
188 GetKeyLocator () const;
189
190 private:
191 uint32_t m_publisherPublicKeyDigest; // fake publisher key digest
192 Time m_timestamp;
193 ContentType m_type;
194 Time m_freshness;
195 // FinalBlockID
196 Ptr<const CcnxNameComponents> m_keyLocator; // support only <KeyName> option for KeyLocator
197 };
198
199 ////////////////////////////////////////////////////////////////////////////
200 ////////////////////////////////////////////////////////////////////////////
201 ////////////////////////////////////////////////////////////////////////////
202 ////////////////////////////////////////////////////////////////////////////
203 ////////////////////////////////////////////////////////////////////////////
204 ////////////////////////////////////////////////////////////////////////////
205
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700206 /**
207 * Constructor
208 *
209 * Creates a null header
210 **/
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700211 CcnxContentObjectHeader ();
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700212
213 /**
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700214 * \brief Set content object name
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700215 *
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700216 * Sets name of the content object. For example, SetName( CcnxNameComponents("prefix")("postfix") );
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700217 **/
218 void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700219 SetName (const Ptr<CcnxNameComponents> &name);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700220
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700221 /**
222 * @brief Get name of the content object
223 */
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700224 const CcnxNameComponents&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700225 GetName () const;
226
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700227 /**
228 * @brief Get editable reference to content object's Signature
229 */
230 inline Signature &
231 GetSignature ();
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700232
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700233 /**
234 * @brief Get read-only reference to content object's Signature
235 */
236 inline const Signature &
237 GetSignature () const;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700238
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700239 /**
240 * @brief Get editable reference to content object's SignedInfo
241 */
242 inline SignedInfo &
243 GetSignedInfo ();
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700244
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700245 /**
246 * @brief Get read-only reference to content object's SignedInfo
247 */
248 inline const SignedInfo &
249 GetSignedInfo () const;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700250
251 //////////////////////////////////////////////////////////////////
252
253 static TypeId GetTypeId (void);
254 virtual TypeId GetInstanceTypeId (void) const;
255 virtual void Print (std::ostream &os) const;
256 virtual uint32_t GetSerializedSize (void) const;
257 virtual void Serialize (Buffer::Iterator start) const;
258 virtual uint32_t Deserialize (Buffer::Iterator start);
Alexander Afanasyev9568f952012-04-05 16:09:14 -0700259
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700260private:
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700261 Signature m_signature;
Alexander Afanasyev9568f952012-04-05 16:09:14 -0700262 Ptr<CcnxNameComponents> m_name;
263 SignedInfo m_signedInfo;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700264};
265
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700266/**
267 * ContentObjectTail should always be 2 bytes, representing two closing tags:
268 * "</Content><ContentObject>"
269 */
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700270class CcnxContentObjectTail : public Trailer
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700271{
272public:
273 CcnxContentObjectTail ();
274 //////////////////////////////////////////////////////////////////
275
276 static TypeId GetTypeId (void);
277 virtual TypeId GetInstanceTypeId (void) const;
278 virtual void Print (std::ostream &os) const;
279 virtual uint32_t GetSerializedSize (void) const;
280 virtual void Serialize (Buffer::Iterator start) const;
281 virtual uint32_t Deserialize (Buffer::Iterator start);
282};
283
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700284
285CcnxContentObjectHeader::Signature::Signature ()
286 : m_digestAlgorithm ("99.0")
287 , m_signatureBits (0)
288{
289}
290
291const std::string &
292CcnxContentObjectHeader::Signature::GetDigestAlgorithm () const
293{
294 return m_digestAlgorithm;
295}
296
297void
298CcnxContentObjectHeader::Signature::SetDigestAlgorithm (const std::string &digestAlgorithm)
299{
300 m_digestAlgorithm = digestAlgorithm;
301}
302
303uint32_t
304CcnxContentObjectHeader::Signature::GetSignatureBits () const
305{
306 return m_signatureBits;
307}
308
309inline void
310CcnxContentObjectHeader::Signature::SetSignatureBits (uint32_t signature)
311{
312 m_signatureBits = signature;
313}
314
315
316CcnxContentObjectHeader::Signature &
317CcnxContentObjectHeader::GetSignature ()
318{
319 return m_signature;
320}
321
322const CcnxContentObjectHeader::Signature &
323CcnxContentObjectHeader::GetSignature () const
324{
325 return m_signature;
326}
327
328CcnxContentObjectHeader::SignedInfo &
329CcnxContentObjectHeader::GetSignedInfo ()
330{
331 return m_signedInfo;
332}
333
334const CcnxContentObjectHeader::SignedInfo &
335CcnxContentObjectHeader::GetSignedInfo () const
336{
337 return m_signedInfo;
338}
339
Alexander Afanasyeve91ab752011-08-31 19:13:40 -0700340class CcnxContentObjectHeaderException {};
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700341
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700342} // namespace ns3
343
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700344#endif // _CCNX_CONTENT_OBJECT_HEADER_H_