A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
ipv4-header.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2005 INRIA
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7
*/
8
9
#ifndef IPV4_HEADER_H
10
#define IPV4_HEADER_H
11
12
#include "ns3/header.h"
13
#include "ns3/ipv4-address.h"
14
15
namespace
ns3
16
{
17
/**
18
* @ingroup ipv4
19
*
20
* @brief Packet header for IPv4
21
*/
22
class
Ipv4Header
:
public
Header
23
{
24
public
:
25
/**
26
* @brief Construct a null IPv4 header
27
*/
28
Ipv4Header
();
29
/**
30
* @brief Enable checksum calculation for this header.
31
*/
32
void
EnableChecksum
();
33
/**
34
* @param size the size of the payload in bytes
35
*/
36
void
SetPayloadSize
(uint16_t size);
37
/**
38
* @param identification the Identification field of IPv4 packets.
39
*
40
* By default, set to zero.
41
*/
42
void
SetIdentification
(uint16_t identification);
43
/**
44
* @param tos the 8 bits of Ipv4 TOS.
45
*/
46
void
SetTos
(uint8_t tos);
47
48
public
:
49
/**
50
* @enum DscpType
51
* @brief DiffServ codepoints
52
*
53
* The values correspond to the 6-bit DSCP codepoint within the 8-bit
54
* DS field defined in \RFC{2474}. ECN bits are separately set with the
55
* SetEcn() method. Codepoints are defined in
56
* Assured Forwarding (AF) \RFC{2597},
57
* Expedited Forwarding (EF) \RFC{2598}, and
58
* Default and Class Selector (CS) \RFC{2474}.
59
*/
60
enum
DscpType
61
{
62
DscpDefault
= 0x00,
63
64
// Prefixed with "DSCP" to avoid name clash (bug 1723)
65
DSCP_CS1
= 0x08,
// octal 010
66
DSCP_AF11
= 0x0A,
// octal 012
67
DSCP_AF12
= 0x0C,
// octal 014
68
DSCP_AF13
= 0x0E,
// octal 016
69
70
DSCP_CS2
= 0x10,
// octal 020
71
DSCP_AF21
= 0x12,
// octal 022
72
DSCP_AF22
= 0x14,
// octal 024
73
DSCP_AF23
= 0x16,
// octal 026
74
75
DSCP_CS3
= 0x18,
// octal 030
76
DSCP_AF31
= 0x1A,
// octal 032
77
DSCP_AF32
= 0x1C,
// octal 034
78
DSCP_AF33
= 0x1E,
// octal 036
79
80
DSCP_CS4
= 0x20,
// octal 040
81
DSCP_AF41
= 0x22,
// octal 042
82
DSCP_AF42
= 0x24,
// octal 044
83
DSCP_AF43
= 0x26,
// octal 046
84
85
DSCP_CS5
= 0x28,
// octal 050
86
DSCP_EF
= 0x2E,
// octal 056
87
88
DSCP_CS6
= 0x30,
// octal 060
89
DSCP_CS7
= 0x38
// octal 070
90
};
91
92
/**
93
* @brief Set DSCP Field
94
* @param dscp DSCP value
95
*/
96
void
SetDscp
(
DscpType
dscp);
97
98
/**
99
* @enum EcnType
100
* @brief ECN Type defined in \RFC{3168}
101
*/
102
enum
EcnType
103
{
104
// Prefixed with "ECN" to avoid name clash (bug 1723)
105
ECN_NotECT
= 0x00,
106
ECN_ECT1
= 0x01,
107
ECN_ECT0
= 0x02,
108
ECN_CE
= 0x03
109
};
110
111
/**
112
* @brief Set ECN Field
113
* @param ecn ECN Type
114
*/
115
void
SetEcn
(
EcnType
ecn);
116
/**
117
* This packet is not the last packet of a fragmented ipv4 packet.
118
*/
119
void
SetMoreFragments
();
120
/**
121
* This packet is the last packet of a fragmented ipv4 packet.
122
*/
123
void
SetLastFragment
();
124
/**
125
* Don't fragment this packet: if you need to anyway, drop it.
126
*/
127
void
SetDontFragment
();
128
/**
129
* If you need to fragment this packet, you can do it.
130
*/
131
void
SetMayFragment
();
132
/**
133
* The offset is measured in bytes for the packet start.
134
* Mind that IPv4 "fragment offset" field is 13 bits long and is measured in 8-bytes words.
135
* Hence, the function does enforce that the offset is a multiple of 8.
136
* @param offsetBytes the ipv4 fragment offset measured in bytes from the start.
137
*/
138
void
SetFragmentOffset
(uint16_t offsetBytes);
139
/**
140
* @param ttl the ipv4 TTL
141
*/
142
void
SetTtl
(uint8_t ttl);
143
/**
144
* @param num the ipv4 protocol field
145
*/
146
void
SetProtocol
(uint8_t num);
147
/**
148
* @param source the source of this packet
149
*/
150
void
SetSource
(
Ipv4Address
source);
151
/**
152
* @param destination the destination of this packet.
153
*/
154
void
SetDestination
(
Ipv4Address
destination);
155
/**
156
* @returns the size of the payload in bytes
157
*/
158
uint16_t
GetPayloadSize
()
const
;
159
/**
160
* @returns the identification field of this packet.
161
*/
162
uint16_t
GetIdentification
()
const
;
163
/**
164
* @returns the TOS field of this packet.
165
*/
166
uint8_t
GetTos
()
const
;
167
/**
168
* @returns the DSCP field of this packet.
169
*/
170
DscpType
GetDscp
()
const
;
171
/**
172
* @param dscp the dscp
173
* @returns std::string of DSCPType
174
*/
175
std::string
DscpTypeToString
(
DscpType
dscp)
const
;
176
/**
177
* @returns the ECN field of this packet.
178
*/
179
EcnType
GetEcn
()
const
;
180
/**
181
* @param ecn the ECNType
182
* @returns std::string of ECNType
183
*/
184
std::string
EcnTypeToString
(
EcnType
ecn)
const
;
185
/**
186
* @returns true if this is the last fragment of a packet, false otherwise.
187
*/
188
bool
IsLastFragment
()
const
;
189
/**
190
* @returns true if this is this packet can be fragmented.
191
*/
192
bool
IsDontFragment
()
const
;
193
/**
194
* @returns the offset of this fragment measured in bytes from the start.
195
*/
196
uint16_t
GetFragmentOffset
()
const
;
197
/**
198
* @returns the TTL field of this packet
199
*/
200
uint8_t
GetTtl
()
const
;
201
/**
202
* @returns the protocol field of this packet
203
*/
204
uint8_t
GetProtocol
()
const
;
205
/**
206
* @returns the source address of this packet
207
*/
208
Ipv4Address
GetSource
()
const
;
209
/**
210
* @returns the destination address of this packet
211
*/
212
Ipv4Address
GetDestination
()
const
;
213
214
/**
215
* @returns true if the ipv4 checksum is correct, false otherwise.
216
*
217
* If Ipv4Header::EnableChecksums has not been called prior to
218
* deserializing this header, this method will always return true.
219
*/
220
bool
IsChecksumOk
()
const
;
221
222
/**
223
* @brief Get the type ID.
224
* @return the object TypeId
225
*/
226
static
TypeId
GetTypeId
();
227
TypeId
GetInstanceTypeId
()
const override
;
228
void
Print
(std::ostream& os)
const override
;
229
uint32_t
GetSerializedSize
()
const override
;
230
void
Serialize
(
Buffer::Iterator
start)
const override
;
231
uint32_t
Deserialize
(
Buffer::Iterator
start)
override
;
232
233
private
:
234
/// flags related to IP fragmentation
235
enum
FlagsE
236
{
237
DONT_FRAGMENT
= (1 << 0),
238
MORE_FRAGMENTS
= (1 << 1)
239
};
240
241
bool
m_calcChecksum
;
//!< true if the checksum must be calculated
242
243
uint16_t
m_payloadSize
;
//!< payload size
244
uint16_t
m_identification
;
//!< identification
245
uint32_t
m_tos
: 8;
//!< TOS, also used as DSCP + ECN value
246
uint32_t
m_ttl
: 8;
//!< TTL
247
uint32_t
m_protocol
: 8;
//!< Protocol
248
uint32_t
m_flags
: 3;
//!< flags
249
uint16_t
m_fragmentOffset
;
//!< Fragment offset
250
Ipv4Address
m_source
;
//!< source address
251
Ipv4Address
m_destination
;
//!< destination address
252
uint16_t
m_checksum
;
//!< checksum
253
bool
m_goodChecksum
;
//!< true if checksum is correct
254
uint16_t
m_headerSize
;
//!< IP header size
255
};
256
257
}
// namespace ns3
258
259
#endif
/* IPV4_HEADER_H */
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::Header
Protocol header serialization and deserialization.
Definition
header.h:33
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::Ipv4Header
Packet header for IPv4.
Definition
ipv4-header.h:23
ns3::Ipv4Header::m_source
Ipv4Address m_source
source address
Definition
ipv4-header.h:250
ns3::Ipv4Header::IsChecksumOk
bool IsChecksumOk() const
Definition
ipv4-header.cc:312
ns3::Ipv4Header::Print
void Print(std::ostream &os) const override
Definition
ipv4-header.cc:336
ns3::Ipv4Header::SetDestination
void SetDestination(Ipv4Address destination)
Definition
ipv4-header.cc:298
ns3::Ipv4Header::GetSource
Ipv4Address GetSource() const
Definition
ipv4-header.cc:291
ns3::Ipv4Header::m_fragmentOffset
uint16_t m_fragmentOffset
Fragment offset.
Definition
ipv4-header.h:249
ns3::Ipv4Header::SetDontFragment
void SetDontFragment()
Don't fragment this packet: if you need to anyway, drop it.
Definition
ipv4-header.cc:213
ns3::Ipv4Header::EcnTypeToString
std::string EcnTypeToString(EcnType ecn) const
Definition
ipv4-header.cc:166
ns3::Ipv4Header::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition
ipv4-header.cc:329
ns3::Ipv4Header::FlagsE
FlagsE
flags related to IP fragmentation
Definition
ipv4-header.h:236
ns3::Ipv4Header::MORE_FRAGMENTS
@ MORE_FRAGMENTS
Definition
ipv4-header.h:238
ns3::Ipv4Header::DONT_FRAGMENT
@ DONT_FRAGMENT
Definition
ipv4-header.h:237
ns3::Ipv4Header::GetTos
uint8_t GetTos() const
Definition
ipv4-header.cc:185
ns3::Ipv4Header::SetLastFragment
void SetLastFragment()
This packet is the last packet of a fragmented ipv4 packet.
Definition
ipv4-header.cc:199
ns3::Ipv4Header::m_ttl
uint32_t m_ttl
TTL.
Definition
ipv4-header.h:246
ns3::Ipv4Header::m_protocol
uint32_t m_protocol
Protocol.
Definition
ipv4-header.h:247
ns3::Ipv4Header::SetPayloadSize
void SetPayloadSize(uint16_t size)
Definition
ipv4-header.cc:46
ns3::Ipv4Header::GetEcn
EcnType GetEcn() const
Definition
ipv4-header.cc:158
ns3::Ipv4Header::m_identification
uint16_t m_identification
identification
Definition
ipv4-header.h:244
ns3::Ipv4Header::GetIdentification
uint16_t GetIdentification() const
Definition
ipv4-header.cc:60
ns3::Ipv4Header::IsDontFragment
bool IsDontFragment() const
Definition
ipv4-header.cc:227
ns3::Ipv4Header::GetProtocol
uint8_t GetProtocol() const
Definition
ipv4-header.cc:270
ns3::Ipv4Header::m_payloadSize
uint16_t m_payloadSize
payload size
Definition
ipv4-header.h:243
ns3::Ipv4Header::SetTtl
void SetTtl(uint8_t ttl)
Definition
ipv4-header.cc:256
ns3::Ipv4Header::IsLastFragment
bool IsLastFragment() const
Definition
ipv4-header.cc:206
ns3::Ipv4Header::m_tos
uint32_t m_tos
TOS, also used as DSCP + ECN value.
Definition
ipv4-header.h:245
ns3::Ipv4Header::m_goodChecksum
bool m_goodChecksum
true if checksum is correct
Definition
ipv4-header.h:253
ns3::Ipv4Header::SetMoreFragments
void SetMoreFragments()
This packet is not the last packet of a fragmented ipv4 packet.
Definition
ipv4-header.cc:192
ns3::Ipv4Header::GetDestination
Ipv4Address GetDestination() const
Definition
ipv4-header.cc:305
ns3::Ipv4Header::Serialize
void Serialize(Buffer::Iterator start) const override
Definition
ipv4-header.cc:381
ns3::Ipv4Header::SetDscp
void SetDscp(DscpType dscp)
Set DSCP Field.
Definition
ipv4-header.cc:81
ns3::Ipv4Header::m_destination
Ipv4Address m_destination
destination address
Definition
ipv4-header.h:251
ns3::Ipv4Header::SetMayFragment
void SetMayFragment()
If you need to fragment this packet, you can do it.
Definition
ipv4-header.cc:220
ns3::Ipv4Header::EcnType
EcnType
ECN Type defined in RFC 3168
Definition
ipv4-header.h:103
ns3::Ipv4Header::ECN_ECT0
@ ECN_ECT0
Definition
ipv4-header.h:107
ns3::Ipv4Header::ECN_NotECT
@ ECN_NotECT
Definition
ipv4-header.h:105
ns3::Ipv4Header::ECN_ECT1
@ ECN_ECT1
Definition
ipv4-header.h:106
ns3::Ipv4Header::ECN_CE
@ ECN_CE
Definition
ipv4-header.h:108
ns3::Ipv4Header::m_checksum
uint16_t m_checksum
checksum
Definition
ipv4-header.h:252
ns3::Ipv4Header::m_headerSize
uint16_t m_headerSize
IP header size.
Definition
ipv4-header.h:254
ns3::Ipv4Header::GetDscp
DscpType GetDscp() const
Definition
ipv4-header.cc:97
ns3::Ipv4Header::GetPayloadSize
uint16_t GetPayloadSize() const
Definition
ipv4-header.cc:53
ns3::Ipv4Header::SetEcn
void SetEcn(EcnType ecn)
Set ECN Field.
Definition
ipv4-header.cc:89
ns3::Ipv4Header::DscpType
DscpType
DiffServ codepoints.
Definition
ipv4-header.h:61
ns3::Ipv4Header::DSCP_AF23
@ DSCP_AF23
Definition
ipv4-header.h:73
ns3::Ipv4Header::DSCP_CS2
@ DSCP_CS2
Definition
ipv4-header.h:70
ns3::Ipv4Header::DscpDefault
@ DscpDefault
Definition
ipv4-header.h:62
ns3::Ipv4Header::DSCP_AF31
@ DSCP_AF31
Definition
ipv4-header.h:76
ns3::Ipv4Header::DSCP_AF32
@ DSCP_AF32
Definition
ipv4-header.h:77
ns3::Ipv4Header::DSCP_AF13
@ DSCP_AF13
Definition
ipv4-header.h:68
ns3::Ipv4Header::DSCP_AF22
@ DSCP_AF22
Definition
ipv4-header.h:72
ns3::Ipv4Header::DSCP_AF43
@ DSCP_AF43
Definition
ipv4-header.h:83
ns3::Ipv4Header::DSCP_AF11
@ DSCP_AF11
Definition
ipv4-header.h:66
ns3::Ipv4Header::DSCP_CS3
@ DSCP_CS3
Definition
ipv4-header.h:75
ns3::Ipv4Header::DSCP_AF42
@ DSCP_AF42
Definition
ipv4-header.h:82
ns3::Ipv4Header::DSCP_AF21
@ DSCP_AF21
Definition
ipv4-header.h:71
ns3::Ipv4Header::DSCP_AF33
@ DSCP_AF33
Definition
ipv4-header.h:78
ns3::Ipv4Header::DSCP_AF12
@ DSCP_AF12
Definition
ipv4-header.h:67
ns3::Ipv4Header::DSCP_CS5
@ DSCP_CS5
Definition
ipv4-header.h:85
ns3::Ipv4Header::DSCP_EF
@ DSCP_EF
Definition
ipv4-header.h:86
ns3::Ipv4Header::DSCP_CS4
@ DSCP_CS4
Definition
ipv4-header.h:80
ns3::Ipv4Header::DSCP_CS7
@ DSCP_CS7
Definition
ipv4-header.h:89
ns3::Ipv4Header::DSCP_CS6
@ DSCP_CS6
Definition
ipv4-header.h:88
ns3::Ipv4Header::DSCP_CS1
@ DSCP_CS1
Definition
ipv4-header.h:65
ns3::Ipv4Header::DSCP_AF41
@ DSCP_AF41
Definition
ipv4-header.h:81
ns3::Ipv4Header::DscpTypeToString
std::string DscpTypeToString(DscpType dscp) const
Definition
ipv4-header.cc:105
ns3::Ipv4Header::m_flags
uint32_t m_flags
flags
Definition
ipv4-header.h:248
ns3::Ipv4Header::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition
ipv4-header.cc:373
ns3::Ipv4Header::GetFragmentOffset
uint16_t GetFragmentOffset() const
Definition
ipv4-header.cc:243
ns3::Ipv4Header::SetProtocol
void SetProtocol(uint8_t num)
Definition
ipv4-header.cc:277
ns3::Ipv4Header::SetFragmentOffset
void SetFragmentOffset(uint16_t offsetBytes)
The offset is measured in bytes for the packet start.
Definition
ipv4-header.cc:234
ns3::Ipv4Header::SetIdentification
void SetIdentification(uint16_t identification)
Definition
ipv4-header.cc:67
ns3::Ipv4Header::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
ipv4-header.cc:319
ns3::Ipv4Header::GetTtl
uint8_t GetTtl() const
Definition
ipv4-header.cc:263
ns3::Ipv4Header::EnableChecksum
void EnableChecksum()
Enable checksum calculation for this header.
Definition
ipv4-header.cc:39
ns3::Ipv4Header::SetTos
void SetTos(uint8_t tos)
Definition
ipv4-header.cc:74
ns3::Ipv4Header::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Definition
ipv4-header.cc:422
ns3::Ipv4Header::SetSource
void SetSource(Ipv4Address source)
Definition
ipv4-header.cc:284
ns3::Ipv4Header::Ipv4Header
Ipv4Header()
Construct a null IPv4 header.
Definition
ipv4-header.cc:23
ns3::Ipv4Header::m_calcChecksum
bool m_calcChecksum
true if the checksum must be calculated
Definition
ipv4-header.h:241
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
uint32_t
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
internet
model
ipv4-header.h
Generated on Sun Dec 1 2024 18:20:38 for ns-3 by
1.11.0