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 #include "wifi-net-device.h"
27 #include "ht-configuration.h"
28 #include "vht-configuration.h"
29 #include "he-configuration.h"
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("WifiMac");
34 
36 
37 Time
39 {
40  //1000m
41  return Seconds (1000.0 / 300000000.0);
42 }
43 
44 Time
46 {
47  //802.11-a specific
48  return MicroSeconds (9);
49 }
50 
51 Time
53 {
54  //802.11-a specific
55  return MicroSeconds (16);
56 }
57 
58 Time
60 {
61  //802.11n specific
62  return MicroSeconds (2);
63 }
64 
65 Time
67 {
69 }
70 
71 Time
73 {
74  //802.11-a specific: at 6 Mbit/s
75  return MicroSeconds (44);
76 }
77 
78 Time
80 {
81  /* Cts_Timeout and Ack_Timeout are specified in the Annex C
82  (Formal description of MAC operation, see details on the
83  Trsp timer setting at page 346)
84  */
85  Time ctsTimeout = GetDefaultSifs ();
86  ctsTimeout += GetDefaultCtsAckDelay ();
87  ctsTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
88  ctsTimeout += GetDefaultSlot ();
89  return ctsTimeout;
90 }
91 
92 Time
94 {
95  //This value must be revisited
96  return MicroSeconds (250);
97 }
98 
99 Time
101 {
102  //This value must be revisited
103  //CompressedBlockAckSize 32 * 8 * time it takes to transfer at the lowest rate (at 6 Mbit/s) + aPhy-StartDelay (33)
104  return MicroSeconds (76);
105 }
106 
107 Time
109 {
110  Time blockAckTimeout = GetDefaultSifs ();
111  blockAckTimeout += GetDefaultBasicBlockAckDelay ();
112  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
113  blockAckTimeout += GetDefaultSlot ();
114  return blockAckTimeout;
115 }
116 
117 Time
119 {
120  Time blockAckTimeout = GetDefaultSifs ();
121  blockAckTimeout += GetDefaultCompressedBlockAckDelay ();
122  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
123  blockAckTimeout += GetDefaultSlot ();
124  return blockAckTimeout;
125 }
126 
127 TypeId
129 {
130  static TypeId tid = TypeId ("ns3::WifiMac")
131  .SetParent<Object> ()
132  .SetGroupName ("Wifi")
133  .AddAttribute ("AckTimeout", "When this timeout expires, the Data/Ack handshake has failed.",
137  MakeTimeChecker ())
138  .AddAttribute ("BasicBlockAckTimeout", "When this timeout expires, the BASIC_BLOCK_ACK_REQ/BASIC_BLOCK_ACK handshake has failed.",
142  MakeTimeChecker ())
143  .AddAttribute ("CompressedBlockAckTimeout", "When this timeout expires, the COMPRESSED_BLOCK_ACK_REQ/COMPRESSED_BLOCK_ACK handshake has failed.",
147  MakeTimeChecker ())
148  .AddAttribute ("Sifs", "The value of the SIFS constant.",
152  MakeTimeChecker ())
153  .AddAttribute ("EifsNoDifs", "The value of EIFS-DIFS.",
157  MakeTimeChecker ())
158  .AddAttribute ("Slot", "The duration of a Slot.",
162  MakeTimeChecker ())
163  .AddAttribute ("Pifs", "The value of the PIFS constant.",
167  MakeTimeChecker ())
168  .AddAttribute ("Rifs", "The value of the RIFS constant.",
172  MakeTimeChecker ())
173  .AddAttribute ("MaxPropagationDelay", "The maximum propagation delay. Unused for now.",
176  MakeTimeChecker ())
177  .AddAttribute ("Ssid", "The ssid we want to belong to.",
178  SsidValue (Ssid ("default")),
181  MakeSsidChecker ())
182  .AddTraceSource ("MacTx",
183  "A packet has been received from higher layers and is being processed in preparation for "
184  "queueing for transmission.",
186  "ns3::Packet::TracedCallback")
187  .AddTraceSource ("MacTxDrop",
188  "A packet has been dropped in the MAC layer before transmission.",
190  "ns3::Packet::TracedCallback")
191  .AddTraceSource ("MacPromiscRx",
192  "A packet has been received by this device, has been passed up from the physical layer "
193  "and is being forwarded up the local protocol stack. This is a promiscuous trace.",
195  "ns3::Packet::TracedCallback")
196  .AddTraceSource ("MacRx",
197  "A packet has been received by this device, has been passed up from the physical layer "
198  "and is being forwarded up the local protocol stack. This is a non-promiscuous trace.",
200  "ns3::Packet::TracedCallback")
201  .AddTraceSource ("MacRxDrop",
202  "A packet has been dropped in the MAC layer after it has been passed up from the physical layer.",
204  "ns3::Packet::TracedCallback")
205  ;
206  return tid;
207 }
208 
209 void
211 {
212  m_device = 0;
213 }
214 
215 void
217 {
218  m_device = device;
219 }
220 
222 WifiMac::GetDevice (void) const
223 {
224  return m_device;
225 }
226 
227 void
229 {
230  NS_LOG_FUNCTION (this << delay);
231  m_maxPropagationDelay = delay;
232 }
233 
234 void
236 {
237  m_macTxTrace (packet);
238 }
239 
240 void
242 {
243  m_macTxDropTrace (packet);
244 }
245 
246 void
248 {
249  m_macRxTrace (packet);
250 }
251 
252 void
254 {
255  m_macPromiscRxTrace (packet);
256 }
257 
258 void
260 {
261  m_macRxDropTrace (packet);
262 }
263 
264 void
266 {
267  NS_LOG_FUNCTION (this << standard);
268  switch (standard)
269  {
271  Configure80211a ();
272  break;
274  Configure80211b ();
275  break;
277  Configure80211g ();
278  break;
281  break;
284  break;
286  Configure80211a ();
287  break;
290  break;
293  break;
295  Configure80211ac ();
296  break;
299  break;
302  break;
304  default:
305  NS_FATAL_ERROR ("Wifi standard not found");
306  break;
307  }
308  FinishConfigureStandard (standard);
309 }
310 
311 void
313 {
314  NS_LOG_FUNCTION (this);
315  SetSifs (MicroSeconds (16));
316  SetSlot (MicroSeconds (9));
317  SetEifsNoDifs (MicroSeconds (16 + 44));
318  SetPifs (MicroSeconds (16 + 9));
319  SetAckTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
320 }
321 
322 void
324 {
325  NS_LOG_FUNCTION (this);
326  SetSifs (MicroSeconds (10));
327  SetSlot (MicroSeconds (20));
328  SetEifsNoDifs (MicroSeconds (10 + 304));
329  SetPifs (MicroSeconds (10 + 20));
330  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
331 }
332 
333 void
335 {
336  NS_LOG_FUNCTION (this);
337  SetSifs (MicroSeconds (10));
338  // Slot time defaults to the "long slot time" of 20 us in the standard
339  // according to mixed 802.11b/g deployments. Short slot time is enabled
340  // if the user sets the ShortSlotTimeSupported flag to true and when the BSS
341  // consists of only ERP STAs capable of supporting this option.
342  SetSlot (MicroSeconds (20));
343  SetEifsNoDifs (MicroSeconds (10 + 304));
344  SetPifs (MicroSeconds (10 + 20));
345  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
346 }
347 
348 void
350 {
351  NS_LOG_FUNCTION (this);
352  SetSifs (MicroSeconds (32));
353  SetSlot (MicroSeconds (13));
354  SetEifsNoDifs (MicroSeconds (32 + 88));
355  SetPifs (MicroSeconds (32 + 13));
356  SetAckTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
357 }
358 
359 void
361 {
362  NS_LOG_FUNCTION (this);
363  SetSifs (MicroSeconds (64));
364  SetSlot (MicroSeconds (21));
365  SetEifsNoDifs (MicroSeconds (64 + 176));
366  SetPifs (MicroSeconds (64 + 21));
367  SetAckTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
368 }
369 
370 void
372 {
373  NS_LOG_FUNCTION (this);
374  Configure80211g ();
375  SetRifs (MicroSeconds (2));
378 }
379 void
381 {
382  NS_LOG_FUNCTION (this);
383  Configure80211a ();
384  SetRifs (MicroSeconds (2));
387 }
388 
389 void
391 {
392  NS_LOG_FUNCTION (this);
394 }
395 
396 void
398 {
399  NS_LOG_FUNCTION (this);
401 }
402 
403 void
405 {
406  NS_LOG_FUNCTION (this);
407  Configure80211ac ();
409 }
410 
411 void
412 WifiMac::ConfigureDcf (Ptr<Txop> dcf, uint32_t cwmin, uint32_t cwmax, bool isDsss, AcIndex ac)
413 {
414  NS_LOG_FUNCTION (this << dcf << cwmin << cwmax << isDsss << ac);
415  /* see IEEE 802.11 section 7.3.2.29 */
416  switch (ac)
417  {
418  case AC_VO:
419  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
420  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
421  dcf->SetAifsn (2);
422  if (isDsss)
423  {
424  dcf->SetTxopLimit (MicroSeconds (3264));
425  }
426  else
427  {
428  dcf->SetTxopLimit (MicroSeconds (1504));
429  }
430  break;
431  case AC_VI:
432  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
433  dcf->SetMaxCw (cwmin);
434  dcf->SetAifsn (2);
435  if (isDsss)
436  {
437  dcf->SetTxopLimit (MicroSeconds (6016));
438  }
439  else
440  {
441  dcf->SetTxopLimit (MicroSeconds (3008));
442  }
443  break;
444  case AC_BE:
445  dcf->SetMinCw (cwmin);
446  dcf->SetMaxCw (cwmax);
447  dcf->SetAifsn (3);
448  dcf->SetTxopLimit (MicroSeconds (0));
449  break;
450  case AC_BK:
451  dcf->SetMinCw (cwmin);
452  dcf->SetMaxCw (cwmax);
453  dcf->SetAifsn (7);
454  dcf->SetTxopLimit (MicroSeconds (0));
455  break;
456  case AC_BE_NQOS:
457  dcf->SetMinCw (cwmin);
458  dcf->SetMaxCw (cwmax);
459  dcf->SetAifsn (2);
460  dcf->SetTxopLimit (MicroSeconds (0));
461  break;
462  case AC_UNDEF:
463  NS_FATAL_ERROR ("I don't know what to do with this");
464  break;
465  }
466 }
467 
470 {
471  Ptr<WifiNetDevice> device = DynamicCast<WifiNetDevice> (GetDevice ());
472  return device->GetHtConfiguration ();
473 }
474 
477 {
478  Ptr<WifiNetDevice> device = DynamicCast<WifiNetDevice> (GetDevice ());
479  return device->GetVhtConfiguration ();
480 }
481 
484 {
485  Ptr<WifiNetDevice> device = DynamicCast<WifiNetDevice> (GetDevice ());
486  return device->GetHeConfiguration ();
487 }
488 
489 } //namespace ns3
490 
ERP-OFDM PHY (Clause 19, Section 19.5)
virtual Time GetPifs(void) const =0
Ptr< HeConfiguration > GetHeConfiguration(void) const
Definition: wifi-mac.cc:483
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#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
Ptr< HeConfiguration > GetHeConfiguration(void) const
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:323
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:38
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:516
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
HE PHY for the 2.4 GHz band (clause 26)
virtual Time GetAckTimeout(void) const =0
static Time GetDefaultCtsAckDelay(void)
Definition: wifi-mac.cc:72
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:390
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:493
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
void ConfigureStandard(WifiPhyStandard standard)
Definition: wifi-mac.cc:265
void NotifyRxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:259
#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:743
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:501
HT PHY for the 2.4 GHz band (clause 20)
static Time GetDefaultSifs(void)
Definition: wifi-mac.cc:52
Video.
Definition: qos-utils.h:45
Voice.
Definition: qos-utils.h:47
Best Effort.
Definition: qos-utils.h:41
void ConfigureDcf(Ptr< Txop > dcf, uint32_t cwmin, uint32_t cwmax, bool isDsss, AcIndex ac)
Definition: wifi-mac.cc:412
virtual void SetSsid(Ssid ssid)=0
Ptr< NetDevice > GetDevice(void) const
Return the device this PHY is associated with.
Definition: wifi-mac.cc:222
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:404
virtual Ssid GetSsid(void) const =0
Background.
Definition: qos-utils.h:43
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
Ptr< HtConfiguration > GetHtConfiguration(void) const
Definition: wifi-mac.cc:469
HE PHY for the 5 GHz band (clause 26)
void SetDevice(const Ptr< NetDevice > device)
Sets the device this PHY is associated with.
Definition: wifi-mac.cc:216
AttributeValue implementation for Time.
Definition: nstime.h:1124
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:486
void NotifyTxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:241
Ptr< const AttributeChecker > MakeSsidChecker(void)
Definition: ssid.cc:118
virtual Time GetSlot(void) const =0
void NotifyPromiscRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:253
virtual void DoDispose()
Destructor implementation.
Definition: wifi-mac.cc:210
void Configure80211n_5Ghz(void)
This method sets 802.11n 5 GHz standards-compliant defaults for following attributes: SIFS...
Definition: wifi-mac.cc:380
void Configure80211_10Mhz(void)
This method sets 802.11 with 10 MHz channel spacing standards-compliant defaults for following attrib...
Definition: wifi-mac.cc:349
virtual void SetBasicBlockAckTimeout(Time blockAckTimeout)=0
void NotifyTx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:235
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:371
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:45
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:105
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:334
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:1125
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:247
static Time GetDefaultBasicBlockAckDelay(void)
Return the default basic BlockAck delay.
Definition: wifi-mac.cc:93
static Time GetDefaultCompressedBlockAckDelay(void)
Return the default compressed BlockAck delay.
Definition: wifi-mac.cc:100
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:509
void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: txop.cc:186
void SetMaxPropagationDelay(Time delay)
Definition: wifi-mac.cc:228
void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: txop.cc:199
Ptr< VhtConfiguration > GetVhtConfiguration(void) const
Definition: wifi-mac.cc:476
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:312
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Definition: txop.cc:277
void Configure80211_5Mhz()
This method sets 802.11 with 5 MHz channel spacing standards-compliant defaults for following attribu...
Definition: wifi-mac.cc:360
virtual void SetSifs(Time sifs)=0
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
AttributeValue implementation for Ssid.
Definition: ssid.h:105
Total number of ACs.
Definition: qos-utils.h:49
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:449
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1078
static Time GetDefaultCompressedBlockAckTimeout(void)
Return the default compressed BlockAck timeout.
Definition: wifi-mac.cc:118
static Time GetDefaultCtsAckTimeout(void)
Definition: wifi-mac.cc:79
void SetAifsn(uint8_t aifsn)
Set the number of slots that make up an AIFS.
Definition: txop.cc:270
Ptr< NetDevice > m_device
Pointer to the device.
Definition: wifi-mac.h:424
Time m_maxPropagationDelay
maximum propagation delay
Definition: wifi-mac.h:423
A base class which provides memory management and object aggregation.
Definition: object.h:87
static Time GetDefaultEifsNoDifs(void)
Definition: wifi-mac.cc:66
static Time GetDefaultRifs(void)
Definition: wifi-mac.cc:59
static Time GetDefaultBasicBlockAckTimeout(void)
Return the default basic BlockAck timeout.
Definition: wifi-mac.cc:108
Ptr< VhtConfiguration > GetVhtConfiguration(void) const
void Configure80211ax_2_4Ghz(void)
This method sets 802.11ax 2.4 GHz standards-compliant defaults for following attributes: SIFS...
Definition: wifi-mac.cc:397
Ptr< HtConfiguration > GetHtConfiguration(void) const
a unique identifier for an interface.
Definition: type-id.h:58
static TypeId GetTypeId(void)
Get the type ID.
Definition: wifi-mac.cc:128
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:38
virtual Time GetEifsNoDifs(void) const =0
virtual void SetSlot(Time slotTime)=0