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