blob: cab33eab6a5b1c1faba9df3b65dd43d698e1400d [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 Afanasyev2a5df202011-08-15 22:39:05 -070029#include "ns3/ccnx-coding-helper.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070030
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070031NS_LOG_COMPONENT_DEFINE ("CcnxInterestHeader");
32
33namespace ns3
34{
35
36NS_OBJECT_ENSURE_REGISTERED (CcnxInterestHeader);
37
38TypeId
39CcnxInterestHeader::GetTypeId (void)
40{
41 static TypeId tid = TypeId ("ns3::CcnxInterestHeader")
42 .SetParent<Header> ()
43 .AddConstructor<CcnxInterestHeader> ()
44 ;
45 return tid;
46}
47
48
49CcnxInterestHeader::CcnxInterestHeader ()
50 : m_minSuffixComponents (-1)
51 , m_maxSuffixComponents (-1)
52 , m_childSelector (false)
53 , m_answerOriginKind (false)
54 , m_scope (-1)
55 , m_interestLifetime (-1)
56 , m_nonce (0)
57{
58}
59
60void
61CcnxInterestHeader::SetName (const Ptr<Name::Components> &name)
62{
63 m_name = name;
64}
65
66const Name::Components&
67CcnxInterestHeader::GetName () const
68{
69 return *m_name;
70}
71
72void
73CcnxInterestHeader::SetMinSuffixComponents (int32_t value)
74{
75 m_minSuffixComponents = value;
76}
77
78int32_t
79CcnxInterestHeader::GetMinSuffixComponents () const
80{
81 return m_minSuffixComponents;
82}
83
84void
85CcnxInterestHeader::SetMaxSuffixComponents (int32_t value)
86{
87 m_maxSuffixComponents = value;
88}
89
90int32_t
91CcnxInterestHeader::GetMaxSuffixComponents () const
92{
93 return m_maxSuffixComponents;
94}
95
96void
97CcnxInterestHeader::SetExclude (const Ptr<Name::Components> &exclude)
98{
99 m_exclude = exclude;
100}
101
102const Name::Components&
103CcnxInterestHeader::GetExclude () const
104{
105 return *m_exclude;
106}
107
108void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700109CcnxInterestHeader::SetChildSelector (bool value)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700110{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700111 m_childSelector = value;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700112}
113
114bool
115CcnxInterestHeader::IsEnabledChildSelector () const
116{
117 return m_childSelector;
118}
119
120void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700121CcnxInterestHeader::SetAnswerOriginKind (bool value)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700122{
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700123 m_answerOriginKind = value;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700124}
125
126bool
127CcnxInterestHeader::IsEnabledAnswerOriginKind () const
128{
129 return m_answerOriginKind;
130}
131
132void
133CcnxInterestHeader::SetScope (int8_t scope)
134{
135 m_scope = scope;
136}
137
138int8_t
139CcnxInterestHeader::GetScope () const
140{
141 return m_scope;
142}
143
144void
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700145CcnxInterestHeader::SetInterestLifetime (Time lifetime)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700146{
147 m_interestLifetime = lifetime;
148}
149
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700150Time
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700151CcnxInterestHeader::GetInterestLifetime () const
152{
153 return m_interestLifetime;
154}
155
156void
157CcnxInterestHeader::SetNonce (uint32_t nonce)
158{
159 m_nonce = nonce;
160}
161
162uint32_t
163CcnxInterestHeader::GetNonce () const
164{
165 return m_nonce;
166}
167
168uint32_t
169CcnxInterestHeader::GetSerializedSize (void) const
170{
Alexander Afanasyev2a5df202011-08-15 22:39:05 -0700171 // unfortunately, 2 serialization required...
172 Buffer tmp;
173
174 return CcnxCodingHelper::Serialize (tmp.Begin(), *this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700175}
176
177void
178CcnxInterestHeader::Serialize (Buffer::Iterator start) const
179{
Alexander Afanasyev2a5df202011-08-15 22:39:05 -0700180 CcnxCodingHelper::Serialize (start, *this);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700181}
182
183uint32_t
184CcnxInterestHeader::Deserialize (Buffer::Iterator start)
185{
Alexander Afanasyev2a5df202011-08-15 22:39:05 -0700186 return 0; // the most complicated part is here
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700187}
188
189TypeId
190CcnxInterestHeader::GetInstanceTypeId (void) const
191{
192 return GetTypeId ();
193}
194
195void
196CcnxInterestHeader::Print (std::ostream &os) const
197{
Alexander Afanasyev2a5df202011-08-15 22:39:05 -0700198 os << "<Interest><Name>" << *m_name << "</Name>";
199 if (m_minSuffixComponents>=0)
200 os << "<MinSuffixComponents>" << m_minSuffixComponents << "</MinSuffixComponents>";
201 if (m_maxSuffixComponents>=0)
202 os << "<MaxSuffixComponents>" << m_maxSuffixComponents << "</MaxSuffixComponents>";
203 if (m_exclude->size()>0)
204 os << "<Exclude>" << *m_exclude << "</Exclude>";
205 if (m_childSelector)
206 os << "<ChildSelector />";
207 if (m_answerOriginKind)
208 os << "<AnswerOriginKind />";
209 if (m_scope>=0)
210 os << "<Scope>" << m_scope << "</Scope>";
211 if (!m_interestLifetime.IsZero())
212 os << "<InterestLifetime>" << m_interestLifetime << "</InterestLifetime>";
213 if (m_nonce>0)
214 os << "<Nonce>" << m_nonce << "</Nonce>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700215}
216
217}