blob: 554cdedd584d926b4deb0c434f3a9360a6c86740 [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
77void
78CcnxInterestHeader::SetMinSuffixComponents (int32_t value)
79{
80 m_minSuffixComponents = value;
81}
82
83int32_t
84CcnxInterestHeader::GetMinSuffixComponents () const
85{
86 return m_minSuffixComponents;
87}
88
89void
90CcnxInterestHeader::SetMaxSuffixComponents (int32_t value)
91{
92 m_maxSuffixComponents = value;
93}
94
95int32_t
96CcnxInterestHeader::GetMaxSuffixComponents () const
97{
98 return m_maxSuffixComponents;
99}
100
101void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700102CcnxInterestHeader::SetExclude (const Ptr<CcnxNameComponents> &exclude)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700103{
104 m_exclude = exclude;
105}
106
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700107bool
108CcnxInterestHeader::IsEnabledExclude () const
109{
110 return m_exclude!=0;
111}
112
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700113const CcnxNameComponents&
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700114CcnxInterestHeader::GetExclude () const
115{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700116 if (m_exclude==0) throw CcnxInterestHeaderException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700117 return *m_exclude;
118}
119
120void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700121CcnxInterestHeader::SetChildSelector (bool value)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700122{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700123 m_childSelector = value;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700124}
125
126bool
127CcnxInterestHeader::IsEnabledChildSelector () const
128{
129 return m_childSelector;
130}
131
132void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700133CcnxInterestHeader::SetAnswerOriginKind (bool value)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700134{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700135 m_answerOriginKind = value;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700136}
137
138bool
139CcnxInterestHeader::IsEnabledAnswerOriginKind () const
140{
141 return m_answerOriginKind;
142}
143
144void
145CcnxInterestHeader::SetScope (int8_t scope)
146{
147 m_scope = scope;
148}
149
150int8_t
151CcnxInterestHeader::GetScope () const
152{
153 return m_scope;
154}
155
156void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700157CcnxInterestHeader::SetInterestLifetime (Time lifetime)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700158{
159 m_interestLifetime = lifetime;
160}
161
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700162Time
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700163CcnxInterestHeader::GetInterestLifetime () const
164{
165 return m_interestLifetime;
166}
167
168void
169CcnxInterestHeader::SetNonce (uint32_t nonce)
170{
171 m_nonce = nonce;
172}
173
174uint32_t
175CcnxInterestHeader::GetNonce () const
176{
177 return m_nonce;
178}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700179
180void
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800181CcnxInterestHeader::SetNack (uint32_t nackType)
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700182{
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800183 m_nackType = nackType;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700184}
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800185
186uint32_t
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800187CcnxInterestHeader::GetNack () const
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700188{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800189 return m_nackType;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700190}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700191
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700192uint32_t
193CcnxInterestHeader::GetSerializedSize (void) const
194{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700195 // unfortunately, we don't know exact header size in advance
196 return CcnxEncodingHelper::GetSerializedSize (*this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700197}
198
199void
200CcnxInterestHeader::Serialize (Buffer::Iterator start) const
201{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700202 size_t size = CcnxEncodingHelper::Serialize (start, *this);
203 NS_UNUSED (size);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700204 NS_LOG_INFO ("Serialize size = " << size);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700205}
206
207uint32_t
208CcnxInterestHeader::Deserialize (Buffer::Iterator start)
209{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700210 return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700211}
212
213TypeId
214CcnxInterestHeader::GetInstanceTypeId (void) const
215{
216 return GetTypeId ();
217}
218
219void
220CcnxInterestHeader::Print (std::ostream &os) const
221{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700222 os << "I: " << GetName ();
223
224 return;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700225 os << "<Interest>\n <Name>" << GetName () << "</Name>\n";
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800226 if (GetNack ()>0)
227 {
228 os << " <NACK>";
229 switch (GetNack ())
230 {
231 case NACK_LOOP:
232 os << "loop";
233 break;
234 case NACK_CONGESTION:
235 os << "congestion";
236 break;
237 default:
238 os << "unknown";
239 break;
240 }
241 os << "</NACK>\n";
242 }
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700243 if (GetMinSuffixComponents () >= 0)
244 os << " <MinSuffixComponents>" << GetMinSuffixComponents () << "</MinSuffixComponents>\n";
245 if (GetMaxSuffixComponents () >= 0)
246 os << " <MaxSuffixComponents>" << m_maxSuffixComponents << "</MaxSuffixComponents>\n";
247 if (IsEnabledExclude () && GetExclude ().size()>0)
248 os << " <Exclude>" << GetExclude () << "</Exclude>\n";
249 if (IsEnabledChildSelector ())
250 os << " <ChildSelector />\n";
251 if (IsEnabledAnswerOriginKind ())
252 os << " <AnswerOriginKind />\n";
253 if (GetScope () >= 0)
254 os << " <Scope>" << GetScope () << "</Scope>\n";
255 if ( !GetInterestLifetime ().IsZero() )
256 os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
257 if (GetNonce ()>0)
258 os << " <Nonce>" << GetNonce () << "</Nonce>\n";
259 os << "</Interest>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700260}
261
262}