blob: 330e2f40516787a4bfe35c01967d38fff691e9d6 [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)
57 , m_interestLifetime (-1)
58 , m_nonce (0)
59{
60}
61
62void
63CcnxInterestHeader::SetName (const Ptr<Name::Components> &name)
64{
65 m_name = name;
66}
67
68const Name::Components&
69CcnxInterestHeader::GetName () const
70{
71 return *m_name;
72}
73
74void
75CcnxInterestHeader::SetMinSuffixComponents (int32_t value)
76{
77 m_minSuffixComponents = value;
78}
79
80int32_t
81CcnxInterestHeader::GetMinSuffixComponents () const
82{
83 return m_minSuffixComponents;
84}
85
86void
87CcnxInterestHeader::SetMaxSuffixComponents (int32_t value)
88{
89 m_maxSuffixComponents = value;
90}
91
92int32_t
93CcnxInterestHeader::GetMaxSuffixComponents () const
94{
95 return m_maxSuffixComponents;
96}
97
98void
99CcnxInterestHeader::SetExclude (const Ptr<Name::Components> &exclude)
100{
101 m_exclude = exclude;
102}
103
104const Name::Components&
105CcnxInterestHeader::GetExclude () const
106{
107 return *m_exclude;
108}
109
110void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700111CcnxInterestHeader::SetChildSelector (bool value)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700112{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700113 m_childSelector = value;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700114}
115
116bool
117CcnxInterestHeader::IsEnabledChildSelector () const
118{
119 return m_childSelector;
120}
121
122void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700123CcnxInterestHeader::SetAnswerOriginKind (bool value)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700124{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700125 m_answerOriginKind = value;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700126}
127
128bool
129CcnxInterestHeader::IsEnabledAnswerOriginKind () const
130{
131 return m_answerOriginKind;
132}
133
134void
135CcnxInterestHeader::SetScope (int8_t scope)
136{
137 m_scope = scope;
138}
139
140int8_t
141CcnxInterestHeader::GetScope () const
142{
143 return m_scope;
144}
145
146void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700147CcnxInterestHeader::SetInterestLifetime (Time lifetime)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700148{
149 m_interestLifetime = lifetime;
150}
151
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700152Time
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700153CcnxInterestHeader::GetInterestLifetime () const
154{
155 return m_interestLifetime;
156}
157
158void
159CcnxInterestHeader::SetNonce (uint32_t nonce)
160{
161 m_nonce = nonce;
162}
163
164uint32_t
165CcnxInterestHeader::GetNonce () const
166{
167 return m_nonce;
168}
169
170uint32_t
171CcnxInterestHeader::GetSerializedSize (void) const
172{
Alexander Afanasyev2a5df202011-08-15 22:39:05 -0700173 // unfortunately, 2 serialization required...
174 Buffer tmp;
175
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700176 return CcnxEncodingHelper::Serialize (tmp.Begin(), *this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700177}
178
179void
180CcnxInterestHeader::Serialize (Buffer::Iterator start) const
181{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700182 CcnxEncodingHelper::Serialize (start, *this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700183}
184
185uint32_t
186CcnxInterestHeader::Deserialize (Buffer::Iterator start)
187{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700188 return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700189}
190
191TypeId
192CcnxInterestHeader::GetInstanceTypeId (void) const
193{
194 return GetTypeId ();
195}
196
197void
198CcnxInterestHeader::Print (std::ostream &os) const
199{
Alexander Afanasyev2a5df202011-08-15 22:39:05 -0700200 os << "<Interest><Name>" << *m_name << "</Name>";
201 if (m_minSuffixComponents>=0)
202 os << "<MinSuffixComponents>" << m_minSuffixComponents << "</MinSuffixComponents>";
203 if (m_maxSuffixComponents>=0)
204 os << "<MaxSuffixComponents>" << m_maxSuffixComponents << "</MaxSuffixComponents>";
205 if (m_exclude->size()>0)
206 os << "<Exclude>" << *m_exclude << "</Exclude>";
207 if (m_childSelector)
208 os << "<ChildSelector />";
209 if (m_answerOriginKind)
210 os << "<AnswerOriginKind />";
211 if (m_scope>=0)
212 os << "<Scope>" << m_scope << "</Scope>";
213 if (!m_interestLifetime.IsZero())
214 os << "<InterestLifetime>" << m_interestLifetime << "</InterestLifetime>";
215 if (m_nonce>0)
216 os << "<Nonce>" << m_nonce << "</Nonce>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700217}
218
219}