blob: 2022f2ff625d6e158fa2b14bf76136d5f8375a9f [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/*
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -07003 * Copyright (c) 2011-2013 University of California, Los Angeles
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -07004 *
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 Afanasyevcfdc14f2013-03-15 14:38:44 -070035#include "ndn-name.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 Afanasyeveae83ee2013-03-15 15:01:10 -070045 * ContentObject serializes/deserializes header up-to and including <Content> tags
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070046 * 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 Afanasyevcfdc14f2013-03-15 14:38:44 -070059class ContentObject : public SimpleRefCount<ContentObject,Header>
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070060{
61public:
62 /**
63 * Constructor
64 *
65 * Creates a null header
66 **/
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070067 ContentObject ();
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 Afanasyevcfdc14f2013-03-15 14:38:44 -070072 * Sets name of the content object. For example, SetName( Name("prefix")("postfix") );
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070073 **/
74 void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070075 SetName (const Ptr<Name> &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 Afanasyevcfdc14f2013-03-15 14:38:44 -070080 const Name&
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 Afanasyevcfdc14f2013-03-15 14:38:44 -070086 Ptr<const Name>
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 Afanasyevcfdc14f2013-03-15 14:38:44 -0700125 Ptr<Name> 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 Afanasyeveae83ee2013-03-15 15:01:10 -0700130typedef ContentObject ContentObjectHeader;
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700131
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700132/**
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800133 * ContentObjectTail for compatibility with other packet formats
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700134 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700135class ContentObjectTail : public Trailer
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700136{
137public:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700138 ContentObjectTail ();
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700139 //////////////////////////////////////////////////////////////////
140
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700141 static TypeId GetTypeId (void); ///< @brief Get TypeId
142 virtual TypeId GetInstanceTypeId (void) const; ///< @brief Get TypeId of the instance
143 virtual void Print (std::ostream &os) const; ///< @brief Print out information about Tail into the stream
144 virtual uint32_t GetSerializedSize (void) const; ///< @brief Get size necessary to serialize the Tail
145 virtual void Serialize (Buffer::Iterator start) const; ///< @brief Serialize the Tail
146 virtual uint32_t Deserialize (Buffer::Iterator start); ///< @brief Deserialize the Tail
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700147};
148
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700149
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700150/**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700151 * @ingroup ndn-exceptions
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700152 * @brief Class for ContentObject parsing exception
153 */
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700154class ContentObjectException {};
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700155
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700156} // namespace ndn
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700157} // namespace ns3
158
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700159#endif // _NDN_CONTENT_OBJECT_HEADER_H_