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