A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  .AddAttribute ("CtsTimeout", "When this timeout expires, the RTS/CTS handshake has failed.",
144  MakeTimeAccessor (&WifiMac::SetCtsTimeout,
146  MakeTimeChecker ())
147  .AddAttribute ("AckTimeout", "When this timeout expires, the DATA/ACK handshake has failed.",
149  MakeTimeAccessor (&WifiMac::GetAckTimeout,
151  MakeTimeChecker ())
152  .AddAttribute ("BasicBlockAckTimeout", "When this timeout expires, the BASIC_BLOCK_ACK_REQ/BASIC_BLOCK_ACK handshake has failed.",
154  MakeTimeAccessor (&WifiMac::GetBasicBlockAckTimeout,
156  MakeTimeChecker ())
157  .AddAttribute ("CompressedBlockAckTimeout", "When this timeout expires, the COMPRESSED_BLOCK_ACK_REQ/COMPRESSED_BLOCK_ACK handshake has failed.",
159  MakeTimeAccessor (&WifiMac::GetCompressedBlockAckTimeout,
161  MakeTimeChecker ())
162  .AddAttribute ("Sifs", "The value of the SIFS constant.",
164  MakeTimeAccessor (&WifiMac::SetSifs,
166  MakeTimeChecker ())
167  .AddAttribute ("EifsNoDifs", "The value of EIFS-DIFS",
169  MakeTimeAccessor (&WifiMac::SetEifsNoDifs,
171  MakeTimeChecker ())
172  .AddAttribute ("Slot", "The duration of a Slot.",
174  MakeTimeAccessor (&WifiMac::SetSlot,
176  MakeTimeChecker ())
177  .AddAttribute ("Pifs", "The value of the PIFS constant.",
179  MakeTimeAccessor (&WifiMac::SetPifs,
181  MakeTimeChecker ())
182 .AddAttribute ("Rifs", "The value of the RIFS constant.",
184  MakeTimeAccessor (&WifiMac::SetRifs,
186  MakeTimeChecker ())
187 
188  .AddAttribute ("MaxPropagationDelay", "The maximum propagation delay. Unused for now.",
190  MakeTimeAccessor (&WifiMac::m_maxPropagationDelay),
191  MakeTimeChecker ())
192  .AddAttribute ("Ssid", "The ssid we want to belong to.",
193  SsidValue (Ssid ("default")),
194  MakeSsidAccessor (&WifiMac::GetSsid,
196  MakeSsidChecker ())
197  .AddTraceSource ("MacTx",
198  "A packet has been received from higher layers and is being processed in preparation for "
199  "queueing for transmission.",
201  .AddTraceSource ("MacTxDrop",
202  "A packet has been dropped in the MAC layer before being queued for transmission.",
204  .AddTraceSource ("MacPromiscRx",
205  "A packet has been received by this device, has been passed up from the physical layer "
206  "and is being forwarded up the local protocol stack. This is a promiscuous trace,",
208  .AddTraceSource ("MacRx",
209  "A packet has been received by this device, has been passed up from the physical layer "
210  "and is being forwarded up the local protocol stack. This is a non-promiscuous trace,",
212  .AddTraceSource ("MacRxDrop",
213  "A packet has been dropped in the MAC layer after it has been passed up from the physical "
214  "layer.",
216 #if 0
217  // Not currently implemented in this device
218  .AddTraceSource ("Sniffer",
219  "Trace source simulating a non-promiscuous packet sniffer attached to the device",
220  MakeTraceSourceAccessor (&WifiMac::m_snifferTrace))
221 #endif
222  ;
223 
224  return tid;
225 }
226 
227 void
229 {
230  m_maxPropagationDelay = delay;
231 }
232 
233 Time
235 {
236  return Seconds (10);
237 }
238 Time
240 {
241  return m_maxPropagationDelay;
242 }
243 
244 void
246 {
247  m_macTxTrace (packet);
248 }
249 
250 void
252 {
253  m_macTxDropTrace (packet);
254 }
255 
256 void
258 {
259  m_macRxTrace (packet);
260 }
261 
262 void
264 {
265  m_macPromiscRxTrace (packet);
266 }
267 
268 void
270 {
271  m_macRxDropTrace (packet);
272 }
273 
274 void
276 {
277  switch (standard)
278  {
280  Configure80211a ();
281  break;
283  Configure80211b ();
284  break;
286  Configure80211g ();
287  break;
290  break;
293  break;
295  Configure80211a ();
296  break;
299  break;
302  break;
303  default:
304  NS_ASSERT (false);
305  break;
306  }
307  FinishConfigureStandard (standard);
308 }
309 
310 void
312 {
313  SetSifs (MicroSeconds (16));
314  SetSlot (MicroSeconds (9));
315  SetEifsNoDifs (MicroSeconds (16 + 44));
316  SetPifs (MicroSeconds (16 + 9));
317  SetCtsTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
318  SetAckTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
319 }
320 
321 void
323 {
324  SetSifs (MicroSeconds (10));
325  SetSlot (MicroSeconds (20));
326  SetEifsNoDifs (MicroSeconds (10 + 304));
327  SetPifs (MicroSeconds (10 + 20));
328  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
329  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
330 }
331 
332 void
334 {
335  SetSifs (MicroSeconds (10));
336  // Note no support for Short Slot Time as yet
337  SetSlot (MicroSeconds (20));
338  SetEifsNoDifs (MicroSeconds (10 + 304));
339  SetPifs (MicroSeconds (10 + 20));
340  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
341  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
342 }
343 
344 void
346 {
347  SetSifs (MicroSeconds (32));
348  SetSlot (MicroSeconds (13));
349  SetEifsNoDifs (MicroSeconds (32 + 88));
350  SetPifs (MicroSeconds (32 + 13));
351  SetCtsTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
352  SetAckTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
353 }
354 
355 void
357 {
358  SetSifs (MicroSeconds (64));
359  SetSlot (MicroSeconds (21));
360  SetEifsNoDifs (MicroSeconds (64 + 176));
361  SetPifs (MicroSeconds (64 + 21));
362  SetCtsTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
363  SetAckTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
364 }
365 
366 void
368 {
369  Configure80211g ();
370  SetRifs(MicroSeconds (2));
371  SetCtsTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
372  SetAckTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
373 }
374 void
376 {
377  Configure80211a ();
378  SetRifs(MicroSeconds (2));
379  SetCtsTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
380  SetAckTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
381 }
382 
383 void
384 WifiMac::ConfigureDcf (Ptr<Dcf> dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
385 {
386  /* see IEE802.11 section 7.3.2.29 */
387  switch (ac)
388  {
389  case AC_VO:
390  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
391  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
392  dcf->SetAifsn (2);
393  break;
394  case AC_VI:
395  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
396  dcf->SetMaxCw (cwmin);
397  dcf->SetAifsn (2);
398  break;
399  case AC_BE:
400  dcf->SetMinCw (cwmin);
401  dcf->SetMaxCw (cwmax);
402  dcf->SetAifsn (3);
403  break;
404  case AC_BK:
405  dcf->SetMinCw (cwmin);
406  dcf->SetMaxCw (cwmax);
407  dcf->SetAifsn (7);
408  break;
409  case AC_BE_NQOS:
410  dcf->SetMinCw (cwmin);
411  dcf->SetMaxCw (cwmax);
412  dcf->SetAifsn (2);
413  break;
414  case AC_UNDEF:
415  NS_FATAL_ERROR ("I don't know what to do with this");
416  break;
417  }
418 }
419 } // 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:79
OFDM PHY for the 5 GHz band (Clause 17 with 5 MHz channel bandwidth)
virtual Time GetRifs(void) const =0
void Configure80211b(void)
Configure appropriate timing parameters for 802.11b.
Definition: wifi-mac.cc:322
virtual void SetPifs(Time pifs)=0
virtual void SetCompressedBlockAckTimeout(Time blockAckTimeout)
Definition: wifi-mac.cc:125
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
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:61
void ConfigureStandard(enum WifiPhyStandard standard)
Definition: wifi-mac.cc:275
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:444
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:418
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
void NotifyRxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:269
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:95
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:427
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
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.
hold objects of type ns3::Time
Definition: nstime.h:1008
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:410
void NotifyTxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:251
void ConfigureDcf(Ptr< Dcf > dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
Definition: wifi-mac.cc:384
virtual Time GetSlot(void) const =0
void NotifyPromiscRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:263
void Configure80211n_5Ghz(void)
Configure appropriate timing parameters for 802.11n operating at 5Ghz.
Definition: wifi-mac.cc:375
void Configure80211_10Mhz(void)
Configure appropriate timing parameters for 802.11 with 10Mhz channel spacing.
Definition: wifi-mac.cc:345
void NotifyTx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:245
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)
Configure appropriate timing parameters for 802.11n operating at 2.4Ghz.
Definition: wifi-mac.cc:367
OFDM PHY for the 5 GHz band (Clause 17)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
static Time GetDefaultSlot(void)
Definition: wifi-mac.cc:37
virtual void SetEifsNoDifs(Time eifsNoDifs)=0
void Configure80211g(void)
Configure appropriate timing parameters for 802.11g.
Definition: wifi-mac.cc:333
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:239
void NotifyRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:257
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:436
void SetMaxPropagationDelay(Time delay)
Definition: wifi-mac.cc:228
void Configure80211a(void)
Configure appropriate timing parameters for 802.11a.
Definition: wifi-mac.cc:311
void Configure80211_5Mhz()
Configure appropriate timing parameters for 802.11 with 5Mhz channel spacing.
Definition: wifi-mac.cc:356
virtual void SetSifs(Time sifs)=0
hold objects of type ns3::Ssid
Total number of ACs.
Definition: qos-utils.h:47
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:441
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:373
a base class which provides memory management and object aggregation
Definition: object.h:64
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:234
virtual Time GetCtsTimeout(void) const =0
a unique identifier for an interface.
Definition: type-id.h:49
static TypeId GetTypeId(void)
Definition: wifi-mac.cc:138
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
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