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 Time
31 {
32  // 1000m
33  return Seconds (1000.0 / 300000000.0);
34 }
35 Time
37 {
38  // 802.11-a specific
39  return MicroSeconds (9);
40 }
41 Time
43 {
44  // 802.11-a specific
45  return MicroSeconds (16);
46 }
47 Time
49 {
50  //802.11n specific
51  return MicroSeconds (2);
52 }
53 Time
55 {
57 }
58 Time
60 {
61  // 802.11-a specific: 6mb/s
62  return MicroSeconds (44);
63 }
64 Time
66 {
67  /* Cts_Timeout and Ack_Timeout are specified in the Annex C
68  (Formal description of MAC operation, see details on the
69  Trsp timer setting at page 346)
70  */
71  Time ctsTimeout = GetDefaultSifs ();
72  ctsTimeout += GetDefaultCtsAckDelay ();
73  ctsTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
74  ctsTimeout += GetDefaultSlot ();
75  return ctsTimeout;
76 }
77 
78 Time
80 {
81  // This value must be rivisited
82  return MicroSeconds (250);
83 }
84 Time
86 {
87  // This value must be rivisited was 68.
88  //CompressedBlockAckSize 32* 8*time it takes to transfer at the lowest rate (6Mb/s)+ aPhy-StartDelay(33)
89  return MicroSeconds (76);
90 }
91 Time
93 {
94  Time blockAckTimeout = GetDefaultSifs ();
95  blockAckTimeout += GetDefaultBasicBlockAckDelay ();
96  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
97  blockAckTimeout += GetDefaultSlot ();
98  return blockAckTimeout;
99 }
100 Time
102 {
103  Time blockAckTimeout = GetDefaultSifs ();
104  blockAckTimeout += GetDefaultCompressedBlockAckDelay ();
105  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
106  blockAckTimeout += GetDefaultSlot ();
107  return blockAckTimeout;
108 }
109 
110 void
112 {
113  //this method must be implemented by QoS WifiMacs
114 }
115 
116 Time
118 {
119  //this method must be implemented by QoS WifiMacs
120  return MicroSeconds (0);
121 }
122 
123 void
125 {
126  //this methos must be implemented by QoS WifiMacs
127 }
128 
129 Time
131 {
132  //this method must be implemented by QoS WifiMacs
133  return MicroSeconds (0);
134 }
135 
136 TypeId
138 {
139  static TypeId tid = TypeId ("ns3::WifiMac")
140  .SetParent<Object> ()
141  .AddAttribute ("CtsTimeout", "When this timeout expires, the RTS/CTS handshake has failed.",
143  MakeTimeAccessor (&WifiMac::SetCtsTimeout,
145  MakeTimeChecker ())
146  .AddAttribute ("AckTimeout", "When this timeout expires, the DATA/ACK handshake has failed.",
148  MakeTimeAccessor (&WifiMac::GetAckTimeout,
150  MakeTimeChecker ())
151  .AddAttribute ("BasicBlockAckTimeout", "When this timeout expires, the BASIC_BLOCK_ACK_REQ/BASIC_BLOCK_ACK handshake has failed.",
153  MakeTimeAccessor (&WifiMac::GetBasicBlockAckTimeout,
155  MakeTimeChecker ())
156  .AddAttribute ("CompressedBlockAckTimeout", "When this timeout expires, the COMPRESSED_BLOCK_ACK_REQ/COMPRESSED_BLOCK_ACK handshake has failed.",
158  MakeTimeAccessor (&WifiMac::GetCompressedBlockAckTimeout,
160  MakeTimeChecker ())
161  .AddAttribute ("Sifs", "The value of the SIFS constant.",
163  MakeTimeAccessor (&WifiMac::SetSifs,
165  MakeTimeChecker ())
166  .AddAttribute ("EifsNoDifs", "The value of EIFS-DIFS",
168  MakeTimeAccessor (&WifiMac::SetEifsNoDifs,
170  MakeTimeChecker ())
171  .AddAttribute ("Slot", "The duration of a Slot.",
173  MakeTimeAccessor (&WifiMac::SetSlot,
175  MakeTimeChecker ())
176  .AddAttribute ("Pifs", "The value of the PIFS constant.",
178  MakeTimeAccessor (&WifiMac::SetPifs,
180  MakeTimeChecker ())
181 .AddAttribute ("Rifs", "The value of the RIFS constant.",
183  MakeTimeAccessor (&WifiMac::SetRifs,
185  MakeTimeChecker ())
186 
187  .AddAttribute ("MaxPropagationDelay", "The maximum propagation delay. Unused for now.",
189  MakeTimeAccessor (&WifiMac::m_maxPropagationDelay),
190  MakeTimeChecker ())
191  .AddAttribute ("Ssid", "The ssid we want to belong to.",
192  SsidValue (Ssid ("default")),
193  MakeSsidAccessor (&WifiMac::GetSsid,
195  MakeSsidChecker ())
196  .AddTraceSource ("MacTx",
197  "A packet has been received from higher layers and is being processed in preparation for "
198  "queueing for transmission.",
200  .AddTraceSource ("MacTxDrop",
201  "A packet has been dropped in the MAC layer before being queued for transmission.",
203  .AddTraceSource ("MacPromiscRx",
204  "A packet has been received by this device, has been passed up from the physical layer "
205  "and is being forwarded up the local protocol stack. This is a promiscuous trace,",
207  .AddTraceSource ("MacRx",
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 non-promiscuous trace,",
211  .AddTraceSource ("MacRxDrop",
212  "A packet has been dropped in the MAC layer after it has been passed up from the physical "
213  "layer.",
215 #if 0
216  // Not currently implemented in this device
217  .AddTraceSource ("Sniffer",
218  "Trace source simulating a non-promiscuous packet sniffer attached to the device",
219  MakeTraceSourceAccessor (&WifiMac::m_snifferTrace))
220 #endif
221  ;
222 
223  return tid;
224 }
225 
226 void
228 {
229  m_maxPropagationDelay = delay;
230 }
231 
232 Time
234 {
235  return Seconds (10);
236 }
237 Time
239 {
240  return m_maxPropagationDelay;
241 }
242 
243 void
245 {
246  m_macTxTrace (packet);
247 }
248 
249 void
251 {
252  m_macTxDropTrace (packet);
253 }
254 
255 void
257 {
258  m_macRxTrace (packet);
259 }
260 
261 void
263 {
264  m_macPromiscRxTrace (packet);
265 }
266 
267 void
269 {
270  m_macRxDropTrace (packet);
271 }
272 
273 void
275 {
276  switch (standard)
277  {
279  Configure80211a ();
280  break;
282  Configure80211b ();
283  break;
285  Configure80211g ();
286  break;
289  break;
292  break;
294  Configure80211a ();
295  break;
298  break;
301  break;
302  default:
303  NS_ASSERT (false);
304  break;
305  }
306  FinishConfigureStandard (standard);
307 }
308 
309 void
311 {
312  SetSifs (MicroSeconds (16));
313  SetSlot (MicroSeconds (9));
314  SetEifsNoDifs (MicroSeconds (16 + 44));
315  SetPifs (MicroSeconds (16 + 9));
316  SetCtsTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
317  SetAckTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
318 }
319 
320 void
322 {
323  SetSifs (MicroSeconds (10));
324  SetSlot (MicroSeconds (20));
325  SetEifsNoDifs (MicroSeconds (10 + 304));
326  SetPifs (MicroSeconds (10 + 20));
327  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
328  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
329 }
330 
331 void
333 {
334  SetSifs (MicroSeconds (10));
335  // Note no support for Short Slot Time as yet
336  SetSlot (MicroSeconds (20));
337  SetEifsNoDifs (MicroSeconds (10 + 304));
338  SetPifs (MicroSeconds (10 + 20));
339  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
340  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
341 }
342 
343 void
345 {
346  SetSifs (MicroSeconds (32));
347  SetSlot (MicroSeconds (13));
348  SetEifsNoDifs (MicroSeconds (32 + 88));
349  SetPifs (MicroSeconds (32 + 13));
350  SetCtsTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
351  SetAckTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
352 }
353 
354 void
356 {
357  SetSifs (MicroSeconds (64));
358  SetSlot (MicroSeconds (21));
359  SetEifsNoDifs (MicroSeconds (64 + 176));
360  SetPifs (MicroSeconds (64 + 21));
361  SetCtsTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
362  SetAckTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
363 }
364 
365 void
367 {
368  Configure80211g ();
369  SetRifs(MicroSeconds (2));
370  SetCtsTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
371  SetAckTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
372 }
373 void
375 {
376  Configure80211a ();
377  SetRifs(MicroSeconds (2));
378  SetCtsTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
379  SetAckTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
380 }
381 
382 void
383 WifiMac::ConfigureDcf (Ptr<Dcf> dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
384 {
385  /* see IEE802.11 section 7.3.2.29 */
386  switch (ac)
387  {
388  case AC_VO:
389  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
390  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
391  dcf->SetAifsn (2);
392  break;
393  case AC_VI:
394  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
395  dcf->SetMaxCw (cwmin);
396  dcf->SetAifsn (2);
397  break;
398  case AC_BE:
399  dcf->SetMinCw (cwmin);
400  dcf->SetMaxCw (cwmax);
401  dcf->SetAifsn (3);
402  break;
403  case AC_BK:
404  dcf->SetMinCw (cwmin);
405  dcf->SetMaxCw (cwmax);
406  dcf->SetAifsn (7);
407  break;
408  case AC_BE_NQOS:
409  dcf->SetMinCw (cwmin);
410  dcf->SetMaxCw (cwmax);
411  dcf->SetAifsn (2);
412  break;
413  case AC_UNDEF:
414  NS_FATAL_ERROR ("I don't know what to do with this");
415  break;
416  }
417 }
418 } // namespace ns3
virtual void FinishConfigureStandard(enum WifiPhyStandard standard)=0
virtual Time GetPifs(void) const =0
virtual void SetBasicBlockAckTimeout(Time blockAckTimeout)
Definition: wifi-mac.cc:111
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
virtual Time GetRifs(void) const =0
void Configure80211b(void)
Definition: wifi-mac.cc:321
virtual void SetPifs(Time pifs)=0
virtual void SetCompressedBlockAckTimeout(Time blockAckTimeout)
Definition: wifi-mac.cc:124
virtual void SetAckTimeout(Time ackTimeout)=0
virtual Time GetCompressedBlockAckTimeout(void) const
Definition: wifi-mac.cc:130
static Time GetDefaultMaxPropagationDelay(void)
Definition: wifi-mac.cc:30
#define NS_ASSERT(condition)
Definition: assert.h:64
void ConfigureStandard(enum WifiPhyStandard standard)
Definition: wifi-mac.cc:274
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
Definition: wifi-mac.h:313
virtual Time GetAckTimeout(void) const =0
static Time GetDefaultCtsAckDelay(void)
Definition: wifi-mac.cc:59
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
Definition: wifi-mac.h:287
void NotifyRxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:268
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
Definition: wifi-mac.h:296
static Time GetDefaultSifs(void)
Definition: wifi-mac.cc:42
virtual void SetSsid(Ssid ssid)=0
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
virtual Ssid GetSsid(void) const =0
hold objects of type ns3::Time
Definition: nstime.h:828
TracedCallback< Ptr< const Packet > > m_macTxTrace
Definition: wifi-mac.h:279
void NotifyTxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:250
void ConfigureDcf(Ptr< Dcf > dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
Definition: wifi-mac.cc:383
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
virtual Time GetSlot(void) const =0
void NotifyPromiscRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:262
void Configure80211n_5Ghz(void)
Definition: wifi-mac.cc:374
void Configure80211_10Mhz(void)
Definition: wifi-mac.cc:344
void NotifyTx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:244
virtual void SetRifs(Time rifs)=0
void Configure80211n_2_4Ghz(void)
Definition: wifi-mac.cc:366
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
static Time GetDefaultSlot(void)
Definition: wifi-mac.cc:36
virtual void SetEifsNoDifs(Time eifsNoDifs)=0
void Configure80211g(void)
Definition: wifi-mac.cc:332
virtual void SetCtsTimeout(Time ctsTimeout)=0
Definition: ssid.h:35
Time GetMaxPropagationDelay(void) const
Definition: wifi-mac.cc:238
void NotifyRx(Ptr< const Packet > packet)
Definition: wifi-mac.cc:256
static Time GetDefaultBasicBlockAckDelay(void)
Definition: wifi-mac.cc:79
static Time GetDefaultCompressedBlockAckDelay(void)
Definition: wifi-mac.cc:85
TracedCallback< Ptr< const Packet > > m_macRxTrace
Definition: wifi-mac.h:305
void SetMaxPropagationDelay(Time delay)
Definition: wifi-mac.cc:227
void Configure80211a(void)
Definition: wifi-mac.cc:310
void Configure80211_5Mhz()
Definition: wifi-mac.cc:355
virtual void SetSifs(Time sifs)=0
hold objects of type ns3::Ssid
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. Both limits are inclusive.
Definition: time.cc:404
static Time GetDefaultCompressedBlockAckTimeout(void)
Definition: wifi-mac.cc:101
static Time GetDefaultCtsAckTimeout(void)
Definition: wifi-mac.cc:65
Time m_maxPropagationDelay
Definition: wifi-mac.h:263
a base class which provides memory management and object aggregation
Definition: object.h:63
static Time GetDefaultEifsNoDifs(void)
Definition: wifi-mac.cc:54
static Time GetDefaultRifs(void)
Definition: wifi-mac.cc:48
static Time GetDefaultBasicBlockAckTimeout(void)
Definition: wifi-mac.cc:92
Time GetMsduLifetime(void) const
Definition: wifi-mac.cc:233
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:137
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
AcIndex
Definition: qos-utils.h:35
virtual Time GetBasicBlockAckTimeout(void) const
Definition: wifi-mac.cc:117
virtual Time GetEifsNoDifs(void) const =0
virtual void SetSlot(Time slotTime)=0