blob: d7ab5df1c7161e5c1f97fb63e025cf11fc34fae4 [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 Afanasyevabb493a2013-07-19 15:31:33 -070030#include <ns3/ndnSIM/ndn.cxx/name.h>
31#include <ns3/ndnSIM/ndn.cxx/exclude.h>
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070032
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070033namespace ns3 {
Alexander Afanasyev663d63f2012-09-09 11:55:36 -070034
35class Packet;
36
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070037namespace ndn {
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070038
39/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070040 * @ingroup ndn
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070041 * @brief NDN Interest (wire formats are defined in wire)
Alexander Afanasyevb989b122013-07-10 17:15:46 -070042 **/
43class Interest : public SimpleRefCount<Interest>
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070044{
45public:
46 /**
Ilya Moiseenko332add02011-12-24 17:21:25 -080047 * \brief Constructor
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070048 *
49 * Creates a null header
50 **/
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070051 Interest (Ptr<Packet> payload = Create<Packet> ());
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070052
53 /**
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070054 * @brief Copy constructor
55 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070056 Interest (const Interest &interest);
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070057
58 /**
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070059 * \brief Set interest name
60 *
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070061 * @param name smart pointer to Name
62 *
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070063 **/
64 void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070065 SetName (Ptr<Name> name);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070066
Ilya Moiseenko332add02011-12-24 17:21:25 -080067 /**
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070068 * \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 Moiseenko332add02011-12-24 17:21:25 -080077 * \brief Get interest name
78 *
79 * Gets name of the interest.
80 **/
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070081 const Name&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070082 GetName () const;
83
Ilya Moiseenko332add02011-12-24 17:21:25 -080084 /**
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070085 * @brief Get smart pointer to the interest name (to avoid extra memory usage)
86 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070087 Ptr<const Name>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070088 GetNamePtr () const;
89
90 /**
Ilya Moiseenko332add02011-12-24 17:21:25 -080091 * \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 Afanasyev8a677dd2011-08-12 13:08:15 -0700100 void
101 SetScope (int8_t scope);
102
Ilya Moiseenko332add02011-12-24 17:21:25 -0800103 /**
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 Afanasyev8a677dd2011-08-12 13:08:15 -0700112 int8_t
113 GetScope () const;
114
Ilya Moiseenko332add02011-12-24 17:21:25 -0800115 /**
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 Afanasyev4aac5572012-08-09 10:49:55 -0700119 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800120 * @param[in] time interest lifetime
121 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700122 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700123 SetInterestLifetime (Time time);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700124
Ilya Moiseenko332add02011-12-24 17:21:25 -0800125 /**
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 Afanasyev4aac5572012-08-09 10:49:55 -0700129 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800130 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700131 Time
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700132 GetInterestLifetime () const;
133
Ilya Moiseenko332add02011-12-24 17:21:25 -0800134 /**
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 Afanasyev8a677dd2011-08-12 13:08:15 -0700139 void
140 SetNonce (uint32_t nonce);
141
Ilya Moiseenko332add02011-12-24 17:21:25 -0800142 /**
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 Afanasyev8a677dd2011-08-12 13:08:15 -0700147 uint32_t
148 GetNonce () const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800149
150 /**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700151 * @brief NACK Type
152 * Specifies the type of Interest packet
Ilya Moiseenko332add02011-12-24 17:21:25 -0800153 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800154 enum
155 {
156 NORMAL_INTEREST = 0,
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800157 NACK_LOOP = 10,
158 NACK_CONGESTION = 11,
159 NACK_GIVEUP_PIT = 12,
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800160 };
161
Ilya Moiseenko332add02011-12-24 17:21:25 -0800162 /**
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 Moiseenko75d9bf52011-10-28 13:18:32 -0700170 void
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800171 SetNack (uint8_t nackType); //using reserved field
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700172
Ilya Moiseenko332add02011-12-24 17:21:25 -0800173 /**
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 Afanasyev5d79e682012-11-19 14:12:23 -0800178 uint8_t
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800179 GetNack () const;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700180
Ilya Moiseenko332add02011-12-24 17:21:25 -0800181 /**
Alexander Afanasyevabb493a2013-07-19 15:31:33 -0700182 * @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 Afanasyevb989b122013-07-10 17:15:46 -0700197 *
198 * This payload can carry packet tags
Ilya Moiseenko332add02011-12-24 17:21:25 -0800199 */
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700200 void
201 SetPayload (Ptr<Packet> payload);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700202
Alexander Afanasyev663d63f2012-09-09 11:55:36 -0700203 /**
Alexander Afanasyevabb493a2013-07-19 15:31:33 -0700204 * @brief Get virtual "payload" to interest packet
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700205 *
206 * This payload can carry packet tags
Alexander Afanasyev663d63f2012-09-09 11:55:36 -0700207 */
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700208 Ptr<const Packet>
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700209 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 Afanasyevfaa01f92013-07-10 18:34:31 -0700225 /**
226 * @brief Print Interest in plain-text to the specified output stream
227 */
228 void
229 Print (std::ostream &os) const;
230
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700231private:
232 // NO_ASSIGN
233 Interest &
234 operator = (const Interest &other) { return *this; }
Alexander Afanasyev663d63f2012-09-09 11:55:36 -0700235
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700236private:
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700237 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 Afanasyevabb493a2013-07-19 15:31:33 -0700242
243 Ptr<Exclude> m_exclude; ///< @brief Exclude filter
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700244 Ptr<Packet> m_payload; ///< @brief virtual payload
245
246 mutable Ptr<const Packet> m_wire;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700247};
248
Alexander Afanasyev76b11572013-07-16 21:49:50 -0700249inline std::ostream &
250operator << (std::ostream &os, const Interest &i)
251{
252 i.Print (os);
253 return os;
254}
255
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700256inline Ptr<const Packet>
257Interest::GetWire () const
258{
259 return m_wire;
260}
261
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700262inline void
263Interest::SetWire (Ptr<const Packet> packet) const
264{
265 m_wire = packet;
266}
267
Ilya Moiseenko332add02011-12-24 17:21:25 -0800268/**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700269 * @brief Class for Interest parsing exception
Ilya Moiseenko332add02011-12-24 17:21:25 -0800270 */
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700271class InterestException {};
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700272
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700273} // namespace ndn
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700274} // namespace ns3
275
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700276#endif // _NDN_INTEREST_HEADER_H_