A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
ethernet-trailer.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 "ns3/assert.h"
22
#include "ns3/log.h"
23
#include "ns3/trailer.h"
24
#include "
ethernet-trailer.h
"
25
#include "
crc32.h
"
26
27
NS_LOG_COMPONENT_DEFINE
(
"EthernetTrailer"
);
28
29
namespace
ns3 {
30
31
NS_OBJECT_ENSURE_REGISTERED
(EthernetTrailer)
32
;
33
34
EthernetTrailer::EthernetTrailer
()
35
: m_calcFcs (false),
36
m_fcs (0)
37
{
38
NS_LOG_FUNCTION
(
this
);
39
}
40
41
void
42
EthernetTrailer::EnableFcs
(
bool
enable)
43
{
44
NS_LOG_FUNCTION
(
this
<< enable);
45
m_calcFcs
= enable;
46
}
47
48
bool
49
EthernetTrailer::CheckFcs
(
Ptr<const Packet>
p)
const
50
{
51
NS_LOG_FUNCTION
(
this
<< p);
52
int
len = p->
GetSize
();
53
uint8_t *buffer;
54
uint32_t crc;
55
56
if
(!
m_calcFcs
)
57
{
58
return
true
;
59
}
60
61
buffer =
new
uint8_t[len];
62
p->
CopyData
(buffer, len);
63
crc =
CRC32Calculate
(buffer, len);
64
delete
[] buffer;
65
return
(
m_fcs
== crc);
66
}
67
68
void
69
EthernetTrailer::CalcFcs
(
Ptr<const Packet>
p)
70
{
71
NS_LOG_FUNCTION
(
this
<< p);
72
int
len = p->
GetSize
();
73
uint8_t *buffer;
74
75
if
(!
m_calcFcs
)
76
{
77
return
;
78
}
79
80
buffer =
new
uint8_t[len];
81
p->
CopyData
(buffer, len);
82
m_fcs
=
CRC32Calculate
(buffer, len);
83
delete
[] buffer;
84
}
85
86
void
87
EthernetTrailer::SetFcs
(uint32_t fcs)
88
{
89
NS_LOG_FUNCTION
(
this
<< fcs);
90
m_fcs
= fcs;
91
}
92
93
uint32_t
94
EthernetTrailer::GetFcs
(
void
)
95
{
96
NS_LOG_FUNCTION
(
this
);
97
return
m_fcs
;
98
}
99
100
uint32_t
101
EthernetTrailer::GetTrailerSize
(
void
)
const
102
{
103
NS_LOG_FUNCTION
(
this
);
104
return
GetSerializedSize
();
105
}
106
107
TypeId
108
EthernetTrailer::GetTypeId
(
void
)
109
{
110
static
TypeId
tid =
TypeId
(
"ns3::EthernetTrailer"
)
111
.
SetParent
<
Trailer
> ()
112
.AddConstructor<EthernetTrailer> ()
113
;
114
return
tid;
115
}
116
TypeId
117
EthernetTrailer::GetInstanceTypeId
(
void
)
const
118
{
119
return
GetTypeId
();
120
}
121
void
122
EthernetTrailer::Print
(std::ostream &os)
const
123
{
124
NS_LOG_FUNCTION
(
this
<< &os);
125
os <<
"fcs="
<<
m_fcs
;
126
}
127
uint32_t
128
EthernetTrailer::GetSerializedSize
(
void
)
const
129
{
130
NS_LOG_FUNCTION
(
this
);
131
return
4;
132
}
133
134
void
135
EthernetTrailer::Serialize
(
Buffer::Iterator
end)
const
136
{
137
NS_LOG_FUNCTION
(
this
<< &end);
138
Buffer::Iterator
i = end;
139
i.
Prev
(
GetSerializedSize
());
140
141
i.
WriteU32
(
m_fcs
);
142
}
143
uint32_t
144
EthernetTrailer::Deserialize
(
Buffer::Iterator
end)
145
{
146
NS_LOG_FUNCTION
(
this
<< &end);
147
Buffer::Iterator
i = end;
148
uint32_t size =
GetSerializedSize
();
149
i.
Prev
(size);
150
151
m_fcs
= i.
ReadU32
();
152
153
return
size;
154
}
155
156
}
// namespace ns3
ns3::Buffer::Iterator::ReadU32
uint32_t ReadU32(void)
Definition:
buffer.cc:997
ns3::Ptr< const Packet >
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
ns3::EthernetTrailer::CalcFcs
void CalcFcs(Ptr< const Packet > p)
Updates the Fcs Field to the correct FCS.
Definition:
ethernet-trailer.cc:69
ns3::EthernetTrailer::SetFcs
void SetFcs(uint32_t fcs)
Sets the FCS to a new value.
Definition:
ethernet-trailer.cc:87
ns3::CRC32Calculate
uint32_t CRC32Calculate(const uint8_t *data, int length)
Definition:
crc32.cc:68
ns3::EthernetTrailer::GetTrailerSize
uint32_t GetTrailerSize() const
Definition:
ethernet-trailer.cc:101
ns3::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
ns3::Packet::GetSize
uint32_t GetSize(void) const
Definition:
packet.h:650
ns3::EthernetTrailer::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Definition:
ethernet-trailer.cc:128
ns3::EthernetTrailer::m_fcs
uint32_t m_fcs
Definition:
ethernet-trailer.h:105
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:98
crc32.h
ns3::EthernetTrailer::GetInstanceTypeId
virtual TypeId GetInstanceTypeId(void) const
Definition:
ethernet-trailer.cc:117
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:49
ns3::EthernetTrailer::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator end)
Definition:
ethernet-trailer.cc:144
ns3::Buffer::Iterator::Prev
void Prev(void)
go backward by one byte
Definition:
buffer.h:672
ns3::EthernetTrailer::Print
virtual void Print(std::ostream &os) const
Definition:
ethernet-trailer.cc:122
ns3::EthernetTrailer::GetTypeId
static TypeId GetTypeId(void)
Definition:
ethernet-trailer.cc:108
ns3::EthernetTrailer::EthernetTrailer
EthernetTrailer()
Construct a null ethernet trailer.
Definition:
ethernet-trailer.cc:34
ns3::EthernetTrailer::m_calcFcs
bool m_calcFcs
Enabled FCS calculations.
Definition:
ethernet-trailer.h:104
ns3::EthernetTrailer::Serialize
virtual void Serialize(Buffer::Iterator end) const
Definition:
ethernet-trailer.cc:135
ns3::Trailer
Protocol trailer serialization and deserialization.
Definition:
trailer.h:40
NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("EthernetTrailer")
ns3::EthernetTrailer::EnableFcs
void EnableFcs(bool enable)
Enable or disable FCS checking and calculations.
Definition:
ethernet-trailer.cc:42
ns3::Packet::CopyData
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition:
packet.cc:381
ethernet-trailer.h
ns3::Buffer::Iterator::WriteU32
void WriteU32(uint32_t data)
Definition:
buffer.cc:903
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:611
ns3::EthernetTrailer::GetFcs
uint32_t GetFcs()
Definition:
ethernet-trailer.cc:94
src
network
utils
ethernet-trailer.cc
Generated on Sat Apr 19 2014 14:07:06 for ns-3 by
1.8.6