A Discrete-Event Network Simulator
API
 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 
28  ;
29 
30 
31 Time
33 {
34  // 1000m
35  return Seconds (1000.0 / 300000000.0);
36 }
37 Time
39 {
40  // 802.11-a specific
41  return MicroSeconds (9);
42 }
43 Time
45 {
46  // 802.11-a specific
47  return MicroSeconds (16);
48 }
49 Time
51 {
52  //802.11n specific
53  return MicroSeconds (2);
54 }
55 Time
57 {
59 }
60 Time
62 {
63  // 802.11-a specific: 6mb/s
64  return MicroSeconds (44);
65 }
66 Time
68 {
69  /* Cts_Timeout and Ack_Timeout are specified in the Annex C
70  (Formal description of MAC operation, see details on the
71  Trsp timer setting at page 346)
72  */
73  Time ctsTimeout = GetDefaultSifs ();
74  ctsTimeout += GetDefaultCtsAckDelay ();
75  ctsTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
76  ctsTimeout += GetDefaultSlot ();
77  return ctsTimeout;
78 }
79 
80 Time
82 {
83  // This value must be rivisited
84  return MicroSeconds (250);
85 }
86 Time
88 {
89  // This value must be rivisited was 68.
90  //CompressedBlockAckSize 32* 8*time it takes to transfer at the lowest rate (6Mb/s)+ aPhy-StartDelay(33)
91  return MicroSeconds (76);
92 }
93 Time
95 {
96  Time blockAckTimeout = GetDefaultSifs ();
97  blockAckTimeout += GetDefaultBasicBlockAckDelay ();
98  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
99  blockAckTimeout += GetDefaultSlot ();
100  return blockAckTimeout;
101 }
102 Time
104 {
105  Time blockAckTimeout = GetDefaultSifs ();
106  blockAckTimeout += GetDefaultCompressedBlockAckDelay ();
107  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
108  blockAckTimeout += GetDefaultSlot ();
109  return blockAckTimeout;
110 }
111 
112 void
114 {
115  //this method must be implemented by QoS WifiMacs
116 }
117 
118 Time
120 {
121  //this method must be implemented by QoS WifiMacs
122  return MicroSeconds (0);
123 }
124 
125 void
127 {
128  //this methos must be implemented by QoS WifiMacs
129 }
130 
131 Time
133 {
134  //this method must be implemented by QoS WifiMacs
135  return MicroSeconds (0);
136 }
137 
138 TypeId
140 {
141  static TypeId tid = TypeId ("ns3::WifiMac")
142  .SetParent<Object> ()
143  .AddAttribute ("CtsTimeout", "When this timeout expires, the RTS/CTS handshake has failed.",
145  MakeTimeAccessor (&WifiMac::SetCtsTimeout,
147  MakeTimeChecker ())
148  .AddAttribute ("AckTimeout", "When this timeout expires, the DATA/ACK handshake has failed.",
150  MakeTimeAccessor (&WifiMac::GetAckTimeout,
152  MakeTimeChecker ())
153  .AddAttribute ("BasicBlockAckTimeout", "When this timeout expires, the BASIC_BLOCK_ACK_REQ/BASIC_BLOCK_ACK handshake has failed.",
155  MakeTimeAccessor (&WifiMac::GetBasicBlockAckTimeout,
157  MakeTimeChecker ())
158  .AddAttribute ("CompressedBlockAckTimeout", "When this timeout expires, the COMPRESSED_BLOCK_ACK_REQ/COMPRESSED_BLOCK_ACK handshake has failed.",
160  MakeTimeAccessor (&WifiMac::GetCompressedBlockAckTimeout,
162  MakeTimeChecker ())
163  .AddAttribute ("Sifs", "The value of the SIFS constant.",
165  MakeTimeAccessor (&WifiMac::SetSifs,
167  MakeTimeChecker ())
168  .AddAttribute ("EifsNoDifs", "The value of EIFS-DIFS",
170  MakeTimeAccessor (&WifiMac::SetEifsNoDifs,
172  MakeTimeChecker ())
173  .AddAttribute ("Slot", "The duration of a Slot.",
175  MakeTimeAccessor (&WifiMac::SetSlot,
177  MakeTimeChecker ())
178  .AddAttribute ("Pifs", "The value of the PIFS constant.",
180  MakeTimeAccessor (&WifiMac::SetPifs,
182  MakeTimeChecker ())
183 .AddAttribute ("Rifs", "The value of the RIFS constant.",
185  MakeTimeAccessor (&WifiMac::SetRifs,
187  MakeTimeChecker ())
188 
189  .AddAttribute ("MaxPropagationDelay", "The maximum propagation delay. Unused for now.",
191  MakeTimeAccessor (&WifiMac::m_maxPropagationDelay),
192  MakeTimeChecker ())
193  .AddAttribute ("Ssid", "The ssid we want to belong to.",
194  SsidValue (Ssid ("default")),
195  MakeSsidAccessor (&WifiMac::GetSsid,
197  MakeSsidChecker ())
198  .AddTraceSource ("MacTx",
199  "A packet has been received from higher layers and is being processed in preparation for "
200  "queueing for transmission.",
202  .AddTraceSource ("MacTxDrop",
203  "A packet has been dropped in the MAC layer before being queued for transmission.",
205  .AddTraceSource ("MacPromiscRx",
206  "A packet has been received by this device, has been passed up from the physical layer "
207  "and is being forwarded up the local protocol stack. This is a promiscuous trace,",
209  .AddTraceSource ("MacRx",
210  "A packet has been received by this device, has been passed up from the physical layer "
211  "and is being forwarded up the local protocol stack. This is a non-promiscuous trace,",
213  .AddTraceSource ("MacRxDrop",
214  "A packet has been dropped in the MAC layer after it has been passed up from the physical "
215  "layer.",
217 #if 0
218  // Not currently implemented in this device
219  .AddTraceSource ("Sniffer",
220  "Trace source simulating a non-promiscuous packet sniffer attached to the device",
221  MakeTraceSourceAccessor (&WifiMac::m_snifferTrace))
222 #endif
223  ;
224 
225  return tid;
226 }
227 
228 void
230 {
231  m_maxPropagationDelay = delay;
232 }
233 
234 Time
236 {
237  return Seconds (10);
238 }
239 Time
241 {
242  return m_maxPropagationDelay;
243 }
244 
245 void
247 {
248  m_macTxTrace (packet);
249 }
250 
251 void
253 {
254  m_macTxDropTrace (packet);
255 }
256 
257 void
259 {
260  m_macRxTrace (packet);
261 }
262 
263 void
265 {
266  m_macPromiscRxTrace (packet);
267 }
268 
269 void
271 {
272  m_macRxDropTrace (packet);
273 }
274 
275 void
277 {
278  switch (standard)
279  {
281  Configure80211a ();
282  break;
284  Configure80211b ();
285  break;
287  Configure80211g ();
288  break;
291  break;
294  break;
296  Configure80211a ();
297  break;
300  break;
303  break;
304  default:
305  NS_ASSERT (false);
306  break;
307  }
308  FinishConfigureStandard (standard);
309 }
310 
311 void
313 {
314  SetSifs (MicroSeconds (16));
315  SetSlot (MicroSeconds (9));
316  SetEifsNoDifs (MicroSeconds (16 + 44));
317  SetPifs (MicroSeconds (16 + 9));
318  SetCtsTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
319  SetAckTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
320 }
321 
322 void
324 {
325  SetSifs (MicroSeconds (10));
326  SetSlot (MicroSeconds (20));
327  SetEifsNoDifs (MicroSeconds (10 + 304));
328  SetPifs (MicroSeconds (10 + 20));
329  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
330  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
331 }
332 
333 void
335 {
336  SetSifs (MicroSeconds (10));
337  // Note no support for Short Slot Time as yet
338  SetSlot (MicroSeconds (20));
339  SetEifsNoDifs (MicroSeconds (10 + 304));
340  SetPifs (MicroSeconds (10 + 20));
341  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
342  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
343 }
344 
345 void
347 {
348  SetSifs (MicroSeconds (32));
349  SetSlot (MicroSeconds (13));
350  SetEifsNoDifs (MicroSeconds (32 + 88));
351  SetPifs (MicroSeconds (32 + 13));
352  SetCtsTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
353  SetAckTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
354 }
355 
356 void
358 {
359  SetSifs (MicroSeconds (64));
360  SetSlot (MicroSeconds (21));
361  SetEifsNoDifs (MicroSeconds (64 + 176));
362  SetPifs (MicroSeconds (64 + 21));
363  SetCtsTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
364  SetAckTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
365 }
366 
367 void
369 {
370  Configure80211g ();
371  SetRifs(MicroSeconds (2));
372  SetCtsTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
373  SetAckTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
374 }
375 void
377 {
378  Configure80211a ();
379  SetRifs(MicroSeconds (2));
380  SetCtsTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
381  SetAckTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
382 }
383 
384 void
385 WifiMac::ConfigureDcf (Ptr<Dcf> dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
386 {
387  /* see IEE802.11 section 7.3.2.29 */
388  switch (ac)
389  {
390  case AC_VO:
391  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
392  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
393  dcf->SetAifsn (2);
394  break;
395  case AC_VI:
396  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
397  dcf->SetMaxCw (cwmin);
398  dcf->SetAifsn (2);
399  break;
400  case AC_BE:
401  dcf->SetMinCw (cwmin);
402  dcf->SetMaxCw (cwmax);
403  dcf->SetAifsn (3);
404  break;
405  case AC_BK:
406  dcf->SetMinCw (cwmin);
407  dcf->SetMaxCw (cwmax);
408  dcf->SetAifsn (7);
409  break;
410  case AC_BE_NQOS:
411  dcf->SetMinCw (cwmin);
412  dcf->SetMaxCw (cwmax);
413  dcf->SetAifsn (2);
414  break;
415  case AC_UNDEF:
416  NS_FATAL_ERROR ("I don't know what to do with this");
417  break;
418  }
419 }
420 } // namespace ns3
ERP-OFDM PHY (Clause 19, Section 19.5)
virtual void FinishConfigureStandard(enum WifiPhyStandard standard)=0
virtual Time GetPifs(void) const =0
virtual void SetBasicBlockAckTimeout(Time blockAckTimeout)
Definition: wifi-mac.cc:113
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
OFDM PHY for the 5 GHz band (Clause 17 with 5 MHz channel bandwidth)
virtual Time GetRifs(void) const =0
void Configure80211b(void)
Configure appropriate timing parameters for 802.11b.
Definition: wifi-mac.cc:323
virtual void SetPifs(Time pifs)=0
virtual void SetCompressedBlockAckTimeout(Time blockAckTimeout)
Definition: wifi-mac.cc:126
virtual void SetAckTimeout(Time ackTimeout)=0
virtual Time GetCompressedBlockAckTimeout(void) const
Definition: wifi-mac.cc:132
static Time GetDefaultMaxPropagationDelay(void)
Definition: wifi-mac.cc:32
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
void ConfigureStandard(enum WifiPhyStandard standard)
Definition: wifi-mac.cc:276
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired when packets coming into the "top" of the device are dropped at the MAC layer ...
Definition: wifi-mac.h:444
virtual Time GetAckTimeout(void) const =0
static Time GetDefaultCtsAckDelay(void)
Definition: wifi-mac.cc:61
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets coming into the "top" of the device are dropped at the MAC layer ...
Definition: wifi-mac.h:418
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
void NotifyRxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:270
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: wifi-mac.h:427
static Time GetDefaultSifs(void)
Definition: wifi-mac.cc:44
Video.
Definition: qos-utils.h:42
Voice.
Definition: qos-utils.h:44
Best Effort.
Definition: qos-utils.h:38
virtual void SetSsid(Ssid ssid)=0
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
virtual Ssid GetSsid(void) const =0
Background.
Definition: qos-utils.h:40
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
hold objects of type ns3::Time
Definition: nstime.h:961
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition...
Definition: wifi-mac.h:410
void NotifyTxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:252
void ConfigureDcf(Ptr< Dcf > dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
Definition: wifi-mac.cc:385
virtual Time GetSlot(void) const =0
void NotifyPromiscRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:264
void Configure80211n_5Ghz(void)
Configure appropriate timing parameters for 802.11n operating at 5Ghz.
Definition: wifi-mac.cc:376
void Configure80211_10Mhz(void)
Configure appropriate timing parameters for 802.11 with 10Mhz channel spacing.
Definition: wifi-mac.cc:346
void NotifyTx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:246
virtual void SetRifs(Time rifs)=0
This is intended to be the configuration used in this paper: Gavin Holland, Nitin Vaidya and Paramvir...
void Configure80211n_2_4Ghz(void)
Configure appropriate timing parameters for 802.11n operating at 2.4Ghz.
Definition: wifi-mac.cc:368
OFDM PHY for the 5 GHz band (Clause 17)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
static Time GetDefaultSlot(void)
Definition: wifi-mac.cc:38
virtual void SetEifsNoDifs(Time eifsNoDifs)=0
void Configure80211g(void)
Configure appropriate timing parameters for 802.11g.
Definition: wifi-mac.cc:334
virtual void SetCtsTimeout(Time ctsTimeout)=0
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
Time GetMaxPropagationDelay(void) const
Definition: wifi-mac.cc:240
void NotifyRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:258
static Time GetDefaultBasicBlockAckDelay(void)
Return the default basic block ACK delay.
Definition: wifi-mac.cc:81
static Time GetDefaultCompressedBlockAckDelay(void)
Return the default compressed block ACK delay.
Definition: wifi-mac.cc:87
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: wifi-mac.h:436
void SetMaxPropagationDelay(Time delay)
Definition: wifi-mac.cc:229
void Configure80211a(void)
Configure appropriate timing parameters for 802.11a.
Definition: wifi-mac.cc:312
void Configure80211_5Mhz()
Configure appropriate timing parameters for 802.11 with 5Mhz channel spacing.
Definition: wifi-mac.cc:357
virtual void SetSifs(Time sifs)=0
hold objects of type ns3::Ssid
Total number of ACs.
Definition: qos-utils.h:47
virtual Time GetSifs(void) const =0
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:452
static Time GetDefaultCompressedBlockAckTimeout(void)
Return the default compressed block ACK timeout.
Definition: wifi-mac.cc:103
static Time GetDefaultCtsAckTimeout(void)
Definition: wifi-mac.cc:67
Time m_maxPropagationDelay
Definition: wifi-mac.h:373
a base class which provides memory management and object aggregation
Definition: object.h:63
static Time GetDefaultEifsNoDifs(void)
Definition: wifi-mac.cc:56
static Time GetDefaultRifs(void)
Definition: wifi-mac.cc:50
static Time GetDefaultBasicBlockAckTimeout(void)
Return the default basic block ACK timeout.
Definition: wifi-mac.cc:94
Time GetMsduLifetime(void) const
Definition: wifi-mac.cc:235
virtual Time GetCtsTimeout(void) const =0
a unique identifier for an interface.
Definition: type-id.h:49
static TypeId GetTypeId(void)
Definition: wifi-mac.cc:139
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:35
virtual Time GetBasicBlockAckTimeout(void) const
Definition: wifi-mac.cc:119
virtual Time GetEifsNoDifs(void) const =0
virtual void SetSlot(Time slotTime)=0