blob: 2c7e79848d532b4e1230a6f01598c6e482ec3b72 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -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
22///< #CCN_PR_SCOPE0 (0x20) local scope,
23///< #CCN_PR_SCOPE1 (0x40) this host,
24///< #CCN_PR_SCOPE2 (0x80) immediate neighborhood
25
26#include "ccnx-interest-header.h"
27
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070028#include "ns3/log.h"
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070029#include "ns3/unused.h"
Alexander Afanasyevf9f4eb02011-12-16 01:51:14 -080030#include "../helper/ccnx-encoding-helper.h"
31#include "../helper/ccnx-decoding-helper.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070032
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070033NS_LOG_COMPONENT_DEFINE ("CcnxInterestHeader");
34
35namespace ns3
36{
37
38NS_OBJECT_ENSURE_REGISTERED (CcnxInterestHeader);
39
40TypeId
41CcnxInterestHeader::GetTypeId (void)
42{
43 static TypeId tid = TypeId ("ns3::CcnxInterestHeader")
Alexander Afanasyev070aa482011-08-20 00:38:25 -070044 .SetGroupName ("Ccnx")
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070045 .SetParent<Header> ()
46 .AddConstructor<CcnxInterestHeader> ()
47 ;
48 return tid;
49}
50
51
52CcnxInterestHeader::CcnxInterestHeader ()
53 : m_minSuffixComponents (-1)
54 , m_maxSuffixComponents (-1)
55 , m_childSelector (false)
56 , m_answerOriginKind (false)
57 , m_scope (-1)
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070058 , m_interestLifetime (Seconds (0))
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070059 , m_nonce (0)
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080060 , m_nackType (NORMAL_INTEREST)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070061{
62}
63
64void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070065CcnxInterestHeader::SetName (const Ptr<CcnxNameComponents> &name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070066{
67 m_name = name;
68}
69
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070070const CcnxNameComponents&
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071CcnxInterestHeader::GetName () const
72{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070073 if (m_name==0) throw CcnxInterestHeaderException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070074 return *m_name;
75}
76
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070077Ptr<const CcnxNameComponents>
78CcnxInterestHeader::GetNamePtr () const
79{
80 return m_name;
81}
82
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070083void
84CcnxInterestHeader::SetMinSuffixComponents (int32_t value)
85{
86 m_minSuffixComponents = value;
87}
88
89int32_t
90CcnxInterestHeader::GetMinSuffixComponents () const
91{
92 return m_minSuffixComponents;
93}
94
95void
96CcnxInterestHeader::SetMaxSuffixComponents (int32_t value)
97{
98 m_maxSuffixComponents = value;
99}
100
101int32_t
102CcnxInterestHeader::GetMaxSuffixComponents () const
103{
104 return m_maxSuffixComponents;
105}
106
107void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700108CcnxInterestHeader::SetExclude (const Ptr<CcnxNameComponents> &exclude)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700109{
110 m_exclude = exclude;
111}
112
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700113bool
114CcnxInterestHeader::IsEnabledExclude () const
115{
116 return m_exclude!=0;
117}
118
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700119const CcnxNameComponents&
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700120CcnxInterestHeader::GetExclude () const
121{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700122 if (m_exclude==0) throw CcnxInterestHeaderException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700123 return *m_exclude;
124}
125
126void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700127CcnxInterestHeader::SetChildSelector (bool value)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700128{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700129 m_childSelector = value;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700130}
131
132bool
133CcnxInterestHeader::IsEnabledChildSelector () const
134{
135 return m_childSelector;
136}
137
138void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700139CcnxInterestHeader::SetAnswerOriginKind (bool value)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700140{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700141 m_answerOriginKind = value;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700142}
143
144bool
145CcnxInterestHeader::IsEnabledAnswerOriginKind () const
146{
147 return m_answerOriginKind;
148}
149
150void
151CcnxInterestHeader::SetScope (int8_t scope)
152{
153 m_scope = scope;
154}
155
156int8_t
157CcnxInterestHeader::GetScope () const
158{
159 return m_scope;
160}
161
162void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700163CcnxInterestHeader::SetInterestLifetime (Time lifetime)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700164{
165 m_interestLifetime = lifetime;
166}
167
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700168Time
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700169CcnxInterestHeader::GetInterestLifetime () const
170{
171 return m_interestLifetime;
172}
173
174void
175CcnxInterestHeader::SetNonce (uint32_t nonce)
176{
177 m_nonce = nonce;
178}
179
180uint32_t
181CcnxInterestHeader::GetNonce () const
182{
183 return m_nonce;
184}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700185
186void
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800187CcnxInterestHeader::SetNack (uint32_t nackType)
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700188{
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800189 m_nackType = nackType;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700190}
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800191
192uint32_t
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800193CcnxInterestHeader::GetNack () const
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700194{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800195 return m_nackType;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700196}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700197
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700198uint32_t
199CcnxInterestHeader::GetSerializedSize (void) const
200{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700201 // unfortunately, we don't know exact header size in advance
202 return CcnxEncodingHelper::GetSerializedSize (*this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700203}
204
205void
206CcnxInterestHeader::Serialize (Buffer::Iterator start) const
207{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700208 size_t size = CcnxEncodingHelper::Serialize (start, *this);
209 NS_UNUSED (size);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700210 NS_LOG_INFO ("Serialize size = " << size);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700211}
212
213uint32_t
214CcnxInterestHeader::Deserialize (Buffer::Iterator start)
215{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700216 return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700217}
218
219TypeId
220CcnxInterestHeader::GetInstanceTypeId (void) const
221{
222 return GetTypeId ();
223}
224
225void
226CcnxInterestHeader::Print (std::ostream &os) const
227{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700228 os << "I: " << GetName ();
229
230 return;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700231 os << "<Interest>\n <Name>" << GetName () << "</Name>\n";
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800232 if (GetNack ()>0)
233 {
234 os << " <NACK>";
235 switch (GetNack ())
236 {
237 case NACK_LOOP:
238 os << "loop";
239 break;
240 case NACK_CONGESTION:
241 os << "congestion";
242 break;
243 default:
244 os << "unknown";
245 break;
246 }
247 os << "</NACK>\n";
248 }
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700249 if (GetMinSuffixComponents () >= 0)
250 os << " <MinSuffixComponents>" << GetMinSuffixComponents () << "</MinSuffixComponents>\n";
251 if (GetMaxSuffixComponents () >= 0)
252 os << " <MaxSuffixComponents>" << m_maxSuffixComponents << "</MaxSuffixComponents>\n";
253 if (IsEnabledExclude () && GetExclude ().size()>0)
254 os << " <Exclude>" << GetExclude () << "</Exclude>\n";
255 if (IsEnabledChildSelector ())
256 os << " <ChildSelector />\n";
257 if (IsEnabledAnswerOriginKind ())
258 os << " <AnswerOriginKind />\n";
259 if (GetScope () >= 0)
260 os << " <Scope>" << GetScope () << "</Scope>\n";
261 if ( !GetInterestLifetime ().IsZero() )
262 os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
263 if (GetNonce ()>0)
264 os << " <Nonce>" << GetNonce () << "</Nonce>\n";
265 os << "</Interest>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700266}
267
268}