blob: 323c5fc8ac5b5509854e94e1c23981257928f499 [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)
59{
60}
61
62void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070063CcnxInterestHeader::SetName (const Ptr<CcnxNameComponents> &name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070064{
65 m_name = name;
66}
67
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070068const CcnxNameComponents&
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070069CcnxInterestHeader::GetName () const
70{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070071 if (m_name==0) throw CcnxInterestHeaderException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070072 return *m_name;
73}
74
75void
76CcnxInterestHeader::SetMinSuffixComponents (int32_t value)
77{
78 m_minSuffixComponents = value;
79}
80
81int32_t
82CcnxInterestHeader::GetMinSuffixComponents () const
83{
84 return m_minSuffixComponents;
85}
86
87void
88CcnxInterestHeader::SetMaxSuffixComponents (int32_t value)
89{
90 m_maxSuffixComponents = value;
91}
92
93int32_t
94CcnxInterestHeader::GetMaxSuffixComponents () const
95{
96 return m_maxSuffixComponents;
97}
98
99void
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700100CcnxInterestHeader::SetExclude (const Ptr<CcnxNameComponents> &exclude)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700101{
102 m_exclude = exclude;
103}
104
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700105bool
106CcnxInterestHeader::IsEnabledExclude () const
107{
108 return m_exclude!=0;
109}
110
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700111const CcnxNameComponents&
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700112CcnxInterestHeader::GetExclude () const
113{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700114 if (m_exclude==0) throw CcnxInterestHeaderException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700115 return *m_exclude;
116}
117
118void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700119CcnxInterestHeader::SetChildSelector (bool value)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700120{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700121 m_childSelector = value;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700122}
123
124bool
125CcnxInterestHeader::IsEnabledChildSelector () const
126{
127 return m_childSelector;
128}
129
130void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700131CcnxInterestHeader::SetAnswerOriginKind (bool value)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700132{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700133 m_answerOriginKind = value;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700134}
135
136bool
137CcnxInterestHeader::IsEnabledAnswerOriginKind () const
138{
139 return m_answerOriginKind;
140}
141
142void
143CcnxInterestHeader::SetScope (int8_t scope)
144{
145 m_scope = scope;
146}
147
148int8_t
149CcnxInterestHeader::GetScope () const
150{
151 return m_scope;
152}
153
154void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700155CcnxInterestHeader::SetInterestLifetime (Time lifetime)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700156{
157 m_interestLifetime = lifetime;
158}
159
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700160Time
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700161CcnxInterestHeader::GetInterestLifetime () const
162{
163 return m_interestLifetime;
164}
165
166void
167CcnxInterestHeader::SetNonce (uint32_t nonce)
168{
169 m_nonce = nonce;
170}
171
172uint32_t
173CcnxInterestHeader::GetNonce () const
174{
175 return m_nonce;
176}
177
178uint32_t
179CcnxInterestHeader::GetSerializedSize (void) const
180{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700181 // unfortunately, we don't know exact header size in advance
182 return CcnxEncodingHelper::GetSerializedSize (*this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700183}
184
185void
186CcnxInterestHeader::Serialize (Buffer::Iterator start) const
187{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700188 size_t size = CcnxEncodingHelper::Serialize (start, *this);
189
190 NS_LOG_INFO ("Serialize size = " << size);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700191}
192
193uint32_t
194CcnxInterestHeader::Deserialize (Buffer::Iterator start)
195{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700196 return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700197}
198
199TypeId
200CcnxInterestHeader::GetInstanceTypeId (void) const
201{
202 return GetTypeId ();
203}
204
205void
206CcnxInterestHeader::Print (std::ostream &os) const
207{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -0700208 os << "<Interest>\n <Name>" << GetName () << "</Name>\n";
209 if (GetMinSuffixComponents () >= 0)
210 os << " <MinSuffixComponents>" << GetMinSuffixComponents () << "</MinSuffixComponents>\n";
211 if (GetMaxSuffixComponents () >= 0)
212 os << " <MaxSuffixComponents>" << m_maxSuffixComponents << "</MaxSuffixComponents>\n";
213 if (IsEnabledExclude () && GetExclude ().size()>0)
214 os << " <Exclude>" << GetExclude () << "</Exclude>\n";
215 if (IsEnabledChildSelector ())
216 os << " <ChildSelector />\n";
217 if (IsEnabledAnswerOriginKind ())
218 os << " <AnswerOriginKind />\n";
219 if (GetScope () >= 0)
220 os << " <Scope>" << GetScope () << "</Scope>\n";
221 if ( !GetInterestLifetime ().IsZero() )
222 os << " <InterestLifetime>" << GetInterestLifetime () << "</InterestLifetime>\n";
223 if (GetNonce ()>0)
224 os << " <Nonce>" << GetNonce () << "</Nonce>\n";
225 os << "</Interest>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700226}
227
228}