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 | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 34 | #include "ndn-name.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 | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame^] | 43 | * @brief NDN Interest (wire formats are defined in wire/*) |
| 44 | * |
| 45 | **/ |
| 46 | class Interest : public SimpleRefCount<Interest> |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 47 | { |
| 48 | public: |
| 49 | /** |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 50 | * \brief Constructor |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 51 | * |
| 52 | * Creates a null header |
| 53 | **/ |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 54 | Interest (); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 57 | * @brief Copy constructor |
| 58 | */ |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 59 | Interest (const Interest &interest); |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 60 | |
| 61 | /** |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 62 | * \brief Set interest name |
| 63 | * |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 64 | * @param name smart pointer to Name |
| 65 | * |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 66 | **/ |
| 67 | void |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 68 | SetName (Ptr<Name> name); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 69 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 70 | /** |
Alexander Afanasyev | cc50d98 | 2013-03-30 19:09:10 -0700 | [diff] [blame] | 71 | * \brief Another variant to set interest name |
| 72 | * |
| 73 | * @param name const reference to Name object |
| 74 | * |
| 75 | **/ |
| 76 | void |
| 77 | SetName (const Name &name); |
| 78 | |
| 79 | /** |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 80 | * \brief Get interest name |
| 81 | * |
| 82 | * Gets name of the interest. |
| 83 | **/ |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 84 | const Name& |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 85 | GetName () const; |
| 86 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 87 | /** |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 88 | * @brief Get smart pointer to the interest name (to avoid extra memory usage) |
| 89 | */ |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 90 | Ptr<const Name> |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 91 | GetNamePtr () const; |
| 92 | |
| 93 | /** |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 94 | * \brief Set Scope |
| 95 | * Scope limits where the Interest may propagate. |
| 96 | * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host). |
| 97 | * Scope 1 limits propagation to the applications on the originating host. |
| 98 | * Scope 2 limits propagation to no further than the next host. |
| 99 | * Other values are not defined, and will cause the Interest message to be dropped. |
| 100 | * Note that this is not a hop count - the value is not decremented as the interest is forwarded. |
| 101 | * @param[in] scope interest scope |
| 102 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 103 | void |
| 104 | SetScope (int8_t scope); |
| 105 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 106 | /** |
| 107 | * \brief Get Scope value |
| 108 | * Scope limits where the Interest may propagate. |
| 109 | * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host). |
| 110 | * Scope 1 limits propagation to the applications on the originating host. |
| 111 | * Scope 2 limits propagation to no further than the next host. |
| 112 | * Other values are not defined, and will cause the Interest message to be dropped. |
| 113 | * Note that this is not a hop count - the value is not decremented as the interest is forwarded. |
| 114 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 115 | int8_t |
| 116 | GetScope () const; |
| 117 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 118 | /** |
| 119 | * \brief Set InterestLifetime |
| 120 | * InterestLifetime indicates the (approximate) time remaining before the interest times out. |
| 121 | * 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] | 122 | * \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] | 123 | * @param[in] time interest lifetime |
| 124 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 125 | void |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 126 | SetInterestLifetime (Time time); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 127 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 128 | /** |
| 129 | * \brief Get InterestLifetime value |
| 130 | * InterestLifetime indicates the (approximate) time remaining before the interest times out. |
| 131 | * 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] | 132 | * \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] | 133 | */ |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 134 | Time |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 135 | GetInterestLifetime () const; |
| 136 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 137 | /** |
| 138 | * \brief Set Nonce |
| 139 | * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages. |
| 140 | * @param[in] nonce Unique packet identification number |
| 141 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 142 | void |
| 143 | SetNonce (uint32_t nonce); |
| 144 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 145 | /** |
| 146 | * \brief Get Nonce value |
| 147 | * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages. |
| 148 | * |
| 149 | */ |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 150 | uint32_t |
| 151 | GetNonce () const; |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 152 | |
| 153 | /** |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 154 | * @brief NACK Type |
| 155 | * Specifies the type of Interest packet |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 156 | */ |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 157 | enum |
| 158 | { |
| 159 | NORMAL_INTEREST = 0, |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 160 | NACK_LOOP = 10, |
| 161 | NACK_CONGESTION = 11, |
| 162 | NACK_GIVEUP_PIT = 12, |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 163 | }; |
| 164 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 165 | /** |
| 166 | * \brief Mark the Interest as a Negative Acknowledgement |
| 167 | * Three types of NACKs are supported |
| 168 | * 1. NACK_LOOP |
| 169 | * 2. NACK_CONGESTION |
| 170 | * 3. NACK_GIVEUP_PIT |
| 171 | * @param[in] nackType NACK_LOOP or NACK_CONGESTION or NACK_GIVEUP_PIT or NORMAL_INTEREST |
| 172 | */ |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 173 | void |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 174 | SetNack (uint8_t nackType); //using reserved field |
Ilya Moiseenko | 75d9bf5 | 2011-10-28 13:18:32 -0700 | [diff] [blame] | 175 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 176 | /** |
| 177 | * \brief Get NACK type |
| 178 | * Returns NACK_LOOP, NACK_CONGESTION or NACK_GIVEUP_PIT. |
| 179 | * Otherwise, in case of normal interest packet, returns NORMAL_INTEREST (equals 0). |
| 180 | */ |
Alexander Afanasyev | 5d79e68 | 2012-11-19 14:12:23 -0800 | [diff] [blame] | 181 | uint8_t |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 182 | GetNack () const; |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 183 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 184 | /** |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame^] | 185 | * @brief Get virtual "payload" of interest packet |
| 186 | * |
| 187 | * This payload can carry packet tags |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 188 | */ |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame^] | 189 | void |
| 190 | SetPayload (Ptr<Packet> payload); |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 191 | |
Alexander Afanasyev | 663d63f | 2012-09-09 11:55:36 -0700 | [diff] [blame] | 192 | /** |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame^] | 193 | * @brief Set virtual "payload" to interest packet |
| 194 | * |
| 195 | * This payload can carry packet tags |
Alexander Afanasyev | 663d63f | 2012-09-09 11:55:36 -0700 | [diff] [blame] | 196 | */ |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame^] | 197 | Ptr<const Payload> |
| 198 | GetPayload () const; |
| 199 | |
| 200 | /** |
| 201 | * @brief Get wire formatted packet |
| 202 | * |
| 203 | * If wire formatted packet has not been set before, 0 will be returned |
| 204 | */ |
| 205 | inline Ptr<const Packet> |
| 206 | GetWire () const; |
| 207 | |
| 208 | /** |
| 209 | * @brief Set (cache) wire formatted packet |
| 210 | */ |
| 211 | inline void |
| 212 | SetWire (Ptr<const Packet> packet) const; |
| 213 | |
| 214 | private: |
| 215 | // NO_ASSIGN |
| 216 | Interest & |
| 217 | operator = (const Interest &other) { return *this; } |
Alexander Afanasyev | 663d63f | 2012-09-09 11:55:36 -0700 | [diff] [blame] | 218 | |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 219 | private: |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame^] | 220 | Ptr<Name> m_name; ///< @brief Interest name |
| 221 | uint8_t m_scope; ///< @brief 0xFF not set, 0 local scope, 1 this host, 2 immediate neighborhood |
| 222 | Time m_interestLifetime; ///< @brief InterestLifetime |
| 223 | uint32_t m_nonce; ///< @brief Nonce. not used if zero |
| 224 | uint8_t m_nackType; ///< @brief Negative Acknowledgement type |
| 225 | Ptr<Packet> m_payload; ///< @brief virtual payload |
| 226 | |
| 227 | mutable Ptr<const Packet> m_wire; |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 228 | }; |
| 229 | |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame^] | 230 | inline Ptr<const Packet> |
| 231 | Interest::GetWire () const |
| 232 | { |
| 233 | return m_wire; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * @brief Set (cache) wire formatted packet |
| 238 | */ |
| 239 | inline void |
| 240 | Interest::SetWire (Ptr<const Packet> packet) const |
| 241 | { |
| 242 | m_wire = packet; |
| 243 | } |
| 244 | |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 245 | /** |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 246 | * @ingroup ndn-exceptions |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 247 | * @brief Class for Interest parsing exception |
Ilya Moiseenko | 332add0 | 2011-12-24 17:21:25 -0800 | [diff] [blame] | 248 | */ |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 249 | class InterestException {}; |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 250 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 251 | } // namespace ndn |
Alexander Afanasyev | 8a677dd | 2011-08-12 13:08:15 -0700 | [diff] [blame] | 252 | } // namespace ns3 |
| 253 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 254 | #endif // _NDN_INTEREST_HEADER_H_ |