blob: c1fb277718c654506a5fab7fb704989eb2305faf [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 Afanasyev2536e202011-08-12 14:13:10 -070025#include "ns3/integer.h"
26#include "ns3/header.h"
Alexander Afanasyeve275cf82012-04-18 14:25:02 -070027#include "ns3/simple-ref-count.h"
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070028#include "ns3/nstime.h"
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070029
30#include <string>
31#include <vector>
32#include <list>
33
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070034#include "ndn-name.h"
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070035
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070036namespace ns3 {
Alexander Afanasyev663d63f2012-09-09 11:55:36 -070037
38class Packet;
39
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070040namespace ndn {
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070041
42/**
Alexander Afanasyevb989b122013-07-10 17:15:46 -070043 * @brief NDN Interest (wire formats are defined in wire/*)
44 *
45 **/
46class Interest : public SimpleRefCount<Interest>
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070047{
48public:
49 /**
Ilya Moiseenko332add02011-12-24 17:21:25 -080050 * \brief Constructor
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070051 *
52 * Creates a null header
53 **/
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070054 Interest ();
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070055
56 /**
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070057 * @brief Copy constructor
58 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070059 Interest (const Interest &interest);
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070060
61 /**
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070062 * \brief Set interest name
63 *
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070064 * @param name smart pointer to Name
65 *
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070066 **/
67 void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070068 SetName (Ptr<Name> name);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070069
Ilya Moiseenko332add02011-12-24 17:21:25 -080070 /**
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070071 * \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 Moiseenko332add02011-12-24 17:21:25 -080080 * \brief Get interest name
81 *
82 * Gets name of the interest.
83 **/
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070084 const Name&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070085 GetName () const;
86
Ilya Moiseenko332add02011-12-24 17:21:25 -080087 /**
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070088 * @brief Get smart pointer to the interest name (to avoid extra memory usage)
89 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070090 Ptr<const Name>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070091 GetNamePtr () const;
92
93 /**
Ilya Moiseenko332add02011-12-24 17:21:25 -080094 * \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 Afanasyev8a677dd2011-08-12 13:08:15 -0700103 void
104 SetScope (int8_t scope);
105
Ilya Moiseenko332add02011-12-24 17:21:25 -0800106 /**
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 Afanasyev8a677dd2011-08-12 13:08:15 -0700115 int8_t
116 GetScope () const;
117
Ilya Moiseenko332add02011-12-24 17:21:25 -0800118 /**
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 Afanasyev4aac5572012-08-09 10:49:55 -0700122 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800123 * @param[in] time interest lifetime
124 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700125 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700126 SetInterestLifetime (Time time);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700127
Ilya Moiseenko332add02011-12-24 17:21:25 -0800128 /**
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 Afanasyev4aac5572012-08-09 10:49:55 -0700132 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800133 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700134 Time
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700135 GetInterestLifetime () const;
136
Ilya Moiseenko332add02011-12-24 17:21:25 -0800137 /**
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 Afanasyev8a677dd2011-08-12 13:08:15 -0700142 void
143 SetNonce (uint32_t nonce);
144
Ilya Moiseenko332add02011-12-24 17:21:25 -0800145 /**
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 Afanasyev8a677dd2011-08-12 13:08:15 -0700150 uint32_t
151 GetNonce () const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800152
153 /**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700154 * @brief NACK Type
155 * Specifies the type of Interest packet
Ilya Moiseenko332add02011-12-24 17:21:25 -0800156 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800157 enum
158 {
159 NORMAL_INTEREST = 0,
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800160 NACK_LOOP = 10,
161 NACK_CONGESTION = 11,
162 NACK_GIVEUP_PIT = 12,
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800163 };
164
Ilya Moiseenko332add02011-12-24 17:21:25 -0800165 /**
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 Moiseenko75d9bf52011-10-28 13:18:32 -0700173 void
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800174 SetNack (uint8_t nackType); //using reserved field
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700175
Ilya Moiseenko332add02011-12-24 17:21:25 -0800176 /**
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 Afanasyev5d79e682012-11-19 14:12:23 -0800181 uint8_t
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800182 GetNack () const;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700183
Ilya Moiseenko332add02011-12-24 17:21:25 -0800184 /**
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700185 * @brief Get virtual "payload" of interest packet
186 *
187 * This payload can carry packet tags
Ilya Moiseenko332add02011-12-24 17:21:25 -0800188 */
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700189 void
190 SetPayload (Ptr<Packet> payload);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700191
Alexander Afanasyev663d63f2012-09-09 11:55:36 -0700192 /**
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700193 * @brief Set virtual "payload" to interest packet
194 *
195 * This payload can carry packet tags
Alexander Afanasyev663d63f2012-09-09 11:55:36 -0700196 */
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700197 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
214private:
215 // NO_ASSIGN
216 Interest &
217 operator = (const Interest &other) { return *this; }
Alexander Afanasyev663d63f2012-09-09 11:55:36 -0700218
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700219private:
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700220 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 Afanasyev8a677dd2011-08-12 13:08:15 -0700228};
229
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700230inline Ptr<const Packet>
231Interest::GetWire () const
232{
233 return m_wire;
234}
235
236/**
237 * @brief Set (cache) wire formatted packet
238 */
239inline void
240Interest::SetWire (Ptr<const Packet> packet) const
241{
242 m_wire = packet;
243}
244
Ilya Moiseenko332add02011-12-24 17:21:25 -0800245/**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700246 * @ingroup ndn-exceptions
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700247 * @brief Class for Interest parsing exception
Ilya Moiseenko332add02011-12-24 17:21:25 -0800248 */
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700249class InterestException {};
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700250
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700251} // namespace ndn
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700252} // namespace ns3
253
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700254#endif // _NDN_INTEREST_HEADER_H_