A Discrete-Event Network Simulator
API
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 
21 #include "ns3/log.h"
22 #include "ns3/packet.h"
23 #include "wifi-mac.h"
24 #include "txop.h"
25 #include "ssid.h"
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("WifiMac");
30 
32 
33 Time
35 {
36  //1000m
37  return Seconds (1000.0 / 300000000.0);
38 }
39 
40 Time
42 {
43  //802.11-a specific
44  return MicroSeconds (9);
45 }
46 
47 Time
49 {
50  //802.11-a specific
51  return MicroSeconds (16);
52 }
53 
54 Time
56 {
57  //802.11n specific
58  return MicroSeconds (2);
59 }
60 
61 Time
63 {
65 }
66 
67 Time
69 {
70  //802.11-a specific: at 6 Mbit/s
71  return MicroSeconds (44);
72 }
73 
74 Time
76 {
77  /* Cts_Timeout and Ack_Timeout are specified in the Annex C
78  (Formal description of MAC operation, see details on the
79  Trsp timer setting at page 346)
80  */
81  Time ctsTimeout = GetDefaultSifs ();
82  ctsTimeout += GetDefaultCtsAckDelay ();
83  ctsTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
84  ctsTimeout += GetDefaultSlot ();
85  return ctsTimeout;
86 }
87 
88 Time
90 {
91  //This value must be rivisited
92  return MicroSeconds (250);
93 }
94 
95 Time
97 {
98  //This value must be rivisited
99  //CompressedBlockAckSize 32 * 8 * time it takes to transfer at the lowest rate (at 6 Mbit/s) + aPhy-StartDelay (33)
100  return MicroSeconds (76);
101 }
102 
103 Time
105 {
106  Time blockAckTimeout = GetDefaultSifs ();
107  blockAckTimeout += GetDefaultBasicBlockAckDelay ();
108  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
109  blockAckTimeout += GetDefaultSlot ();
110  return blockAckTimeout;
111 }
112 
113 Time
115 {
116  Time blockAckTimeout = GetDefaultSifs ();
117  blockAckTimeout += GetDefaultCompressedBlockAckDelay ();
118  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
119  blockAckTimeout += GetDefaultSlot ();
120  return blockAckTimeout;
121 }
122 
123 TypeId
125 {
126  static TypeId tid = TypeId ("ns3::WifiMac")
127  .SetParent<Object> ()
128  .SetGroupName ("Wifi")
129  .AddAttribute ("CtsTimeout", "When this timeout expires, the RTS/CTS handshake has failed.",
133  MakeTimeChecker ())
134  .AddAttribute ("AckTimeout", "When this timeout expires, the DATA/ACK handshake has failed.",
138  MakeTimeChecker ())
139  .AddAttribute ("BasicBlockAckTimeout", "When this timeout expires, the BASIC_BLOCK_ACK_REQ/BASIC_BLOCK_ACK handshake has failed.",
143  MakeTimeChecker ())
144  .AddAttribute ("CompressedBlockAckTimeout", "When this timeout expires, the COMPRESSED_BLOCK_ACK_REQ/COMPRESSED_BLOCK_ACK handshake has failed.",
148  MakeTimeChecker ())
149  .AddAttribute ("Sifs", "The value of the SIFS constant.",
153  MakeTimeChecker ())
154  .AddAttribute ("EifsNoDifs", "The value of EIFS-DIFS.",
158  MakeTimeChecker ())
159  .AddAttribute ("Slot", "The duration of a Slot.",
163  MakeTimeChecker ())
164  .AddAttribute ("Pifs", "The value of the PIFS constant.",
168  MakeTimeChecker ())
169  .AddAttribute ("Rifs", "The value of the RIFS constant.",
173  MakeTimeChecker ())
174  .AddAttribute ("MaxPropagationDelay", "The maximum propagation delay. Unused for now.",
177  MakeTimeChecker ())
178  .AddAttribute ("Ssid", "The ssid we want to belong to.",
179  SsidValue (Ssid ("default")),
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.",
187  "ns3::Packet::TracedCallback")
188  .AddTraceSource ("MacTxDrop",
189  "A packet has been dropped in the MAC layer before transmission.",
191  "ns3::Packet::TracedCallback")
192  .AddTraceSource ("MacPromiscRx",
193  "A packet has been received by this device, has been passed up from the physical layer "
194  "and is being forwarded up the local protocol stack. This is a promiscuous trace.",
196  "ns3::Packet::TracedCallback")
197  .AddTraceSource ("MacRx",
198  "A packet has been received by this device, has been passed up from the physical layer "
199  "and is being forwarded up the local protocol stack. This is a non-promiscuous trace.",
201  "ns3::Packet::TracedCallback")
202  .AddTraceSource ("MacRxDrop",
203  "A packet has been dropped in the MAC layer after it has been passed up from the physical layer.",
205  "ns3::Packet::TracedCallback")
206  ;
207  return tid;
208 }
209 
210 void
212 {
213  NS_LOG_FUNCTION (this << delay);
214  m_maxPropagationDelay = delay;
215 }
216 
217 void
219 {
220  m_macTxTrace (packet);
221 }
222 
223 void
225 {
226  m_macTxDropTrace (packet);
227 }
228 
229 void
231 {
232  m_macRxTrace (packet);
233 }
234 
235 void
237 {
238  m_macPromiscRxTrace (packet);
239 }
240 
241 void
243 {
244  m_macRxDropTrace (packet);
245 }
246 
247 void
249 {
250  NS_LOG_FUNCTION (this << standard);
251  switch (standard)
252  {
254  Configure80211a ();
255  break;
257  Configure80211b ();
258  break;
260  Configure80211g ();
261  break;
264  break;
267  break;
269  Configure80211a ();
270  break;
273  break;
276  break;
278  Configure80211ac ();
279  break;
282  break;
285  break;
287  default:
288  NS_FATAL_ERROR ("Wifi standard not found");
289  break;
290  }
291  FinishConfigureStandard (standard);
292 }
293 
294 void
296 {
297  NS_LOG_FUNCTION (this);
298  SetSifs (MicroSeconds (16));
299  SetSlot (MicroSeconds (9));
300  SetEifsNoDifs (MicroSeconds (16 + 44));
301  SetPifs (MicroSeconds (16 + 9));
302  SetCtsTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
303  SetAckTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
304 }
305 
306 void
308 {
309  NS_LOG_FUNCTION (this);
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
320 {
321  NS_LOG_FUNCTION (this);
322  SetSifs (MicroSeconds (10));
323  // Slot time defaults to the "long slot time" of 20 us in the standard
324  // according to mixed 802.11b/g deployments. Short slot time is enabled
325  // if the user sets the ShortSlotTimeSupported flag to true and when the BSS
326  // consists of only ERP STAs capable of supporting this option.
327  SetSlot (MicroSeconds (20));
328  SetEifsNoDifs (MicroSeconds (10 + 304));
329  SetPifs (MicroSeconds (10 + 20));
330  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
331  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
332 }
333 
334 void
336 {
337  NS_LOG_FUNCTION (this);
338  SetSifs (MicroSeconds (32));
339  SetSlot (MicroSeconds (13));
340  SetEifsNoDifs (MicroSeconds (32 + 88));
341  SetPifs (MicroSeconds (32 + 13));
342  SetCtsTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
343  SetAckTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
344 }
345 
346 void
348 {
349  NS_LOG_FUNCTION (this);
350  SetSifs (MicroSeconds (64));
351  SetSlot (MicroSeconds (21));
352  SetEifsNoDifs (MicroSeconds (64 + 176));
353  SetPifs (MicroSeconds (64 + 21));
354  SetCtsTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
355  SetAckTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
356 }
357 
358 void
360 {
361  NS_LOG_FUNCTION (this);
362  Configure80211g ();
363  SetRifs (MicroSeconds (2));
366 }
367 void
369 {
370  NS_LOG_FUNCTION (this);
371  Configure80211a ();
372  SetRifs (MicroSeconds (2));
375 }
376 
377 void
379 {
380  NS_LOG_FUNCTION (this);
382 }
383 
384 void
386 {
387  NS_LOG_FUNCTION (this);
389 }
390 
391 void
393 {
394  NS_LOG_FUNCTION (this);
395  Configure80211ac ();
396 }
397 
398 void
399 WifiMac::ConfigureDcf (Ptr<Txop> dcf, uint32_t cwmin, uint32_t cwmax, bool isDsss, AcIndex ac)
400 {
401  NS_LOG_FUNCTION (this << dcf << cwmin << cwmax << isDsss << ac);
402  /* see IEE802.11 section 7.3.2.29 */
403  switch (ac)
404  {
405  case AC_VO:
406  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
407  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
408  dcf->SetAifsn (2);
409  if (isDsss)
410  {
411  dcf->SetTxopLimit (MicroSeconds (3264));
412  }
413  else
414  {
415  dcf->SetTxopLimit (MicroSeconds (1504));
416  }
417  break;
418  case AC_VI:
419  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
420  dcf->SetMaxCw (cwmin);
421  dcf->SetAifsn (2);
422  if (isDsss)
423  {
424  dcf->SetTxopLimit (MicroSeconds (6016));
425  }
426  else
427  {
428  dcf->SetTxopLimit (MicroSeconds (3008));
429  }
430  break;
431  case AC_BE:
432  dcf->SetMinCw (cwmin);
433  dcf->SetMaxCw (cwmax);
434  dcf->SetAifsn (3);
435  dcf->SetTxopLimit (MicroSeconds (0));
436  break;
437  case AC_BK:
438  dcf->SetMinCw (cwmin);
439  dcf->SetMaxCw (cwmax);
440  dcf->SetAifsn (7);
441  dcf->SetTxopLimit (MicroSeconds (0));
442  break;
443  case AC_BE_NQOS:
444  dcf->SetMinCw (cwmin);
445  dcf->SetMaxCw (cwmax);
446  dcf->SetAifsn (2);
447  dcf->SetTxopLimit (MicroSeconds (0));
448  break;
449  case AC_UNDEF:
450  NS_FATAL_ERROR ("I don't know what to do with this");
451  break;
452  }
453 }
454 
455 } //namespace ns3
456 
ERP-OFDM PHY (Clause 19, Section 19.5)
virtual Time GetPifs(void) const =0
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
OFDM PHY for the 5 GHz band (Clause 17 with 5 MHz channel bandwidth)
virtual Time GetRifs(void) const =0
virtual void SetCompressedBlockAckTimeout(Time blockAckTimeout)=0
void Configure80211b(void)
This method sets 802.11b standards-compliant defaults for following attributes: Sifs, Slot, EifsNoDifs, Pifs, CtsTimeout, and AckTimeout.
Definition: wifi-mac.cc:307
HT PHY for the 5 GHz band (clause 20)
virtual void SetPifs(Time pifs)=0
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
virtual void FinishConfigureStandard(WifiPhyStandard standard)=0
virtual void SetAckTimeout(Time ackTimeout)=0
static Time GetDefaultMaxPropagationDelay(void)
Definition: wifi-mac.cc:34
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:492
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
HE PHY for the 2.4 GHz band (clause 26)
virtual Time GetAckTimeout(void) const =0
static Time GetDefaultCtsAckDelay(void)
Definition: wifi-mac.cc:68
void Configure80211ac(void)
This method sets 802.11ac standards-compliant defaults for following attributes: Sifs, Slot, EifsNoDifs, Pifs, CtsTimeout, and AckTimeout.
Definition: wifi-mac.cc:378
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:469
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
void ConfigureStandard(WifiPhyStandard standard)
Definition: wifi-mac.cc:248
void NotifyRxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:242
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:740
virtual Time GetBasicBlockAckTimeout(void) const =0
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:477
HT PHY for the 2.4 GHz band (clause 20)
static Time GetDefaultSifs(void)
Definition: wifi-mac.cc:48
Video.
Definition: qos-utils.h:44
Voice.
Definition: qos-utils.h:46
Best Effort.
Definition: qos-utils.h:40
void ConfigureDcf(Ptr< Txop > dcf, uint32_t cwmin, uint32_t cwmax, bool isDsss, AcIndex ac)
Definition: wifi-mac.cc:399
virtual void SetSsid(Ssid ssid)=0
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void Configure80211ax_5Ghz(void)
This method sets 802.11ax 5 GHz standards-compliant defaults for following attributes: Sifs...
Definition: wifi-mac.cc:392
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
virtual Ssid GetSsid(void) const =0
Background.
Definition: qos-utils.h:42
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
HE PHY for the 5 GHz band (clause 26)
AttributeValue implementation for Time.
Definition: nstime.h:1076
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:462
void NotifyTxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:224
virtual Time GetSlot(void) const =0
void NotifyPromiscRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:236
void Configure80211n_5Ghz(void)
This method sets 802.11n 5 GHz standards-compliant defaults for following attributes: Sifs...
Definition: wifi-mac.cc:368
void Configure80211_10Mhz(void)
This method sets 802.11 with 10Mhz channel spacing standards-compliant defaults for following attribu...
Definition: wifi-mac.cc:335
virtual void SetBasicBlockAckTimeout(Time blockAckTimeout)=0
void NotifyTx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:218
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)
This method sets 802.11n 2.4 GHz standards-compliant defaults for following attributes: Sifs...
Definition: wifi-mac.cc:359
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
static Time GetDefaultSlot(void)
Definition: wifi-mac.cc:41
Ptr< const AttributeAccessor > MakeSsidAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: ssid.h:110
virtual void SetEifsNoDifs(Time eifsNoDifs)=0
void Configure80211g(void)
This method sets 802.11g standards-compliant defaults for following attributes: Sifs, Slot, EifsNoDifs, Pifs, CtsTimeout, and AckTimeout.
Definition: wifi-mac.cc:319
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:1077
virtual void SetCtsTimeout(Time ctsTimeout)=0
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
virtual Time GetCompressedBlockAckTimeout(void) const =0
void NotifyRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:230
static Time GetDefaultBasicBlockAckDelay(void)
Return the default basic block ACK delay.
Definition: wifi-mac.cc:89
static Time GetDefaultCompressedBlockAckDelay(void)
Return the default compressed block ACK delay.
Definition: wifi-mac.cc:96
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:485
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: txop.cc:175
void SetMaxPropagationDelay(Time delay)
Definition: wifi-mac.cc:211
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: txop.cc:187
void Configure80211a(void)
This method sets 802.11a standards-compliant defaults for following attributes: Sifs, Slot, EifsNoDifs, Pifs, CtsTimeout, and AckTimeout.
Definition: wifi-mac.cc:295
Ptr< const AttributeChecker > MakeSsidChecker(void)
Definition: ssid.cc:118
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: txop.cc:264
void Configure80211_5Mhz()
This method sets 802.11 with 5Mhz channel spacing standards-compliant defaults for following attribut...
Definition: wifi-mac.cc:347
virtual void SetSifs(Time sifs)=0
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
AttributeValue implementation for Ssid.
Definition: ssid.h:110
Total number of ACs.
Definition: qos-utils.h:48
virtual Time GetSifs(void) const =0
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1030
static Time GetDefaultCompressedBlockAckTimeout(void)
Return the default compressed block ACK timeout.
Definition: wifi-mac.cc:114
static Time GetDefaultCtsAckTimeout(void)
Definition: wifi-mac.cc:75
void SetAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS.
Definition: txop.cc:257
Time m_maxPropagationDelay
maximum propagation delay
Definition: wifi-mac.h:400
A base class which provides memory management and object aggregation.
Definition: object.h:87
static Time GetDefaultEifsNoDifs(void)
Definition: wifi-mac.cc:62
static Time GetDefaultRifs(void)
Definition: wifi-mac.cc:55
static Time GetDefaultBasicBlockAckTimeout(void)
Return the default basic block ACK timeout.
Definition: wifi-mac.cc:104
virtual Time GetCtsTimeout(void) const =0
void Configure80211ax_2_4Ghz(void)
This method sets 802.11ax 2.4 GHz standards-compliant defaults for following attributes: Sifs...
Definition: wifi-mac.cc:385
a unique identifier for an interface.
Definition: type-id.h:58
static TypeId GetTypeId(void)
Get the type ID.
Definition: wifi-mac.cc:124
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:37
virtual Time GetEifsNoDifs(void) const =0
virtual void SetSlot(Time slotTime)=0