blob: 941fc02189208902cb376e24a0e5706ebba76cc9 [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 Afanasyevf9f4eb02011-12-16 01:51:14 -080029#include "../helper/ccnx-encoding-helper.h"
30#include "../helper/ccnx-decoding-helper.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070031
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070032NS_LOG_COMPONENT_DEFINE ("CcnxInterestHeader");
33
34namespace ns3
35{
36
37NS_OBJECT_ENSURE_REGISTERED (CcnxInterestHeader);
38
39TypeId
40CcnxInterestHeader::GetTypeId (void)
41{
42 static TypeId tid = TypeId ("ns3::CcnxInterestHeader")
Alexander Afanasyev070aa482011-08-20 00:38:25 -070043 .SetGroupName ("Ccnx")
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070044 .SetParent<Header> ()
45 .AddConstructor<CcnxInterestHeader> ()
46 ;
47 return tid;
48}
49
50
51CcnxInterestHeader::CcnxInterestHeader ()
52 : m_minSuffixComponents (-1)
53 , m_maxSuffixComponents (-1)
54 , m_childSelector (false)
55 , m_answerOriginKind (false)
56 , m_scope (-1)
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070057 , m_interestLifetime (Seconds (0))
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070058 , m_nonce (0)
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080059 , m_nackType (NORMAL_INTEREST)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070060{
61}
62
63void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070064CcnxInterestHeader::SetName (const Ptr<CcnxNameComponents> &name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070065{
66 m_name = name;
67}
68
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070069const CcnxNameComponents&
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070070CcnxInterestHeader::GetName () const
71{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070072 if (m_name==0) throw CcnxInterestHeaderException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070073 return *m_name;
74}
75
76void
77CcnxInterestHeader::SetMinSuffixComponents (int32_t value)
78{
79 m_minSuffixComponents = value;
80}
81
82int32_t
83CcnxInterestHeader::GetMinSuffixComponents () const
84{
85 return m_minSuffixComponents;
86}
87
88void
89CcnxInterestHeader::SetMaxSuffixComponents (int32_t value)
90{
91 m_maxSuffixComponents = value;
92}
93
94int32_t
95CcnxInterestHeader::GetMaxSuffixComponents () const
96{
97 return m_maxSuffixComponents;
98}
99
100void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700101CcnxInterestHeader::SetExclude (const Ptr<CcnxNameComponents> &exclude)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700102{
103 m_exclude = exclude;
104}
105
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700106bool
107CcnxInterestHeader::IsEnabledExclude () const
108{
109 return m_exclude!=0;
110}
111
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700112const CcnxNameComponents&
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700113CcnxInterestHeader::GetExclude () const
114{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700115 if (m_exclude==0) throw CcnxInterestHeaderException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700116 return *m_exclude;
117}
118
119void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700120CcnxInterestHeader::SetChildSelector (bool value)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700121{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700122 m_childSelector = value;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700123}
124
125bool
126CcnxInterestHeader::IsEnabledChildSelector () const
127{
128 return m_childSelector;
129}
130
131void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700132CcnxInterestHeader::SetAnswerOriginKind (bool value)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700133{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700134 m_answerOriginKind = value;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700135}
136
137bool
138CcnxInterestHeader::IsEnabledAnswerOriginKind () const
139{
140 return m_answerOriginKind;
141}
142
143void
144CcnxInterestHeader::SetScope (int8_t scope)
145{
146 m_scope = scope;
147}
148
149int8_t
150CcnxInterestHeader::GetScope () const
151{
152 return m_scope;
153}
154
155void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700156CcnxInterestHeader::SetInterestLifetime (Time lifetime)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700157{
158 m_interestLifetime = lifetime;
159}
160
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700161Time
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700162CcnxInterestHeader::GetInterestLifetime () const
163{
164 return m_interestLifetime;
165}
166
167void
168CcnxInterestHeader::SetNonce (uint32_t nonce)
169{
170 m_nonce = nonce;
171}
172
173uint32_t
174CcnxInterestHeader::GetNonce () const
175{
176 return m_nonce;
177}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700178
179void
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800180CcnxInterestHeader::SetNack (uint32_t nackType)
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700181{
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800182 m_nackType = nackType;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700183}
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800184
185uint32_t
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800186CcnxInterestHeader::GetNack () const
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700187{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800188 return m_nackType;
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700189}
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700190
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700191uint32_t
192CcnxInterestHeader::GetSerializedSize (void) const
193{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700194 // unfortunately, we don't know exact header size in advance
195 return CcnxEncodingHelper::GetSerializedSize (*this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700196}
197
198void
199CcnxInterestHeader::Serialize (Buffer::Iterator start) const
200{
Alexander Afanasyev3b8c50c2011-11-15 23:49:55 -0800201 size_t size __attribute__ ((__unused__)) = CcnxEncodingHelper::Serialize (start, *this);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700202
203 NS_LOG_INFO ("Serialize size = " << size);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700204}
205
206uint32_t
207CcnxInterestHeader::Deserialize (Buffer::Iterator start)
208{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700209 return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700210}
211
212TypeId
213CcnxInterestHeader::GetInstanceTypeId (void) const
214{
215 return GetTypeId ();
216}
217
218void
219CcnxInterestHeader::Print (std::ostream &os) const
220{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700221 os << "<Interest>\n <Name>" << GetName () << "</Name>\n";
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800222 if (GetNack ()>0)
223 {
224 os << " <NACK>";
225 switch (GetNack ())
226 {
227 case NACK_LOOP:
228 os << "loop";
229 break;
230 case NACK_CONGESTION:
231 os << "congestion";
232 break;
233 default:
234 os << "unknown";
235 break;
236 }
237 os << "</NACK>\n";
238 }
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700239 if (GetMinSuffixComponents () >= 0)
240 os << " <MinSuffixComponents>" << GetMinSuffixComponents () << "</MinSuffixComponents>\n";
241 if (GetMaxSuffixComponents () >= 0)
242 os << " <MaxSuffixComponents>" << m_maxSuffixComponents << "</MaxSuffixComponents>\n";
243 if (IsEnabledExclude () && GetExclude ().size()>0)
244 os << " <Exclude>" << GetExclude () << "</Exclude>\n";
245 if (IsEnabledChildSelector ())
246 os << " <ChildSelector />\n";
247 if (IsEnabledAnswerOriginKind ())
248 os << " <AnswerOriginKind />\n";
249 if (GetScope () >= 0)
250 os << " <Scope>" << GetScope () << "</Scope>\n";
251 if ( !GetInterestLifetime ().IsZero() )
252 os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
253 if (GetNonce ()>0)
254 os << " <Nonce>" << GetNonce () << "</Nonce>\n";
255 os << "</Interest>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700256}
257
258}