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 | e275cf8 | 2012-04-18 14:25:02 -0700 | [diff] [blame] | 25 | #include "ns3/simple-ref-count.h" |
Alexander Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 26 | #include "ns3/nstime.h" |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 27 | #include "ns3/packet.h" |
Alexander Afanasyev | e4795ae | 2013-07-11 20:01:31 -0700 | [diff] [blame] | 28 | #include "ns3/ptr.h" |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | e4795ae | 2013-07-11 20:01:31 -0700 | [diff] [blame] | 30 | #include <ns3/ndn-name.h> |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 31 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 32 | namespace ns3 { |
| 33 | namespace ndn { |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
Alexander Afanasyev | e4795ae | 2013-07-11 20:01:31 -0700 | [diff] [blame] | 36 | * @ingroup Ndn |
| 37 | * @brief ContentObject header |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 38 | */ |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 39 | class ContentObject : public SimpleRefCount<ContentObject> |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 40 | { |
| 41 | public: |
| 42 | /** |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 43 | * @brief Constructor |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 44 | * |
| 45 | * Creates a null header |
| 46 | **/ |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 47 | ContentObject (Ptr<Packet> payload = Create<Packet> ()); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 50 | * @brief Copy constructor |
| 51 | */ |
| 52 | ContentObject (const ContentObject &other); |
| 53 | |
| 54 | /** |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 55 | * \brief Set content object name |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 56 | * |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 57 | * Sets name of the content object |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 58 | **/ |
| 59 | void |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 60 | SetName (Ptr<Name> name); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 61 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 62 | /** |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 63 | * @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 Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 71 | * @brief Get name of the content object |
| 72 | */ |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 73 | const Name& |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 74 | GetName () const; |
| 75 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 76 | /** |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 77 | * @brief Get smart pointer to the interest name (to avoid extra memory usage) |
| 78 | */ |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 79 | Ptr<const Name> |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 80 | GetNamePtr () const; |
| 81 | |
| 82 | /** |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 83 | * @brief Set content object timestamp |
| 84 | * @param timestamp timestamp |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 85 | */ |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 86 | void |
| 87 | SetTimestamp (const Time ×tamp); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 88 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 89 | /** |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 90 | * @brief Get timestamp of the content object |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 91 | */ |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 92 | Time |
| 93 | GetTimestamp () const; |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 94 | |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 95 | /** |
| 96 | * @brief Set freshness of the content object |
| 97 | * @param freshness Freshness, 0s means infinity |
| 98 | */ |
| 99 | void |
| 100 | SetFreshness (const Time &freshness); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 101 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 102 | /** |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 103 | * @brief Get freshness of the content object |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 104 | */ |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 105 | Time |
| 106 | GetFreshness () const; |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 107 | |
Alexander Afanasyev | d6e5c5f | 2013-03-30 19:09:56 -0700 | [diff] [blame] | 108 | /** |
| 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 Afanasyev | 1043c70 | 2013-07-15 16:21:09 -0700 | [diff] [blame] | 125 | /** |
| 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 Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 140 | ////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 141 | /** |
| 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 Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 148 | |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 149 | /** |
| 150 | * @brief Set payload of data packet |
| 151 | * |
| 152 | * This payload can also carry packet tags |
| 153 | */ |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 154 | Ptr<const Packet> |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 155 | 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 Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 164 | |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 165 | /** |
| 166 | * @brief Set (cache) wire formatted packet |
| 167 | */ |
| 168 | inline void |
| 169 | SetWire (Ptr<const Packet> packet) const; |
| 170 | |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 171 | /** |
| 172 | * @brief Print Interest in plain-text to the specified output stream |
| 173 | */ |
| 174 | void |
| 175 | Print (std::ostream &os) const; |
| 176 | |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 177 | private: |
| 178 | // NO_ASSIGN |
| 179 | ContentObject & |
| 180 | operator = (const ContentObject &other) { return *this; } |
| 181 | |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 182 | private: |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 183 | Ptr<Name> m_name; |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 184 | Time m_freshness; |
| 185 | Time m_timestamp; |
Alexander Afanasyev | d6e5c5f | 2013-03-30 19:09:56 -0700 | [diff] [blame] | 186 | uint32_t m_signature; // 0, means no signature, any other value application dependent (not a real signature) |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 187 | Ptr<Packet> m_payload; |
Alexander Afanasyev | 1043c70 | 2013-07-15 16:21:09 -0700 | [diff] [blame] | 188 | Ptr<Name> m_keyLocator; |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 189 | |
| 190 | mutable Ptr<const Packet> m_wire; |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 191 | }; |
| 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 | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 199 | inline Ptr<const Packet> |
| 200 | ContentObject::GetWire () const |
| 201 | { |
| 202 | return m_wire; |
| 203 | } |
| 204 | |
| 205 | inline void |
| 206 | ContentObject::SetWire (Ptr<const Packet> packet) const |
| 207 | { |
| 208 | m_wire = packet; |
| 209 | } |
| 210 | |
| 211 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 212 | } // namespace ndn |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 213 | } // namespace ns3 |
| 214 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 215 | #endif // _NDN_CONTENT_OBJECT_HEADER_H_ |