Alexander Afanasyev | 6eba36f | 2013-08-07 17:42:54 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011-2013 University of California, Los Angeles |
| 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 | |
| 22 | #ifndef _NDN_CONTENT_OBJECT_HEADER_H_ |
| 23 | #define _NDN_CONTENT_OBJECT_HEADER_H_ |
| 24 | |
| 25 | #include "ns3/simple-ref-count.h" |
| 26 | #include "ns3/nstime.h" |
| 27 | #include "ns3/packet.h" |
| 28 | #include "ns3/ptr.h" |
| 29 | |
| 30 | #include <ns3/ndn-name.h> |
| 31 | |
| 32 | namespace ns3 { |
| 33 | namespace ndn { |
| 34 | |
| 35 | /** |
| 36 | * @ingroup ndn |
| 37 | * @brief Data header |
| 38 | */ |
| 39 | class Data : public SimpleRefCount<Data> |
| 40 | { |
| 41 | public: |
| 42 | /** |
| 43 | * @brief Constructor |
| 44 | * |
| 45 | * Creates a null header |
| 46 | **/ |
| 47 | Data (Ptr<Packet> payload = Create<Packet> ()); |
| 48 | |
| 49 | /** |
| 50 | * @brief Copy constructor |
| 51 | */ |
| 52 | Data (const Data &other); |
| 53 | |
| 54 | /** |
| 55 | * \brief Set content object name |
| 56 | * |
| 57 | * Sets name of the content object |
| 58 | **/ |
| 59 | void |
| 60 | SetName (Ptr<Name> name); |
| 61 | |
| 62 | /** |
| 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 | /** |
| 71 | * @brief Get name of the content object |
| 72 | */ |
| 73 | const Name& |
| 74 | GetName () const; |
| 75 | |
| 76 | /** |
| 77 | * @brief Get smart pointer to the interest name (to avoid extra memory usage) |
| 78 | */ |
| 79 | Ptr<const Name> |
| 80 | GetNamePtr () const; |
| 81 | |
| 82 | /** |
| 83 | * @brief Set content object timestamp |
| 84 | * @param timestamp timestamp |
| 85 | */ |
| 86 | void |
| 87 | SetTimestamp (const Time ×tamp); |
| 88 | |
| 89 | /** |
| 90 | * @brief Get timestamp of the content object |
| 91 | */ |
| 92 | Time |
| 93 | GetTimestamp () const; |
| 94 | |
| 95 | /** |
| 96 | * @brief Set freshness of the content object |
| 97 | * @param freshness Freshness, 0s means infinity |
| 98 | */ |
| 99 | void |
| 100 | SetFreshness (const Time &freshness); |
| 101 | |
| 102 | /** |
| 103 | * @brief Get freshness of the content object |
| 104 | */ |
| 105 | Time |
| 106 | GetFreshness () const; |
| 107 | |
| 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 | |
| 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 | |
| 140 | ////////////////////////////////////////////////////////////////// |
| 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); |
| 148 | |
| 149 | /** |
| 150 | * @brief Set payload of data packet |
| 151 | * |
| 152 | * This payload can also carry packet tags |
| 153 | */ |
| 154 | Ptr<const Packet> |
| 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; |
| 164 | |
| 165 | /** |
| 166 | * @brief Set (cache) wire formatted packet |
| 167 | */ |
| 168 | inline void |
| 169 | SetWire (Ptr<const Packet> packet) const; |
| 170 | |
| 171 | /** |
| 172 | * @brief Print Interest in plain-text to the specified output stream |
| 173 | */ |
| 174 | void |
| 175 | Print (std::ostream &os) const; |
| 176 | |
| 177 | private: |
| 178 | // NO_ASSIGN |
| 179 | Data & |
| 180 | operator = (const Data &other) { return *this; } |
| 181 | |
| 182 | private: |
| 183 | Ptr<Name> m_name; |
| 184 | Time m_freshness; |
| 185 | Time m_timestamp; |
| 186 | uint32_t m_signature; // 0, means no signature, any other value application dependent (not a real signature) |
| 187 | Ptr<Packet> m_payload; |
| 188 | Ptr<Name> m_keyLocator; |
| 189 | |
| 190 | mutable Ptr<const Packet> m_wire; |
| 191 | }; |
| 192 | |
| 193 | inline std::ostream & |
| 194 | operator << (std::ostream &os, const Data &d) |
| 195 | { |
| 196 | d.Print (os); |
| 197 | return os; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * @brief Class for Data parsing exception |
| 202 | */ |
| 203 | class DataException {}; |
| 204 | |
| 205 | inline Ptr<const Packet> |
| 206 | Data::GetWire () const |
| 207 | { |
| 208 | return m_wire; |
| 209 | } |
| 210 | |
| 211 | inline void |
| 212 | Data::SetWire (Ptr<const Packet> packet) const |
| 213 | { |
| 214 | m_wire = packet; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | } // namespace ndn |
| 219 | } // namespace ns3 |
| 220 | |
| 221 | #endif // _NDN_CONTENT_OBJECT_HEADER_H_ |