blob: d44ac451a2bcfab6728916aae99afac4e38796c8 [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 Afanasyev834f35c2011-08-16 17:13:50 -070029#include "ns3/ccnx-encoding-helper.h"
30#include "ns3/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)
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -070059 , m_nack (false)
60 , m_congested (false)
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
181CcnxInterestHeader::SetNack (bool isNack)
182{
183 m_nack = isNack;
184}
185
186bool
187CcnxInterestHeader::IsNack () const
188{
189 return m_nack;
190}
191
192void
193CcnxInterestHeader::SetCongested (bool IsCongested)
194{
195 m_congested = IsCongested;
196}
197
198bool
199CcnxInterestHeader::IsCongested () const
200{
201 return m_congested;
202}
203
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700204uint32_t
205CcnxInterestHeader::GetSerializedSize (void) const
206{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700207 // unfortunately, we don't know exact header size in advance
208 return CcnxEncodingHelper::GetSerializedSize (*this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700209}
210
211void
212CcnxInterestHeader::Serialize (Buffer::Iterator start) const
213{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700214 size_t size = CcnxEncodingHelper::Serialize (start, *this);
215
216 NS_LOG_INFO ("Serialize size = " << size);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700217}
218
219uint32_t
220CcnxInterestHeader::Deserialize (Buffer::Iterator start)
221{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700222 return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700223}
224
225TypeId
226CcnxInterestHeader::GetInstanceTypeId (void) const
227{
228 return GetTypeId ();
229}
230
231void
232CcnxInterestHeader::Print (std::ostream &os) const
233{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700234 os << "<Interest>\n <Name>" << GetName () << "</Name>\n";
Ilya Moiseenko75d9bf52011-10-28 13:18:32 -0700235 if (IsNack ())
236 os << " <NACK />\n";
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700237 if (GetMinSuffixComponents () >= 0)
238 os << " <MinSuffixComponents>" << GetMinSuffixComponents () << "</MinSuffixComponents>\n";
239 if (GetMaxSuffixComponents () >= 0)
240 os << " <MaxSuffixComponents>" << m_maxSuffixComponents << "</MaxSuffixComponents>\n";
241 if (IsEnabledExclude () && GetExclude ().size()>0)
242 os << " <Exclude>" << GetExclude () << "</Exclude>\n";
243 if (IsEnabledChildSelector ())
244 os << " <ChildSelector />\n";
245 if (IsEnabledAnswerOriginKind ())
246 os << " <AnswerOriginKind />\n";
247 if (GetScope () >= 0)
248 os << " <Scope>" << GetScope () << "</Scope>\n";
249 if ( !GetInterestLifetime ().IsZero() )
250 os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
251 if (GetNonce ()>0)
252 os << " <Nonce>" << GetNonce () << "</Nonce>\n";
253 os << "</Interest>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700254}
255
256}