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 "wifi-mac.h"
22 #include "ns3/log.h"
23 
24 namespace ns3 {
25 
26 NS_LOG_COMPONENT_DEFINE ("WifiMac");
27 
29 
30 Time
32 {
33  //1000m
34  return Seconds (1000.0 / 300000000.0);
35 }
36 
37 Time
39 {
40  //802.11-a specific
41  return MicroSeconds (9);
42 }
43 
44 Time
46 {
47  //802.11-a specific
48  return MicroSeconds (16);
49 }
50 
51 Time
53 {
54  //802.11n specific
55  return MicroSeconds (2);
56 }
57 
58 Time
60 {
62 }
63 
64 Time
66 {
67  //802.11-a specific: at 6 Mbit/s
68  return MicroSeconds (44);
69 }
70 
71 Time
73 {
74  /* Cts_Timeout and Ack_Timeout are specified in the Annex C
75  (Formal description of MAC operation, see details on the
76  Trsp timer setting at page 346)
77  */
78  Time ctsTimeout = GetDefaultSifs ();
79  ctsTimeout += GetDefaultCtsAckDelay ();
80  ctsTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
81  ctsTimeout += GetDefaultSlot ();
82  return ctsTimeout;
83 }
84 
85 Time
87 {
88  //This value must be rivisited
89  return MicroSeconds (250);
90 }
91 
92 Time
94 {
95  //This value must be rivisited
96  //CompressedBlockAckSize 32 * 8 * time it takes to transfer at the lowest rate (at 6 Mbit/s) + aPhy-StartDelay (33)
97  return MicroSeconds (76);
98 }
99 
100 Time
102 {
103  Time blockAckTimeout = GetDefaultSifs ();
104  blockAckTimeout += GetDefaultBasicBlockAckDelay ();
105  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
106  blockAckTimeout += GetDefaultSlot ();
107  return blockAckTimeout;
108 }
109 
110 Time
112 {
113  Time blockAckTimeout = GetDefaultSifs ();
114  blockAckTimeout += GetDefaultCompressedBlockAckDelay ();
115  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
116  blockAckTimeout += GetDefaultSlot ();
117  return blockAckTimeout;
118 }
119 
120 void
122 {
123  //this method must be implemented by QoS WifiMacs
124 }
125 
126 Time
128 {
129  //this method must be implemented by QoS WifiMacs
130  return MicroSeconds (0);
131 }
132 
133 void
135 {
136  //this methos must be implemented by QoS WifiMacs
137 }
138 
139 Time
141 {
142  //this method must be implemented by QoS WifiMacs
143  return MicroSeconds (0);
144 }
145 
146 TypeId
148 {
149  static TypeId tid = TypeId ("ns3::WifiMac")
150  .SetParent<Object> ()
151  .SetGroupName ("Wifi")
152  .AddAttribute ("CtsTimeout", "When this timeout expires, the RTS/CTS handshake has failed.",
156  MakeTimeChecker ())
157  .AddAttribute ("AckTimeout", "When this timeout expires, the DATA/ACK handshake has failed.",
161  MakeTimeChecker ())
162  .AddAttribute ("BasicBlockAckTimeout", "When this timeout expires, the BASIC_BLOCK_ACK_REQ/BASIC_BLOCK_ACK handshake has failed.",
166  MakeTimeChecker ())
167  .AddAttribute ("CompressedBlockAckTimeout", "When this timeout expires, the COMPRESSED_BLOCK_ACK_REQ/COMPRESSED_BLOCK_ACK handshake has failed.",
171  MakeTimeChecker ())
172  .AddAttribute ("Sifs", "The value of the SIFS constant.",
176  MakeTimeChecker ())
177  .AddAttribute ("EifsNoDifs", "The value of EIFS-DIFS.",
181  MakeTimeChecker ())
182  .AddAttribute ("Slot", "The duration of a Slot.",
186  MakeTimeChecker ())
187  .AddAttribute ("Pifs", "The value of the PIFS constant.",
191  MakeTimeChecker ())
192  .AddAttribute ("Rifs", "The value of the RIFS constant.",
196  MakeTimeChecker ())
197  .AddAttribute ("MaxPropagationDelay", "The maximum propagation delay. Unused for now.",
200  MakeTimeChecker ())
201  .AddAttribute ("Ssid", "The ssid we want to belong to.",
202  SsidValue (Ssid ("default")),
205  MakeSsidChecker ())
206  .AddTraceSource ("MacTx",
207  "A packet has been received from higher layers and is being processed in preparation for "
208  "queueing for transmission.",
210  "ns3::Packet::TracedCallback")
211  .AddTraceSource ("MacTxDrop",
212  "A packet has been dropped in the MAC layer before transmission.",
214  "ns3::Packet::TracedCallback")
215  .AddTraceSource ("MacPromiscRx",
216  "A packet has been received by this device, has been passed up from the physical layer "
217  "and is being forwarded up the local protocol stack. This is a promiscuous trace.",
219  "ns3::Packet::TracedCallback")
220  .AddTraceSource ("MacRx",
221  "A packet has been received by this device, has been passed up from the physical layer "
222  "and is being forwarded up the local protocol stack. This is a non-promiscuous trace.",
224  "ns3::Packet::TracedCallback")
225  .AddTraceSource ("MacRxDrop",
226  "A packet has been dropped in the MAC layer after it has been passed up from the physical layer.",
228  "ns3::Packet::TracedCallback")
229  //Not currently implemented in this device
230  /*
231  .AddTraceSource ("Sniffer",
232  "Trace source simulating a non-promiscuous packet sniffer attached to the device",
233  MakeTraceSourceAccessor (&WifiMac::m_snifferTrace))
234  */
235  ;
236  return tid;
237 }
238 
239 void
241 {
242  NS_LOG_FUNCTION (this << delay);
243  m_maxPropagationDelay = delay;
244 }
245 
246 Time
248 {
249  return Seconds (10);
250 }
251 
252 Time
254 {
255  return m_maxPropagationDelay;
256 }
257 
258 void
260 {
261  m_macTxTrace (packet);
262 }
263 
264 void
266 {
267  m_macTxDropTrace (packet);
268 }
269 
270 void
272 {
273  m_macRxTrace (packet);
274 }
275 
276 void
278 {
279  m_macPromiscRxTrace (packet);
280 }
281 
282 void
284 {
285  m_macRxDropTrace (packet);
286 }
287 
288 void
290 {
291  NS_LOG_FUNCTION (this << standard);
292  switch (standard)
293  {
295  Configure80211a ();
296  break;
298  Configure80211b ();
299  break;
301  Configure80211g ();
302  break;
305  break;
308  break;
310  Configure80211a ();
311  break;
314  break;
317  break;
319  Configure80211ac ();
320  break;
323  break;
326  break;
328  default:
329  NS_FATAL_ERROR ("Wifi standard not found");
330  break;
331  }
332  FinishConfigureStandard (standard);
333 }
334 
335 void
337 {
338  NS_LOG_FUNCTION (this);
339  SetSifs (MicroSeconds (16));
340  SetSlot (MicroSeconds (9));
341  SetEifsNoDifs (MicroSeconds (16 + 44));
342  SetPifs (MicroSeconds (16 + 9));
343  SetCtsTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
344  SetAckTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
345 }
346 
347 void
349 {
350  NS_LOG_FUNCTION (this);
351  SetSifs (MicroSeconds (10));
352  SetSlot (MicroSeconds (20));
353  SetEifsNoDifs (MicroSeconds (10 + 304));
354  SetPifs (MicroSeconds (10 + 20));
355  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
356  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
357 }
358 
359 void
361 {
362  NS_LOG_FUNCTION (this);
363  SetSifs (MicroSeconds (10));
364  // Slot time defaults to the "long slot time" of 20 us in the standard
365  // according to mixed 802.11b/g deployments. Short slot time is enabled
366  // if the user sets the ShortSlotTimeSupported flag to true and when the BSS
367  // consists of only ERP STAs capable of supporting this option.
368  SetSlot (MicroSeconds (20));
369  SetEifsNoDifs (MicroSeconds (10 + 304));
370  SetPifs (MicroSeconds (10 + 20));
371  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
372  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
373 }
374 
375 void
377 {
378  NS_LOG_FUNCTION (this);
379  SetSifs (MicroSeconds (32));
380  SetSlot (MicroSeconds (13));
381  SetEifsNoDifs (MicroSeconds (32 + 88));
382  SetPifs (MicroSeconds (32 + 13));
383  SetCtsTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
384  SetAckTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
385 }
386 
387 void
389 {
390  NS_LOG_FUNCTION (this);
391  SetSifs (MicroSeconds (64));
392  SetSlot (MicroSeconds (21));
393  SetEifsNoDifs (MicroSeconds (64 + 176));
394  SetPifs (MicroSeconds (64 + 21));
395  SetCtsTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
396  SetAckTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
397 }
398 
399 void
401 {
402  NS_LOG_FUNCTION (this);
403  Configure80211g ();
404  SetRifs (MicroSeconds (2));
407 }
408 void
410 {
411  NS_LOG_FUNCTION (this);
412  Configure80211a ();
413  SetRifs (MicroSeconds (2));
416 }
417 
418 void
420 {
421  NS_LOG_FUNCTION (this);
423 }
424 
425 void
427 {
428  NS_LOG_FUNCTION (this);
430 }
431 
432 void
434 {
435  NS_LOG_FUNCTION (this);
436  Configure80211ac ();
437 }
438 
439 void
440 WifiMac::ConfigureDcf (Ptr<DcaTxop> dcf, uint32_t cwmin, uint32_t cwmax, bool isDsss, AcIndex ac)
441 {
442  NS_LOG_FUNCTION (this << dcf << cwmin << cwmax << isDsss << ac);
443  /* see IEE802.11 section 7.3.2.29 */
444  switch (ac)
445  {
446  case AC_VO:
447  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
448  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
449  dcf->SetAifsn (2);
450  if (isDsss)
451  {
452  dcf->SetTxopLimit (MicroSeconds (3264));
453  }
454  else
455  {
456  dcf->SetTxopLimit (MicroSeconds (1504));
457  }
458  break;
459  case AC_VI:
460  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
461  dcf->SetMaxCw (cwmin);
462  dcf->SetAifsn (2);
463  if (isDsss)
464  {
465  dcf->SetTxopLimit (MicroSeconds (6016));
466  }
467  else
468  {
469  dcf->SetTxopLimit (MicroSeconds (3008));
470  }
471  break;
472  case AC_BE:
473  dcf->SetMinCw (cwmin);
474  dcf->SetMaxCw (cwmax);
475  dcf->SetAifsn (3);
476  dcf->SetTxopLimit (MicroSeconds (0));
477  break;
478  case AC_BK:
479  dcf->SetMinCw (cwmin);
480  dcf->SetMaxCw (cwmax);
481  dcf->SetAifsn (7);
482  dcf->SetTxopLimit (MicroSeconds (0));
483  break;
484  case AC_BE_NQOS:
485  dcf->SetMinCw (cwmin);
486  dcf->SetMaxCw (cwmax);
487  dcf->SetAifsn (2);
488  dcf->SetTxopLimit (MicroSeconds (0));
489  break;
490  case AC_UNDEF:
491  NS_FATAL_ERROR ("I don't know what to do with this");
492  break;
493  }
494 }
495 
496 } //namespace ns3
497 
ERP-OFDM PHY (Clause 19, Section 19.5)
virtual Time GetPifs(void) const =0
virtual void SetBasicBlockAckTimeout(Time blockAckTimeout)
Definition: wifi-mac.cc:121
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
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:348
HT PHY for the 5 GHz band (clause 20)
virtual void SetPifs(Time pifs)=0
virtual void SetCompressedBlockAckTimeout(Time blockAckTimeout)
Definition: wifi-mac.cc:134
#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
virtual Time GetCompressedBlockAckTimeout(void) const
Definition: wifi-mac.cc:140
static Time GetDefaultMaxPropagationDelay(void)
Definition: wifi-mac.cc:31
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:503
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
HE PHY for the 2.4 GHz band (clause 26)
virtual Time GetAckTimeout(void) const =0
static Time GetDefaultCtsAckDelay(void)
Definition: wifi-mac.cc:65
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:419
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:480
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
void ConfigureStandard(WifiPhyStandard standard)
Definition: wifi-mac.cc:289
void NotifyRxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:283
#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:719
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:488
HT PHY for the 2.4 GHz band (clause 20)
static Time GetDefaultSifs(void)
Definition: wifi-mac.cc:45
Video.
Definition: qos-utils.h:45
Voice.
Definition: qos-utils.h:47
Best Effort.
Definition: qos-utils.h:41
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:433
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:43
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:1055
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:473
void NotifyTxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:265
virtual Time GetSlot(void) const =0
void NotifyPromiscRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:277
void Configure80211n_5Ghz(void)
This method sets 802.11n 5 GHz standards-compliant defaults for following attributes: Sifs...
Definition: wifi-mac.cc:409
void Configure80211_10Mhz(void)
This method sets 802.11 with 10Mhz channel spacing standards-compliant defaults for following attribu...
Definition: wifi-mac.cc:376
void NotifyTx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:259
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:400
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:38
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:117
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:360
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:1056
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:253
void NotifyRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:271
void ConfigureDcf(Ptr< DcaTxop > dcf, uint32_t cwmin, uint32_t cwmax, bool isDsss, AcIndex ac)
Definition: wifi-mac.cc:440
static Time GetDefaultBasicBlockAckDelay(void)
Return the default basic block ACK delay.
Definition: wifi-mac.cc:86
static Time GetDefaultCompressedBlockAckDelay(void)
Return the default compressed block ACK delay.
Definition: wifi-mac.cc:93
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:496
void SetMaxPropagationDelay(Time delay)
Definition: wifi-mac.cc:240
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:336
Ptr< const AttributeChecker > MakeSsidChecker(void)
Definition: ssid.cc:135
void Configure80211_5Mhz()
This method sets 802.11 with 5Mhz channel spacing standards-compliant defaults for following attribut...
Definition: wifi-mac.cc:388
virtual void SetSifs(Time sifs)=0
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
AttributeValue implementation for Ssid.
Definition: ssid.h:117
Total number of ACs.
Definition: qos-utils.h:49
virtual Time GetSifs(void) const =0
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1009
static Time GetDefaultCompressedBlockAckTimeout(void)
Return the default compressed block ACK timeout.
Definition: wifi-mac.cc:111
static Time GetDefaultCtsAckTimeout(void)
Definition: wifi-mac.cc:72
Time m_maxPropagationDelay
maximum propagation delay
Definition: wifi-mac.h:411
A base class which provides memory management and object aggregation.
Definition: object.h:87
static Time GetDefaultEifsNoDifs(void)
Definition: wifi-mac.cc:59
static Time GetDefaultRifs(void)
Definition: wifi-mac.cc:52
static Time GetDefaultBasicBlockAckTimeout(void)
Return the default basic block ACK timeout.
Definition: wifi-mac.cc:101
Time GetMsduLifetime(void) const
Definition: wifi-mac.cc:247
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:426
a unique identifier for an interface.
Definition: type-id.h:58
static TypeId GetTypeId(void)
Get the type ID.
Definition: wifi-mac.cc:147
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:38
virtual Time GetBasicBlockAckTimeout(void) const
Definition: wifi-mac.cc:127
virtual Time GetEifsNoDifs(void) const =0
virtual void SetSlot(Time slotTime)=0