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
error-net-device.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2011 Universita' di Firenze, Italy
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: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19
*/
20
#include "
error-net-device.h
"
21
#include "
error-channel.h
"
22
#include "ns3/node.h"
23
#include "ns3/packet.h"
24
#include "ns3/log.h"
25
#include "ns3/pointer.h"
26
#include "ns3/error-model.h"
27
#include "ns3/trace-source-accessor.h"
28
29
NS_LOG_COMPONENT_DEFINE
(
"ErrorNetDevice"
);
30
31
namespace
ns3 {
32
33
NS_OBJECT_ENSURE_REGISTERED
(ErrorNetDevice);
34
35
TypeId
36
ErrorNetDevice::GetTypeId
(
void
)
37
{
38
static
TypeId
tid =
TypeId
(
"ns3::ErrorNetDevice"
)
39
.
SetParent
<
NetDevice
> ()
40
.AddConstructor<ErrorNetDevice> ()
41
.AddAttribute (
"ReceiveErrorModel"
,
42
"The receiver error model used to simulate packet loss"
,
43
PointerValue
(),
44
MakePointerAccessor (&
ErrorNetDevice::m_receiveErrorModel
),
45
MakePointerChecker<ErrorModel> ())
46
.AddTraceSource (
"PhyRxDrop"
,
47
"Trace source indicating a packet has been dropped by the device during reception"
,
48
MakeTraceSourceAccessor
(&
ErrorNetDevice::m_phyRxDropTrace
))
49
;
50
return
tid;
51
}
52
53
ErrorNetDevice::ErrorNetDevice
()
54
: m_channel (0),
55
m_node (0),
56
m_mtu (0xffff),
57
m_ifIndex (0)
58
{}
59
60
void
61
ErrorNetDevice::Receive
(
Ptr<Packet>
packet, uint16_t protocol,
62
Mac48Address
to,
Mac48Address
from)
63
{
64
NS_LOG_FUNCTION
(packet << protocol << to << from << *packet);
65
NetDevice::PacketType
packetType;
66
67
if
(
m_receiveErrorModel
&&
m_receiveErrorModel
->
IsCorrupt
(packet) )
68
{
69
m_phyRxDropTrace
(packet);
70
return
;
71
}
72
73
if
(to ==
m_address
)
74
{
75
packetType =
NetDevice::PACKET_HOST
;
76
}
77
else
if
(to.
IsBroadcast
())
78
{
79
packetType =
NetDevice::PACKET_HOST
;
80
}
81
else
if
(to.
IsGroup
())
82
{
83
packetType =
NetDevice::PACKET_MULTICAST
;
84
}
85
else
86
{
87
packetType =
NetDevice::PACKET_OTHERHOST
;
88
}
89
m_rxCallback
(
this
, packet, protocol, from);
90
if
(!
m_promiscCallback
.
IsNull
())
91
{
92
m_promiscCallback
(
this
, packet, protocol, from, to, packetType);
93
}
94
}
95
96
void
97
ErrorNetDevice::SetChannel
(
Ptr<ErrorChannel>
channel)
98
{
99
m_channel
= channel;
100
m_channel
->
Add
(
this
);
101
}
102
103
void
104
ErrorNetDevice::SetReceiveErrorModel
(
Ptr<ErrorModel>
em)
105
{
106
m_receiveErrorModel
= em;
107
}
108
109
void
110
ErrorNetDevice::SetIfIndex
(
const
uint32_t index)
111
{
112
m_ifIndex
= index;
113
}
114
uint32_t
115
ErrorNetDevice::GetIfIndex
(
void
)
const
116
{
117
return
m_ifIndex
;
118
}
119
Ptr<Channel>
120
ErrorNetDevice::GetChannel
(
void
)
const
121
{
122
return
m_channel
;
123
}
124
void
125
ErrorNetDevice::SetAddress
(
Address
address)
126
{
127
m_address
=
Mac48Address::ConvertFrom
(address);
128
}
129
Address
130
ErrorNetDevice::GetAddress
(
void
)
const
131
{
132
//
133
// Implicit conversion from Mac48Address to Address
134
//
135
return
m_address
;
136
}
137
bool
138
ErrorNetDevice::SetMtu
(
const
uint16_t mtu)
139
{
140
m_mtu
= mtu;
141
return
true
;
142
}
143
uint16_t
144
ErrorNetDevice::GetMtu
(
void
)
const
145
{
146
return
m_mtu
;
147
}
148
bool
149
ErrorNetDevice::IsLinkUp
(
void
)
const
150
{
151
return
true
;
152
}
153
void
154
ErrorNetDevice::AddLinkChangeCallback
(
Callback<void>
callback)
155
{}
156
bool
157
ErrorNetDevice::IsBroadcast
(
void
)
const
158
{
159
return
true
;
160
}
161
Address
162
ErrorNetDevice::GetBroadcast
(
void
)
const
163
{
164
return
Mac48Address
(
"ff:ff:ff:ff:ff:ff"
);
165
}
166
bool
167
ErrorNetDevice::IsMulticast
(
void
)
const
168
{
169
return
false
;
170
}
171
Address
172
ErrorNetDevice::GetMulticast
(
Ipv4Address
multicastGroup)
const
173
{
174
return
Mac48Address::GetMulticast
(multicastGroup);
175
}
176
177
Address
ErrorNetDevice::GetMulticast
(
Ipv6Address
addr)
const
178
{
179
return
Mac48Address::GetMulticast
(addr);
180
}
181
182
bool
183
ErrorNetDevice::IsPointToPoint
(
void
)
const
184
{
185
return
false
;
186
}
187
188
bool
189
ErrorNetDevice::IsBridge
(
void
)
const
190
{
191
return
false
;
192
}
193
194
bool
195
ErrorNetDevice::Send
(
Ptr<Packet>
packet,
const
Address
& dest, uint16_t protocolNumber)
196
{
197
NS_LOG_FUNCTION
(packet << dest << protocolNumber << *packet);
198
Mac48Address
to =
Mac48Address::ConvertFrom
(dest);
199
m_channel
->
Send
(packet, protocolNumber, to,
m_address
,
this
);
200
return
true
;
201
}
202
bool
203
ErrorNetDevice::SendFrom
(
Ptr<Packet>
packet,
const
Address
& source,
const
Address
& dest, uint16_t protocolNumber)
204
{
205
NS_LOG_FUNCTION
(packet << source << dest << protocolNumber << *packet);
206
Mac48Address
to =
Mac48Address::ConvertFrom
(dest);
207
Mac48Address
from =
Mac48Address::ConvertFrom
(source);
208
m_channel
->
Send
(packet, protocolNumber, to, from,
this
);
209
return
true
;
210
}
211
212
Ptr<Node>
213
ErrorNetDevice::GetNode
(
void
)
const
214
{
215
return
m_node
;
216
}
217
void
218
ErrorNetDevice::SetNode
(
Ptr<Node>
node)
219
{
220
m_node
= node;
221
}
222
bool
223
ErrorNetDevice::NeedsArp
(
void
)
const
224
{
225
return
false
;
226
}
227
void
228
ErrorNetDevice::SetReceiveCallback
(
NetDevice::ReceiveCallback
cb)
229
{
230
m_rxCallback
= cb;
231
}
232
233
void
234
ErrorNetDevice::DoDispose
(
void
)
235
{
236
m_channel
= 0;
237
m_node
= 0;
238
m_receiveErrorModel
= 0;
239
NetDevice::DoDispose
();
240
}
241
242
243
void
244
ErrorNetDevice::SetPromiscReceiveCallback
(
PromiscReceiveCallback
cb)
245
{
246
m_promiscCallback
= cb;
247
}
248
249
bool
250
ErrorNetDevice::SupportsSendFrom
(
void
)
const
251
{
252
return
true
;
253
}
254
255
}
// namespace ns3
src
internet
test
error-net-device.cc
Generated on Tue Oct 9 2012 16:45:39 for ns-3 by
1.8.1.2