A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ipv6-option-header.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007-2009 Strasbourg University
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: David Gross <gdavid.devel@gmail.com>
19  */
20 
21 #include "ns3/assert.h"
22 #include "ns3/log.h"
23 #include "ns3/header.h"
24 #include "ipv6-option-header.h"
25 
26 namespace ns3
27 {
28 
29 NS_LOG_COMPONENT_DEFINE ("Ipv6OptionHeader");
30 
31 NS_OBJECT_ENSURE_REGISTERED (Ipv6OptionHeader);
32 
34 {
35  static TypeId tid = TypeId ("ns3::Ipv6OptionHeader")
37  .SetParent<Header> ()
38  ;
39  return tid;
40 }
41 
43 {
44  return GetTypeId ();
45 }
46 
48  : m_type (0),
49  m_length (0)
50 {
51 }
52 
54 {
55 }
56 
57 void Ipv6OptionHeader::SetType (uint8_t type)
58 {
59  m_type = type;
60 }
61 
62 uint8_t Ipv6OptionHeader::GetType () const
63 {
64  return m_type;
65 }
66 
67 void Ipv6OptionHeader::SetLength (uint8_t length)
68 {
69  m_length = length;
70 }
71 
72 uint8_t Ipv6OptionHeader::GetLength () const
73 {
74  return m_length;
75 }
76 
77 void Ipv6OptionHeader::Print (std::ostream &os) const
78 {
79  os << "( type = " << (uint32_t)m_type << " )";
80 }
81 
83 {
84  return m_length + 2;
85 }
86 
88 {
90 
91  i.WriteU8 (m_type);
92  i.WriteU8 (m_length);
93 
94  i.Write (m_data.Begin (), m_data.End ());
95 }
96 
98 {
100 
101  m_type = i.ReadU8 ();
102  m_length = i.ReadU8 ();
103 
104  m_data = Buffer ();
106  Buffer::Iterator dataStart = i;
107  i.Next (m_length);
108  Buffer::Iterator dataEnd = i;
109  m_data.Begin ().Write (dataStart, dataEnd);
110 
111  return GetSerializedSize ();
112 }
113 
115 {
116  return (Alignment){ 1,0};
117 }
118 
120 
122 {
123  static TypeId tid = TypeId ("ns3::Ipv6OptionPad1Header")
125  .SetParent<Ipv6OptionHeader> ()
126  ;
127  return tid;
128 }
129 
131 {
132  return GetTypeId ();
133 }
134 
136 {
137  SetType (0);
138 }
139 
141 {
142 }
143 
144 void Ipv6OptionPad1Header::Print (std::ostream &os) const
145 {
146  os << "( type = " << (uint32_t)GetType () << " )";
147 }
148 
150 {
151  return 1;
152 }
153 
155 {
157 
158  i.WriteU8 (GetType ());
159 }
160 
162 {
164 
165  SetType (i.ReadU8 ());
166 
167  return GetSerializedSize ();
168 }
169 
171 
173 {
174  static TypeId tid = TypeId ("ns3::Ipv6OptionPadnHeader")
176  .SetParent<Ipv6OptionHeader> ()
177  ;
178  return tid;
179 }
180 
182 {
183  return GetTypeId ();
184 }
185 
187 {
188  SetType (1);
189  NS_ASSERT_MSG (pad >= 2, "PadN must be at least 2 bytes long");
190  SetLength (pad - 2);
191 }
192 
194 {
195 }
196 
197 void Ipv6OptionPadnHeader::Print (std::ostream &os) const
198 {
199  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " )";
200 }
201 
203 {
204  return GetLength () + 2;
205 }
206 
208 {
210 
211  i.WriteU8 (GetType ());
212  i.WriteU8 (GetLength ());
213 
214  for (int padding = 0; padding < GetLength (); padding++)
215  {
216  i.WriteU8 (0);
217  }
218 }
219 
221 {
223 
224  SetType (i.ReadU8 ());
225  SetLength (i.ReadU8 ());
226 
227  return GetSerializedSize ();
228 }
229 
231 
233 {
234  static TypeId tid = TypeId ("ns3::Ipv6OptionJumbogramHeader")
236  .SetParent<Ipv6OptionHeader> ()
237  ;
238  return tid;
239 }
240 
242 {
243  return GetTypeId ();
244 }
245 
247 {
248  SetType (0xC2);
249  SetLength (4);
250 }
251 
253 {
254 }
255 
257 {
258  m_dataLength = dataLength;
259 }
260 
262 {
263  return m_dataLength;
264 }
265 
266 void Ipv6OptionJumbogramHeader::Print (std::ostream &os) const
267 {
268  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " data length = " << (uint32_t)m_dataLength << " )";
269 }
270 
272 {
273  return GetLength () + 2;
274 }
275 
277 {
279 
280  i.WriteU8 (GetType ());
281  i.WriteU8 (GetLength ());
283 }
284 
286 {
288 
289  SetType (i.ReadU8 ());
290  SetLength (i.ReadU8 ());
291  m_dataLength = i.ReadNtohU16 ();
292 
293  return GetSerializedSize ();
294 }
295 
297 {
298  return (Alignment){ 4,2}; //4n+2
299 }
300 
302 
304 {
305  static TypeId tid = TypeId ("ns3::Ipv6OptionRouterAlertHeader")
307  .SetParent<Ipv6OptionHeader> ()
308  ;
309  return tid;
310 }
311 
313 {
314  return GetTypeId ();
315 }
316 
318  : m_value (0)
319 {
320  SetLength (2);
321 }
322 
324 {
325 }
326 
328 {
329  m_value = value;
330 }
331 
333 {
334  return m_value;
335 }
336 
337 void Ipv6OptionRouterAlertHeader::Print (std::ostream &os) const
338 {
339  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " value = " << (uint32_t)m_value << " )";
340 }
341 
343 {
344  return GetLength () + 2;
345 }
346 
348 {
350 
351  i.WriteU8 (GetType ());
352  i.WriteU8 (GetLength ());
353  i.WriteHtonU16 (m_value);
354 }
355 
357 {
359 
360  SetType (i.ReadU8 ());
361  SetLength (i.ReadU8 ());
362  m_value = i.ReadNtohU16 ();
363 
364  return GetSerializedSize ();
365 }
366 
368 {
369  return (Alignment){ 2,0}; //2n+0
370 }
371 
372 } /* namespace ns3 */
373