A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-header.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2008 Louis Pasteur University
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
18 */
19
20#ifndef IPV6_HEADER_H
21#define IPV6_HEADER_H
22
23#include "ns3/header.h"
24#include "ns3/ipv6-address.h"
25
26namespace ns3
27{
28
29/**
30 * \ingroup ipv6
31 *
32 * \brief Packet header for IPv6
33 */
34class Ipv6Header : public Header
35{
36 public:
37 /**
38 * \enum DscpType
39 * \brief DiffServ Code Points
40 * Code Points defined in
41 * Assured Forwarding (AF) \RFC{2597}
42 * Expedited Forwarding (EF) \RFC{2598}
43 * Default and Class Selector (CS) \RFC{2474}
44 */
46 {
48
49 // Prefixed with "DSCP" to avoid name clash (bug 1723)
50 DSCP_CS1 = 0x08, // octal 010
51 DSCP_AF11 = 0x0A, // octal 012
52 DSCP_AF12 = 0x0C, // octal 014
53 DSCP_AF13 = 0x0E, // octal 016
54
55 DSCP_CS2 = 0x10, // octal 020
56 DSCP_AF21 = 0x12, // octal 022
57 DSCP_AF22 = 0x14, // octal 024
58 DSCP_AF23 = 0x16, // octal 026
59
60 DSCP_CS3 = 0x18, // octal 030
61 DSCP_AF31 = 0x1A, // octal 032
62 DSCP_AF32 = 0x1C, // octal 034
63 DSCP_AF33 = 0x1E, // octal 036
64
65 DSCP_CS4 = 0x20, // octal 040
66 DSCP_AF41 = 0x22, // octal 042
67 DSCP_AF42 = 0x24, // octal 044
68 DSCP_AF43 = 0x26, // octal 046
69
70 DSCP_CS5 = 0x28, // octal 050
71 DSCP_EF = 0x2E, // octal 056
72
73 DSCP_CS6 = 0x30, // octal 060
74 DSCP_CS7 = 0x38 // octal 070
75 };
76
77 /**
78 * \enum NextHeader_e
79 * \brief IPv6 next-header value
80 */
82 {
95 IPV6_SCTP = 135,
98 };
99
100 /**
101 * \brief Get the type identifier.
102 * \return type identifier
103 */
104 static TypeId GetTypeId();
105
106 /**
107 * \brief Return the instance type identifier.
108 * \return instance type ID
109 */
110 TypeId GetInstanceTypeId() const override;
111
112 /**
113 * \brief Constructor.
114 */
115 Ipv6Header();
116
117 /**
118 * \brief Set the "Traffic class" field.
119 * \param traffic the 8-bit value
120 */
121 void SetTrafficClass(uint8_t traffic);
122
123 /**
124 * \brief Get the "Traffic class" field.
125 * \return the traffic value
126 */
127 uint8_t GetTrafficClass() const;
128
129 /**
130 * \brief Set DSCP Field
131 * \param dscp DSCP value
132 */
133 void SetDscp(DscpType dscp);
134
135 /**
136 * \returns the DSCP field of this packet.
137 */
138 DscpType GetDscp() const;
139
140 /**
141 * \param dscp the dscp
142 * \returns std::string of DSCPType
143 */
144 std::string DscpTypeToString(DscpType dscp) const;
145
146 /**
147 * \enum EcnType
148 * \brief ECN field bits
149 */
151 {
152 // Prefixed with "ECN" to avoid name clash
154 ECN_ECT1 = 0x01,
155 ECN_ECT0 = 0x02,
156 ECN_CE = 0x03
157 };
158
159 /**
160 * \brief Set ECN field bits
161 * \param ecn ECN field bits
162 */
163 void SetEcn(EcnType ecn);
164
165 /**
166 * \return the ECN field bits of this packet.
167 */
168 EcnType GetEcn() const;
169
170 /**
171 * \param ecn the ECNType
172 * \return std::string of ECNType
173 */
174 std::string EcnTypeToString(EcnType ecn) const;
175
176 /**
177 * \brief Set the "Flow label" field.
178 * \param flow the 20-bit value
179 */
180 void SetFlowLabel(uint32_t flow);
181
182 /**
183 * \brief Get the "Flow label" field.
184 * \return the flow label value
185 */
186 uint32_t GetFlowLabel() const;
187
188 /**
189 * \brief Set the "Payload length" field.
190 * \param len the length of the payload in bytes
191 */
192 void SetPayloadLength(uint16_t len);
193
194 /**
195 * \brief Get the "Payload length" field.
196 * \return the payload length
197 */
198 uint16_t GetPayloadLength() const;
199
200 /**
201 * \brief Set the "Next header" field.
202 * \param next the next header number
203 */
204 void SetNextHeader(uint8_t next);
205
206 /**
207 * \brief Get the next header.
208 * \return the next header number
209 */
210 uint8_t GetNextHeader() const;
211
212 /**
213 * \brief Set the "Hop limit" field (TTL).
214 * \param limit the 8-bit value
215 */
216 void SetHopLimit(uint8_t limit);
217
218 /**
219 * \brief Get the "Hop limit" field (TTL).
220 * \return the hop limit value
221 */
222 uint8_t GetHopLimit() const;
223
224 /**
225 * \brief Set the "Source address" field.
226 * \param src the source address
227 */
228 void SetSource(Ipv6Address src);
229
230 /**
231 * \brief Get the "Source address" field.
232 * \return the source address
233 */
234 Ipv6Address GetSource() const;
235
236 /**
237 * \brief Set the "Destination address" field.
238 * \param dst the destination address
239 */
240 void SetDestination(Ipv6Address dst);
241
242 /**
243 * \brief Get the "Destination address" field.
244 * \return the destination address
245 */
247
248 /**
249 * \brief Print some information about the packet.
250 * \param os output stream
251 */
252 void Print(std::ostream& os) const override;
253
254 /**
255 * \brief Get the serialized size of the packet.
256 * \return size
257 */
258 uint32_t GetSerializedSize() const override;
259
260 /**
261 * \brief Serialize the packet.
262 * \param start Buffer iterator
263 */
264 void Serialize(Buffer::Iterator start) const override;
265
266 /**
267 * \brief Deserialize the packet.
268 * \param start Buffer iterator
269 * \return size of the packet
270 */
271 uint32_t Deserialize(Buffer::Iterator start) override;
272
273 private:
274 /**
275 * \brief The traffic class.
276 */
278
279 /**
280 * \brief The flow label.
281 * \note This is 20-bit value.
282 */
284
285 /**
286 * \brief The payload length.
287 */
289
290 /**
291 * \brief The Next header number.
292 */
294
295 /**
296 * \brief The Hop limit value.
297 */
298 uint8_t m_hopLimit;
299
300 /**
301 * \brief The source address.
302 */
304
305 /**
306 * \brief The destination address.
307 */
309};
310
311} /* namespace ns3 */
312
313#endif /* IPV6_HEADER_H */
iterator in a Buffer instance
Definition: buffer.h:100
Protocol header serialization and deserialization.
Definition: header.h:44
Describes an IPv6 address.
Definition: ipv6-address.h:49
Packet header for IPv6.
Definition: ipv6-header.h:35
void SetDestination(Ipv6Address dst)
Set the "Destination address" field.
Definition: ipv6-header.cc:118
uint32_t GetFlowLabel() const
Get the "Flow label" field.
Definition: ipv6-header.cc:64
void SetEcn(EcnType ecn)
Set ECN field bits.
Definition: ipv6-header.cc:215
NextHeader_e
IPv6 next-header value.
Definition: ipv6-header.h:82
@ IPV6_EXT_CONFIDENTIALITY
Definition: ipv6-header.h:90
DscpType GetDscp() const
Definition: ipv6-header.cc:223
Ipv6Address m_destinationAddress
The destination address.
Definition: ipv6-header.h:308
void SetSource(Ipv6Address src)
Set the "Source address" field.
Definition: ipv6-header.cc:106
void Print(std::ostream &os) const override
Print some information about the packet.
Definition: ipv6-header.cc:146
uint8_t GetHopLimit() const
Get the "Hop limit" field (TTL).
Definition: ipv6-header.cc:100
uint8_t GetNextHeader() const
Get the next header.
Definition: ipv6-header.cc:88
static TypeId GetTypeId()
Get the type identifier.
Definition: ipv6-header.cc:130
void SetHopLimit(uint8_t limit)
Set the "Hop limit" field (TTL).
Definition: ipv6-header.cc:94
Ipv6Address GetDestination() const
Get the "Destination address" field.
Definition: ipv6-header.cc:124
uint16_t GetPayloadLength() const
Get the "Payload length" field.
Definition: ipv6-header.cc:76
uint8_t GetTrafficClass() const
Get the "Traffic class" field.
Definition: ipv6-header.cc:52
uint32_t m_flowLabel
The flow label.
Definition: ipv6-header.h:283
TypeId GetInstanceTypeId() const override
Return the instance type identifier.
Definition: ipv6-header.cc:140
EcnType GetEcn() const
Definition: ipv6-header.cc:284
void SetPayloadLength(uint16_t len)
Set the "Payload length" field.
Definition: ipv6-header.cc:70
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Definition: ipv6-header.cc:159
void SetFlowLabel(uint32_t flow)
Set the "Flow label" field.
Definition: ipv6-header.cc:58
Ipv6Header()
Constructor.
Definition: ipv6-header.cc:34
Ipv6Address m_sourceAddress
The source address.
Definition: ipv6-header.h:303
Ipv6Address GetSource() const
Get the "Source address" field.
Definition: ipv6-header.cc:112
EcnType
ECN field bits.
Definition: ipv6-header.h:151
uint16_t m_payloadLength
The payload length.
Definition: ipv6-header.h:288
uint8_t m_nextHeader
The Next header number.
Definition: ipv6-header.h:293
std::string DscpTypeToString(DscpType dscp) const
Definition: ipv6-header.cc:231
std::string EcnTypeToString(EcnType ecn) const
Definition: ipv6-header.cc:292
void SetTrafficClass(uint8_t traffic)
Set the "Traffic class" field.
Definition: ipv6-header.cc:46
void SetDscp(DscpType dscp)
Set DSCP Field.
Definition: ipv6-header.cc:207
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Definition: ipv6-header.cc:165
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
Definition: ipv6-header.cc:182
void SetNextHeader(uint8_t next)
Set the "Next header" field.
Definition: ipv6-header.cc:82
uint32_t m_trafficClass
The traffic class.
Definition: ipv6-header.h:277
uint8_t m_hopLimit
The Hop limit value.
Definition: ipv6-header.h:298
DscpType
DiffServ Code Points Code Points defined in Assured Forwarding (AF) RFC 2597 Expedited Forwarding (EF...
Definition: ipv6-header.h:46
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.