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
wifi-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) 2005,2006 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 "
wifi-net-device.h
"
21
#include "
wifi-mac.h
"
22
#include "
wifi-phy.h
"
23
#include "
wifi-remote-station-manager.h
"
24
#include "
wifi-channel.h
"
25
#include "ns3/llc-snap-header.h"
26
#include "ns3/packet.h"
27
#include "ns3/uinteger.h"
28
#include "ns3/pointer.h"
29
#include "ns3/node.h"
30
#include "ns3/trace-source-accessor.h"
31
#include "ns3/log.h"
32
33
NS_LOG_COMPONENT_DEFINE
(
"WifiNetDevice"
);
34
35
namespace
ns3 {
36
37
NS_OBJECT_ENSURE_REGISTERED
(WifiNetDevice);
38
39
TypeId
40
WifiNetDevice::GetTypeId
(
void
)
41
{
42
static
TypeId
tid =
TypeId
(
"ns3::WifiNetDevice"
)
43
.
SetParent
<
NetDevice
> ()
44
.AddConstructor<WifiNetDevice> ()
45
.AddAttribute (
"Mtu"
,
"The MAC-level Maximum Transmission Unit"
,
46
UintegerValue
(
MAX_MSDU_SIZE
-
LLC_SNAP_HEADER_LENGTH
),
47
MakeUintegerAccessor (&
WifiNetDevice::SetMtu
,
48
&
WifiNetDevice::GetMtu
),
49
MakeUintegerChecker<uint16_t> (1,
MAX_MSDU_SIZE
-
LLC_SNAP_HEADER_LENGTH
))
50
.AddAttribute (
"Channel"
,
"The channel attached to this device"
,
51
PointerValue
(),
52
MakePointerAccessor (&
WifiNetDevice::DoGetChannel
),
53
MakePointerChecker<WifiChannel> ())
54
.AddAttribute (
"Phy"
,
"The PHY layer attached to this device."
,
55
PointerValue
(),
56
MakePointerAccessor (&
WifiNetDevice::GetPhy
,
57
&
WifiNetDevice::SetPhy
),
58
MakePointerChecker<WifiPhy> ())
59
.AddAttribute (
"Mac"
,
"The MAC layer attached to this device."
,
60
PointerValue
(),
61
MakePointerAccessor (&
WifiNetDevice::GetMac
,
62
&
WifiNetDevice::SetMac
),
63
MakePointerChecker<WifiMac> ())
64
.AddAttribute (
"RemoteStationManager"
,
"The station manager attached to this device."
,
65
PointerValue
(),
66
MakePointerAccessor (&
WifiNetDevice::SetRemoteStationManager
,
67
&
WifiNetDevice::GetRemoteStationManager
),
68
MakePointerChecker<WifiRemoteStationManager> ())
69
;
70
return
tid;
71
}
72
73
WifiNetDevice::WifiNetDevice
()
74
: m_configComplete (false)
75
{
76
NS_LOG_FUNCTION_NOARGS
();
77
}
78
WifiNetDevice::~WifiNetDevice
()
79
{
80
NS_LOG_FUNCTION_NOARGS
();
81
}
82
83
void
84
WifiNetDevice::DoDispose
(
void
)
85
{
86
NS_LOG_FUNCTION_NOARGS
();
87
m_node
= 0;
88
m_mac
->
Dispose
();
89
m_phy
->
Dispose
();
90
m_stationManager
->
Dispose
();
91
m_mac
= 0;
92
m_phy
= 0;
93
m_stationManager
= 0;
94
// chain up.
95
NetDevice::DoDispose
();
96
}
97
98
void
99
WifiNetDevice::DoStart
(
void
)
100
{
101
m_phy
->
Start
();
102
m_mac
->
Start
();
103
m_stationManager
->
Start
();
104
NetDevice::DoStart
();
105
}
106
107
void
108
WifiNetDevice::CompleteConfig
(
void
)
109
{
110
if
(
m_mac
== 0
111
||
m_phy
== 0
112
||
m_stationManager
== 0
113
||
m_node
== 0
114
||
m_configComplete
)
115
{
116
return
;
117
}
118
m_mac
->
SetWifiRemoteStationManager
(
m_stationManager
);
119
m_mac
->
SetWifiPhy
(
m_phy
);
120
m_mac
->
SetForwardUpCallback
(
MakeCallback
(&
WifiNetDevice::ForwardUp
,
this
));
121
m_mac
->
SetLinkUpCallback
(
MakeCallback
(&
WifiNetDevice::LinkUp
,
this
));
122
m_mac
->
SetLinkDownCallback
(
MakeCallback
(&
WifiNetDevice::LinkDown
,
this
));
123
m_stationManager
->
SetupPhy
(
m_phy
);
124
m_configComplete
=
true
;
125
}
126
127
void
128
WifiNetDevice::SetMac
(
Ptr<WifiMac>
mac)
129
{
130
m_mac
= mac;
131
CompleteConfig
();
132
}
133
void
134
WifiNetDevice::SetPhy
(
Ptr<WifiPhy>
phy)
135
{
136
m_phy
= phy;
137
CompleteConfig
();
138
}
139
void
140
WifiNetDevice::SetRemoteStationManager
(
Ptr<WifiRemoteStationManager>
manager)
141
{
142
m_stationManager
= manager;
143
CompleteConfig
();
144
}
145
Ptr<WifiMac>
146
WifiNetDevice::GetMac
(
void
)
const
147
{
148
return
m_mac
;
149
}
150
Ptr<WifiPhy>
151
WifiNetDevice::GetPhy
(
void
)
const
152
{
153
return
m_phy
;
154
}
155
Ptr<WifiRemoteStationManager>
156
WifiNetDevice::GetRemoteStationManager
(
void
)
const
157
{
158
return
m_stationManager
;
159
}
160
161
void
162
WifiNetDevice::SetIfIndex
(
const
uint32_t index)
163
{
164
m_ifIndex
= index;
165
}
166
uint32_t
167
WifiNetDevice::GetIfIndex
(
void
)
const
168
{
169
return
m_ifIndex
;
170
}
171
Ptr<Channel>
172
WifiNetDevice::GetChannel
(
void
)
const
173
{
174
return
m_phy
->
GetChannel
();
175
}
176
Ptr<WifiChannel>
177
WifiNetDevice::DoGetChannel
(
void
)
const
178
{
179
return
m_phy
->
GetChannel
();
180
}
181
void
182
WifiNetDevice::SetAddress
(
Address
address)
183
{
184
m_mac
->
SetAddress
(
Mac48Address::ConvertFrom
(address));
185
}
186
Address
187
WifiNetDevice::GetAddress
(
void
)
const
188
{
189
return
m_mac
->
GetAddress
();
190
}
191
bool
192
WifiNetDevice::SetMtu
(
const
uint16_t mtu)
193
{
194
if
(mtu >
MAX_MSDU_SIZE
-
LLC_SNAP_HEADER_LENGTH
)
195
{
196
return
false
;
197
}
198
m_mtu
= mtu;
199
return
true
;
200
}
201
uint16_t
202
WifiNetDevice::GetMtu
(
void
)
const
203
{
204
return
m_mtu
;
205
}
206
bool
207
WifiNetDevice::IsLinkUp
(
void
)
const
208
{
209
return
m_phy
!= 0 &&
m_linkUp
;
210
}
211
void
212
WifiNetDevice::AddLinkChangeCallback
(
Callback<void>
callback)
213
{
214
m_linkChanges
.
ConnectWithoutContext
(callback);
215
}
216
bool
217
WifiNetDevice::IsBroadcast
(
void
)
const
218
{
219
return
true
;
220
}
221
Address
222
WifiNetDevice::GetBroadcast
(
void
)
const
223
{
224
return
Mac48Address::GetBroadcast
();
225
}
226
bool
227
WifiNetDevice::IsMulticast
(
void
)
const
228
{
229
return
true
;
230
}
231
Address
232
WifiNetDevice::GetMulticast
(
Ipv4Address
multicastGroup)
const
233
{
234
return
Mac48Address::GetMulticast
(multicastGroup);
235
}
236
Address
WifiNetDevice::GetMulticast
(
Ipv6Address
addr)
const
237
{
238
return
Mac48Address::GetMulticast
(addr);
239
}
240
bool
241
WifiNetDevice::IsPointToPoint
(
void
)
const
242
{
243
return
false
;
244
}
245
bool
246
WifiNetDevice::IsBridge
(
void
)
const
247
{
248
return
false
;
249
}
250
bool
251
WifiNetDevice::Send
(
Ptr<Packet>
packet,
const
Address
& dest, uint16_t protocolNumber)
252
{
253
NS_ASSERT
(
Mac48Address::IsMatchingType
(dest));
254
255
Mac48Address
realTo =
Mac48Address::ConvertFrom
(dest);
256
257
LlcSnapHeader
llc;
258
llc.
SetType
(protocolNumber);
259
packet->
AddHeader
(llc);
260
261
m_mac
->
NotifyTx
(packet);
262
m_mac
->
Enqueue
(packet, realTo);
263
return
true
;
264
}
265
Ptr<Node>
266
WifiNetDevice::GetNode
(
void
)
const
267
{
268
return
m_node
;
269
}
270
void
271
WifiNetDevice::SetNode
(
Ptr<Node>
node)
272
{
273
m_node
= node;
274
CompleteConfig
();
275
}
276
bool
277
WifiNetDevice::NeedsArp
(
void
)
const
278
{
279
return
true
;
280
}
281
void
282
WifiNetDevice::SetReceiveCallback
(
NetDevice::ReceiveCallback
cb)
283
{
284
m_forwardUp
= cb;
285
}
286
287
void
288
WifiNetDevice::ForwardUp
(
Ptr<Packet>
packet,
Mac48Address
from,
Mac48Address
to)
289
{
290
LlcSnapHeader
llc;
291
packet->
RemoveHeader
(llc);
292
enum
NetDevice::PacketType
type;
293
if
(to.
IsBroadcast
())
294
{
295
type =
NetDevice::PACKET_BROADCAST
;
296
}
297
else
if
(to.
IsGroup
())
298
{
299
type =
NetDevice::PACKET_MULTICAST
;
300
}
301
else
if
(to ==
m_mac
->
GetAddress
())
302
{
303
type =
NetDevice::PACKET_HOST
;
304
}
305
else
306
{
307
type =
NetDevice::PACKET_OTHERHOST
;
308
}
309
310
if
(type !=
NetDevice::PACKET_OTHERHOST
)
311
{
312
m_mac
->
NotifyRx
(packet);
313
m_forwardUp
(
this
, packet, llc.
GetType
(), from);
314
}
315
316
if
(!
m_promiscRx
.
IsNull
())
317
{
318
m_mac
->
NotifyPromiscRx
(packet);
319
m_promiscRx
(
this
, packet, llc.
GetType
(), from, to, type);
320
}
321
}
322
323
void
324
WifiNetDevice::LinkUp
(
void
)
325
{
326
m_linkUp
=
true
;
327
m_linkChanges
();
328
}
329
void
330
WifiNetDevice::LinkDown
(
void
)
331
{
332
m_linkUp
=
false
;
333
m_linkChanges
();
334
}
335
336
bool
337
WifiNetDevice::SendFrom
(
Ptr<Packet>
packet,
const
Address
& source,
const
Address
& dest, uint16_t protocolNumber)
338
{
339
NS_ASSERT
(
Mac48Address::IsMatchingType
(dest));
340
NS_ASSERT
(
Mac48Address::IsMatchingType
(source));
341
342
Mac48Address
realTo =
Mac48Address::ConvertFrom
(dest);
343
Mac48Address
realFrom =
Mac48Address::ConvertFrom
(source);
344
345
LlcSnapHeader
llc;
346
llc.
SetType
(protocolNumber);
347
packet->
AddHeader
(llc);
348
349
m_mac
->
NotifyTx
(packet);
350
m_mac
->
Enqueue
(packet, realTo, realFrom);
351
352
return
true
;
353
}
354
355
void
356
WifiNetDevice::SetPromiscReceiveCallback
(
PromiscReceiveCallback
cb)
357
{
358
m_promiscRx
= cb;
359
m_mac
->
SetPromisc
();
360
}
361
362
bool
363
WifiNetDevice::SupportsSendFrom
(
void
)
const
364
{
365
return
m_mac
->
SupportsSendFrom
();
366
}
367
368
}
// namespace ns3
369
src
wifi
model
wifi-net-device.cc
Generated on Tue Oct 9 2012 16:45:49 for ns-3 by
1.8.1.2