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