A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
ethernet-header.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2005 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
19
*/
20
21
#include <iomanip>
22
#include <iostream>
23
#include "ns3/assert.h"
24
#include "ns3/log.h"
25
#include "ns3/header.h"
26
#include "
ethernet-header.h
"
27
#include "
address-utils.h
"
28
29
namespace
ns3
{
30
31
NS_LOG_COMPONENT_DEFINE
(
"EthernetHeader"
);
32
33
NS_OBJECT_ENSURE_REGISTERED
(EthernetHeader);
34
35
EthernetHeader::EthernetHeader
(
bool
hasPreamble)
36
: m_enPreambleSfd (hasPreamble),
37
m_lengthType (0)
38
{
39
NS_LOG_FUNCTION
(
this
<< hasPreamble);
40
}
41
42
EthernetHeader::EthernetHeader
()
43
: m_enPreambleSfd (false),
44
m_lengthType (0)
45
{
46
NS_LOG_FUNCTION
(
this
);
47
}
48
49
void
50
EthernetHeader::SetLengthType
(uint16_t lengthType)
51
{
52
NS_LOG_FUNCTION
(
this
<< lengthType);
53
m_lengthType
= lengthType;
54
}
55
uint16_t
56
EthernetHeader::GetLengthType
(
void
)
const
57
{
58
NS_LOG_FUNCTION
(
this
);
59
return
m_lengthType
;
60
}
61
62
void
63
EthernetHeader::SetPreambleSfd
(uint64_t preambleSfd)
64
{
65
NS_LOG_FUNCTION
(
this
<< preambleSfd);
66
m_preambleSfd
= preambleSfd;
67
}
68
uint64_t
69
EthernetHeader::GetPreambleSfd
(
void
)
const
70
{
71
NS_LOG_FUNCTION
(
this
);
72
return
m_preambleSfd
;
73
}
74
75
void
76
EthernetHeader::SetSource
(
Mac48Address
source)
77
{
78
NS_LOG_FUNCTION
(
this
<< source);
79
m_source
= source;
80
}
81
Mac48Address
82
EthernetHeader::GetSource
(
void
)
const
83
{
84
NS_LOG_FUNCTION
(
this
);
85
return
m_source
;
86
}
87
88
void
89
EthernetHeader::SetDestination
(
Mac48Address
dst)
90
{
91
NS_LOG_FUNCTION
(
this
<< dst);
92
m_destination
= dst;
93
}
94
Mac48Address
95
EthernetHeader::GetDestination
(
void
)
const
96
{
97
NS_LOG_FUNCTION
(
this
);
98
return
m_destination
;
99
}
100
101
ethernet_header_t
102
EthernetHeader::GetPacketType
(
void
)
const
103
{
104
NS_LOG_FUNCTION
(
this
);
105
return
LENGTH
;
106
}
107
108
uint32_t
109
EthernetHeader::GetHeaderSize
(
void
)
const
110
{
111
NS_LOG_FUNCTION
(
this
);
112
return
GetSerializedSize
();
113
}
114
115
116
TypeId
117
EthernetHeader::GetTypeId
(
void
)
118
{
119
static
TypeId
tid =
TypeId
(
"ns3::EthernetHeader"
)
120
.
SetParent
<
Header
> ()
121
.SetGroupName(
"Network"
)
122
.AddConstructor<
EthernetHeader
> ()
123
;
124
return
tid;
125
}
126
TypeId
127
EthernetHeader::GetInstanceTypeId
(
void
)
const
128
{
129
return
GetTypeId
();
130
}
131
void
132
EthernetHeader::Print
(std::ostream &os)
const
133
{
134
NS_LOG_FUNCTION
(
this
<< &os);
135
// ethernet, right ?
136
if
(
m_enPreambleSfd
)
137
{
138
os <<
"preamble/sfd="
<<
m_preambleSfd
<<
","
;
139
}
140
141
os <<
" length/type=0x"
<< std::hex <<
m_lengthType
<< std::dec
142
<<
", source="
<<
m_source
143
<<
", destination="
<<
m_destination
;
144
}
145
uint32_t
146
EthernetHeader::GetSerializedSize
(
void
)
const
147
{
148
NS_LOG_FUNCTION
(
this
);
149
if
(
m_enPreambleSfd
)
150
{
151
return
PREAMBLE_SIZE
+
LENGTH_SIZE
+ 2*
MAC_ADDR_SIZE
;
152
}
153
else
154
{
155
return
LENGTH_SIZE
+ 2*
MAC_ADDR_SIZE
;
156
}
157
}
158
159
void
160
EthernetHeader::Serialize
(
Buffer::Iterator
start
)
const
161
{
162
NS_LOG_FUNCTION
(
this
<< &
start
);
163
Buffer::Iterator
i =
start
;
164
165
if
(
m_enPreambleSfd
)
166
{
167
i.
WriteU64
(
m_preambleSfd
);
168
}
169
WriteTo
(i,
m_destination
);
170
WriteTo
(i,
m_source
);
171
i.
WriteHtonU16
(
m_lengthType
);
172
}
173
uint32_t
174
EthernetHeader::Deserialize
(
Buffer::Iterator
start
)
175
{
176
NS_LOG_FUNCTION
(
this
<< &
start
);
177
Buffer::Iterator
i =
start
;
178
179
if
(
m_enPreambleSfd
)
180
{
181
m_enPreambleSfd
= i.
ReadU64
();
182
}
183
184
ReadFrom
(i,
m_destination
);
185
ReadFrom
(i,
m_source
);
186
m_lengthType
= i.
ReadNtohU16
();
187
188
return
GetSerializedSize
();
189
}
190
191
}
// namespace ns3
address-utils.h
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:99
ns3::Buffer::Iterator::WriteU64
void WriteU64(uint64_t data)
Definition:
buffer.cc:891
ns3::Buffer::Iterator::ReadNtohU16
uint16_t ReadNtohU16(void)
Definition:
buffer.h:946
ns3::Buffer::Iterator::WriteHtonU16
void WriteHtonU16(uint16_t data)
Definition:
buffer.h:905
ns3::Buffer::Iterator::ReadU64
uint64_t ReadU64(void)
Definition:
buffer.cc:990
ns3::EthernetHeader
Packet header for Ethernet.
Definition:
ethernet-header.h:53
ns3::EthernetHeader::m_lengthType
uint16_t m_lengthType
Length or type of the packet.
Definition:
ethernet-header.h:128
ns3::EthernetHeader::GetHeaderSize
uint32_t GetHeaderSize() const
Definition:
ethernet-header.cc:109
ns3::EthernetHeader::m_enPreambleSfd
bool m_enPreambleSfd
If false, the preamble/sfd are not serialised/deserialised.
Definition:
ethernet-header.h:126
ns3::EthernetHeader::m_destination
Mac48Address m_destination
Destination address.
Definition:
ethernet-header.h:130
ns3::EthernetHeader::SetDestination
void SetDestination(Mac48Address destination)
Definition:
ethernet-header.cc:89
ns3::EthernetHeader::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition:
ethernet-header.cc:117
ns3::EthernetHeader::PREAMBLE_SIZE
static const int PREAMBLE_SIZE
size of the preamble_sfd header field
Definition:
ethernet-header.h:119
ns3::EthernetHeader::MAC_ADDR_SIZE
static const int MAC_ADDR_SIZE
size of src/dest addr header fields
Definition:
ethernet-header.h:121
ns3::EthernetHeader::m_source
Mac48Address m_source
Source address.
Definition:
ethernet-header.h:129
ns3::EthernetHeader::Print
virtual void Print(std::ostream &os) const
Definition:
ethernet-header.cc:132
ns3::EthernetHeader::SetLengthType
void SetLengthType(uint16_t size)
Definition:
ethernet-header.cc:50
ns3::EthernetHeader::SetSource
void SetSource(Mac48Address source)
Definition:
ethernet-header.cc:76
ns3::EthernetHeader::EthernetHeader
EthernetHeader()
Construct a null ethernet header By default, does not add or remove an ethernet preamble.
Definition:
ethernet-header.cc:42
ns3::EthernetHeader::GetDestination
Mac48Address GetDestination(void) const
Definition:
ethernet-header.cc:95
ns3::EthernetHeader::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Definition:
ethernet-header.cc:146
ns3::EthernetHeader::GetSource
Mac48Address GetSource(void) const
Definition:
ethernet-header.cc:82
ns3::EthernetHeader::GetLengthType
uint16_t GetLengthType(void) const
Definition:
ethernet-header.cc:56
ns3::EthernetHeader::GetPacketType
ethernet_header_t GetPacketType(void) const
Definition:
ethernet-header.cc:102
ns3::EthernetHeader::m_preambleSfd
uint64_t m_preambleSfd
Value of the Preamble/SFD fields.
Definition:
ethernet-header.h:127
ns3::EthernetHeader::SetPreambleSfd
void SetPreambleSfd(uint64_t preambleSfd)
Definition:
ethernet-header.cc:63
ns3::EthernetHeader::Serialize
virtual void Serialize(Buffer::Iterator start) const
Definition:
ethernet-header.cc:160
ns3::EthernetHeader::GetInstanceTypeId
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition:
ethernet-header.cc:127
ns3::EthernetHeader::LENGTH_SIZE
static const int LENGTH_SIZE
size of the length_type header field
Definition:
ethernet-header.h:120
ns3::EthernetHeader::GetPreambleSfd
uint64_t GetPreambleSfd() const
Definition:
ethernet-header.cc:69
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:43
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:44
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:922
ethernet-header.h
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
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:244
ns3::ethernet_header_t
ethernet_header_t
Types of ethernet packets.
Definition:
ethernet-header.h:36
ns3::LENGTH
@ LENGTH
Basic ethernet packet, no tags, type/length field indicates packet length or IP/ARP packet.
Definition:
ethernet-header.h:37
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:45
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:28
ns3::ReadFrom
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
Definition:
address-utils.cc:70
visualizer.core.start
def start()
Definition:
core.py:1853
src
network
utils
ethernet-header.cc
Generated on Tue Feb 6 2024 19:21:25 for ns-3 by
1.9.1