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 | /* |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 3 | * Copyright (c) 2011-2013 University of California, Los Angeles |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 22 | #ifndef _NDN_CONTENT_OBJECT_HEADER_H_ |
| 23 | #define _NDN_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 | |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 35 | #include "ndn-name.h" |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 36 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 37 | namespace ns3 { |
| 38 | namespace ndn { |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 41 | * ContentObject header |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 42 | * |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 43 | * Only few important fields are actually implemented in the simulation |
| 44 | * |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 45 | * @see http://ndnsim.net/new-packet-formats.html |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 46 | * |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 47 | * Optimized and simplified formatting of Interest packets |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 48 | * |
| 49 | * ContentObject ::= Signature |
| 50 | * Name |
| 51 | * Content |
| 52 | * |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 53 | * 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 Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 74 | * |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 75 | */ |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 76 | class ContentObject : public SimpleRefCount<ContentObject,Header> |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 77 | { |
| 78 | public: |
| 79 | /** |
| 80 | * Constructor |
| 81 | * |
| 82 | * Creates a null header |
| 83 | **/ |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 84 | ContentObject (); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 87 | * \brief Set content object name |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 88 | * |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 89 | * Sets name of the content object |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 90 | **/ |
| 91 | void |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 92 | SetName (Ptr<Name> name); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 94 | /** |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 95 | * @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 Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 103 | * @brief Get name of the content object |
| 104 | */ |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 105 | const Name& |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 106 | GetName () const; |
| 107 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 108 | /** |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 109 | * @brief Get smart pointer to the interest name (to avoid extra memory usage) |
| 110 | */ |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 111 | Ptr<const Name> |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 112 | GetNamePtr () const; |
| 113 | |
| 114 | /** |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 115 | * @brief Set content object timestamp |
| 116 | * @param timestamp timestamp |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 117 | */ |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 118 | void |
| 119 | SetTimestamp (const Time ×tamp); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 120 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 121 | /** |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 122 | * @brief Get timestamp of the content object |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 123 | */ |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 124 | Time |
| 125 | GetTimestamp () const; |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 126 | |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 127 | /** |
| 128 | * @brief Set freshness of the content object |
| 129 | * @param freshness Freshness, 0s means infinity |
| 130 | */ |
| 131 | void |
| 132 | SetFreshness (const Time &freshness); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 133 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 134 | /** |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 135 | * @brief Get freshness of the content object |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 136 | */ |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 137 | Time |
| 138 | GetFreshness () const; |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 139 | |
Alexander Afanasyev | d6e5c5f | 2013-03-30 19:09:56 -0700 | [diff] [blame] | 140 | /** |
| 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 Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 157 | ////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 158 | |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 159 | 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 Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 165 | |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 166 | private: |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 167 | Ptr<Name> m_name; |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 168 | Time m_freshness; |
| 169 | Time m_timestamp; |
Alexander Afanasyev | d6e5c5f | 2013-03-30 19:09:56 -0700 | [diff] [blame] | 170 | uint32_t m_signature; // 0, means no signature, any other value application dependent (not a real signature) |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 171 | }; |
| 172 | |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 173 | typedef ContentObject ContentObjectHeader; |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 174 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 175 | /** |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 176 | * ContentObjectTail for compatibility with other packet formats |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 177 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 178 | class ContentObjectTail : public Trailer |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 179 | { |
| 180 | public: |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 181 | ContentObjectTail (); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 182 | ////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 183 | |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 184 | 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 Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 190 | }; |
| 191 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 192 | |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 193 | /** |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 194 | * @ingroup ndn-exceptions |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 195 | * @brief Class for ContentObject parsing exception |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 196 | */ |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 197 | class ContentObjectException {}; |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 198 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 199 | } // namespace ndn |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 200 | } // namespace ns3 |
| 201 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 202 | #endif // _NDN_CONTENT_OBJECT_HEADER_H_ |