blob: 9803efebac999ca6b2df747d1c51be881e775c94 [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 Afanasyev73f06f62013-03-15 15:41:38 -070042 *
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070043 * Only few important fields are actually implemented in the simulation
44 *
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070045 * @see http://ndnsim.net/new-packet-formats.html
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070046 *
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070047 * Optimized and simplified formatting of Interest packets
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080048 *
49 * ContentObject ::= Signature
50 * Name
51 * Content
52 *
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070053 * 0 1 2 3
54 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
55 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56 * | Length | |
57 * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
58 * ~ ~
59 * ~ Signature ~
60 * | |
61 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62 * | Length | |
63 * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
64 * ~ ~
65 * ~ Name ~
66 * | |
67 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 * | Length | |
69 * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
70 * ~ ~
71 * ~ Content ~
72 * | |
73 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070074 *
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070075 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070076class ContentObject : public SimpleRefCount<ContentObject,Header>
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070077{
78public:
79 /**
80 * Constructor
81 *
82 * Creates a null header
83 **/
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070084 ContentObject ();
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070085
86 /**
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070087 * \brief Set content object name
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070088 *
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070089 * Sets name of the content object
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070090 **/
91 void
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070092 SetName (Ptr<Name> name);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070093
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070094 /**
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070095 * @brief Another, less efficient, variant of setting content object name
96 *
97 * Sets name of the content object
98 */
99 void
100 SetName (const Name &name);
101
102 /**
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700103 * @brief Get name of the content object
104 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700105 const Name&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700106 GetName () const;
107
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700108 /**
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700109 * @brief Get smart pointer to the interest name (to avoid extra memory usage)
110 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700111 Ptr<const Name>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700112 GetNamePtr () const;
113
114 /**
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800115 * @brief Set content object timestamp
116 * @param timestamp timestamp
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700117 */
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800118 void
119 SetTimestamp (const Time &timestamp);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700120
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700121 /**
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800122 * @brief Get timestamp of the content object
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700123 */
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800124 Time
125 GetTimestamp () const;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -0700126
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800127 /**
128 * @brief Set freshness of the content object
129 * @param freshness Freshness, 0s means infinity
130 */
131 void
132 SetFreshness (const Time &freshness);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700133
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700134 /**
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800135 * @brief Get freshness of the content object
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700136 */
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800137 Time
138 GetFreshness () const;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -0700139
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700140 /**
141 * @brief Set "fake" signature on the content object
142 * @param signature uint32_t number, simulating content object signature
143 *
144 * Values for the signature totally depend on the application
145 */
146 void
147 SetSignature (uint32_t signature);
148
149 /**
150 * @brief Get "fake" signature of the content object
151 *
152 * Values for the signature totally depend on the application
153 */
154 uint32_t
155 GetSignature () const;
156
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700157 //////////////////////////////////////////////////////////////////
Alexander Afanasyev73f06f62013-03-15 15:41:38 -0700158
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700159 static TypeId GetTypeId (void); ///< @brief Get TypeId
160 virtual TypeId GetInstanceTypeId (void) const; ///< @brief Get TypeId of the instance
161 virtual void Print (std::ostream &os) const; ///< @brief Print out information about the Header into the stream
162 virtual uint32_t GetSerializedSize (void) const; ///< @brief Get size necessary to serialize the Header
163 virtual void Serialize (Buffer::Iterator start) const; ///< @brief Serialize the Header
164 virtual uint32_t Deserialize (Buffer::Iterator start); ///< @brief Deserialize the Header
Alexander Afanasyev73f06f62013-03-15 15:41:38 -0700165
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700166private:
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700167 Ptr<Name> m_name;
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800168 Time m_freshness;
169 Time m_timestamp;
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700170 uint32_t m_signature; // 0, means no signature, any other value application dependent (not a real signature)
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700171};
172
Alexander Afanasyev73f06f62013-03-15 15:41:38 -0700173typedef ContentObject ContentObjectHeader;
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700174
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700175/**
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800176 * ContentObjectTail for compatibility with other packet formats
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700177 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700178class ContentObjectTail : public Trailer
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700179{
180public:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700181 ContentObjectTail ();
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700182 //////////////////////////////////////////////////////////////////
Alexander Afanasyev73f06f62013-03-15 15:41:38 -0700183
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700184 static TypeId GetTypeId (void); ///< @brief Get TypeId
185 virtual TypeId GetInstanceTypeId (void) const; ///< @brief Get TypeId of the instance
186 virtual void Print (std::ostream &os) const; ///< @brief Print out information about Tail into the stream
187 virtual uint32_t GetSerializedSize (void) const; ///< @brief Get size necessary to serialize the Tail
188 virtual void Serialize (Buffer::Iterator start) const; ///< @brief Serialize the Tail
189 virtual uint32_t Deserialize (Buffer::Iterator start); ///< @brief Deserialize the Tail
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700190};
191
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700192
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700193/**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700194 * @ingroup ndn-exceptions
Alexander Afanasyev73f06f62013-03-15 15:41:38 -0700195 * @brief Class for ContentObject parsing exception
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700196 */
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700197class ContentObjectException {};
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700198
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700199} // namespace ndn
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700200} // namespace ns3
201
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700202#endif // _NDN_CONTENT_OBJECT_HEADER_H_