blob: 32dfcd85497e855ca172d7b437467ca4e01333a5 [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 Afanasyevfaa01f92013-07-10 18:34:31 -070029#include "ns3/packet.h"
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070030
31#include <string>
32#include <vector>
33#include <list>
34
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070035#include "ndn-name.h"
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070036
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070037namespace ns3 {
Alexander Afanasyev663d63f2012-09-09 11:55:36 -070038
39class Packet;
40
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070041namespace ndn {
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070042
43/**
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070044 * @brief NDN Interest (wire formats are defined in wire)
Alexander Afanasyevb989b122013-07-10 17:15:46 -070045 *
46 **/
47class Interest : public SimpleRefCount<Interest>
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070048{
49public:
50 /**
Ilya Moiseenko332add02011-12-24 17:21:25 -080051 * \brief Constructor
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070052 *
53 * Creates a null header
54 **/
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -070055 Interest (Ptr<Packet> payload = Create<Packet> ());
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070056
57 /**
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070058 * @brief Copy constructor
59 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070060 Interest (const Interest &interest);
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070061
62 /**
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070063 * \brief Set interest name
64 *
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070065 * @param name smart pointer to Name
66 *
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070067 **/
68 void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070069 SetName (Ptr<Name> name);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070070
Ilya Moiseenko332add02011-12-24 17:21:25 -080071 /**
Alexander Afanasyevcc50d982013-03-30 19:09:10 -070072 * \brief Another variant to set interest name
73 *
74 * @param name const reference to Name object
75 *
76 **/
77 void
78 SetName (const Name &name);
79
80 /**
Ilya Moiseenko332add02011-12-24 17:21:25 -080081 * \brief Get interest name
82 *
83 * Gets name of the interest.
84 **/
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070085 const Name&
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -070086 GetName () const;
87
Ilya Moiseenko332add02011-12-24 17:21:25 -080088 /**
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070089 * @brief Get smart pointer to the interest name (to avoid extra memory usage)
90 */
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070091 Ptr<const Name>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070092 GetNamePtr () const;
93
94 /**
Ilya Moiseenko332add02011-12-24 17:21:25 -080095 * \brief Set Scope
96 * Scope limits where the Interest may propagate.
97 * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host).
98 * Scope 1 limits propagation to the applications on the originating host.
99 * Scope 2 limits propagation to no further than the next host.
100 * Other values are not defined, and will cause the Interest message to be dropped.
101 * Note that this is not a hop count - the value is not decremented as the interest is forwarded.
102 * @param[in] scope interest scope
103 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700104 void
105 SetScope (int8_t scope);
106
Ilya Moiseenko332add02011-12-24 17:21:25 -0800107 /**
108 * \brief Get Scope value
109 * Scope limits where the Interest may propagate.
110 * Scope 0 prevents propagation beyond the local ccnd (even to other applications on the same host).
111 * Scope 1 limits propagation to the applications on the originating host.
112 * Scope 2 limits propagation to no further than the next host.
113 * Other values are not defined, and will cause the Interest message to be dropped.
114 * Note that this is not a hop count - the value is not decremented as the interest is forwarded.
115 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700116 int8_t
117 GetScope () const;
118
Ilya Moiseenko332add02011-12-24 17:21:25 -0800119 /**
120 * \brief Set InterestLifetime
121 * InterestLifetime indicates the (approximate) time remaining before the interest times out.
122 * The timeout is relative to the arrival time of the interest at the current node.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700123 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800124 * @param[in] time interest lifetime
125 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700126 void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700127 SetInterestLifetime (Time time);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700128
Ilya Moiseenko332add02011-12-24 17:21:25 -0800129 /**
130 * \brief Get InterestLifetime value
131 * InterestLifetime indicates the (approximate) time remaining before the interest times out.
132 * The timeout is relative to the arrival time of the interest at the current node.
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700133 * \see http://www.ndn.org/releases/latest/doc/technical/InterestMessage.html for more information.
Ilya Moiseenko332add02011-12-24 17:21:25 -0800134 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700135 Time
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700136 GetInterestLifetime () const;
137
Ilya Moiseenko332add02011-12-24 17:21:25 -0800138 /**
139 * \brief Set Nonce
140 * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages.
141 * @param[in] nonce Unique packet identification number
142 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700143 void
144 SetNonce (uint32_t nonce);
145
Ilya Moiseenko332add02011-12-24 17:21:25 -0800146 /**
147 * \brief Get Nonce value
148 * Nonce carries a randomly-genenerated bytestring that is used to detect and discard duplicate Interest messages.
149 *
150 */
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700151 uint32_t
152 GetNonce () const;
Ilya Moiseenko332add02011-12-24 17:21:25 -0800153
154 /**
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700155 * @brief NACK Type
156 * Specifies the type of Interest packet
Ilya Moiseenko332add02011-12-24 17:21:25 -0800157 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800158 enum
159 {
160 NORMAL_INTEREST = 0,
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800161 NACK_LOOP = 10,
162 NACK_CONGESTION = 11,
163 NACK_GIVEUP_PIT = 12,
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800164 };
165
Ilya Moiseenko332add02011-12-24 17:21:25 -0800166 /**
167 * \brief Mark the Interest as a Negative Acknowledgement
168 * Three types of NACKs are supported
169 * 1. NACK_LOOP
170 * 2. NACK_CONGESTION
171 * 3. NACK_GIVEUP_PIT
172 * @param[in] nackType NACK_LOOP or NACK_CONGESTION or NACK_GIVEUP_PIT or NORMAL_INTEREST
173 */
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700174 void
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800175 SetNack (uint8_t nackType); //using reserved field
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700176
Ilya Moiseenko332add02011-12-24 17:21:25 -0800177 /**
178 * \brief Get NACK type
179 * Returns NACK_LOOP, NACK_CONGESTION or NACK_GIVEUP_PIT.
180 * Otherwise, in case of normal interest packet, returns NORMAL_INTEREST (equals 0).
181 */
Alexander Afanasyev5d79e682012-11-19 14:12:23 -0800182 uint8_t
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800183 GetNack () const;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700184
Ilya Moiseenko332add02011-12-24 17:21:25 -0800185 /**
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700186 * @brief Get virtual "payload" of interest packet
187 *
188 * This payload can carry packet tags
Ilya Moiseenko332add02011-12-24 17:21:25 -0800189 */
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700190 void
191 SetPayload (Ptr<Packet> payload);
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700192
Alexander Afanasyev663d63f2012-09-09 11:55:36 -0700193 /**
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700194 * @brief Set virtual "payload" to interest packet
195 *
196 * This payload can carry packet tags
Alexander Afanasyev663d63f2012-09-09 11:55:36 -0700197 */
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700198 Ptr<const Packet>
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700199 GetPayload () const;
200
201 /**
202 * @brief Get wire formatted packet
203 *
204 * If wire formatted packet has not been set before, 0 will be returned
205 */
206 inline Ptr<const Packet>
207 GetWire () const;
208
209 /**
210 * @brief Set (cache) wire formatted packet
211 */
212 inline void
213 SetWire (Ptr<const Packet> packet) const;
214
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700215 /**
216 * @brief Print Interest in plain-text to the specified output stream
217 */
218 void
219 Print (std::ostream &os) const;
220
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700221private:
222 // NO_ASSIGN
223 Interest &
224 operator = (const Interest &other) { return *this; }
Alexander Afanasyev663d63f2012-09-09 11:55:36 -0700225
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700226private:
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700227 Ptr<Name> m_name; ///< @brief Interest name
228 uint8_t m_scope; ///< @brief 0xFF not set, 0 local scope, 1 this host, 2 immediate neighborhood
229 Time m_interestLifetime; ///< @brief InterestLifetime
230 uint32_t m_nonce; ///< @brief Nonce. not used if zero
231 uint8_t m_nackType; ///< @brief Negative Acknowledgement type
232 Ptr<Packet> m_payload; ///< @brief virtual payload
233
234 mutable Ptr<const Packet> m_wire;
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700235};
236
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700237inline Ptr<const Packet>
238Interest::GetWire () const
239{
240 return m_wire;
241}
242
Alexander Afanasyevb989b122013-07-10 17:15:46 -0700243inline void
244Interest::SetWire (Ptr<const Packet> packet) const
245{
246 m_wire = packet;
247}
248
Ilya Moiseenko332add02011-12-24 17:21:25 -0800249/**
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700250 * @ingroup ndn-exceptions
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700251 * @brief Class for Interest parsing exception
Ilya Moiseenko332add02011-12-24 17:21:25 -0800252 */
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700253class InterestException {};
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700254
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700255} // namespace ndn
Alexander Afanasyev8a677dd2011-08-12 13:08:15 -0700256} // namespace ns3
257
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700258#endif // _NDN_INTEREST_HEADER_H_