A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ipv6-option.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/log.h"
22 #include "ns3/assert.h"
23 #include "ns3/uinteger.h"
24 #include "ipv6-option.h"
25 #include "ipv6-option-header.h"
26 
27 NS_LOG_COMPONENT_DEFINE ("Ipv6Option");
28 
29 namespace ns3
30 {
31 
32 NS_OBJECT_ENSURE_REGISTERED (Ipv6Option);
33 
35 {
36  static TypeId tid = TypeId ("ns3::Ipv6Option")
37  .SetParent<Object> ()
38  .AddAttribute ("OptionNumber", "The IPv6 option number.",
39  UintegerValue (0),
40  MakeUintegerAccessor (&Ipv6Option::GetOptionNumber),
41  MakeUintegerChecker<uint8_t> ())
42  ;
43  return tid;
44 }
45 
47 {
49 }
50 
52 {
53  NS_LOG_FUNCTION (this << node);
54  m_node = node;
55 }
56 
57 
59 
61 {
62  static TypeId tid = TypeId ("ns3::Ipv6OptionPad1")
64  .AddConstructor<Ipv6OptionPad1> ()
65  ;
66  return tid;
67 }
68 
70 {
72 }
73 
75 {
77 }
78 
80 {
82 
83  return OPT_NUMBER;
84 }
85 
86 uint8_t Ipv6OptionPad1::Process (Ptr<Packet> packet, uint8_t offset, Ipv6Header const& ipv6Header, bool& isDropped)
87 {
88  NS_LOG_FUNCTION (this << packet << offset << ipv6Header << isDropped);
89 
90  Ptr<Packet> p = packet->Copy ();
91  p->RemoveAtStart (offset);
92 
93  Ipv6OptionPad1Header pad1Header;
94  p->RemoveHeader (pad1Header);
95 
96  isDropped = false;
97 
98  return pad1Header.GetSerializedSize ();
99 }
100 
101 
103 
105 {
106  static TypeId tid = TypeId ("ns3::Ipv6OptionPadn")
107  .SetParent<Ipv6Option> ()
108  .AddConstructor<Ipv6OptionPadn> ()
109  ;
110  return tid;
111 }
112 
114 {
116 }
117 
119 {
121 }
122 
124 {
126 
127  return OPT_NUMBER;
128 }
129 
130 uint8_t Ipv6OptionPadn::Process (Ptr<Packet> packet, uint8_t offset, Ipv6Header const& ipv6Header, bool& isDropped)
131 {
132  NS_LOG_FUNCTION (this << packet << offset << ipv6Header << isDropped);
133 
134  Ptr<Packet> p = packet->Copy ();
135  p->RemoveAtStart (offset);
136 
137  Ipv6OptionPadnHeader padnHeader;
138  p->RemoveHeader (padnHeader);
139 
140  isDropped = false;
141 
142  return padnHeader.GetSerializedSize ();
143 }
144 
145 
147 
149 {
150  static TypeId tid = TypeId ("ns3::Ipv6OptionJumbogram")
151  .SetParent<Ipv6Option> ()
152  .AddConstructor<Ipv6OptionJumbogram> ()
153  ;
154  return tid;
155 }
156 
158 {
160 }
161 
163 {
165 }
166 
168 {
170 
171  return OPT_NUMBER;
172 }
173 
174 uint8_t Ipv6OptionJumbogram::Process (Ptr<Packet> packet, uint8_t offset, Ipv6Header const& ipv6Header, bool& isDropped)
175 {
176  NS_LOG_FUNCTION (this << packet << offset << ipv6Header << isDropped);
177 
178  Ptr<Packet> p = packet->Copy ();
179  p->RemoveAtStart (offset);
180 
181  Ipv6OptionJumbogramHeader jumbogramHeader;
182  p->RemoveHeader (jumbogramHeader);
183 
184  isDropped = false;
185 
186  return jumbogramHeader.GetSerializedSize ();
187 }
188 
189 
191 
193 {
194  static TypeId tid = TypeId ("ns3::Ipv6OptionRouterAlert")
195  .SetParent<Ipv6Option> ()
196  .AddConstructor<Ipv6OptionRouterAlert> ()
197  ;
198  return tid;
199 }
200 
202 {
204 }
205 
207 {
209 }
210 
212 {
214 
215  return OPT_NUMBER;
216 }
217 
218 uint8_t Ipv6OptionRouterAlert::Process (Ptr<Packet> packet, uint8_t offset, Ipv6Header const& ipv6Header, bool& isDropped)
219 {
220  NS_LOG_FUNCTION (this << packet << offset << ipv6Header << isDropped);
221 
222  Ptr<Packet> p = packet->Copy ();
223  p->RemoveAtStart (offset);
224 
225  Ipv6OptionRouterAlertHeader routerAlertHeader;
226  p->RemoveHeader (routerAlertHeader);
227 
228  isDropped = false;
229 
230  return routerAlertHeader.GetSerializedSize ();
231 }
232 
233 } /* namespace ns3 */
234