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-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
NS_LOG_COMPONENT_DEFINE
(
"EthernetHeader"
);
30
31
namespace
ns3 {
32
33
NS_OBJECT_ENSURE_REGISTERED
(EthernetHeader);
34
35
EthernetHeader::EthernetHeader
(
bool
hasPreamble)
36
: m_enPreambleSfd (hasPreamble),
37
m_lengthType (0)
38
{
39
}
40
41
EthernetHeader::EthernetHeader
()
42
: m_enPreambleSfd (false),
43
m_lengthType (0)
44
{
45
}
46
47
void
48
EthernetHeader::SetLengthType
(uint16_t lengthType)
49
{
50
m_lengthType
= lengthType;
51
}
52
uint16_t
53
EthernetHeader::GetLengthType
(
void
)
const
54
{
55
return
m_lengthType
;
56
}
57
58
void
59
EthernetHeader::SetPreambleSfd
(uint64_t preambleSfd)
60
{
61
m_preambleSfd
= preambleSfd;
62
}
63
uint64_t
64
EthernetHeader::GetPreambleSfd
(
void
)
const
65
{
66
return
m_preambleSfd
;
67
}
68
69
void
70
EthernetHeader::SetSource
(
Mac48Address
source)
71
{
72
m_source
= source;
73
}
74
Mac48Address
75
EthernetHeader::GetSource
(
void
)
const
76
{
77
return
m_source
;
78
}
79
80
void
81
EthernetHeader::SetDestination
(
Mac48Address
dst)
82
{
83
m_destination
= dst;
84
}
85
Mac48Address
86
EthernetHeader::GetDestination
(
void
)
const
87
{
88
return
m_destination
;
89
}
90
91
ethernet_header_t
92
EthernetHeader::GetPacketType
(
void
)
const
93
{
94
return
LENGTH
;
95
}
96
97
uint32_t
98
EthernetHeader::GetHeaderSize
(
void
)
const
99
{
100
return
GetSerializedSize
();
101
}
102
103
104
TypeId
105
EthernetHeader::GetTypeId
(
void
)
106
{
107
static
TypeId
tid =
TypeId
(
"ns3::EthernetHeader"
)
108
.
SetParent
<
Header
> ()
109
.AddConstructor<EthernetHeader> ()
110
;
111
return
tid;
112
}
113
TypeId
114
EthernetHeader::GetInstanceTypeId
(
void
)
const
115
{
116
return
GetTypeId
();
117
}
118
void
119
EthernetHeader::Print
(std::ostream &os)
const
120
{
121
// ethernet, right ?
122
if
(
m_enPreambleSfd
)
123
{
124
os <<
"preamble/sfd="
<<
m_preambleSfd
<<
","
;
125
}
126
127
os <<
" length/type=0x"
<< std::hex <<
m_lengthType
<< std::dec
128
<<
", source="
<<
m_source
129
<<
", destination="
<<
m_destination
;
130
}
131
uint32_t
132
EthernetHeader::GetSerializedSize
(
void
)
const
133
{
134
if
(
m_enPreambleSfd
)
135
{
136
return
PREAMBLE_SIZE
+
LENGTH_SIZE
+ 2*
MAC_ADDR_SIZE
;
137
}
138
else
139
{
140
return
LENGTH_SIZE
+ 2*
MAC_ADDR_SIZE
;
141
}
142
}
143
144
void
145
EthernetHeader::Serialize
(
Buffer::Iterator
start
)
const
146
{
147
Buffer::Iterator
i =
start
;
148
149
if
(
m_enPreambleSfd
)
150
{
151
i.
WriteU64
(
m_preambleSfd
);
152
}
153
WriteTo
(i,
m_destination
);
154
WriteTo
(i,
m_source
);
155
i.
WriteHtonU16
(
m_lengthType
);
156
}
157
uint32_t
158
EthernetHeader::Deserialize
(
Buffer::Iterator
start
)
159
{
160
Buffer::Iterator
i =
start
;
161
162
if
(
m_enPreambleSfd
)
163
{
164
m_enPreambleSfd
= i.
ReadU64
();
165
}
166
167
ReadFrom
(i,
m_destination
);
168
ReadFrom
(i,
m_source
);
169
m_lengthType
= i.
ReadNtohU16
();
170
171
return
GetSerializedSize
();
172
}
173
174
}
// namespace ns3
src
network
utils
ethernet-header.cc
Generated on Tue Nov 13 2012 10:32:20 for ns-3 by
1.8.1.2