blob: d0959a977518d6b2135bdce4ab78381f8ebf081a [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -07002/*
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 Afanasyev4aac5572012-08-09 10:49:55 -070022#ifndef _NDN_INTEREST_HEADER_H_
23#define _NDN_INTEREST_HEADER_H_
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070024
Alexander Afanasyeve275cf82012-04-18 14:25:02 -070025#include "ns3/simple-ref-count.h"
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070026#include "ns3/nstime.h"
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070027#include "ns3/packet.h"
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070028#include "ns3/ptr.h"
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070029
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -070030#include <ns3/ndn-name.h>
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070031
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070032namespace ns3 {
Alexander Afanasyev663d63f2012-09-09 11:55:36 -070033
34class Packet;
35
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070036namespace ndn {
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070037
38/**
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070039 * @brief NDN Interest (wire formats are defined in wire)
Alexander Afanasyevb989b122013-07-10 17:15:46 -070040 *
41 **/
42class Interest : public SimpleRefCount<Interest>
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070043{
44public:
45 /**
Ilya Moiseenko332add02011-12-24 17:21:25 -080046 * \brief Constructor
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070047 *
48 * Creates a null header
49 **/
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070050 Interest (Ptr<Packet> payload = Create<Packet> ());
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070051
52 /**
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070053 * @brief Copy constructor
54 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070055 Interest (const Interest &interest);
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070056
57 /**
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070058 * \brief Set interest name
59 *
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070060 * @param name smart pointer to Name
61 *
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070062 **/
63 void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070064 SetName (Ptr<Name> name);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070065
Ilya Moiseenko332add02011-12-24 17:21:25 -080066 /**
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070067 * \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 Moiseenko332add02011-12-24 17:21:25 -080076 * \brief Get interest name
77 *
78 * Gets name of the interest.
79 **/
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070080 const Name&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070081 GetName () const;
82
Ilya Moiseenko332add02011-12-24 17:21:25 -080083 /**
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070084 * @brief Get smart pointer to the interest name (to avoid extra memory usage)
85 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070086 Ptr<const Name>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070087 GetNamePtr () const;
88
89 /**
Ilya Moiseenko332add02011-12-24 17:21:25 -080090 * \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 Afanasyev8a677dd2011-08-12 13:08:15 -070099 void
100 SetScope (int8_t scope);
101
Ilya Moiseenko332add02011-12-24 17:21:25 -0800102 /**
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 Afanasyev8a677dd2011-08-12 13:08:15 -0700111 int8_t
112 GetScope () const;
113
Ilya Moiseenko332add02011-12-24 17:21:25 -0800114 /**
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 Afanasyev4aac5572012-08-09 10:49:55 -0700118 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800119 * @param[in] time interest lifetime
120 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700121 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700122 SetInterestLifetime (Time time);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700123
Ilya Moiseenko332add02011-12-24 17:21:25 -0800124 /**
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 Afanasyev4aac5572012-08-09 10:49:55 -0700128 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800129 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700130 Time
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700131 GetInterestLifetime () const;
132
Ilya Moiseenko332add02011-12-24 17:21:25 -0800133 /**
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 Afanasyev8a677dd2011-08-12 13:08:15 -0700138 void
139 SetNonce (uint32_t nonce);
140
Ilya Moiseenko332add02011-12-24 17:21:25 -0800141 /**
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 Afanasyev8a677dd2011-08-12 13:08:15 -0700146 uint32_t
147 GetNonce () const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800148
149 /**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700150 * @brief NACK Type
151 * Specifies the type of Interest packet
Ilya Moiseenko332add02011-12-24 17:21:25 -0800152 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800153 enum
154 {
155 NORMAL_INTEREST = 0,
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800156 NACK_LOOP = 10,
157 NACK_CONGESTION = 11,
158 NACK_GIVEUP_PIT = 12,
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800159 };
160
Ilya Moiseenko332add02011-12-24 17:21:25 -0800161 /**
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 Moiseenko75d9bf52011-10-28 13:18:32 -0700169 void
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800170 SetNack (uint8_t nackType); //using reserved field
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700171
Ilya Moiseenko332add02011-12-24 17:21:25 -0800172 /**
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 Afanasyev5d79e682012-11-19 14:12:23 -0800177 uint8_t
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800178 GetNack () const;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700179
Ilya Moiseenko332add02011-12-24 17:21:25 -0800180 /**
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700181 * @brief Get virtual "payload" of interest packet
182 *
183 * This payload can carry packet tags
Ilya Moiseenko332add02011-12-24 17:21:25 -0800184 */
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700185 void
186 SetPayload (Ptr<Packet> payload);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700187
Alexander Afanasyev663d63f2012-09-09 11:55:36 -0700188 /**
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700189 * @brief Set virtual "payload" to interest packet
190 *
191 * This payload can carry packet tags
Alexander Afanasyev663d63f2012-09-09 11:55:36 -0700192 */
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700193 Ptr<const Packet>
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700194 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 Afanasyevfaa01f92013-07-10 18:34:31 -0700210 /**
211 * @brief Print Interest in plain-text to the specified output stream
212 */
213 void
214 Print (std::ostream &os) const;
215
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700216private:
217 // NO_ASSIGN
218 Interest &
219 operator = (const Interest &other) { return *this; }
Alexander Afanasyev663d63f2012-09-09 11:55:36 -0700220
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700221private:
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700222 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 Afanasyev8a677dd2011-08-12 13:08:15 -0700230};
231
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700232inline Ptr<const Packet>
233Interest::GetWire () const
234{
235 return m_wire;
236}
237
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700238inline void
239Interest::SetWire (Ptr<const Packet> packet) const
240{
241 m_wire = packet;
242}
243
Ilya Moiseenko332add02011-12-24 17:21:25 -0800244/**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700245 * @ingroup ndn-exceptions
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700246 * @brief Class for Interest parsing exception
Ilya Moiseenko332add02011-12-24 17:21:25 -0800247 */
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700248class InterestException {};
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700249
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700250} // namespace ndn
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700251} // namespace ns3
252
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700253#endif // _NDN_INTEREST_HEADER_H_