A Discrete-Event Network Simulator
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
30namespace ns3
31{
40class UdpHeader : public Header
41{
42 public:
48 UdpHeader();
49 ~UdpHeader() override;
50
54 void EnableChecksums();
58 void SetDestinationPort(uint16_t port);
62 void SetSourcePort(uint16_t port);
66 uint16_t GetSourcePort() const;
70 uint16_t GetDestinationPort() const;
71
83 void InitializeChecksum(Address source, Address destination, uint8_t protocol);
84
96 void InitializeChecksum(Ipv4Address source, Ipv4Address destination, uint8_t protocol);
97
109 void InitializeChecksum(Ipv6Address source, Ipv6Address destination, uint8_t protocol);
110
115 static TypeId GetTypeId();
116 TypeId GetInstanceTypeId() const override;
117 void Print(std::ostream& os) const override;
118 uint32_t GetSerializedSize() const override;
119 void Serialize(Buffer::Iterator start) const override;
120 uint32_t Deserialize(Buffer::Iterator start) override;
121
126 bool IsChecksumOk() const;
127
145 void ForceChecksum(uint16_t checksum);
146
155 void ForcePayloadSize(uint16_t payloadSize);
156
161 uint16_t GetChecksum() const;
162
163 private:
169 uint16_t CalculateHeaderChecksum(uint16_t size) const;
170 uint16_t m_sourcePort;
172 uint16_t m_payloadSize;
173
176 uint8_t m_protocol;
177 uint16_t m_checksum;
180};
181
182} // namespace ns3
183
184#endif /* UDP_HEADER */
a polymophic address class
Definition: address.h:100
iterator in a Buffer instance
Definition: buffer.h:100
Protocol header serialization and deserialization.
Definition: header.h:44
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
a unique identifier for an interface.
Definition: type-id.h:59
Packet header for UDP packets.
Definition: udp-header.h:41
uint32_t GetSerializedSize() const override
Definition: udp-header.cc:180
void Serialize(Buffer::Iterator start) const override
Definition: udp-header.cc:186
~UdpHeader() override
Definition: udp-header.cc:43
Address m_destination
Destination IP address.
Definition: udp-header.h:175
uint16_t CalculateHeaderChecksum(uint16_t size) const
Calculate the header checksum.
Definition: udp-header.cc:105
void EnableChecksums()
Enable checksum calculation for UDP.
Definition: udp-header.cc:51
uint8_t m_protocol
Protocol number.
Definition: udp-header.h:176
UdpHeader()
Constructor.
Definition: udp-header.cc:33
uint16_t m_destinationPort
Destination port.
Definition: udp-header.h:171
uint16_t GetDestinationPort() const
Definition: udp-header.cc:75
Address m_source
Source IP address.
Definition: udp-header.h:174
uint16_t m_payloadSize
Payload size.
Definition: udp-header.h:172
void ForceChecksum(uint16_t checksum)
Force the UDP checksum to a given value.
Definition: udp-header.cc:145
uint16_t m_sourcePort
Source port.
Definition: udp-header.h:170
uint16_t GetSourcePort() const
Definition: udp-header.cc:69
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: udp-header.cc:167
bool m_calcChecksum
Flag to calculate checksum.
Definition: udp-header.h:178
void Print(std::ostream &os) const override
Definition: udp-header.cc:173
void ForcePayloadSize(uint16_t payloadSize)
Force the UDP payload length to a given value.
Definition: udp-header.cc:151
bool IsChecksumOk() const
Is the UDP checksum correct ?
Definition: udp-header.cc:139
uint32_t Deserialize(Buffer::Iterator start) override
Definition: udp-header.cc:223
uint16_t GetChecksum() const
Return the checksum (only known after a Deserialize)
Definition: udp-header.cc:244
uint16_t m_checksum
Forced Checksum value.
Definition: udp-header.h:177
void InitializeChecksum(Address source, Address destination, uint8_t protocol)
Definition: udp-header.cc:81
static TypeId GetTypeId()
Get the type ID.
Definition: udp-header.cc:157
void SetSourcePort(uint16_t port)
Definition: udp-header.cc:63
bool m_goodChecksum
Flag to indicate that checksum is correct.
Definition: udp-header.h:179
void SetDestinationPort(uint16_t port)
Definition: udp-header.cc:57
uint16_t port
Definition: dsdv-manet.cc:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.