A Discrete-Event Network Simulator
API
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 namespace ns3
28 {
29 
30 NS_LOG_COMPONENT_DEFINE ("Ipv6Option");
31 
32 NS_OBJECT_ENSURE_REGISTERED (Ipv6Option);
33 
35 {
36  static TypeId tid = TypeId ("ns3::Ipv6Option")
37  .SetParent<Object> ()
38  .SetGroupName ("Internet")
39  .AddAttribute ("OptionNumber", "The IPv6 option number.",
40  UintegerValue (0),
42  MakeUintegerChecker<uint8_t> ())
43  ;
44  return tid;
45 }
46 
48 {
49  NS_LOG_FUNCTION (this);
50 }
51 
53 {
54  NS_LOG_FUNCTION (this << node);
55  m_node = node;
56 }
57 
58 
60 
62 {
63  static TypeId tid = TypeId ("ns3::Ipv6OptionPad1")
65  .SetGroupName ("Internet")
66  .AddConstructor<Ipv6OptionPad1> ()
67  ;
68  return tid;
69 }
70 
72 {
73  NS_LOG_FUNCTION (this);
74 }
75 
77 {
78  NS_LOG_FUNCTION (this);
79 }
80 
82 {
83  NS_LOG_FUNCTION (this);
84 
85  return OPT_NUMBER;
86 }
87 
88 uint8_t Ipv6OptionPad1::Process (Ptr<Packet> packet, uint8_t offset, Ipv6Header const& ipv6Header, bool& isDropped)
89 {
90  NS_LOG_FUNCTION (this << packet << offset << ipv6Header << isDropped);
91 
92  Ptr<Packet> p = packet->Copy ();
93  p->RemoveAtStart (offset);
94 
95  Ipv6OptionPad1Header pad1Header;
96  p->RemoveHeader (pad1Header);
97 
98  isDropped = false;
99 
100  return pad1Header.GetSerializedSize ();
101 }
102 
103 
105 
107 {
108  static TypeId tid = TypeId ("ns3::Ipv6OptionPadn")
109  .SetParent<Ipv6Option> ()
110  .SetGroupName ("Internet")
111  .AddConstructor<Ipv6OptionPadn> ()
112  ;
113  return tid;
114 }
115 
117 {
118  NS_LOG_FUNCTION (this);
119 }
120 
122 {
123  NS_LOG_FUNCTION (this);
124 }
125 
127 {
128  NS_LOG_FUNCTION (this);
129 
130  return OPT_NUMBER;
131 }
132 
133 uint8_t Ipv6OptionPadn::Process (Ptr<Packet> packet, uint8_t offset, Ipv6Header const& ipv6Header, bool& isDropped)
134 {
135  NS_LOG_FUNCTION (this << packet << offset << ipv6Header << isDropped);
136 
137  Ptr<Packet> p = packet->Copy ();
138  p->RemoveAtStart (offset);
139 
140  Ipv6OptionPadnHeader padnHeader;
141  p->RemoveHeader (padnHeader);
142 
143  isDropped = false;
144 
145  return padnHeader.GetSerializedSize ();
146 }
147 
148 
150 
152 {
153  static TypeId tid = TypeId ("ns3::Ipv6OptionJumbogram")
154  .SetParent<Ipv6Option> ()
155  .SetGroupName ("Internet")
156  .AddConstructor<Ipv6OptionJumbogram> ()
157  ;
158  return tid;
159 }
160 
162 {
163  NS_LOG_FUNCTION (this);
164 }
165 
167 {
168  NS_LOG_FUNCTION (this);
169 }
170 
172 {
173  NS_LOG_FUNCTION (this);
174 
175  return OPT_NUMBER;
176 }
177 
178 uint8_t Ipv6OptionJumbogram::Process (Ptr<Packet> packet, uint8_t offset, Ipv6Header const& ipv6Header, bool& isDropped)
179 {
180  NS_LOG_FUNCTION (this << packet << offset << ipv6Header << isDropped);
181 
182  Ptr<Packet> p = packet->Copy ();
183  p->RemoveAtStart (offset);
184 
185  Ipv6OptionJumbogramHeader jumbogramHeader;
186  p->RemoveHeader (jumbogramHeader);
187 
188  isDropped = false;
189 
190  return jumbogramHeader.GetSerializedSize ();
191 }
192 
193 
195 
197 {
198  static TypeId tid = TypeId ("ns3::Ipv6OptionRouterAlert")
199  .SetParent<Ipv6Option> ()
200  .SetGroupName ("Internet")
201  .AddConstructor<Ipv6OptionRouterAlert> ()
202  ;
203  return tid;
204 }
205 
207 {
208  NS_LOG_FUNCTION (this);
209 }
210 
212 {
213  NS_LOG_FUNCTION (this);
214 }
215 
217 {
218  NS_LOG_FUNCTION (this);
219 
220  return OPT_NUMBER;
221 }
222 
223 uint8_t Ipv6OptionRouterAlert::Process (Ptr<Packet> packet, uint8_t offset, Ipv6Header const& ipv6Header, bool& isDropped)
224 {
225  NS_LOG_FUNCTION (this << packet << offset << ipv6Header << isDropped);
226 
227  Ptr<Packet> p = packet->Copy ();
228  p->RemoveAtStart (offset);
229 
230  Ipv6OptionRouterAlertHeader routerAlertHeader;
231  p->RemoveHeader (routerAlertHeader);
232 
233  isDropped = false;
234 
235  return routerAlertHeader.GetSerializedSize ();
236 }
237 
238 } /* namespace ns3 */
239 
Packet header for IPv6.
Definition: ipv6-header.h:36
IPv6 Option base.
Definition: ipv6-option.h:47
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:34
virtual uint8_t GetOptionNumber() const =0
Get the option number.
Ptr< Node > m_node
The node.
Definition: ipv6-option.h:88
virtual ~Ipv6Option()
Destructor.
Definition: ipv6-option.cc:47
void SetNode(Ptr< Node > node)
Set the node.
Definition: ipv6-option.cc:52
Header of IPv6 Option Jumbogram.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
IPv6 Option Jumbogram.
Definition: ipv6-option.h:193
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:151
virtual uint8_t Process(Ptr< Packet > packet, uint8_t offset, Ipv6Header const &ipv6Header, bool &isDropped)
Process method Called from Ipv6L3Protocol::Receive.
Definition: ipv6-option.cc:178
~Ipv6OptionJumbogram()
Destructor.
Definition: ipv6-option.cc:166
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: ipv6-option.cc:171
static const uint8_t OPT_NUMBER
Jumbogram option number.
Definition: ipv6-option.h:198
Ipv6OptionJumbogram()
Constructor.
Definition: ipv6-option.cc:161
Header of IPv6 Option Pad1.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
IPv6 Option Pad1.
Definition: ipv6-option.h:97
~Ipv6OptionPad1()
Destructor.
Definition: ipv6-option.cc:76
virtual uint8_t Process(Ptr< Packet > packet, uint8_t offset, Ipv6Header const &ipv6Header, bool &isDropped)
Process method.
Definition: ipv6-option.cc:88
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: ipv6-option.cc:81
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:61
static const uint8_t OPT_NUMBER
Pad1 option number.
Definition: ipv6-option.h:102
Ipv6OptionPad1()
Constructor.
Definition: ipv6-option.cc:71
Header of IPv6 Option Padn.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
IPv6 Option Padn.
Definition: ipv6-option.h:145
virtual uint8_t Process(Ptr< Packet > packet, uint8_t offset, Ipv6Header const &ipv6Header, bool &isDropped)
Process method.
Definition: ipv6-option.cc:133
static const uint8_t OPT_NUMBER
PadN option number.
Definition: ipv6-option.h:150
~Ipv6OptionPadn()
Destructor.
Definition: ipv6-option.cc:121
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: ipv6-option.cc:126
Ipv6OptionPadn()
Constructor.
Definition: ipv6-option.cc:116
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:106
Header of IPv6 Option Router Alert.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
IPv6 Option Router Alert.
Definition: ipv6-option.h:240
static const uint8_t OPT_NUMBER
Router alert option number.
Definition: ipv6-option.h:245
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:196
virtual uint8_t Process(Ptr< Packet > packet, uint8_t offset, Ipv6Header const &ipv6Header, bool &isDropped)
Process method.
Definition: ipv6-option.cc:223
Ipv6OptionRouterAlert()
Constructor.
Definition: ipv6-option.cc:206
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: ipv6-option.cc:216
~Ipv6OptionRouterAlert()
Destructor.
Definition: ipv6-option.cc:211
A base class which provides memory management and object aggregation.
Definition: object.h:88
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
Definition: packet.cc:362
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.