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
ethernet-header.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2007 Emmanuelle Laprise
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
7
*/
8
9
#ifndef ETHERNET_HEADER_H
10
#define ETHERNET_HEADER_H
11
12
#include "
mac48-address.h
"
13
14
#include "ns3/header.h"
15
16
#include <string>
17
18
namespace
ns3
19
{
20
21
/**
22
* @ingroup network
23
*
24
* Types of ethernet packets. Indicates the type of the current
25
* header.
26
*/
27
enum
ethernet_header_t
28
{
29
LENGTH
,
/**< Basic ethernet packet, no tags, type/length field
30
indicates packet length or IP/ARP packet */
31
VLAN
,
/**< Single tagged packet. Header includes VLAN tag */
32
QINQ
/**< Double tagged packet. Header includes two VLAN tags */
33
};
34
35
/**
36
* @ingroup network
37
*
38
* @brief Packet header for Ethernet
39
*
40
* This class can be used to add a header to an ethernet packet that
41
* will specify the source and destination addresses and the length of
42
* the packet. Eventually the class will be improved to also support
43
* VLAN tags in packet headers.
44
*/
45
class
EthernetHeader
:
public
Header
46
{
47
public
:
48
/**
49
* @brief Construct a null ethernet header
50
* @param hasPreamble if true, insert and remove an ethernet preamble from the
51
* packet, if false, does not insert and remove it.
52
*/
53
EthernetHeader
(
bool
hasPreamble);
54
/**
55
* @brief Construct a null ethernet header
56
* By default, does not add or remove an ethernet preamble
57
*/
58
EthernetHeader
();
59
/**
60
* @param size The size of the payload in bytes
61
*/
62
void
SetLengthType
(uint16_t size);
63
/**
64
* @param source The source address of this packet
65
*/
66
void
SetSource
(
Mac48Address
source);
67
/**
68
* @param destination The destination address of this packet.
69
*/
70
void
SetDestination
(
Mac48Address
destination);
71
/**
72
* @param preambleSfd The value that the preambleSfd field should take
73
*/
74
void
SetPreambleSfd
(uint64_t preambleSfd);
75
/**
76
* @return The size of the payload in bytes
77
*/
78
uint16_t
GetLengthType
()
const
;
79
/**
80
* @return The type of packet (only basic Ethernet is currently supported)
81
*/
82
ethernet_header_t
GetPacketType
()
const
;
83
/**
84
* @return The source address of this packet
85
*/
86
Mac48Address
GetSource
()
const
;
87
/**
88
* @return The destination address of this packet
89
*/
90
Mac48Address
GetDestination
()
const
;
91
/**
92
* @return The value of the PreambleSfd field
93
*/
94
uint64_t
GetPreambleSfd
()
const
;
95
/**
96
* @return The size of the header
97
*/
98
uint32_t
GetHeaderSize
()
const
;
99
100
/**
101
* @brief Get the type ID.
102
* @return the object TypeId
103
*/
104
static
TypeId
GetTypeId
();
105
TypeId
GetInstanceTypeId
()
const override
;
106
void
Print
(std::ostream& os)
const override
;
107
uint32_t
GetSerializedSize
()
const override
;
108
void
Serialize
(
Buffer::Iterator
start)
const override
;
109
uint32_t
Deserialize
(
Buffer::Iterator
start)
override
;
110
111
private
:
112
static
const
int
PREAMBLE_SIZE
= 8;
//!< size of the preamble_sfd header field
113
static
const
int
LENGTH_SIZE
= 2;
//!< size of the length_type header field
114
static
const
int
MAC_ADDR_SIZE
= 6;
//!< size of src/dest addr header fields
115
116
/**
117
* If false, the preamble/sfd are not serialised/deserialised.
118
*/
119
bool
m_enPreambleSfd
;
120
uint64_t
m_preambleSfd
;
//!< Value of the Preamble/SFD fields
121
uint16_t
m_lengthType
;
//!< Length or type of the packet
122
Mac48Address
m_source
;
//!< Source address
123
Mac48Address
m_destination
;
//!< Destination address
124
};
125
126
}
// namespace ns3
127
128
#endif
/* ETHERNET_HEADER_H */
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::EthernetHeader
Packet header for Ethernet.
Definition
ethernet-header.h:46
ns3::EthernetHeader::GetLengthType
uint16_t GetLengthType() const
Definition
ethernet-header.cc:49
ns3::EthernetHeader::m_lengthType
uint16_t m_lengthType
Length or type of the packet.
Definition
ethernet-header.h:121
ns3::EthernetHeader::GetHeaderSize
uint32_t GetHeaderSize() const
Definition
ethernet-header.cc:105
ns3::EthernetHeader::m_enPreambleSfd
bool m_enPreambleSfd
If false, the preamble/sfd are not serialised/deserialised.
Definition
ethernet-header.h:119
ns3::EthernetHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition
ethernet-header.cc:142
ns3::EthernetHeader::m_destination
Mac48Address m_destination
Destination address.
Definition
ethernet-header.h:123
ns3::EthernetHeader::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
ethernet-header.cc:112
ns3::EthernetHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition
ethernet-header.cc:122
ns3::EthernetHeader::SetDestination
void SetDestination(Mac48Address destination)
Definition
ethernet-header.cc:84
ns3::EthernetHeader::PREAMBLE_SIZE
static const int PREAMBLE_SIZE
size of the preamble_sfd header field
Definition
ethernet-header.h:112
ns3::EthernetHeader::MAC_ADDR_SIZE
static const int MAC_ADDR_SIZE
size of src/dest addr header fields
Definition
ethernet-header.h:114
ns3::EthernetHeader::m_source
Mac48Address m_source
Source address.
Definition
ethernet-header.h:122
ns3::EthernetHeader::GetDestination
Mac48Address GetDestination() const
Definition
ethernet-header.cc:91
ns3::EthernetHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition
ethernet-header.cc:156
ns3::EthernetHeader::SetLengthType
void SetLengthType(uint16_t size)
Definition
ethernet-header.cc:42
ns3::EthernetHeader::SetSource
void SetSource(Mac48Address source)
Definition
ethernet-header.cc:70
ns3::EthernetHeader::EthernetHeader
EthernetHeader()
Construct a null ethernet header By default, does not add or remove an ethernet preamble.
Definition
ethernet-header.cc:34
ns3::EthernetHeader::GetPacketType
ethernet_header_t GetPacketType() const
Definition
ethernet-header.cc:98
ns3::EthernetHeader::Print
void Print(std::ostream &os) const override
Definition
ethernet-header.cc:128
ns3::EthernetHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Definition
ethernet-header.cc:171
ns3::EthernetHeader::m_preambleSfd
uint64_t m_preambleSfd
Value of the Preamble/SFD fields.
Definition
ethernet-header.h:120
ns3::EthernetHeader::SetPreambleSfd
void SetPreambleSfd(uint64_t preambleSfd)
Definition
ethernet-header.cc:56
ns3::EthernetHeader::GetSource
Mac48Address GetSource() const
Definition
ethernet-header.cc:77
ns3::EthernetHeader::LENGTH_SIZE
static const int LENGTH_SIZE
size of the length_type header field
Definition
ethernet-header.h:113
ns3::EthernetHeader::GetPreambleSfd
uint64_t GetPreambleSfd() const
Definition
ethernet-header.cc:63
ns3::Header
Protocol header serialization and deserialization.
Definition
header.h:33
ns3::Mac48Address
an EUI-48 address
Definition
mac48-address.h:35
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
uint32_t
ns3::ethernet_header_t
ethernet_header_t
Types of ethernet packets.
Definition
ethernet-header.h:28
ns3::LENGTH
@ LENGTH
Basic ethernet packet, no tags, type/length field indicates packet length or IP/ARP packet.
Definition
ethernet-header.h:29
ns3::VLAN
@ VLAN
Single tagged packet.
Definition
ethernet-header.h:31
ns3::QINQ
@ QINQ
Double tagged packet.
Definition
ethernet-header.h:32
mac48-address.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
network
utils
ethernet-header.h
Generated on Wed Dec 11 2024 18:20:48 for ns-3 by
1.11.0