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