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;
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 {
375 }
376 
377 void
379 {
381 }
382 void
384 {
385  Configure80211g ();
386  SetRifs(MicroSeconds (2));
387  SetCtsTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
388  SetAckTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
389 }
390 void
392 {
393  Configure80211a ();
394  SetRifs(MicroSeconds (2));
395  SetCtsTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
396  SetAckTimeout (MicroSeconds (10 + 52 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
397 }
398 
399 void
400 WifiMac::ConfigureDcf (Ptr<Dcf> dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
401 {
402  /* see IEE802.11 section 7.3.2.29 */
403  switch (ac)
404  {
405  case AC_VO:
406  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
407  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
408  dcf->SetAifsn (2);
409  break;
410  case AC_VI:
411  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
412  dcf->SetMaxCw (cwmin);
413  dcf->SetAifsn (2);
414  break;
415  case AC_BE:
416  dcf->SetMinCw (cwmin);
417  dcf->SetMaxCw (cwmax);
418  dcf->SetAifsn (3);
419  break;
420  case AC_BK:
421  dcf->SetMinCw (cwmin);
422  dcf->SetMaxCw (cwmax);
423  dcf->SetAifsn (7);
424  break;
425  case AC_BE_NQOS:
426  dcf->SetMinCw (cwmin);
427  dcf->SetMaxCw (cwmax);
428  dcf->SetAifsn (2);
429  break;
430  case AC_UNDEF:
431  NS_FATAL_ERROR ("I don't know what to do with this");
432  break;
433  }
434 }
435 
436 void
437 WifiMac::ConfigureCCHDcf (Ptr<Dcf> dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
438 {
439  /* see IEEE 1609.4-2006 section 6.3.1, Table 1 */
440  switch (ac)
441  {
442  case AC_VO:
443  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
444  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
445  dcf->SetAifsn (2);
446  break;
447  case AC_VI:
448  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
449  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
450  dcf->SetAifsn (3);
451  break;
452  case AC_BE:
453  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
454  dcf->SetMaxCw (cwmin);
455  dcf->SetAifsn (6);
456  break;
457  case AC_BK:
458  dcf->SetMinCw (cwmin);
459  dcf->SetMaxCw (cwmax);
460  dcf->SetAifsn (9);
461  break;
462  case AC_BE_NQOS:
463  dcf->SetMinCw (cwmin);
464  dcf->SetMaxCw (cwmax);
465  dcf->SetAifsn (2);
466  break;
467  case AC_UNDEF:
468  NS_FATAL_ERROR ("I don't know what to do with this");
469  break;
470  }
471 }
472 } // namespace ns3