blob: ee9f63b1a4dd75818c0b42a2853cd7cd5b9d6667 [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
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{
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
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070099CcnxInterestHeader::SetExclude (const Ptr<CcnxNameComponents> &exclude)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700100{
101 m_exclude = exclude;
102}
103
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -0700104const CcnxNameComponents&
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700105CcnxInterestHeader::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...
Alexander Afanasyevae0d6522011-08-30 13:29:55 -0700174 /// \todo This is totally wrong. Need to do some simple packet buffer estimation
175 Buffer tmp(2048);
Alexander Afanasyev2a5df202011-08-15 22:39:05 -0700176
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700177 return CcnxEncodingHelper::Serialize (tmp.Begin(), *this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700178}
179
180void
181CcnxInterestHeader::Serialize (Buffer::Iterator start) const
182{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700183 CcnxEncodingHelper::Serialize (start, *this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700184}
185
186uint32_t
187CcnxInterestHeader::Deserialize (Buffer::Iterator start)
188{
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700189 return CcnxDecodingHelper::Deserialize (start, *this); // \todo Debugging is necessary
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700190}
191
192TypeId
193CcnxInterestHeader::GetInstanceTypeId (void) const
194{
195 return GetTypeId ();
196}
197
198void
199CcnxInterestHeader::Print (std::ostream &os) const
200{
Alexander Afanasyev2a5df202011-08-15 22:39:05 -0700201 os << "<Interest><Name>" << *m_name << "</Name>";
202 if (m_minSuffixComponents>=0)
203 os << "<MinSuffixComponents>" << m_minSuffixComponents << "</MinSuffixComponents>";
204 if (m_maxSuffixComponents>=0)
205 os << "<MaxSuffixComponents>" << m_maxSuffixComponents << "</MaxSuffixComponents>";
206 if (m_exclude->size()>0)
207 os << "<Exclude>" << *m_exclude << "</Exclude>";
208 if (m_childSelector)
209 os << "<ChildSelector />";
210 if (m_answerOriginKind)
211 os << "<AnswerOriginKind />";
212 if (m_scope>=0)
213 os << "<Scope>" << m_scope << "</Scope>";
214 if (!m_interestLifetime.IsZero())
215 os << "<InterestLifetime>" << m_interestLifetime << "</InterestLifetime>";
216 if (m_nonce>0)
217 os << "<Nonce>" << m_nonce << "</Nonce>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700218}
219
220}