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 "dcf.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/boolean.h"
25 #include "ns3/trace-source-accessor.h"
26 
27 namespace ns3 {
28 
30 
31 
32 Time
34 {
35  //1000m
36  return Seconds (1000.0 / 300000000.0);
37 }
38 
39 Time
41 {
42  //802.11-a specific
43  return MicroSeconds (9);
44 }
45 
46 Time
48 {
49  //802.11-a specific
50  return MicroSeconds (16);
51 }
52 
53 Time
55 {
56  //802.11n specific
57  return MicroSeconds (2);
58 }
59 
60 Time
62 {
64 }
65 
66 Time
68 {
69  //802.11-a specific: at 6 Mbit/s
70  return MicroSeconds (44);
71 }
72 
73 Time
75 {
76  /* Cts_Timeout and Ack_Timeout are specified in the Annex C
77  (Formal description of MAC operation, see details on the
78  Trsp timer setting at page 346)
79  */
80  Time ctsTimeout = GetDefaultSifs ();
81  ctsTimeout += GetDefaultCtsAckDelay ();
82  ctsTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
83  ctsTimeout += GetDefaultSlot ();
84  return ctsTimeout;
85 }
86 
87 Time
89 {
90  //This value must be rivisited
91  return MicroSeconds (250);
92 }
93 
94 Time
96 {
97  //This value must be rivisited
98  //CompressedBlockAckSize 32 * 8 * time it takes to transfer at the lowest rate (at 6 Mbit/s) + aPhy-StartDelay (33)
99  return MicroSeconds (76);
100 }
101 
102 Time
104 {
105  Time blockAckTimeout = GetDefaultSifs ();
106  blockAckTimeout += GetDefaultBasicBlockAckDelay ();
107  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
108  blockAckTimeout += GetDefaultSlot ();
109  return blockAckTimeout;
110 }
111 
112 Time
114 {
115  Time blockAckTimeout = GetDefaultSifs ();
116  blockAckTimeout += GetDefaultCompressedBlockAckDelay ();
117  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
118  blockAckTimeout += GetDefaultSlot ();
119  return blockAckTimeout;
120 }
121 
122 void
124 {
125  //this method must be implemented by QoS WifiMacs
126 }
127 
128 Time
130 {
131  //this method must be implemented by QoS WifiMacs
132  return MicroSeconds (0);
133 }
134 
135 void
137 {
138  //this methos must be implemented by QoS WifiMacs
139 }
140 
141 Time
143 {
144  //this method must be implemented by QoS WifiMacs
145  return MicroSeconds (0);
146 }
147 
148 TypeId
150 {
151  static TypeId tid = TypeId ("ns3::WifiMac")
152  .SetParent<Object> ()
153  .SetGroupName ("Wifi")
154  .AddAttribute ("CtsTimeout", "When this timeout expires, the RTS/CTS handshake has failed.",
158  MakeTimeChecker ())
159  .AddAttribute ("AckTimeout", "When this timeout expires, the DATA/ACK handshake has failed.",
163  MakeTimeChecker ())
164  .AddAttribute ("BasicBlockAckTimeout", "When this timeout expires, the BASIC_BLOCK_ACK_REQ/BASIC_BLOCK_ACK handshake has failed.",
168  MakeTimeChecker ())
169  .AddAttribute ("CompressedBlockAckTimeout", "When this timeout expires, the COMPRESSED_BLOCK_ACK_REQ/COMPRESSED_BLOCK_ACK handshake has failed.",
173  MakeTimeChecker ())
174  .AddAttribute ("Sifs", "The value of the SIFS constant.",
178  MakeTimeChecker ())
179  .AddAttribute ("EifsNoDifs", "The value of EIFS-DIFS.",
183  MakeTimeChecker ())
184  .AddAttribute ("Slot", "The duration of a Slot.",
188  MakeTimeChecker ())
189  .AddAttribute ("Pifs", "The value of the PIFS constant.",
193  MakeTimeChecker ())
194  .AddAttribute ("Rifs", "The value of the RIFS constant.",
198  MakeTimeChecker ())
199  .AddAttribute ("MaxPropagationDelay", "The maximum propagation delay. Unused for now.",
202  MakeTimeChecker ())
203  .AddAttribute ("Ssid", "The ssid we want to belong to.",
204  SsidValue (Ssid ("default")),
207  MakeSsidChecker ())
208  .AddTraceSource ("MacTx",
209  "A packet has been received from higher layers and is being processed in preparation for "
210  "queueing for transmission.",
212  "ns3::Packet::TracedCallback")
213  .AddTraceSource ("MacTxDrop",
214  "A packet has been dropped in the MAC layer before being queued for transmission.",
216  "ns3::Packet::TracedCallback")
217  .AddTraceSource ("MacPromiscRx",
218  "A packet has been received by this device, has been passed up from the physical layer "
219  "and is being forwarded up the local protocol stack. This is a promiscuous trace.",
221  "ns3::Packet::TracedCallback")
222  .AddTraceSource ("MacRx",
223  "A packet has been received by this device, has been passed up from the physical layer "
224  "and is being forwarded up the local protocol stack. This is a non-promiscuous trace.",
226  "ns3::Packet::TracedCallback")
227  .AddTraceSource ("MacRxDrop",
228  "A packet has been dropped in the MAC layer after it has been passed up from the physical layer.",
230  "ns3::Packet::TracedCallback")
231  //Not currently implemented in this device
232  /*
233  .AddTraceSource ("Sniffer",
234  "Trace source simulating a non-promiscuous packet sniffer attached to the device",
235  MakeTraceSourceAccessor (&WifiMac::m_snifferTrace))
236  */
237  ;
238  return tid;
239 }
240 
241 void
243 {
244  m_maxPropagationDelay = delay;
245 }
246 
247 Time
249 {
250  return Seconds (10);
251 }
252 
253 Time
255 {
256  return m_maxPropagationDelay;
257 }
258 
259 void
261 {
262  m_macTxTrace (packet);
263 }
264 
265 void
267 {
268  m_macTxDropTrace (packet);
269 }
270 
271 void
273 {
274  m_macRxTrace (packet);
275 }
276 
277 void
279 {
280  m_macPromiscRxTrace (packet);
281 }
282 
283 void
285 {
286  m_macRxDropTrace (packet);
287 }
288 
289 void
291 {
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;
321  default:
322  NS_ASSERT (false);
323  break;
324  }
325  FinishConfigureStandard (standard);
326 }
327 
328 void
330 {
331  SetSifs (MicroSeconds (16));
332  SetSlot (MicroSeconds (9));
333  SetEifsNoDifs (MicroSeconds (16 + 44));
334  SetPifs (MicroSeconds (16 + 9));
335  SetCtsTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
336  SetAckTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
337 }
338 
339 void
341 {
342  SetSifs (MicroSeconds (10));
343  SetSlot (MicroSeconds (20));
344  SetEifsNoDifs (MicroSeconds (10 + 304));
345  SetPifs (MicroSeconds (10 + 20));
346  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
347  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
348 }
349 
350 void
352 {
353  SetSifs (MicroSeconds (10));
354  // Slot time defaults to the "long slot time" of 20 us in the standard
355  // according to mixed 802.11b/g deployments. Short slot time is enabled
356  // if the user sets the ShortSlotTimeSupported flag to true and when the BSS
357  // consists of only ERP STAs capable of supporting this option.
358  SetSlot (MicroSeconds (20));
359  SetEifsNoDifs (MicroSeconds (10 + 304));
360  SetPifs (MicroSeconds (10 + 20));
361  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
362  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
363 }
364 
365 void
367 {
368  SetSifs (MicroSeconds (32));
369  SetSlot (MicroSeconds (13));
370  SetEifsNoDifs (MicroSeconds (32 + 88));
371  SetPifs (MicroSeconds (32 + 13));
372  SetCtsTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
373  SetAckTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
374 }
375 
376 void
378 {
379  SetSifs (MicroSeconds (64));
380  SetSlot (MicroSeconds (21));
381  SetEifsNoDifs (MicroSeconds (64 + 176));
382  SetPifs (MicroSeconds (64 + 21));
383  SetCtsTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
384  SetAckTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
385 }
386 
387 void
389 {
390  Configure80211g ();
391  SetRifs (MicroSeconds (2));
394 }
395 void
397 {
398  Configure80211a ();
399  SetRifs (MicroSeconds (2));
402 }
403 
404 void
406 {
408 }
409 
410 void
411 WifiMac::ConfigureDcf (Ptr<Dcf> dcf, uint32_t cwmin, uint32_t cwmax, bool isDsss, enum AcIndex ac)
412 {
413  /* see IEE802.11 section 7.3.2.29 */
414  switch (ac)
415  {
416  case AC_VO:
417  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
418  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
419  dcf->SetAifsn (2);
420  if (isDsss)
421  {
422  dcf->SetTxopLimit (MicroSeconds (3264));
423  }
424  else
425  {
426  dcf->SetTxopLimit (MicroSeconds (1504));
427  }
428  break;
429  case AC_VI:
430  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
431  dcf->SetMaxCw (cwmin);
432  dcf->SetAifsn (2);
433  if (isDsss)
434  {
435  dcf->SetTxopLimit (MicroSeconds (6016));
436  }
437  else
438  {
439  dcf->SetTxopLimit (MicroSeconds (3008));
440  }
441  break;
442  case AC_BE:
443  dcf->SetMinCw (cwmin);
444  dcf->SetMaxCw (cwmax);
445  dcf->SetAifsn (3);
446  dcf->SetTxopLimit (MicroSeconds (0));
447  break;
448  case AC_BK:
449  dcf->SetMinCw (cwmin);
450  dcf->SetMaxCw (cwmax);
451  dcf->SetAifsn (7);
452  dcf->SetTxopLimit (MicroSeconds (0));
453  break;
454  case AC_BE_NQOS:
455  dcf->SetMinCw (cwmin);
456  dcf->SetMaxCw (cwmax);
457  dcf->SetAifsn (2);
458  dcf->SetTxopLimit (MicroSeconds (0));
459  break;
460  case AC_UNDEF:
461  NS_FATAL_ERROR ("I don't know what to do with this");
462  break;
463  }
464 }
465 
466 } //namespace ns3
467 
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:123
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
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:340
HT OFDM PHY for the 5 GHz band (clause 20)
virtual void SetPifs(Time pifs)=0
virtual void SetCompressedBlockAckTimeout(Time blockAckTimeout)
Definition: wifi-mac.cc:136
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
virtual void SetAckTimeout(Time ackTimeout)=0
virtual Time GetCompressedBlockAckTimeout(void) const
Definition: wifi-mac.cc:142
static Time GetDefaultMaxPropagationDelay(void)
Definition: wifi-mac.cc:33
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
void ConfigureStandard(enum WifiPhyStandard standard)
Definition: wifi-mac.cc:290
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:485
virtual Time GetAckTimeout(void) const =0
static Time GetDefaultCtsAckDelay(void)
Definition: wifi-mac.cc:67
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:405
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:462
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
void NotifyRxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:284
#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:470
HT OFDM PHY for the 2.4 GHz band (clause 20)
static Time GetDefaultSifs(void)
Definition: wifi-mac.cc:47
Video.
Definition: qos-utils.h:43
Voice.
Definition: qos-utils.h:45
Best Effort.
Definition: qos-utils.h:39
virtual void SetSsid(Ssid ssid)=0
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
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:41
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
AttributeValue implementation for Time.
Definition: nstime.h:957
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:455
void NotifyTxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:266
void ConfigureDcf(Ptr< Dcf > dcf, uint32_t cwmin, uint32_t cwmax, bool isDsss, enum AcIndex ac)
Definition: wifi-mac.cc:411
virtual Time GetSlot(void) const =0
void NotifyPromiscRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:278
void Configure80211n_5Ghz(void)
This method sets 802.11n 5 GHz standards-compliant defaults for following attributes: Sifs...
Definition: wifi-mac.cc:396
void Configure80211_10Mhz(void)
This method sets 802.11 with 10Mhz channel spacing standards-compliant defaults for following attribu...
Definition: wifi-mac.cc:366
void NotifyTx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:260
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:388
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
VHT OFDM PHY (clause 22)
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
static Time GetDefaultSlot(void)
Definition: wifi-mac.cc:40
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:95
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:351
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:958
virtual void SetCtsTimeout(Time ctsTimeout)=0
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:38
Time GetMaxPropagationDelay(void) const
Definition: wifi-mac.cc:254
void NotifyRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:272
static Time GetDefaultBasicBlockAckDelay(void)
Return the default basic block ACK delay.
Definition: wifi-mac.cc:88
static Time GetDefaultCompressedBlockAckDelay(void)
Return the default compressed block ACK delay.
Definition: wifi-mac.cc:95
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:478
void SetMaxPropagationDelay(Time delay)
Definition: wifi-mac.cc:242
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:329
Ptr< const AttributeChecker > MakeSsidChecker(void)
Definition: ssid.cc:136
void Configure80211_5Mhz()
This method sets 802.11 with 5Mhz channel spacing standards-compliant defaults for following attribut...
Definition: wifi-mac.cc:377
virtual void SetSifs(Time sifs)=0
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
AttributeValue implementation for Ssid.
Definition: ssid.h:95
Total number of ACs.
Definition: qos-utils.h:47
virtual Time GetSifs(void) const =0
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:911
static Time GetDefaultCompressedBlockAckTimeout(void)
Return the default compressed block ACK timeout.
Definition: wifi-mac.cc:113
static Time GetDefaultCtsAckTimeout(void)
Definition: wifi-mac.cc:74
Time m_maxPropagationDelay
Definition: wifi-mac.h:404
A base class which provides memory management and object aggregation.
Definition: object.h:87
static Time GetDefaultEifsNoDifs(void)
Definition: wifi-mac.cc:61
static Time GetDefaultRifs(void)
Definition: wifi-mac.cc:54
static Time GetDefaultBasicBlockAckTimeout(void)
Return the default basic block ACK timeout.
Definition: wifi-mac.cc:103
Time GetMsduLifetime(void) const
Definition: wifi-mac.cc:248
virtual Time GetCtsTimeout(void) const =0
a unique identifier for an interface.
Definition: type-id.h:58
static TypeId GetTypeId(void)
Definition: wifi-mac.cc:149
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:36
virtual Time GetBasicBlockAckTimeout(void) const
Definition: wifi-mac.cc:129
virtual Time GetEifsNoDifs(void) const =0
virtual void SetSlot(Time slotTime)=0