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 | /* |
| 3 | * Copyright (c) 2011 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 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 22 | #ifndef _NDN_INTEREST_HEADER_H_ |
| 23 | #define _NDN_INTEREST_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 | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 28 | #include "ns3/nstime.h" |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 29 | |
| 30 | #include <string> |
| 31 | #include <vector> |
| 32 | #include <list> |
| 33 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 34 | #include "ndn-name-components.h" |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 36 | namespace ns3 { |
Alexander Afanasyev | 663d63f | 2012-09-09 11:55:36 -0700 | [diff] [blame] | 37 | |
| 38 | class Packet; |
| 39 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 40 | namespace ndn { |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 43 | * @brief NDN InterestHeader and routines to serialize/deserialize |
| 44 | * |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 45 | * Optimized and simplified formatting of Interest packets |
| 46 | * |
| 47 | * Interest ::= Nonce |
| 48 | * Scope |
| 49 | * InterestLifetime |
| 50 | * Name |
| 51 | * Selectors |
| 52 | * Options |
| 53 | * |
| 54 | * Minumum size of the Interest packet: 1 + 4 + 2 + 1 + (2 + 0) + (2 + 0) + (2 + 0) = 14 |
| 55 | * |
| 56 | * Maximum size of the Interest packet: 1 + 4 + 2 + 1 + (2 + 65535) + (2 + 65535) + (2 + 65535) = 196619 |
| 57 | * |
| 58 | * :: |
| 59 | * |
| 60 | * 0 1 2 3 |
| 61 | * 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 |
| 62 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 63 | * | Nonce | |
| 64 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 65 | * | Scope | Reserved | InterestLifetime | |
| 66 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 67 | * | Length | | |
| 68 | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 69 | * ~ ~ |
| 70 | * ~ Name ~ |
| 71 | * | | |
| 72 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 73 | * | Length | | |
| 74 | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 75 | * ~ ~ |
| 76 | * ~ Selectors ~ |
| 77 | * | | |
| 78 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 79 | * | Length | | |
| 80 | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
| 81 | * ~ ~ |
| 82 | * ~ Options ~ |
| 83 | * | | |
| 84 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 85 | * **/ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 86 | class InterestHeader : public SimpleRefCount<InterestHeader, Header> |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 87 | { |
| 88 | public: |
| 89 | /** |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 90 | * \brief Constructor |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 91 | * |
| 92 | * Creates a null header |
| 93 | **/ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 94 | InterestHeader (); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 97 | * @brief Copy constructor |
| 98 | */ |
| 99 | InterestHeader (const InterestHeader &interest); |
| 100 | |
| 101 | /** |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 102 | * \brief Set interest name |
| 103 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 104 | * Sets name of the interest. For example, SetName( ndnNameComponents("prefix")("postfix") ); |
| 105 | * @param[in] name const pointer to ndnNameComponents object that contains an interest name |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 106 | **/ |
| 107 | void |
Alexander Afanasyev | ec1e395 | 2012-08-20 13:48:15 -0700 | [diff] [blame] | 108 | SetName (Ptr<NameComponents> name); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 109 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 110 | /** |
| 111 | * \brief Get interest name |
| 112 | * |
| 113 | * Gets name of the interest. |
| 114 | **/ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 115 | const NameComponents& |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 116 | GetName () const; |
| 117 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 118 | /** |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 119 | * @brief Get smart pointer to the interest name (to avoid extra memory usage) |
| 120 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 121 | Ptr<const NameComponents> |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 122 | GetNamePtr () const; |
| 123 | |
| 124 | /** |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 125 | * \brief Set Scope |
| 126 | * Scope limits where the Interest may propagate. |
| 127 | * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host). |
| 128 | * Scope 1 limits propagation to the applications on the originating host. |
| 129 | * Scope 2 limits propagation to no further than the next host. |
| 130 | * Other values are not defined, and will cause the Interest message to be dropped. |
| 131 | * Note that this is not a hop count - the value is not decremented as the interest is forwarded. |
| 132 | * @param[in] scope interest scope |
| 133 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 134 | void |
| 135 | SetScope (int8_t scope); |
| 136 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 137 | /** |
| 138 | * \brief Get Scope value |
| 139 | * Scope limits where the Interest may propagate. |
| 140 | * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host). |
| 141 | * Scope 1 limits propagation to the applications on the originating host. |
| 142 | * Scope 2 limits propagation to no further than the next host. |
| 143 | * Other values are not defined, and will cause the Interest message to be dropped. |
| 144 | * Note that this is not a hop count - the value is not decremented as the interest is forwarded. |
| 145 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 146 | int8_t |
| 147 | GetScope () const; |
| 148 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 149 | /** |
| 150 | * \brief Set InterestLifetime |
| 151 | * InterestLifetime indicates the (approximate) time remaining before the interest times out. |
| 152 | * The timeout is relative to the arrival time of the interest at the current node. |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 153 | * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information. |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 154 | * @param[in] time interest lifetime |
| 155 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 156 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 157 | SetInterestLifetime (Time time); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 158 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 159 | /** |
| 160 | * \brief Get InterestLifetime value |
| 161 | * InterestLifetime indicates the (approximate) time remaining before the interest times out. |
| 162 | * The timeout is relative to the arrival time of the interest at the current node. |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 163 | * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information. |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 164 | */ |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 165 | Time |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 166 | GetInterestLifetime () const; |
| 167 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 168 | /** |
| 169 | * \brief Set Nonce |
| 170 | * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages. |
| 171 | * @param[in] nonce Unique packet identification number |
| 172 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 173 | void |
| 174 | SetNonce (uint32_t nonce); |
| 175 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 176 | /** |
| 177 | * \brief Get Nonce value |
| 178 | * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages. |
| 179 | * |
| 180 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 181 | uint32_t |
| 182 | GetNonce () const; |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 183 | |
| 184 | /** |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 185 | * @brief NACK Type |
| 186 | * Specifies the type of Interest packet |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 187 | */ |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 188 | enum |
| 189 | { |
| 190 | NORMAL_INTEREST = 0, |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 191 | NACK_LOOP = 10, |
| 192 | NACK_CONGESTION = 11, |
| 193 | NACK_GIVEUP_PIT = 12, |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 194 | }; |
| 195 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 196 | /** |
| 197 | * \brief Mark the Interest as a Negative Acknowledgement |
| 198 | * Three types of NACKs are supported |
| 199 | * 1. NACK_LOOP |
| 200 | * 2. NACK_CONGESTION |
| 201 | * 3. NACK_GIVEUP_PIT |
| 202 | * @param[in] nackType NACK_LOOP or NACK_CONGESTION or NACK_GIVEUP_PIT or NORMAL_INTEREST |
| 203 | */ |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 204 | void |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 205 | SetNack (uint8_t nackType); //using reserved field |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 206 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 207 | /** |
| 208 | * \brief Get NACK type |
| 209 | * Returns NACK_LOOP, NACK_CONGESTION or NACK_GIVEUP_PIT. |
| 210 | * Otherwise, in case of normal interest packet, returns NORMAL_INTEREST (equals 0). |
| 211 | */ |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 212 | uint8_t |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 213 | GetNack () const; |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 214 | |
| 215 | ////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 216 | |
| 217 | static TypeId GetTypeId (void); ///< @brief Get TypeId of the class |
| 218 | virtual TypeId GetInstanceTypeId (void) const; ///< @brief Get TypeId of the instance |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 219 | |
| 220 | /** |
| 221 | * \brief Print Interest packet |
| 222 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 223 | virtual void Print (std::ostream &os) const; |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 224 | |
| 225 | /** |
| 226 | * \brief Get the size of Interest packet |
| 227 | * Returns the Interest packet size after serialization |
| 228 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 229 | virtual uint32_t GetSerializedSize (void) const; |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 230 | |
| 231 | /** |
| 232 | * \brief Serialize Interest packet |
| 233 | * Serializes Interest packet into Buffer::Iterator |
| 234 | * @param[in] start buffer to contain serialized Interest packet |
| 235 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 236 | virtual void Serialize (Buffer::Iterator start) const; |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 237 | |
| 238 | /** |
| 239 | * \brief Deserialize Interest packet |
| 240 | * Deserializes Buffer::Iterator into Interest packet |
| 241 | * @param[in] start buffer that contains serialized Interest packet |
| 242 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 243 | virtual uint32_t Deserialize (Buffer::Iterator start); |
| 244 | |
Alexander Afanasyev | 663d63f | 2012-09-09 11:55:36 -0700 | [diff] [blame] | 245 | /** |
| 246 | * @brief Cheat for python bindings |
| 247 | */ |
| 248 | static Ptr<InterestHeader> |
| 249 | GetInterest (Ptr<Packet> packet); |
| 250 | |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 251 | private: |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 252 | Ptr<NameComponents> m_name; ///< Interest name |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 253 | uint8_t m_scope; ///< 0xFF not set, 0 local scope, 1 this host, 2 immediate neighborhood |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 254 | Time m_interestLifetime; ///< InterestLifetime |
| 255 | uint32_t m_nonce; ///< Nonce. not used if zero |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 256 | uint8_t m_nackType; ///< Negative Acknowledgement type |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 257 | }; |
| 258 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 259 | /** |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 260 | * @ingroup ndn-exceptions |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 261 | * @brief Class for Interest parsing exception |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 262 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 263 | class InterestHeaderException {}; |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 264 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 265 | } // namespace ndn |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 266 | } // namespace ns3 |
| 267 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 268 | #endif // _NDN_INTEREST_HEADER_H_ |