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 #include "wifi-mac.h"
21 #include "dcf.h"
22 #include "ns3/uinteger.h"
23 #include "ns3/trace-source-accessor.h"
24 
25 namespace ns3 {
26 
28 
29 
30 Time
32 {
33  // 1000m
34  return Seconds (1000.0 / 300000000.0);
35 }
36 Time
38 {
39  // 802.11-a specific
40  return MicroSeconds (9);
41 }
42 Time
44 {
45  // 802.11-a specific
46  return MicroSeconds (16);
47 }
48 Time
50 {
51  //802.11n specific
52  return MicroSeconds (2);
53 }
54 Time
56 {
58 }
59 Time
61 {
62  // 802.11-a specific: 6mb/s
63  return MicroSeconds (44);
64 }
65 Time
67 {
68  /* Cts_Timeout and Ack_Timeout are specified in the Annex C
69  (Formal description of MAC operation, see details on the
70  Trsp timer setting at page 346)
71  */
72  Time ctsTimeout = GetDefaultSifs ();
73  ctsTimeout += GetDefaultCtsAckDelay ();
74  ctsTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
75  ctsTimeout += GetDefaultSlot ();
76  return ctsTimeout;
77 }
78 
79 Time
81 {
82  // This value must be rivisited
83  return MicroSeconds (250);
84 }
85 Time
87 {
88  // This value must be rivisited was 68.
89  //CompressedBlockAckSize 32* 8*time it takes to transfer at the lowest rate (6Mb/s)+ aPhy-StartDelay(33)
90  return MicroSeconds (76);
91 }
92 Time
94 {
95  Time blockAckTimeout = GetDefaultSifs ();
96  blockAckTimeout += GetDefaultBasicBlockAckDelay ();
97  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
98  blockAckTimeout += GetDefaultSlot ();
99  return blockAckTimeout;
100 }
101 Time
103 {
104  Time blockAckTimeout = GetDefaultSifs ();
105  blockAckTimeout += GetDefaultCompressedBlockAckDelay ();
106  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
107  blockAckTimeout += GetDefaultSlot ();
108  return blockAckTimeout;
109 }
110 
111 void
113 {
114  //this method must be implemented by QoS WifiMacs
115 }
116 
117 Time
119 {
120  //this method must be implemented by QoS WifiMacs
121  return MicroSeconds (0);
122 }
123 
124 void
126 {
127  //this methos must be implemented by QoS WifiMacs
128 }
129 
130 Time
132 {
133  //this method must be implemented by QoS WifiMacs
134  return MicroSeconds (0);
135 }
136 
137 TypeId
139 {
140  static TypeId tid = TypeId ("ns3::WifiMac")
141  .SetParent<Object> ()
142  .SetGroupName ("Wifi")
143  .AddAttribute ("CtsTimeout", "When this timeout expires, the RTS/CTS handshake has failed.",
147  MakeTimeChecker ())
148  .AddAttribute ("AckTimeout", "When this timeout expires, the DATA/ACK handshake has failed.",
152  MakeTimeChecker ())
153  .AddAttribute ("BasicBlockAckTimeout", "When this timeout expires, the BASIC_BLOCK_ACK_REQ/BASIC_BLOCK_ACK handshake has failed.",
157  MakeTimeChecker ())
158  .AddAttribute ("CompressedBlockAckTimeout", "When this timeout expires, the COMPRESSED_BLOCK_ACK_REQ/COMPRESSED_BLOCK_ACK handshake has failed.",
162  MakeTimeChecker ())
163  .AddAttribute ("Sifs", "The value of the SIFS constant.",
167  MakeTimeChecker ())
168  .AddAttribute ("EifsNoDifs", "The value of EIFS-DIFS",
172  MakeTimeChecker ())
173  .AddAttribute ("Slot", "The duration of a Slot.",
177  MakeTimeChecker ())
178  .AddAttribute ("Pifs", "The value of the PIFS constant.",
182  MakeTimeChecker ())
183 .AddAttribute ("Rifs", "The value of the RIFS constant.",
187  MakeTimeChecker ())
188 
189  .AddAttribute ("MaxPropagationDelay", "The maximum propagation delay. Unused for now.",
192  MakeTimeChecker ())
193  .AddAttribute ("Ssid", "The ssid we want to belong to.",
194  SsidValue (Ssid ("default")),
197  MakeSsidChecker ())
198  .AddTraceSource ("MacTx",
199  "A packet has been received from higher layers and is being processed in preparation for "
200  "queueing for transmission.",
202  "ns3::Packet::TracedCallback")
203  .AddTraceSource ("MacTxDrop",
204  "A packet has been dropped in the MAC layer before being queued for transmission.",
206  "ns3::Packet::TracedCallback")
207  .AddTraceSource ("MacPromiscRx",
208  "A packet has been received by this device, has been passed up from the physical layer "
209  "and is being forwarded up the local protocol stack. This is a promiscuous trace,",
211  "ns3::Packet::TracedCallback")
212  .AddTraceSource ("MacRx",
213  "A packet has been received by this device, has been passed up from the physical layer "
214  "and is being forwarded up the local protocol stack. This is a non-promiscuous trace,",
216  "ns3::Packet::TracedCallback")
217  .AddTraceSource ("MacRxDrop",
218  "A packet has been dropped in the MAC layer after it has been passed up from the physical "
219  "layer.",
221  "ns3::Packet::TracedCallback")
222 #if 0
223  // Not currently implemented in this device
224  .AddTraceSource ("Sniffer",
225  "Trace source simulating a non-promiscuous packet sniffer attached to the device",
226  MakeTraceSourceAccessor (&WifiMac::m_snifferTrace))
227 #endif
228  ;
229 
230  return tid;
231 }
232 
233 void
235 {
236  m_maxPropagationDelay = delay;
237 }
238 
239 Time
241 {
242  return Seconds (10);
243 }
244 Time
246 {
247  return m_maxPropagationDelay;
248 }
249 
250 void
252 {
253  m_macTxTrace (packet);
254 }
255 
256 void
258 {
259  m_macTxDropTrace (packet);
260 }
261 
262 void
264 {
265  m_macRxTrace (packet);
266 }
267 
268 void
270 {
271  m_macPromiscRxTrace (packet);
272 }
273 
274 void
276 {
277  m_macRxDropTrace (packet);
278 }
279 
280 void
282 {
283  switch (standard)
284  {
286  Configure80211a ();
287  break;
289  Configure80211b ();
290  break;
292  Configure80211g ();
293  break;
296  break;
299  break;
301  Configure80211a ();
302  break;
305  break;
308  break;
309  default:
310  NS_ASSERT (false);
311  break;
312  }
313  FinishConfigureStandard (standard);
314 }
315 
316 void
318 {
319  SetSifs (MicroSeconds (16));
320  SetSlot (MicroSeconds (9));
321  SetEifsNoDifs (MicroSeconds (16 + 44));
322  SetPifs (MicroSeconds (16 + 9));
323  SetCtsTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
324  SetAckTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
325 }
326 
327 void
329 {
330  SetSifs (MicroSeconds (10));
331  SetSlot (MicroSeconds (20));
332  SetEifsNoDifs (MicroSeconds (10 + 304));
333  SetPifs (MicroSeconds (10 + 20));
334  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
335  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
336 }
337 
338 void
340 {
341  SetSifs (MicroSeconds (10));
342  // Note no support for Short Slot Time as yet
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 (32));
354  SetSlot (MicroSeconds (13));
355  SetEifsNoDifs (MicroSeconds (32 + 88));
356  SetPifs (MicroSeconds (32 + 13));
357  SetCtsTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
358  SetAckTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
359 }
360 
361 void
363 {
364  SetSifs (MicroSeconds (64));
365  SetSlot (MicroSeconds (21));
366  SetEifsNoDifs (MicroSeconds (64 + 176));
367  SetPifs (MicroSeconds (64 + 21));
368  SetCtsTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
369  SetAckTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
370 }
371 
372 void
374 {
375  Configure80211g ();
376  SetRifs(MicroSeconds (2));
379 }
380 void
382 {
383  Configure80211a ();
384  SetRifs(MicroSeconds (2));
387 }
388 
389 void
390 WifiMac::ConfigureDcf (Ptr<Dcf> dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
391 {
392  /* see IEE802.11 section 7.3.2.29 */
393  switch (ac)
394  {
395  case AC_VO:
396  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
397  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
398  dcf->SetAifsn (2);
399  break;
400  case AC_VI:
401  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
402  dcf->SetMaxCw (cwmin);
403  dcf->SetAifsn (2);
404  break;
405  case AC_BE:
406  dcf->SetMinCw (cwmin);
407  dcf->SetMaxCw (cwmax);
408  dcf->SetAifsn (3);
409  break;
410  case AC_BK:
411  dcf->SetMinCw (cwmin);
412  dcf->SetMaxCw (cwmax);
413  dcf->SetAifsn (7);
414  break;
415  case AC_BE_NQOS:
416  dcf->SetMinCw (cwmin);
417  dcf->SetMaxCw (cwmax);
418  dcf->SetAifsn (2);
419  break;
420  case AC_UNDEF:
421  NS_FATAL_ERROR ("I don't know what to do with this");
422  break;
423  }
424 }
425 } // namespace ns3
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:112
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:328
virtual void SetPifs(Time pifs)=0
virtual void SetCompressedBlockAckTimeout(Time blockAckTimeout)
Definition: wifi-mac.cc:125
#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:131
static Time GetDefaultMaxPropagationDelay(void)
Definition: wifi-mac.cc:31
#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:281
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:477
virtual Time GetAckTimeout(void) const =0
static Time GetDefaultCtsAckDelay(void)
Definition: wifi-mac.cc:60
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:451
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
void NotifyRxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:275
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
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:460
static Time GetDefaultSifs(void)
Definition: wifi-mac.cc:43
Video.
Definition: qos-utils.h:42
Voice.
Definition: qos-utils.h:44
Best Effort.
Definition: qos-utils.h:38
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:40
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
AttributeValue implementation for Time.
Definition: nstime.h:928
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:443
void NotifyTxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:257
void ConfigureDcf(Ptr< Dcf > dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
Definition: wifi-mac.cc:390
virtual Time GetSlot(void) const =0
void NotifyPromiscRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:269
void Configure80211n_5Ghz(void)
This method sets 802.11n 5 GHz standards-compliant defaults for following attributes: Sifs...
Definition: wifi-mac.cc:381
void Configure80211_10Mhz(void)
This method sets 802.11 with 10Mhz channel spacing standards-compliant defaults for following attribu...
Definition: wifi-mac.cc:351
void NotifyTx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:251
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:373
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:37
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:93
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:339
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:929
virtual void SetCtsTimeout(Time ctsTimeout)=0
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:37
Time GetMaxPropagationDelay(void) const
Definition: wifi-mac.cc:245
void NotifyRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:263
static Time GetDefaultBasicBlockAckDelay(void)
Return the default basic block ACK delay.
Definition: wifi-mac.cc:80
static Time GetDefaultCompressedBlockAckDelay(void)
Return the default compressed block ACK delay.
Definition: wifi-mac.cc:86
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:234
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:317
Ptr< const AttributeChecker > MakeSsidChecker(void)
Definition: ssid.cc:130
void Configure80211_5Mhz()
This method sets 802.11 with 5Mhz channel spacing standards-compliant defaults for following attribut...
Definition: wifi-mac.cc:362
virtual void SetSifs(Time sifs)=0
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:866
AttributeValue implementation for Ssid.
Definition: ssid.h:93
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:882
static Time GetDefaultCompressedBlockAckTimeout(void)
Return the default compressed block ACK timeout.
Definition: wifi-mac.cc:102
static Time GetDefaultCtsAckTimeout(void)
Definition: wifi-mac.cc:66
Time m_maxPropagationDelay
Definition: wifi-mac.h:397
A base class which provides memory management and object aggregation.
Definition: object.h:87
static Time GetDefaultEifsNoDifs(void)
Definition: wifi-mac.cc:55
static Time GetDefaultRifs(void)
Definition: wifi-mac.cc:49
static Time GetDefaultBasicBlockAckTimeout(void)
Return the default basic block ACK timeout.
Definition: wifi-mac.cc:93
Time GetMsduLifetime(void) const
Definition: wifi-mac.cc:240
virtual Time GetCtsTimeout(void) const =0
a unique identifier for an interface.
Definition: type-id.h:57
static TypeId GetTypeId(void)
Definition: wifi-mac.cc:138
TypeId SetParent(TypeId tid)
Definition: type-id.cc:638
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:35
virtual Time GetBasicBlockAckTimeout(void) const
Definition: wifi-mac.cc:118
virtual Time GetEifsNoDifs(void) const =0
virtual void SetSlot(Time slotTime)=0