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  .AddAttribute ("CtsTimeout", "When this timeout expires, the RTS/CTS handshake has failed.",
146  MakeTimeChecker ())
147  .AddAttribute ("AckTimeout", "When this timeout expires, the DATA/ACK handshake has failed.",
151  MakeTimeChecker ())
152  .AddAttribute ("BasicBlockAckTimeout", "When this timeout expires, the BASIC_BLOCK_ACK_REQ/BASIC_BLOCK_ACK handshake has failed.",
156  MakeTimeChecker ())
157  .AddAttribute ("CompressedBlockAckTimeout", "When this timeout expires, the COMPRESSED_BLOCK_ACK_REQ/COMPRESSED_BLOCK_ACK handshake has failed.",
161  MakeTimeChecker ())
162  .AddAttribute ("Sifs", "The value of the SIFS constant.",
166  MakeTimeChecker ())
167  .AddAttribute ("EifsNoDifs", "The value of EIFS-DIFS",
171  MakeTimeChecker ())
172  .AddAttribute ("Slot", "The duration of a Slot.",
176  MakeTimeChecker ())
177  .AddAttribute ("Pifs", "The value of the PIFS constant.",
181  MakeTimeChecker ())
182 .AddAttribute ("Rifs", "The value of the RIFS constant.",
186  MakeTimeChecker ())
187 
188  .AddAttribute ("MaxPropagationDelay", "The maximum propagation delay. Unused for now.",
191  MakeTimeChecker ())
192  .AddAttribute ("Ssid", "The ssid we want to belong to.",
193  SsidValue (Ssid ("default")),
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  "ns3::Packet::TracedCallback")
202  .AddTraceSource ("MacTxDrop",
203  "A packet has been dropped in the MAC layer before being queued for transmission.",
205  "ns3::Packet::TracedCallback")
206  .AddTraceSource ("MacPromiscRx",
207  "A packet has been received by this device, has been passed up from the physical layer "
208  "and is being forwarded up the local protocol stack. This is a promiscuous trace,",
210  "ns3::Packet::TracedCallback")
211  .AddTraceSource ("MacRx",
212  "A packet has been received by this device, has been passed up from the physical layer "
213  "and is being forwarded up the local protocol stack. This is a non-promiscuous trace,",
215  "ns3::Packet::TracedCallback")
216  .AddTraceSource ("MacRxDrop",
217  "A packet has been dropped in the MAC layer after it has been passed up from the physical "
218  "layer.",
220  "ns3::Packet::TracedCallback")
221 #if 0
222  // Not currently implemented in this device
223  .AddTraceSource ("Sniffer",
224  "Trace source simulating a non-promiscuous packet sniffer attached to the device",
225  MakeTraceSourceAccessor (&WifiMac::m_snifferTrace))
226 #endif
227  ;
228 
229  return tid;
230 }
231 
232 void
234 {
235  m_maxPropagationDelay = delay;
236 }
237 
238 Time
240 {
241  return Seconds (10);
242 }
243 Time
245 {
246  return m_maxPropagationDelay;
247 }
248 
249 void
251 {
252  m_macTxTrace (packet);
253 }
254 
255 void
257 {
258  m_macTxDropTrace (packet);
259 }
260 
261 void
263 {
264  m_macRxTrace (packet);
265 }
266 
267 void
269 {
270  m_macPromiscRxTrace (packet);
271 }
272 
273 void
275 {
276  m_macRxDropTrace (packet);
277 }
278 
279 void
281 {
282  switch (standard)
283  {
285  Configure80211a ();
286  break;
288  Configure80211b ();
289  break;
291  Configure80211g ();
292  break;
295  break;
298  break;
300  Configure80211a ();
301  break;
304  break;
307  break;
308  default:
309  NS_ASSERT (false);
310  break;
311  }
312  FinishConfigureStandard (standard);
313 }
314 
315 void
317 {
318  SetSifs (MicroSeconds (16));
319  SetSlot (MicroSeconds (9));
320  SetEifsNoDifs (MicroSeconds (16 + 44));
321  SetPifs (MicroSeconds (16 + 9));
322  SetCtsTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
323  SetAckTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
324 }
325 
326 void
328 {
329  SetSifs (MicroSeconds (10));
330  SetSlot (MicroSeconds (20));
331  SetEifsNoDifs (MicroSeconds (10 + 304));
332  SetPifs (MicroSeconds (10 + 20));
333  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
334  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
335 }
336 
337 void
339 {
340  SetSifs (MicroSeconds (10));
341  // Note no support for Short Slot Time as yet
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 (32));
353  SetSlot (MicroSeconds (13));
354  SetEifsNoDifs (MicroSeconds (32 + 88));
355  SetPifs (MicroSeconds (32 + 13));
356  SetCtsTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
357  SetAckTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
358 }
359 
360 void
362 {
363  SetSifs (MicroSeconds (64));
364  SetSlot (MicroSeconds (21));
365  SetEifsNoDifs (MicroSeconds (64 + 176));
366  SetPifs (MicroSeconds (64 + 21));
367  SetCtsTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
368  SetAckTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
369 }
370 
371 void
373 {
374  Configure80211g ();
375  SetRifs(MicroSeconds (2));
376  SetCtsTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
377  SetAckTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
380 }
381 void
383 {
384  Configure80211a ();
385  SetRifs(MicroSeconds (2));
386  SetCtsTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
387  SetAckTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
390 }
391 
392 void
393 WifiMac::ConfigureDcf (Ptr<Dcf> dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
394 {
395  /* see IEE802.11 section 7.3.2.29 */
396  switch (ac)
397  {
398  case AC_VO:
399  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
400  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
401  dcf->SetAifsn (2);
402  break;
403  case AC_VI:
404  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
405  dcf->SetMaxCw (cwmin);
406  dcf->SetAifsn (2);
407  break;
408  case AC_BE:
409  dcf->SetMinCw (cwmin);
410  dcf->SetMaxCw (cwmax);
411  dcf->SetAifsn (3);
412  break;
413  case AC_BK:
414  dcf->SetMinCw (cwmin);
415  dcf->SetMaxCw (cwmax);
416  dcf->SetAifsn (7);
417  break;
418  case AC_BE_NQOS:
419  dcf->SetMinCw (cwmin);
420  dcf->SetMaxCw (cwmax);
421  dcf->SetAifsn (2);
422  break;
423  case AC_UNDEF:
424  NS_FATAL_ERROR ("I don't know what to do with this");
425  break;
426  }
427 }
428 } // 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:95
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:327
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:61
void ConfigureStandard(enum WifiPhyStandard standard)
Definition: wifi-mac.cc:280
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:274
#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:439
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:921
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:256
void ConfigureDcf(Ptr< Dcf > dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
Definition: wifi-mac.cc:393
virtual Time GetSlot(void) const =0
void NotifyPromiscRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:268
void Configure80211n_5Ghz(void)
This method sets 802.11n 5 GHz standards-compliant defaults for following attributes: Sifs...
Definition: wifi-mac.cc:382
void Configure80211_10Mhz(void)
This method sets 802.11 with 10Mhz channel spacing standards-compliant defaults for following attribu...
Definition: wifi-mac.cc:350
void NotifyTx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:250
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:372
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:338
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:922
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:244
void NotifyRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:262
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:233
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:316
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:361
virtual void SetSifs(Time sifs)=0
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:859
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:875
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:239
virtual Time GetCtsTimeout(void) const =0
a unique identifier for an interface.
Definition: type-id.h:51
static TypeId GetTypeId(void)
Definition: wifi-mac.cc:138
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
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