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.cc
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: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
7
*/
8
9
#include "
ethernet-header.h
"
10
11
#include "
address-utils.h
"
12
13
#include "ns3/assert.h"
14
#include "ns3/header.h"
15
#include "ns3/log.h"
16
17
#include <iomanip>
18
#include <iostream>
19
20
namespace
ns3
21
{
22
23
NS_LOG_COMPONENT_DEFINE
(
"EthernetHeader"
);
24
25
NS_OBJECT_ENSURE_REGISTERED
(EthernetHeader);
26
27
EthernetHeader::EthernetHeader
(
bool
hasPreamble)
28
: m_enPreambleSfd(hasPreamble),
29
m_lengthType(0)
30
{
31
NS_LOG_FUNCTION
(
this
<< hasPreamble);
32
}
33
34
EthernetHeader::EthernetHeader
()
35
: m_enPreambleSfd(false),
36
m_lengthType(0)
37
{
38
NS_LOG_FUNCTION
(
this
);
39
}
40
41
void
42
EthernetHeader::SetLengthType
(uint16_t lengthType)
43
{
44
NS_LOG_FUNCTION
(
this
<< lengthType);
45
m_lengthType
= lengthType;
46
}
47
48
uint16_t
49
EthernetHeader::GetLengthType
()
const
50
{
51
NS_LOG_FUNCTION
(
this
);
52
return
m_lengthType
;
53
}
54
55
void
56
EthernetHeader::SetPreambleSfd
(uint64_t preambleSfd)
57
{
58
NS_LOG_FUNCTION
(
this
<< preambleSfd);
59
m_preambleSfd
= preambleSfd;
60
}
61
62
uint64_t
63
EthernetHeader::GetPreambleSfd
()
const
64
{
65
NS_LOG_FUNCTION
(
this
);
66
return
m_preambleSfd
;
67
}
68
69
void
70
EthernetHeader::SetSource
(
Mac48Address
source)
71
{
72
NS_LOG_FUNCTION
(
this
<< source);
73
m_source
= source;
74
}
75
76
Mac48Address
77
EthernetHeader::GetSource
()
const
78
{
79
NS_LOG_FUNCTION
(
this
);
80
return
m_source
;
81
}
82
83
void
84
EthernetHeader::SetDestination
(
Mac48Address
dst)
85
{
86
NS_LOG_FUNCTION
(
this
<< dst);
87
m_destination
= dst;
88
}
89
90
Mac48Address
91
EthernetHeader::GetDestination
()
const
92
{
93
NS_LOG_FUNCTION
(
this
);
94
return
m_destination
;
95
}
96
97
ethernet_header_t
98
EthernetHeader::GetPacketType
()
const
99
{
100
NS_LOG_FUNCTION
(
this
);
101
return
LENGTH
;
102
}
103
104
uint32_t
105
EthernetHeader::GetHeaderSize
()
const
106
{
107
NS_LOG_FUNCTION
(
this
);
108
return
GetSerializedSize
();
109
}
110
111
TypeId
112
EthernetHeader::GetTypeId
()
113
{
114
static
TypeId
tid =
TypeId
(
"ns3::EthernetHeader"
)
115
.
SetParent
<
Header
>()
116
.SetGroupName(
"Network"
)
117
.AddConstructor<
EthernetHeader
>();
118
return
tid;
119
}
120
121
TypeId
122
EthernetHeader::GetInstanceTypeId
()
const
123
{
124
return
GetTypeId
();
125
}
126
127
void
128
EthernetHeader::Print
(std::ostream& os)
const
129
{
130
NS_LOG_FUNCTION
(
this
<< &os);
131
// ethernet, right ?
132
if
(
m_enPreambleSfd
)
133
{
134
os <<
"preamble/sfd="
<<
m_preambleSfd
<<
","
;
135
}
136
137
os <<
" length/type=0x"
<< std::hex <<
m_lengthType
<< std::dec <<
", source="
<<
m_source
138
<<
", destination="
<<
m_destination
;
139
}
140
141
uint32_t
142
EthernetHeader::GetSerializedSize
()
const
143
{
144
NS_LOG_FUNCTION
(
this
);
145
if
(
m_enPreambleSfd
)
146
{
147
return
PREAMBLE_SIZE
+
LENGTH_SIZE
+ 2 *
MAC_ADDR_SIZE
;
148
}
149
else
150
{
151
return
LENGTH_SIZE
+ 2 *
MAC_ADDR_SIZE
;
152
}
153
}
154
155
void
156
EthernetHeader::Serialize
(
Buffer::Iterator
start)
const
157
{
158
NS_LOG_FUNCTION
(
this
<< &start);
159
Buffer::Iterator
i = start;
160
161
if
(
m_enPreambleSfd
)
162
{
163
i.
WriteU64
(
m_preambleSfd
);
164
}
165
WriteTo
(i,
m_destination
);
166
WriteTo
(i,
m_source
);
167
i.
WriteHtonU16
(
m_lengthType
);
168
}
169
170
uint32_t
171
EthernetHeader::Deserialize
(
Buffer::Iterator
start)
172
{
173
NS_LOG_FUNCTION
(
this
<< &start);
174
Buffer::Iterator
i = start;
175
176
if
(
m_enPreambleSfd
)
177
{
178
m_enPreambleSfd
= i.
ReadU64
();
179
}
180
181
ReadFrom
(i,
m_destination
);
182
ReadFrom
(i,
m_source
);
183
m_lengthType
= i.
ReadNtohU16
();
184
185
return
GetSerializedSize
();
186
}
187
188
}
// namespace ns3
address-utils.h
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::Buffer::Iterator::WriteU64
void WriteU64(uint64_t data)
Definition
buffer.cc:870
ns3::Buffer::Iterator::ReadU64
uint64_t ReadU64()
Definition
buffer.cc:973
ns3::Buffer::Iterator::WriteHtonU16
void WriteHtonU16(uint16_t data)
Definition
buffer.h:904
ns3::Buffer::Iterator::ReadNtohU16
uint16_t ReadNtohU16()
Definition
buffer.h:943
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
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
uint32_t
ethernet-header.h
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
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
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition
object-base.h:35
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WriteTo
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
Definition
address-utils.cc:21
ns3::ReadFrom
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
Definition
address-utils.cc:74
src
network
utils
ethernet-header.cc
Generated on Fri Nov 8 2024 13:59:05 for ns-3 by
1.11.0