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/trace-source-accessor.h"
25 
26 namespace ns3 {
27 
29 
30 
31 Time
33 {
34  //1000m
35  return Seconds (1000.0 / 300000000.0);
36 }
37 
38 Time
40 {
41  //802.11-a specific
42  return MicroSeconds (9);
43 }
44 
45 Time
47 {
48  //802.11-a specific
49  return MicroSeconds (16);
50 }
51 
52 Time
54 {
55  //802.11n specific
56  return MicroSeconds (2);
57 }
58 
59 Time
61 {
63 }
64 
65 Time
67 {
68  //802.11-a specific: at 6 Mbit/s
69  return MicroSeconds (44);
70 }
71 
72 Time
74 {
75  /* Cts_Timeout and Ack_Timeout are specified in the Annex C
76  (Formal description of MAC operation, see details on the
77  Trsp timer setting at page 346)
78  */
79  Time ctsTimeout = GetDefaultSifs ();
80  ctsTimeout += GetDefaultCtsAckDelay ();
81  ctsTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
82  ctsTimeout += GetDefaultSlot ();
83  return ctsTimeout;
84 }
85 
86 Time
88 {
89  //This value must be rivisited
90  return MicroSeconds (250);
91 }
92 
93 Time
95 {
96  //This value must be rivisited
97  //CompressedBlockAckSize 32 * 8 * time it takes to transfer at the lowest rate (at 6 Mbit/s) + aPhy-StartDelay (33)
98  return MicroSeconds (76);
99 }
100 
101 Time
103 {
104  Time blockAckTimeout = GetDefaultSifs ();
105  blockAckTimeout += GetDefaultBasicBlockAckDelay ();
106  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
107  blockAckTimeout += GetDefaultSlot ();
108  return blockAckTimeout;
109 }
110 
111 Time
113 {
114  Time blockAckTimeout = GetDefaultSifs ();
115  blockAckTimeout += GetDefaultCompressedBlockAckDelay ();
116  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
117  blockAckTimeout += GetDefaultSlot ();
118  return blockAckTimeout;
119 }
120 
121 void
123 {
124  //this method must be implemented by QoS WifiMacs
125 }
126 
127 Time
129 {
130  //this method must be implemented by QoS WifiMacs
131  return MicroSeconds (0);
132 }
133 
134 void
136 {
137  //this methos must be implemented by QoS WifiMacs
138 }
139 
140 Time
142 {
143  //this method must be implemented by QoS WifiMacs
144  return MicroSeconds (0);
145 }
146 
147 TypeId
149 {
150  static TypeId tid = TypeId ("ns3::WifiMac")
151  .SetParent<Object> ()
152  .SetGroupName ("Wifi")
153  .AddAttribute ("CtsTimeout", "When this timeout expires, the RTS/CTS handshake has failed.",
157  MakeTimeChecker ())
158  .AddAttribute ("AckTimeout", "When this timeout expires, the DATA/ACK handshake has failed.",
162  MakeTimeChecker ())
163  .AddAttribute ("BasicBlockAckTimeout", "When this timeout expires, the BASIC_BLOCK_ACK_REQ/BASIC_BLOCK_ACK handshake has failed.",
167  MakeTimeChecker ())
168  .AddAttribute ("CompressedBlockAckTimeout", "When this timeout expires, the COMPRESSED_BLOCK_ACK_REQ/COMPRESSED_BLOCK_ACK handshake has failed.",
172  MakeTimeChecker ())
173  .AddAttribute ("Sifs", "The value of the SIFS constant.",
177  MakeTimeChecker ())
178  .AddAttribute ("EifsNoDifs", "The value of EIFS-DIFS.",
182  MakeTimeChecker ())
183  .AddAttribute ("Slot", "The duration of a Slot.",
187  MakeTimeChecker ())
188  .AddAttribute ("Pifs", "The value of the PIFS constant.",
192  MakeTimeChecker ())
193  .AddAttribute ("Rifs", "The value of the RIFS constant.",
197  MakeTimeChecker ())
198  .AddAttribute ("MaxPropagationDelay", "The maximum propagation delay. Unused for now.",
201  MakeTimeChecker ())
202  .AddAttribute ("Ssid", "The ssid we want to belong to.",
203  SsidValue (Ssid ("default")),
206  MakeSsidChecker ())
207  .AddTraceSource ("MacTx",
208  "A packet has been received from higher layers and is being processed in preparation for "
209  "queueing for transmission.",
211  "ns3::Packet::TracedCallback")
212  .AddTraceSource ("MacTxDrop",
213  "A packet has been dropped in the MAC layer before being queued for transmission.",
215  "ns3::Packet::TracedCallback")
216  .AddTraceSource ("MacPromiscRx",
217  "A packet has been received by this device, has been passed up from the physical layer "
218  "and is being forwarded up the local protocol stack. This is a promiscuous trace.",
220  "ns3::Packet::TracedCallback")
221  .AddTraceSource ("MacRx",
222  "A packet has been received by this device, has been passed up from the physical layer "
223  "and is being forwarded up the local protocol stack. This is a non-promiscuous trace.",
225  "ns3::Packet::TracedCallback")
226  .AddTraceSource ("MacRxDrop",
227  "A packet has been dropped in the MAC layer after it has been passed up from the physical layer.",
229  "ns3::Packet::TracedCallback")
230  //Not currently implemented in this device
231  /*
232  .AddTraceSource ("Sniffer",
233  "Trace source simulating a non-promiscuous packet sniffer attached to the device",
234  MakeTraceSourceAccessor (&WifiMac::m_snifferTrace))
235  */
236  ;
237  return tid;
238 }
239 
240 void
242 {
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  switch (standard)
292  {
294  Configure80211a ();
295  break;
297  Configure80211b ();
298  break;
300  Configure80211g ();
301  break;
304  break;
307  break;
309  Configure80211a ();
310  break;
313  break;
316  break;
318  Configure80211ac ();
319  break;
320  default:
321  NS_ASSERT (false);
322  break;
323  }
324  FinishConfigureStandard (standard);
325 }
326 
327 void
329 {
330  SetSifs (MicroSeconds (16));
331  SetSlot (MicroSeconds (9));
332  SetEifsNoDifs (MicroSeconds (16 + 44));
333  SetPifs (MicroSeconds (16 + 9));
334  SetCtsTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
335  SetAckTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
336 }
337 
338 void
340 {
341  SetSifs (MicroSeconds (10));
342  SetSlot (MicroSeconds (20));
343  SetEifsNoDifs (MicroSeconds (10 + 304));
344  SetPifs (MicroSeconds (10 + 20));
345  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
346  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
347 }
348 
349 void
351 {
352  SetSifs (MicroSeconds (10));
353  // Slot time defaults to the "long slot time" of 20 us in the standard
354  // according to mixed 802.11b/g deployments. Short slot time is supported
355  // if the user sets the slot to 9 us *after* calling Configure80211g().
356  // The other parameters below should also be adjusted accordingly as they
357  // depend on slot time.
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, 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  break;
421  case AC_VI:
422  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
423  dcf->SetMaxCw (cwmin);
424  dcf->SetAifsn (2);
425  break;
426  case AC_BE:
427  dcf->SetMinCw (cwmin);
428  dcf->SetMaxCw (cwmax);
429  dcf->SetAifsn (3);
430  break;
431  case AC_BK:
432  dcf->SetMinCw (cwmin);
433  dcf->SetMaxCw (cwmax);
434  dcf->SetAifsn (7);
435  break;
436  case AC_BE_NQOS:
437  dcf->SetMinCw (cwmin);
438  dcf->SetMaxCw (cwmax);
439  dcf->SetAifsn (2);
440  break;
441  case AC_UNDEF:
442  NS_FATAL_ERROR ("I don't know what to do with this");
443  break;
444  }
445 }
446 
447 } //namespace ns3
448 
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:122
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:339
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:135
#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:141
static Time GetDefaultMaxPropagationDelay(void)
Definition: wifi-mac.cc:32
#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:289
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:476
virtual Time GetAckTimeout(void) const =0
static Time GetDefaultCtsAckDelay(void)
Definition: wifi-mac.cc:66
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:453
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
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:145
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:461
HT OFDM PHY for the 2.4 GHz band (clause 20)
static Time GetDefaultSifs(void)
Definition: wifi-mac.cc:46
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:446
void NotifyTxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:265
void ConfigureDcf(Ptr< Dcf > dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
Definition: wifi-mac.cc:411
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: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: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: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:39
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:350
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:253
void NotifyRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:271
static Time GetDefaultBasicBlockAckDelay(void)
Return the default basic block ACK delay.
Definition: wifi-mac.cc:87
static Time GetDefaultCompressedBlockAckDelay(void)
Return the default compressed block ACK delay.
Definition: wifi-mac.cc:94
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:469
void SetMaxPropagationDelay(Time delay)
Definition: wifi-mac.cc:241
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:328
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:112
static Time GetDefaultCtsAckTimeout(void)
Definition: wifi-mac.cc:73
Time m_maxPropagationDelay
Definition: wifi-mac.h:395
A base class which provides memory management and object aggregation.
Definition: object.h:87
static Time GetDefaultEifsNoDifs(void)
Definition: wifi-mac.cc:60
static Time GetDefaultRifs(void)
Definition: wifi-mac.cc:53
static Time GetDefaultBasicBlockAckTimeout(void)
Return the default basic block ACK timeout.
Definition: wifi-mac.cc:102
Time GetMsduLifetime(void) const
Definition: wifi-mac.cc:247
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:148
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:826
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:128
virtual Time GetEifsNoDifs(void) const =0
virtual void SetSlot(Time slotTime)=0