blob: c79ddf9e79ef47700644d6431b8422f6514fd1f0 [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 Afanasyeve275cf82012-04-18 14:25:02 -070025#include "ns3/simple-ref-count.h"
Alexander Afanasyev9568f952012-04-05 16:09:14 -070026#include "ns3/nstime.h"
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070027#include "ns3/packet.h"
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070028#include "ns3/ptr.h"
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070029
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070030#include <ns3/ndn-name.h>
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070031
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070032namespace ns3 {
33namespace ndn {
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070034
35/**
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070036 * @ingroup Ndn
37 * @brief ContentObject header
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070038 */
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070039class ContentObject : public SimpleRefCount<ContentObject>
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070040{
41public:
42 /**
Alexander Afanasyevb989b122013-07-10 17:15:46 -070043 * @brief Constructor
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070044 *
45 * Creates a null header
46 **/
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070047 ContentObject (Ptr<Packet> payload = Create<Packet> ());
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070048
49 /**
Alexander Afanasyevb989b122013-07-10 17:15:46 -070050 * @brief Copy constructor
51 */
52 ContentObject (const ContentObject &other);
53
54 /**
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070055 * \brief Set content object name
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070056 *
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070057 * Sets name of the content object
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070058 **/
59 void
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070060 SetName (Ptr<Name> name);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070061
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070062 /**
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070063 * @brief Another, less efficient, variant of setting content object name
64 *
65 * Sets name of the content object
66 */
67 void
68 SetName (const Name &name);
69
70 /**
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070071 * @brief Get name of the content object
72 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070073 const Name&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070074 GetName () const;
75
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070076 /**
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070077 * @brief Get smart pointer to the interest name (to avoid extra memory usage)
78 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070079 Ptr<const Name>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070080 GetNamePtr () const;
81
82 /**
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080083 * @brief Set content object timestamp
84 * @param timestamp timestamp
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070085 */
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080086 void
87 SetTimestamp (const Time &timestamp);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070088
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070089 /**
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080090 * @brief Get timestamp of the content object
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070091 */
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080092 Time
93 GetTimestamp () const;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070094
Alexander Afanasyev5d79e682012-11-19 14:12:23 -080095 /**
96 * @brief Set freshness of the content object
97 * @param freshness Freshness, 0s means infinity
98 */
99 void
100 SetFreshness (const Time &freshness);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700101
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700102 /**
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800103 * @brief Get freshness of the content object
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700104 */
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800105 Time
106 GetFreshness () const;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -0700107
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700108 /**
109 * @brief Set "fake" signature on the content object
110 * @param signature uint32_t number, simulating content object signature
111 *
112 * Values for the signature totally depend on the application
113 */
114 void
115 SetSignature (uint32_t signature);
116
117 /**
118 * @brief Get "fake" signature of the content object
119 *
120 * Values for the signature totally depend on the application
121 */
122 uint32_t
123 GetSignature () const;
124
Alexander Afanasyev1043c702013-07-15 16:21:09 -0700125 /**
126 * @brief Set key locator
127 * @param keyLocator name of the key
128 */
129 void
130 SetKeyLocator (Ptr<Name> keyLocator);
131
132 /**
133 * @brief Get key locator
134 *
135 * Note that only <KeyName> option for the key locator is supported
136 */
137 Ptr<const Name>
138 GetKeyLocator () const;
139
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700140 //////////////////////////////////////////////////////////////////
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700141 /**
142 * @brief Get payload of data packet
143 *
144 * This payload can also carry packet tags
145 */
146 void
147 SetPayload (Ptr<Packet> payload);
Alexander Afanasyev73f06f62013-03-15 15:41:38 -0700148
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700149 /**
150 * @brief Set payload of data packet
151 *
152 * This payload can also carry packet tags
153 */
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700154 Ptr<const Packet>
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700155 GetPayload () const;
156
157 /**
158 * @brief Get wire formatted packet
159 *
160 * If wire formatted packet has not been set before, 0 will be returned
161 */
162 inline Ptr<const Packet>
163 GetWire () const;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -0700164
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700165 /**
166 * @brief Set (cache) wire formatted packet
167 */
168 inline void
169 SetWire (Ptr<const Packet> packet) const;
170
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700171 /**
172 * @brief Print Interest in plain-text to the specified output stream
173 */
174 void
175 Print (std::ostream &os) const;
176
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700177private:
178 // NO_ASSIGN
179 ContentObject &
180 operator = (const ContentObject &other) { return *this; }
181
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700182private:
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700183 Ptr<Name> m_name;
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800184 Time m_freshness;
185 Time m_timestamp;
Alexander Afanasyevd6e5c5f2013-03-30 19:09:56 -0700186 uint32_t m_signature; // 0, means no signature, any other value application dependent (not a real signature)
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700187 Ptr<Packet> m_payload;
Alexander Afanasyev1043c702013-07-15 16:21:09 -0700188 Ptr<Name> m_keyLocator;
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700189
190 mutable Ptr<const Packet> m_wire;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700191};
192
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 Afanasyevfaa01f92013-07-10 18:34:31 -0700199inline Ptr<const Packet>
200ContentObject::GetWire () const
201{
202 return m_wire;
203}
204
205inline void
206ContentObject::SetWire (Ptr<const Packet> packet) const
207{
208 m_wire = packet;
209}
210
211
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700212} // namespace ndn
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700213} // namespace ns3
214
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700215#endif // _NDN_CONTENT_OBJECT_HEADER_H_