Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 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 Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 22 | #ifndef _CCNX_CONTENT_OBJECT_HEADER_H_ |
| 23 | #define _CCNX_CONTENT_OBJECT_HEADER_H_ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 2536e20 | 2011-08-12 14:13:10 -0700 | [diff] [blame] | 25 | #include "ns3/integer.h" |
| 26 | #include "ns3/header.h" |
Alexander Afanasyev | e275cf8 | 2012-04-18 14:25:02 -0700 | [diff] [blame] | 27 | #include "ns3/simple-ref-count.h" |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 28 | #include "ns3/trailer.h" |
Alexander Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 29 | #include "ns3/nstime.h" |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 30 | |
| 31 | #include <string> |
| 32 | #include <vector> |
| 33 | #include <list> |
| 34 | |
Ilya Moiseenko | d26e682 | 2011-08-23 17:48:38 -0700 | [diff] [blame] | 35 | #include "ccnx-name-components.h" |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 36 | |
| 37 | namespace ns3 |
| 38 | { |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * CCNx XML definition of ContentObject |
| 42 | * |
| 43 | * Only few important fields are actually implemented in the simulation |
| 44 | * |
| 45 | * |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 46 | * ContentObjectHeader serializes/deserializes header up-to and including <Content> tags |
| 47 | * Necessary closing tags should be added using ContentObjectTail |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 48 | * |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 49 | * This hacks are necessary to optimize memory use (i.e., virtual payload) |
| 50 | * |
| 51 | * "<ContentObject><Signature>..</Signature><Name>...</Name><SignedInfo>...</SignedInfo><Content>" |
| 52 | * |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 53 | */ |
Alexander Afanasyev | e275cf8 | 2012-04-18 14:25:02 -0700 | [diff] [blame] | 54 | class CcnxContentObjectHeader : public SimpleRefCount<CcnxContentObjectHeader,Header> |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 55 | { |
| 56 | public: |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 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 | 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 ×tamp); |
| 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 Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 206 | /** |
| 207 | * Constructor |
| 208 | * |
| 209 | * Creates a null header |
| 210 | **/ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 211 | CcnxContentObjectHeader (); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 212 | |
| 213 | /** |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 214 | * \brief Set content object name |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 215 | * |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 216 | * Sets name of the content object. For example, SetName( CcnxNameComponents("prefix")("postfix") ); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 217 | **/ |
| 218 | void |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 219 | SetName (const Ptr<CcnxNameComponents> &name); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 220 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 221 | /** |
| 222 | * @brief Get name of the content object |
| 223 | */ |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 224 | const CcnxNameComponents& |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 225 | GetName () const; |
| 226 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 227 | /** |
| 228 | * @brief Get editable reference to content object's Signature |
| 229 | */ |
| 230 | inline Signature & |
| 231 | GetSignature (); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 232 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 233 | /** |
| 234 | * @brief Get read-only reference to content object's Signature |
| 235 | */ |
| 236 | inline const Signature & |
| 237 | GetSignature () const; |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 238 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 239 | /** |
| 240 | * @brief Get editable reference to content object's SignedInfo |
| 241 | */ |
| 242 | inline SignedInfo & |
| 243 | GetSignedInfo (); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 244 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 245 | /** |
| 246 | * @brief Get read-only reference to content object's SignedInfo |
| 247 | */ |
| 248 | inline const SignedInfo & |
| 249 | GetSignedInfo () const; |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 250 | |
| 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 Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 259 | |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 260 | private: |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 261 | Signature m_signature; |
Alexander Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 262 | Ptr<CcnxNameComponents> m_name; |
| 263 | SignedInfo m_signedInfo; |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 264 | }; |
| 265 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 266 | /** |
| 267 | * ContentObjectTail should always be 2 bytes, representing two closing tags: |
| 268 | * "</Content><ContentObject>" |
| 269 | */ |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 270 | class CcnxContentObjectTail : public Trailer |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 271 | { |
| 272 | public: |
| 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 Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 284 | |
| 285 | CcnxContentObjectHeader::Signature::Signature () |
| 286 | : m_digestAlgorithm ("99.0") |
| 287 | , m_signatureBits (0) |
| 288 | { |
| 289 | } |
| 290 | |
| 291 | const std::string & |
| 292 | CcnxContentObjectHeader::Signature::GetDigestAlgorithm () const |
| 293 | { |
| 294 | return m_digestAlgorithm; |
| 295 | } |
| 296 | |
| 297 | void |
| 298 | CcnxContentObjectHeader::Signature::SetDigestAlgorithm (const std::string &digestAlgorithm) |
| 299 | { |
| 300 | m_digestAlgorithm = digestAlgorithm; |
| 301 | } |
| 302 | |
| 303 | uint32_t |
| 304 | CcnxContentObjectHeader::Signature::GetSignatureBits () const |
| 305 | { |
| 306 | return m_signatureBits; |
| 307 | } |
| 308 | |
| 309 | inline void |
| 310 | CcnxContentObjectHeader::Signature::SetSignatureBits (uint32_t signature) |
| 311 | { |
| 312 | m_signatureBits = signature; |
| 313 | } |
| 314 | |
| 315 | |
| 316 | CcnxContentObjectHeader::Signature & |
| 317 | CcnxContentObjectHeader::GetSignature () |
| 318 | { |
| 319 | return m_signature; |
| 320 | } |
| 321 | |
| 322 | const CcnxContentObjectHeader::Signature & |
| 323 | CcnxContentObjectHeader::GetSignature () const |
| 324 | { |
| 325 | return m_signature; |
| 326 | } |
| 327 | |
| 328 | CcnxContentObjectHeader::SignedInfo & |
| 329 | CcnxContentObjectHeader::GetSignedInfo () |
| 330 | { |
| 331 | return m_signedInfo; |
| 332 | } |
| 333 | |
| 334 | const CcnxContentObjectHeader::SignedInfo & |
| 335 | CcnxContentObjectHeader::GetSignedInfo () const |
| 336 | { |
| 337 | return m_signedInfo; |
| 338 | } |
| 339 | |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 340 | class CcnxContentObjectHeaderException {}; |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 341 | |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 342 | } // namespace ns3 |
| 343 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 344 | #endif // _CCNX_CONTENT_OBJECT_HEADER_H_ |