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