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-trailer.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-trailer.h
"
10
11
#include "
crc32.h
"
12
13
#include "ns3/assert.h"
14
#include "ns3/log.h"
15
#include "ns3/trailer.h"
16
17
namespace
ns3
18
{
19
20
NS_LOG_COMPONENT_DEFINE
(
"EthernetTrailer"
);
21
22
NS_OBJECT_ENSURE_REGISTERED
(EthernetTrailer);
23
24
EthernetTrailer::EthernetTrailer
()
25
: m_calcFcs(false),
26
m_fcs(0)
27
{
28
NS_LOG_FUNCTION
(
this
);
29
}
30
31
void
32
EthernetTrailer::EnableFcs
(
bool
enable)
33
{
34
NS_LOG_FUNCTION
(
this
<< enable);
35
m_calcFcs
= enable;
36
}
37
38
bool
39
EthernetTrailer::CheckFcs
(
Ptr<const Packet>
p)
const
40
{
41
NS_LOG_FUNCTION
(
this
<< p);
42
int
len = p->GetSize();
43
uint8_t* buffer;
44
uint32_t
crc;
45
46
if
(!
m_calcFcs
)
47
{
48
return
true
;
49
}
50
51
buffer =
new
uint8_t[len];
52
p->CopyData(buffer, len);
53
crc =
CRC32Calculate
(buffer, len);
54
delete
[] buffer;
55
return
(
m_fcs
== crc);
56
}
57
58
void
59
EthernetTrailer::CalcFcs
(
Ptr<const Packet>
p)
60
{
61
NS_LOG_FUNCTION
(
this
<< p);
62
int
len = p->GetSize();
63
uint8_t* buffer;
64
65
if
(!
m_calcFcs
)
66
{
67
return
;
68
}
69
70
buffer =
new
uint8_t[len];
71
p->CopyData(buffer, len);
72
m_fcs
=
CRC32Calculate
(buffer, len);
73
delete
[] buffer;
74
}
75
76
void
77
EthernetTrailer::SetFcs
(
uint32_t
fcs)
78
{
79
NS_LOG_FUNCTION
(
this
<< fcs);
80
m_fcs
= fcs;
81
}
82
83
uint32_t
84
EthernetTrailer::GetFcs
()
const
85
{
86
NS_LOG_FUNCTION
(
this
);
87
return
m_fcs
;
88
}
89
90
uint32_t
91
EthernetTrailer::GetTrailerSize
()
const
92
{
93
NS_LOG_FUNCTION
(
this
);
94
return
GetSerializedSize
();
95
}
96
97
TypeId
98
EthernetTrailer::GetTypeId
()
99
{
100
static
TypeId
tid =
TypeId
(
"ns3::EthernetTrailer"
)
101
.
SetParent
<
Trailer
>()
102
.SetGroupName(
"Network"
)
103
.AddConstructor<
EthernetTrailer
>();
104
return
tid;
105
}
106
107
TypeId
108
EthernetTrailer::GetInstanceTypeId
()
const
109
{
110
return
GetTypeId
();
111
}
112
113
void
114
EthernetTrailer::Print
(std::ostream& os)
const
115
{
116
NS_LOG_FUNCTION
(
this
<< &os);
117
os <<
"fcs="
<<
m_fcs
;
118
}
119
120
uint32_t
121
EthernetTrailer::GetSerializedSize
()
const
122
{
123
NS_LOG_FUNCTION
(
this
);
124
return
4;
125
}
126
127
void
128
EthernetTrailer::Serialize
(
Buffer::Iterator
end)
const
129
{
130
NS_LOG_FUNCTION
(
this
<< &end);
131
Buffer::Iterator
i = end;
132
i.
Prev
(
GetSerializedSize
());
133
134
i.
WriteU32
(
m_fcs
);
135
}
136
137
uint32_t
138
EthernetTrailer::Deserialize
(
Buffer::Iterator
end)
139
{
140
NS_LOG_FUNCTION
(
this
<< &end);
141
Buffer::Iterator
i = end;
142
uint32_t
size =
GetSerializedSize
();
143
i.
Prev
(size);
144
145
m_fcs
= i.
ReadU32
();
146
147
return
size;
148
}
149
150
}
// namespace ns3
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::Buffer::Iterator::WriteU32
void WriteU32(uint32_t data)
Definition
buffer.cc:857
ns3::Buffer::Iterator::ReadU32
uint32_t ReadU32()
Definition
buffer.cc:955
ns3::Buffer::Iterator::Prev
void Prev()
go backward by one byte
Definition
buffer.h:849
ns3::EthernetTrailer
Packet trailer for Ethernet.
Definition
ethernet-trailer.h:29
ns3::EthernetTrailer::GetFcs
uint32_t GetFcs() const
Definition
ethernet-trailer.cc:84
ns3::EthernetTrailer::Deserialize
uint32_t Deserialize(Buffer::Iterator end) override
Definition
ethernet-trailer.cc:138
ns3::EthernetTrailer::Print
void Print(std::ostream &os) const override
Definition
ethernet-trailer.cc:114
ns3::EthernetTrailer::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition
ethernet-trailer.cc:108
ns3::EthernetTrailer::CheckFcs
bool CheckFcs(Ptr< const Packet > p) const
Calculate an FCS on the provided packet and check this value against the FCS found when the trailer w...
Definition
ethernet-trailer.cc:39
ns3::EthernetTrailer::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition
ethernet-trailer.cc:121
ns3::EthernetTrailer::Serialize
void Serialize(Buffer::Iterator end) const override
Definition
ethernet-trailer.cc:128
ns3::EthernetTrailer::GetTrailerSize
uint32_t GetTrailerSize() const
Definition
ethernet-trailer.cc:91
ns3::EthernetTrailer::EnableFcs
void EnableFcs(bool enable)
Enable or disable FCS checking and calculations.
Definition
ethernet-trailer.cc:32
ns3::EthernetTrailer::EthernetTrailer
EthernetTrailer()
Construct a null ethernet trailer.
Definition
ethernet-trailer.cc:24
ns3::EthernetTrailer::m_calcFcs
bool m_calcFcs
Enabled FCS calculations.
Definition
ethernet-trailer.h:98
ns3::EthernetTrailer::CalcFcs
void CalcFcs(Ptr< const Packet > p)
Updates the Fcs Field to the correct FCS.
Definition
ethernet-trailer.cc:59
ns3::EthernetTrailer::m_fcs
uint32_t m_fcs
Value of the fcs contained in the trailer.
Definition
ethernet-trailer.h:99
ns3::EthernetTrailer::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
ethernet-trailer.cc:98
ns3::EthernetTrailer::SetFcs
void SetFcs(uint32_t fcs)
Sets the FCS to a new value.
Definition
ethernet-trailer.cc:77
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::Trailer
Protocol trailer serialization and deserialization.
Definition
trailer.h:30
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
crc32.h
ethernet-trailer.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
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::CRC32Calculate
uint32_t CRC32Calculate(const uint8_t *data, int length)
Calculates the CRC-32 for a given input.
Definition
crc32.cc:60
src
network
utils
ethernet-trailer.cc
Generated on Fri Nov 8 2024 13:59:05 for ns-3 by
1.11.0