blob: 79f04dfa2f5c4a7cce3a6e5172bb36eec80525e5 [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 Afanasyev4aac5572012-08-09 10:49:55 -070022#ifndef _NDN_CONTENT_OBJECT_HEADER_H_
23#define _NDN_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
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070035#include "ndn-name-components.h"
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070036
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070037namespace ns3 {
38namespace ndn {
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070039
40/**
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080041 * ContentObject header
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070042 *
43 * Only few important fields are actually implemented in the simulation
44 *
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070045 * ContentObjectHeader serializes/deserializes header up-to and including <Content> tags
46 * Necessary closing tags should be added using ContentObjectTail
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070047 *
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080048 * Optimized and simplified formatting of Interest packets
49 *
50 * ContentObject ::= Signature
51 * Name
52 * Content
53 *
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070054 * This hacks are necessary to optimize memory use (i.e., virtual payload)
55 *
56 * "<ContentObject><Signature>..</Signature><Name>...</Name><SignedInfo>...</SignedInfo><Content>"
57 *
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070058 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070059class ContentObjectHeader : public SimpleRefCount<ContentObjectHeader,Header>
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070060{
61public:
62 /**
63 * Constructor
64 *
65 * Creates a null header
66 **/
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070067 ContentObjectHeader ();
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070068
69 /**
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070070 * \brief Set content object name
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070071 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070072 * Sets name of the content object. For example, SetName( NameComponents("prefix")("postfix") );
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070073 **/
74 void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070075 SetName (const Ptr<NameComponents> &name);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070076
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070077 /**
78 * @brief Get name of the content object
79 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070080 const NameComponents&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070081 GetName () const;
82
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070083 /**
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070084 * @brief Get smart pointer to the interest name (to avoid extra memory usage)
85 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070086 Ptr<const NameComponents>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070087 GetNamePtr () const;
88
89 /**
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080090 * @brief Set content object timestamp
91 * @param timestamp timestamp
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070092 */
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080093 void
94 SetTimestamp (const Time &timestamp);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070095
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070096 /**
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080097 * @brief Get timestamp of the content object
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070098 */
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080099 Time
100 GetTimestamp () const;
101
102 /**
103 * @brief Set freshness of the content object
104 * @param freshness Freshness, 0s means infinity
105 */
106 void
107 SetFreshness (const Time &freshness);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700108
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700109 /**
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800110 * @brief Get freshness of the content object
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700111 */
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800112 Time
113 GetFreshness () const;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700114
115 //////////////////////////////////////////////////////////////////
116
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700117 static TypeId GetTypeId (void); ///< @brief Get TypeId
118 virtual TypeId GetInstanceTypeId (void) const; ///< @brief Get TypeId of the instance
119 virtual void Print (std::ostream &os) const; ///< @brief Print out information about the Header into the stream
120 virtual uint32_t GetSerializedSize (void) const; ///< @brief Get size necessary to serialize the Header
121 virtual void Serialize (Buffer::Iterator start) const; ///< @brief Serialize the Header
122 virtual uint32_t Deserialize (Buffer::Iterator start); ///< @brief Deserialize the Header
Alexander Afanasyev9568f952012-04-05 16:09:14 -0700123
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700124private:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700125 Ptr<NameComponents> m_name;
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800126 Time m_freshness;
127 Time m_timestamp;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700128};
129
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700130/**
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800131 * ContentObjectTail for compatibility with other packet formats
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700132 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700133class ContentObjectTail : public Trailer
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700134{
135public:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700136 ContentObjectTail ();
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700137 //////////////////////////////////////////////////////////////////
138
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700139 static TypeId GetTypeId (void); ///< @brief Get TypeId
140 virtual TypeId GetInstanceTypeId (void) const; ///< @brief Get TypeId of the instance
141 virtual void Print (std::ostream &os) const; ///< @brief Print out information about Tail into the stream
142 virtual uint32_t GetSerializedSize (void) const; ///< @brief Get size necessary to serialize the Tail
143 virtual void Serialize (Buffer::Iterator start) const; ///< @brief Serialize the Tail
144 virtual uint32_t Deserialize (Buffer::Iterator start); ///< @brief Deserialize the Tail
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700145};
146
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700147
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700148/**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700149 * @ingroup ndn-exceptions
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700150 * @brief Class for ContentObject parsing exception
151 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700152class ContentObjectHeaderException {};
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700153
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700154} // namespace ndn
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700155} // namespace ns3
156
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700157#endif // _NDN_CONTENT_OBJECT_HEADER_H_