A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
ethernet-header.cc
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: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
18
*/
19
20
#include "
ethernet-header.h
"
21
22
#include "
address-utils.h
"
23
24
#include "ns3/assert.h"
25
#include "ns3/header.h"
26
#include "ns3/log.h"
27
28
#include <iomanip>
29
#include <iostream>
30
31
namespace
ns3
32
{
33
34
NS_LOG_COMPONENT_DEFINE
(
"EthernetHeader"
);
35
36
NS_OBJECT_ENSURE_REGISTERED
(EthernetHeader);
37
38
EthernetHeader::EthernetHeader
(
bool
hasPreamble)
39
: m_enPreambleSfd(hasPreamble),
40
m_lengthType(0)
41
{
42
NS_LOG_FUNCTION
(
this
<< hasPreamble);
43
}
44
45
EthernetHeader::EthernetHeader
()
46
: m_enPreambleSfd(false),
47
m_lengthType(0)
48
{
49
NS_LOG_FUNCTION
(
this
);
50
}
51
52
void
53
EthernetHeader::SetLengthType
(uint16_t lengthType)
54
{
55
NS_LOG_FUNCTION
(
this
<< lengthType);
56
m_lengthType
= lengthType;
57
}
58
59
uint16_t
60
EthernetHeader::GetLengthType
()
const
61
{
62
NS_LOG_FUNCTION
(
this
);
63
return
m_lengthType
;
64
}
65
66
void
67
EthernetHeader::SetPreambleSfd
(uint64_t preambleSfd)
68
{
69
NS_LOG_FUNCTION
(
this
<< preambleSfd);
70
m_preambleSfd
= preambleSfd;
71
}
72
73
uint64_t
74
EthernetHeader::GetPreambleSfd
()
const
75
{
76
NS_LOG_FUNCTION
(
this
);
77
return
m_preambleSfd
;
78
}
79
80
void
81
EthernetHeader::SetSource
(
Mac48Address
source)
82
{
83
NS_LOG_FUNCTION
(
this
<< source);
84
m_source
= source;
85
}
86
87
Mac48Address
88
EthernetHeader::GetSource
()
const
89
{
90
NS_LOG_FUNCTION
(
this
);
91
return
m_source
;
92
}
93
94
void
95
EthernetHeader::SetDestination
(
Mac48Address
dst)
96
{
97
NS_LOG_FUNCTION
(
this
<< dst);
98
m_destination
= dst;
99
}
100
101
Mac48Address
102
EthernetHeader::GetDestination
()
const
103
{
104
NS_LOG_FUNCTION
(
this
);
105
return
m_destination
;
106
}
107
108
ethernet_header_t
109
EthernetHeader::GetPacketType
()
const
110
{
111
NS_LOG_FUNCTION
(
this
);
112
return
LENGTH
;
113
}
114
115
uint32_t
116
EthernetHeader::GetHeaderSize
()
const
117
{
118
NS_LOG_FUNCTION
(
this
);
119
return
GetSerializedSize
();
120
}
121
122
TypeId
123
EthernetHeader::GetTypeId
()
124
{
125
static
TypeId
tid =
TypeId
(
"ns3::EthernetHeader"
)
126
.
SetParent
<
Header
>()
127
.SetGroupName(
"Network"
)
128
.AddConstructor<
EthernetHeader
>();
129
return
tid;
130
}
131
132
TypeId
133
EthernetHeader::GetInstanceTypeId
()
const
134
{
135
return
GetTypeId
();
136
}
137
138
void
139
EthernetHeader::Print
(std::ostream& os)
const
140
{
141
NS_LOG_FUNCTION
(
this
<< &os);
142
// ethernet, right ?
143
if
(
m_enPreambleSfd
)
144
{
145
os <<
"preamble/sfd="
<<
m_preambleSfd
<<
","
;
146
}
147
148
os <<
" length/type=0x"
<< std::hex <<
m_lengthType
<< std::dec <<
", source="
<<
m_source
149
<<
", destination="
<<
m_destination
;
150
}
151
152
uint32_t
153
EthernetHeader::GetSerializedSize
()
const
154
{
155
NS_LOG_FUNCTION
(
this
);
156
if
(
m_enPreambleSfd
)
157
{
158
return
PREAMBLE_SIZE
+
LENGTH_SIZE
+ 2 *
MAC_ADDR_SIZE
;
159
}
160
else
161
{
162
return
LENGTH_SIZE
+ 2 *
MAC_ADDR_SIZE
;
163
}
164
}
165
166
void
167
EthernetHeader::Serialize
(
Buffer::Iterator
start
)
const
168
{
169
NS_LOG_FUNCTION
(
this
<< &
start
);
170
Buffer::Iterator
i =
start
;
171
172
if
(
m_enPreambleSfd
)
173
{
174
i.
WriteU64
(
m_preambleSfd
);
175
}
176
WriteTo
(i,
m_destination
);
177
WriteTo
(i,
m_source
);
178
i.
WriteHtonU16
(
m_lengthType
);
179
}
180
181
uint32_t
182
EthernetHeader::Deserialize
(
Buffer::Iterator
start
)
183
{
184
NS_LOG_FUNCTION
(
this
<< &
start
);
185
Buffer::Iterator
i =
start
;
186
187
if
(
m_enPreambleSfd
)
188
{
189
m_enPreambleSfd
= i.
ReadU64
();
190
}
191
192
ReadFrom
(i,
m_destination
);
193
ReadFrom
(i,
m_source
);
194
m_lengthType
= i.
ReadNtohU16
();
195
196
return
GetSerializedSize
();
197
}
198
199
}
// namespace ns3
address-utils.h
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:100
ns3::Buffer::Iterator::WriteU64
void WriteU64(uint64_t data)
Definition:
buffer.cc:881
ns3::Buffer::Iterator::ReadU64
uint64_t ReadU64()
Definition:
buffer.cc:984
ns3::Buffer::Iterator::WriteHtonU16
void WriteHtonU16(uint16_t data)
Definition:
buffer.h:915
ns3::Buffer::Iterator::ReadNtohU16
uint16_t ReadNtohU16()
Definition:
buffer.h:954
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::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::Header::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
ns3::Mac48Address
an EUI-48 address
Definition:
mac48-address.h:46
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:931
ethernet-header.h
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
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:240
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
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:46
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:31
ns3::ReadFrom
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
Definition:
address-utils.cc:84
two-ray-to-three-gpp-ch-calibration.start
start
Definition:
two-ray-to-three-gpp-ch-calibration.py:520
src
network
utils
ethernet-header.cc
Generated on Sun Mar 3 2024 17:11:06 for ns-3 by
1.9.1