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-mac.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 "
wifi-mac.h
"
21
#include "
dcf.h
"
22
#include "ns3/uinteger.h"
23
#include "ns3/trace-source-accessor.h"
24
25
namespace
ns3 {
26
27
NS_OBJECT_ENSURE_REGISTERED
(WifiMac);
28
29
Time
30
WifiMac::GetDefaultMaxPropagationDelay
(
void
)
31
{
32
// 1000m
33
return
Seconds
(1000.0 / 300000000.0);
34
}
35
Time
36
WifiMac::GetDefaultSlot
(
void
)
37
{
38
// 802.11-a specific
39
return
MicroSeconds
(9);
40
}
41
Time
42
WifiMac::GetDefaultSifs
(
void
)
43
{
44
// 802.11-a specific
45
return
MicroSeconds
(16);
46
}
47
Time
48
WifiMac::GetDefaultEifsNoDifs
(
void
)
49
{
50
return
GetDefaultSifs
() +
GetDefaultCtsAckDelay
();
51
}
52
Time
53
WifiMac::GetDefaultCtsAckDelay
(
void
)
54
{
55
// 802.11-a specific: 6mb/s
56
return
MicroSeconds
(44);
57
}
58
Time
59
WifiMac::GetDefaultCtsAckTimeout
(
void
)
60
{
61
/* Cts_Timeout and Ack_Timeout are specified in the Annex C
62
(Formal description of MAC operation, see details on the
63
Trsp timer setting at page 346)
64
*/
65
Time
ctsTimeout =
GetDefaultSifs
();
66
ctsTimeout +=
GetDefaultCtsAckDelay
();
67
ctsTimeout +=
MicroSeconds
(
GetDefaultMaxPropagationDelay
().GetMicroSeconds () * 2);
68
ctsTimeout +=
GetDefaultSlot
();
69
return
ctsTimeout;
70
}
71
72
Time
73
WifiMac::GetDefaultBasicBlockAckDelay
(
void
)
74
{
75
// This value must be rivisited
76
return
MicroSeconds
(250);
77
}
78
Time
79
WifiMac::GetDefaultCompressedBlockAckDelay
(
void
)
80
{
81
// This value must be rivisited
82
return
MicroSeconds
(68);
83
}
84
Time
85
WifiMac::GetDefaultBasicBlockAckTimeout
(
void
)
86
{
87
Time
blockAckTimeout =
GetDefaultSifs
();
88
blockAckTimeout +=
GetDefaultBasicBlockAckDelay
();
89
blockAckTimeout +=
MicroSeconds
(
GetDefaultMaxPropagationDelay
().GetMicroSeconds () * 2);
90
blockAckTimeout +=
GetDefaultSlot
();
91
return
blockAckTimeout;
92
}
93
Time
94
WifiMac::GetDefaultCompressedBlockAckTimeout
(
void
)
95
{
96
Time
blockAckTimeout =
GetDefaultSifs
();
97
blockAckTimeout +=
GetDefaultCompressedBlockAckDelay
();
98
blockAckTimeout +=
MicroSeconds
(
GetDefaultMaxPropagationDelay
().GetMicroSeconds () * 2);
99
blockAckTimeout +=
GetDefaultSlot
();
100
return
blockAckTimeout;
101
}
102
103
void
104
WifiMac::SetBasicBlockAckTimeout
(
Time
blockAckTimeout)
105
{
106
//this method must be implemented by QoS WifiMacs
107
}
108
109
Time
110
WifiMac::GetBasicBlockAckTimeout
(
void
)
const
111
{
112
//this method must be implemented by QoS WifiMacs
113
return
MicroSeconds
(0);
114
}
115
116
void
117
WifiMac::SetCompressedBlockAckTimeout
(
Time
blockAckTimeout)
118
{
119
//this methos must be implemented by QoS WifiMacs
120
}
121
122
Time
123
WifiMac::GetCompressedBlockAckTimeout
(
void
)
const
124
{
125
//this method must be implemented by QoS WifiMacs
126
return
MicroSeconds
(0);
127
}
128
129
TypeId
130
WifiMac::GetTypeId
(
void
)
131
{
132
static
TypeId
tid =
TypeId
(
"ns3::WifiMac"
)
133
.
SetParent
<
Object
> ()
134
.AddAttribute (
"CtsTimeout"
,
"When this timeout expires, the RTS/CTS handshake has failed."
,
135
TimeValue
(
GetDefaultCtsAckTimeout
()),
136
MakeTimeAccessor (&
WifiMac::SetCtsTimeout
,
137
&
WifiMac::GetCtsTimeout
),
138
MakeTimeChecker ())
139
.AddAttribute (
"AckTimeout"
,
"When this timeout expires, the DATA/ACK handshake has failed."
,
140
TimeValue
(
GetDefaultCtsAckTimeout
()),
141
MakeTimeAccessor (&
WifiMac::GetAckTimeout
,
142
&
WifiMac::SetAckTimeout
),
143
MakeTimeChecker ())
144
.AddAttribute (
"BasicBlockAckTimeout"
,
"When this timeout expires, the BASIC_BLOCK_ACK_REQ/BASIC_BLOCK_ACK handshake has failed."
,
145
TimeValue
(
GetDefaultBasicBlockAckTimeout
()),
146
MakeTimeAccessor (&
WifiMac::GetBasicBlockAckTimeout
,
147
&
WifiMac::SetBasicBlockAckTimeout
),
148
MakeTimeChecker ())
149
.AddAttribute (
"CompressedBlockAckTimeout"
,
"When this timeout expires, the COMPRESSED_BLOCK_ACK_REQ/COMPRESSED_BLOCK_ACK handshake has failed."
,
150
TimeValue
(
GetDefaultCompressedBlockAckTimeout
()),
151
MakeTimeAccessor (&
WifiMac::GetCompressedBlockAckTimeout
,
152
&
WifiMac::SetCompressedBlockAckTimeout
),
153
MakeTimeChecker ())
154
.AddAttribute (
"Sifs"
,
"The value of the SIFS constant."
,
155
TimeValue
(
GetDefaultSifs
()),
156
MakeTimeAccessor (&
WifiMac::SetSifs
,
157
&
WifiMac::GetSifs
),
158
MakeTimeChecker ())
159
.AddAttribute (
"EifsNoDifs"
,
"The value of EIFS-DIFS"
,
160
TimeValue
(
GetDefaultEifsNoDifs
()),
161
MakeTimeAccessor (&
WifiMac::SetEifsNoDifs
,
162
&
WifiMac::GetEifsNoDifs
),
163
MakeTimeChecker ())
164
.AddAttribute (
"Slot"
,
"The duration of a Slot."
,
165
TimeValue
(
GetDefaultSlot
()),
166
MakeTimeAccessor (&
WifiMac::SetSlot
,
167
&
WifiMac::GetSlot
),
168
MakeTimeChecker ())
169
.AddAttribute (
"Pifs"
,
"The value of the PIFS constant."
,
170
TimeValue
(
GetDefaultSifs
() +
GetDefaultSlot
()),
171
MakeTimeAccessor (&
WifiMac::SetPifs
,
172
&
WifiMac::GetPifs
),
173
MakeTimeChecker ())
174
.AddAttribute (
"MaxPropagationDelay"
,
"The maximum propagation delay. Unused for now."
,
175
TimeValue
(
GetDefaultMaxPropagationDelay
()),
176
MakeTimeAccessor (&
WifiMac::m_maxPropagationDelay
),
177
MakeTimeChecker ())
178
.AddAttribute (
"Ssid"
,
"The ssid we want to belong to."
,
179
SsidValue
(
Ssid
(
"default"
)),
180
MakeSsidAccessor (&
WifiMac::GetSsid
,
181
&
WifiMac::SetSsid
),
182
MakeSsidChecker ())
183
.AddTraceSource (
"MacTx"
,
184
"A packet has been received from higher layers and is being processed in preparation for "
185
"queueing for transmission."
,
186
MakeTraceSourceAccessor
(&
WifiMac::m_macTxTrace
))
187
.AddTraceSource (
"MacTxDrop"
,
188
"A packet has been dropped in the MAC layer before being queued for transmission."
,
189
MakeTraceSourceAccessor
(&
WifiMac::m_macTxDropTrace
))
190
.AddTraceSource (
"MacPromiscRx"
,
191
"A packet has been received by this device, has been passed up from the physical layer "
192
"and is being forwarded up the local protocol stack. This is a promiscuous trace,"
,
193
MakeTraceSourceAccessor
(&
WifiMac::m_macPromiscRxTrace
))
194
.AddTraceSource (
"MacRx"
,
195
"A packet has been received by this device, has been passed up from the physical layer "
196
"and is being forwarded up the local protocol stack. This is a non-promiscuous trace,"
,
197
MakeTraceSourceAccessor
(&
WifiMac::m_macRxTrace
))
198
.AddTraceSource (
"MacRxDrop"
,
199
"A packet has been dropped in the MAC layer after it has been passed up from the physical "
200
"layer."
,
201
MakeTraceSourceAccessor
(&
WifiMac::m_macRxDropTrace
))
202
#
if
0
203
// Not currently implemented in this device
204
.AddTraceSource (
"Sniffer"
,
205
"Trace source simulating a non-promiscuous packet sniffer attached to the device"
,
206
MakeTraceSourceAccessor
(&WifiMac::m_snifferTrace))
207
#endif
208
;
209
210
return
tid;
211
}
212
213
void
214
WifiMac::SetMaxPropagationDelay
(
Time
delay)
215
{
216
m_maxPropagationDelay
= delay;
217
}
218
219
Time
220
WifiMac::GetMsduLifetime
(
void
)
const
221
{
222
return
Seconds
(10);
223
}
224
Time
225
WifiMac::GetMaxPropagationDelay
(
void
)
const
226
{
227
return
m_maxPropagationDelay
;
228
}
229
230
void
231
WifiMac::NotifyTx
(
Ptr<const Packet>
packet)
232
{
233
m_macTxTrace
(packet);
234
}
235
236
void
237
WifiMac::NotifyTxDrop
(
Ptr<const Packet>
packet)
238
{
239
m_macTxDropTrace
(packet);
240
}
241
242
void
243
WifiMac::NotifyRx
(
Ptr<const Packet>
packet)
244
{
245
m_macRxTrace
(packet);
246
}
247
248
void
249
WifiMac::NotifyPromiscRx
(
Ptr<const Packet>
packet)
250
{
251
m_macPromiscRxTrace
(packet);
252
}
253
254
void
255
WifiMac::NotifyRxDrop
(
Ptr<const Packet>
packet)
256
{
257
m_macRxDropTrace
(packet);
258
}
259
260
void
261
WifiMac::ConfigureStandard
(
enum
WifiPhyStandard
standard)
262
{
263
switch
(standard)
264
{
265
case
WIFI_PHY_STANDARD_80211a
:
266
Configure80211a
();
267
break
;
268
case
WIFI_PHY_STANDARD_80211b
:
269
Configure80211b
();
270
break
;
271
case
WIFI_PHY_STANDARD_80211g
:
272
Configure80211g
();
273
break
;
274
case
WIFI_PHY_STANDARD_80211_10MHZ
:
275
Configure80211_10Mhz
();
276
break
;
277
case
WIFI_PHY_STANDARD_80211_5MHZ
:
278
Configure80211_5Mhz
();
279
break
;
280
case
WIFI_PHY_STANDARD_holland
:
281
Configure80211a
();
282
break
;
283
case
WIFI_PHY_STANDARD_80211p_CCH
:
284
Configure80211p_CCH
();
285
break
;
286
case
WIFI_PHY_STANDARD_80211p_SCH
:
287
Configure80211p_SCH
();
288
break
;
289
default
:
290
NS_ASSERT
(
false
);
291
break
;
292
}
293
FinishConfigureStandard
(standard);
294
}
295
296
void
297
WifiMac::Configure80211a
(
void
)
298
{
299
SetSifs
(
MicroSeconds
(16));
300
SetSlot
(
MicroSeconds
(9));
301
SetEifsNoDifs
(
MicroSeconds
(16 + 44));
302
SetPifs
(
MicroSeconds
(16 + 9));
303
SetCtsTimeout
(
MicroSeconds
(16 + 44 + 9 +
GetDefaultMaxPropagationDelay
().GetMicroSeconds () * 2));
304
SetAckTimeout
(
MicroSeconds
(16 + 44 + 9 +
GetDefaultMaxPropagationDelay
().GetMicroSeconds () * 2));
305
}
306
307
void
308
WifiMac::Configure80211b
(
void
)
309
{
310
SetSifs
(
MicroSeconds
(10));
311
SetSlot
(
MicroSeconds
(20));
312
SetEifsNoDifs
(
MicroSeconds
(10 + 304));
313
SetPifs
(
MicroSeconds
(10 + 20));
314
SetCtsTimeout
(
MicroSeconds
(10 + 304 + 20 +
GetDefaultMaxPropagationDelay
().GetMicroSeconds () * 2));
315
SetAckTimeout
(
MicroSeconds
(10 + 304 + 20 +
GetDefaultMaxPropagationDelay
().GetMicroSeconds () * 2));
316
}
317
318
void
319
WifiMac::Configure80211g
(
void
)
320
{
321
SetSifs
(
MicroSeconds
(10));
322
// Note no support for Short Slot Time as yet
323
SetSlot
(
MicroSeconds
(20));
324
SetEifsNoDifs
(
MicroSeconds
(10 + 304));
325
SetPifs
(
MicroSeconds
(10 + 20));
326
SetCtsTimeout
(
MicroSeconds
(10 + 304 + 20 +
GetDefaultMaxPropagationDelay
().GetMicroSeconds () * 2));
327
SetAckTimeout
(
MicroSeconds
(10 + 304 + 20 +
GetDefaultMaxPropagationDelay
().GetMicroSeconds () * 2));
328
}
329
330
void
331
WifiMac::Configure80211_10Mhz
(
void
)
332
{
333
SetSifs
(
MicroSeconds
(32));
334
SetSlot
(
MicroSeconds
(13));
335
SetEifsNoDifs
(
MicroSeconds
(32 + 88));
336
SetPifs
(
MicroSeconds
(32 + 13));
337
SetCtsTimeout
(
MicroSeconds
(32 + 88 + 13 +
GetDefaultMaxPropagationDelay
().GetMicroSeconds () * 2));
338
SetAckTimeout
(
MicroSeconds
(32 + 88 + 13 +
GetDefaultMaxPropagationDelay
().GetMicroSeconds () * 2));
339
}
340
341
void
342
WifiMac::Configure80211_5Mhz
(
void
)
343
{
344
SetSifs
(
MicroSeconds
(64));
345
SetSlot
(
MicroSeconds
(21));
346
SetEifsNoDifs
(
MicroSeconds
(64 + 176));
347
SetPifs
(
MicroSeconds
(64 + 21));
348
SetCtsTimeout
(
MicroSeconds
(64 + 176 + 21 +
GetDefaultMaxPropagationDelay
().GetMicroSeconds () * 2));
349
SetAckTimeout
(
MicroSeconds
(64 + 176 + 21 +
GetDefaultMaxPropagationDelay
().GetMicroSeconds () * 2));
350
}
351
352
void
353
WifiMac::Configure80211p_CCH
(
void
)
354
{
355
Configure80211_10Mhz
();
356
}
357
358
void
359
WifiMac::Configure80211p_SCH
(
void
)
360
{
361
Configure80211_10Mhz
();
362
}
363
364
void
365
WifiMac::ConfigureDcf
(
Ptr<Dcf>
dcf, uint32_t cwmin, uint32_t cwmax,
enum
AcIndex
ac)
366
{
367
/* see IEE802.11 section 7.3.2.29 */
368
switch
(ac)
369
{
370
case
AC_VO
:
371
dcf->SetMinCw ((cwmin + 1) / 4 - 1);
372
dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
373
dcf->SetAifsn (2);
374
break
;
375
case
AC_VI
:
376
dcf->SetMinCw ((cwmin + 1) / 2 - 1);
377
dcf->SetMaxCw (cwmin);
378
dcf->SetAifsn (2);
379
break
;
380
case
AC_BE
:
381
dcf->SetMinCw (cwmin);
382
dcf->SetMaxCw (cwmax);
383
dcf->SetAifsn (3);
384
break
;
385
case
AC_BK
:
386
dcf->SetMinCw (cwmin);
387
dcf->SetMaxCw (cwmax);
388
dcf->SetAifsn (7);
389
break
;
390
case
AC_BE_NQOS
:
391
dcf->SetMinCw (cwmin);
392
dcf->SetMaxCw (cwmax);
393
dcf->SetAifsn (2);
394
break
;
395
case
AC_UNDEF
:
396
NS_FATAL_ERROR
(
"I don't know what to do with this"
);
397
break
;
398
}
399
}
400
401
void
402
WifiMac::ConfigureCCHDcf
(
Ptr<Dcf>
dcf, uint32_t cwmin, uint32_t cwmax,
enum
AcIndex
ac)
403
{
404
/* see IEEE 1609.4-2006 section 6.3.1, Table 1 */
405
switch
(ac)
406
{
407
case
AC_VO
:
408
dcf->SetMinCw ((cwmin + 1) / 4 - 1);
409
dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
410
dcf->SetAifsn (2);
411
break
;
412
case
AC_VI
:
413
dcf->SetMinCw ((cwmin + 1) / 4 - 1);
414
dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
415
dcf->SetAifsn (3);
416
break
;
417
case
AC_BE
:
418
dcf->SetMinCw ((cwmin + 1) / 2 - 1);
419
dcf->SetMaxCw (cwmin);
420
dcf->SetAifsn (6);
421
break
;
422
case
AC_BK
:
423
dcf->SetMinCw (cwmin);
424
dcf->SetMaxCw (cwmax);
425
dcf->SetAifsn (9);
426
break
;
427
case
AC_BE_NQOS
:
428
dcf->SetMinCw (cwmin);
429
dcf->SetMaxCw (cwmax);
430
dcf->SetAifsn (2);
431
break
;
432
case
AC_UNDEF
:
433
NS_FATAL_ERROR
(
"I don't know what to do with this"
);
434
break
;
435
}
436
}
437
}
// namespace ns3
src
wifi
model
wifi-mac.cc
Generated on Tue Oct 9 2012 16:45:49 for ns-3 by
1.8.1.2