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
udp-header.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2005 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
*/
19
20
#ifndef UDP_HEADER_H
21
#define UDP_HEADER_H
22
23
#include "ns3/header.h"
24
#include "ns3/ipv4-address.h"
25
#include "ns3/ipv6-address.h"
26
27
#include <stdint.h>
28
#include <string>
29
30
namespace
ns3
31
{
32
/**
33
* \ingroup udp
34
* \brief Packet header for UDP packets
35
*
36
* This class has fields corresponding to those in a network UDP header
37
* (port numbers, payload size, checksum) as well as methods for serialization
38
* to and deserialization from a byte buffer.
39
*/
40
class
UdpHeader
:
public
Header
41
{
42
public
:
43
/**
44
* \brief Enable checksum calculation for UDP
45
*/
46
void
EnableChecksums
();
47
/**
48
* \param port the destination port for this UdpHeader
49
*/
50
void
SetDestinationPort
(uint16_t
port
);
51
/**
52
* \param port The source port for this UdpHeader
53
*/
54
void
SetSourcePort
(uint16_t
port
);
55
/**
56
* \return The source port for this UdpHeader
57
*/
58
uint16_t
GetSourcePort
()
const
;
59
/**
60
* \return the destination port for this UdpHeader
61
*/
62
uint16_t
GetDestinationPort
()
const
;
63
64
/**
65
* \param source the ip source to use in the underlying
66
* ip packet.
67
* \param destination the ip destination to use in the
68
* underlying ip packet.
69
* \param protocol the protocol number to use in the underlying
70
* ip packet.
71
*
72
* If you want to use udp checksums, you should call this
73
* method prior to adding the header to a packet.
74
*/
75
void
InitializeChecksum
(
Address
source,
Address
destination, uint8_t protocol);
76
77
/**
78
* \param source the ip source to use in the underlying
79
* ip packet.
80
* \param destination the ip destination to use in the
81
* underlying ip packet.
82
* \param protocol the protocol number to use in the underlying
83
* ip packet.
84
*
85
* If you want to use udp checksums, you should call this
86
* method prior to adding the header to a packet.
87
*/
88
void
InitializeChecksum
(
Ipv4Address
source,
Ipv4Address
destination, uint8_t protocol);
89
90
/**
91
* \param source the ip source to use in the underlying
92
* ip packet.
93
* \param destination the ip destination to use in the
94
* underlying ip packet.
95
* \param protocol the protocol number to use in the underlying
96
* ip packet.
97
*
98
* If you want to use udp checksums, you should call this
99
* method prior to adding the header to a packet.
100
*/
101
void
InitializeChecksum
(
Ipv6Address
source,
Ipv6Address
destination, uint8_t protocol);
102
103
/**
104
* \brief Get the type ID.
105
* \return the object TypeId
106
*/
107
static
TypeId
GetTypeId
();
108
TypeId
GetInstanceTypeId
()
const override
;
109
void
Print
(std::ostream& os)
const override
;
110
uint32_t
GetSerializedSize
()
const override
;
111
void
Serialize
(
Buffer::Iterator
start)
const override
;
112
uint32_t
Deserialize
(
Buffer::Iterator
start)
override
;
113
114
/**
115
* \brief Is the UDP checksum correct ?
116
* \returns true if the checksum is correct, false otherwise.
117
*/
118
bool
IsChecksumOk
()
const
;
119
120
/**
121
* \brief Force the UDP checksum to a given value.
122
*
123
* This might be useful for test purposes or to
124
* restore the UDP checksum when the UDP header
125
* has been compressed (e.g., in 6LoWPAN).
126
* Note that, normally, the header checksum is
127
* calculated on the fly when the packet is
128
* serialized.
129
*
130
* When this option is used, the UDP checksum is written in
131
* the header, regardless of the global ChecksumEnabled option.
132
*
133
* \note The checksum value must be a big endian number.
134
*
135
* \param checksum the checksum to use (big endian).
136
*/
137
void
ForceChecksum
(uint16_t checksum);
138
139
/**
140
* \brief Force the UDP payload length to a given value.
141
*
142
* This might be useful when forging a packet for test
143
* purposes.
144
*
145
* \param payloadSize the payload length to use.
146
*/
147
void
ForcePayloadSize
(uint16_t payloadSize);
148
149
/**
150
* \brief Return the checksum (only known after a Deserialize)
151
* \return The checksum for this UdpHeader
152
*/
153
uint16_t
GetChecksum
()
const
;
154
155
private
:
156
/**
157
* \brief Calculate the header checksum
158
* \param size packet size
159
* \returns the checksum
160
*/
161
uint16_t
CalculateHeaderChecksum
(uint16_t size)
const
;
162
163
// The magic values below are used only for debugging.
164
// They can be used to easily detect memory corruption
165
// problems so you can see the patterns in memory.
166
uint16_t
m_sourcePort
{0xfffd};
//!< Source port
167
uint16_t
m_destinationPort
{0xfffd};
//!< Destination port
168
uint16_t
m_payloadSize
{0};
//!< Payload size
169
uint16_t
m_forcedPayloadSize
{0};
//!< Payload size (forced)
170
171
Address
m_source
;
//!< Source IP address
172
Address
m_destination
;
//!< Destination IP address
173
uint8_t
m_protocol
{17};
//!< Protocol number
174
uint16_t
m_checksum
{0};
//!< Forced Checksum value
175
bool
m_calcChecksum
{
false
};
//!< Flag to calculate checksum
176
bool
m_goodChecksum
{
true
};
//!< Flag to indicate that checksum is correct
177
};
178
179
}
// namespace ns3
180
181
#endif
/* UDP_HEADER */
ns3::Address
a polymophic address class
Definition:
address.h:101
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:100
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:44
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:42
ns3::Ipv6Address
Describes an IPv6 address.
Definition:
ipv6-address.h:49
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::UdpHeader
Packet header for UDP packets.
Definition:
udp-header.h:41
ns3::UdpHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition:
udp-header.cc:159
ns3::UdpHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition:
udp-header.cc:165
ns3::UdpHeader::m_destination
Address m_destination
Destination IP address.
Definition:
udp-header.h:172
ns3::UdpHeader::CalculateHeaderChecksum
uint16_t CalculateHeaderChecksum(uint16_t size) const
Calculate the header checksum.
Definition:
udp-header.cc:84
ns3::UdpHeader::EnableChecksums
void EnableChecksums()
Enable checksum calculation for UDP.
Definition:
udp-header.cc:30
ns3::UdpHeader::m_protocol
uint8_t m_protocol
Protocol number.
Definition:
udp-header.h:173
ns3::UdpHeader::m_destinationPort
uint16_t m_destinationPort
Destination port.
Definition:
udp-header.h:167
ns3::UdpHeader::GetDestinationPort
uint16_t GetDestinationPort() const
Definition:
udp-header.cc:54
ns3::UdpHeader::m_source
Address m_source
Source IP address.
Definition:
udp-header.h:171
ns3::UdpHeader::m_payloadSize
uint16_t m_payloadSize
Payload size.
Definition:
udp-header.h:168
ns3::UdpHeader::ForceChecksum
void ForceChecksum(uint16_t checksum)
Force the UDP checksum to a given value.
Definition:
udp-header.cc:124
ns3::UdpHeader::m_sourcePort
uint16_t m_sourcePort
Source port.
Definition:
udp-header.h:166
ns3::UdpHeader::GetSourcePort
uint16_t GetSourcePort() const
Definition:
udp-header.cc:48
ns3::UdpHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition:
udp-header.cc:146
ns3::UdpHeader::m_calcChecksum
bool m_calcChecksum
Flag to calculate checksum.
Definition:
udp-header.h:175
ns3::UdpHeader::Print
void Print(std::ostream &os) const override
Definition:
udp-header.cc:152
ns3::UdpHeader::ForcePayloadSize
void ForcePayloadSize(uint16_t payloadSize)
Force the UDP payload length to a given value.
Definition:
udp-header.cc:130
ns3::UdpHeader::IsChecksumOk
bool IsChecksumOk() const
Is the UDP checksum correct ?
Definition:
udp-header.cc:118
ns3::UdpHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Definition:
udp-header.cc:208
ns3::UdpHeader::m_forcedPayloadSize
uint16_t m_forcedPayloadSize
Payload size (forced)
Definition:
udp-header.h:169
ns3::UdpHeader::GetChecksum
uint16_t GetChecksum() const
Return the checksum (only known after a Deserialize)
Definition:
udp-header.cc:246
ns3::UdpHeader::m_checksum
uint16_t m_checksum
Forced Checksum value.
Definition:
udp-header.h:174
ns3::UdpHeader::InitializeChecksum
void InitializeChecksum(Address source, Address destination, uint8_t protocol)
Definition:
udp-header.cc:60
ns3::UdpHeader::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition:
udp-header.cc:136
ns3::UdpHeader::SetSourcePort
void SetSourcePort(uint16_t port)
Definition:
udp-header.cc:42
ns3::UdpHeader::m_goodChecksum
bool m_goodChecksum
Flag to indicate that checksum is correct.
Definition:
udp-header.h:176
ns3::UdpHeader::SetDestinationPort
void SetDestinationPort(uint16_t port)
Definition:
udp-header.cc:36
uint32_t
port
uint16_t port
Definition:
dsdv-manet.cc:44
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
internet
model
udp-header.h
Generated on Tue May 28 2024 23:36:21 for ns-3 by
1.9.6