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 {
51 }
52 Time
54 {
55  // 802.11-a specific: 6mb/s
56  return MicroSeconds (44);
57 }
58 Time
60 {
61  /* Cts_Timeout and Ack_Timeout are specified in the Annex C
62  (Formal description of MAC operation, see details on the
63  Trsp timer setting at page 346)
64  */
65  Time ctsTimeout = GetDefaultSifs ();
66  ctsTimeout += GetDefaultCtsAckDelay ();
67  ctsTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
68  ctsTimeout += GetDefaultSlot ();
69  return ctsTimeout;
70 }
71 
72 Time
74 {
75  // This value must be rivisited
76  return MicroSeconds (250);
77 }
78 Time
80 {
81  // This value must be rivisited
82  return MicroSeconds (68);
83 }
84 Time
86 {
87  Time blockAckTimeout = GetDefaultSifs ();
88  blockAckTimeout += GetDefaultBasicBlockAckDelay ();
89  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
90  blockAckTimeout += GetDefaultSlot ();
91  return blockAckTimeout;
92 }
93 Time
95 {
96  Time blockAckTimeout = GetDefaultSifs ();
97  blockAckTimeout += GetDefaultCompressedBlockAckDelay ();
98  blockAckTimeout += MicroSeconds (GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2);
99  blockAckTimeout += GetDefaultSlot ();
100  return blockAckTimeout;
101 }
102 
103 void
105 {
106  //this method must be implemented by QoS WifiMacs
107 }
108 
109 Time
111 {
112  //this method must be implemented by QoS WifiMacs
113  return MicroSeconds (0);
114 }
115 
116 void
118 {
119  //this methos must be implemented by QoS WifiMacs
120 }
121 
122 Time
124 {
125  //this method must be implemented by QoS WifiMacs
126  return MicroSeconds (0);
127 }
128 
129 TypeId
131 {
132  static TypeId tid = TypeId ("ns3::WifiMac")
133  .SetParent<Object> ()
134  .AddAttribute ("CtsTimeout", "When this timeout expires, the RTS/CTS handshake has failed.",
136  MakeTimeAccessor (&WifiMac::SetCtsTimeout,
138  MakeTimeChecker ())
139  .AddAttribute ("AckTimeout", "When this timeout expires, the DATA/ACK handshake has failed.",
141  MakeTimeAccessor (&WifiMac::GetAckTimeout,
143  MakeTimeChecker ())
144  .AddAttribute ("BasicBlockAckTimeout", "When this timeout expires, the BASIC_BLOCK_ACK_REQ/BASIC_BLOCK_ACK handshake has failed.",
146  MakeTimeAccessor (&WifiMac::GetBasicBlockAckTimeout,
148  MakeTimeChecker ())
149  .AddAttribute ("CompressedBlockAckTimeout", "When this timeout expires, the COMPRESSED_BLOCK_ACK_REQ/COMPRESSED_BLOCK_ACK handshake has failed.",
151  MakeTimeAccessor (&WifiMac::GetCompressedBlockAckTimeout,
153  MakeTimeChecker ())
154  .AddAttribute ("Sifs", "The value of the SIFS constant.",
156  MakeTimeAccessor (&WifiMac::SetSifs,
158  MakeTimeChecker ())
159  .AddAttribute ("EifsNoDifs", "The value of EIFS-DIFS",
161  MakeTimeAccessor (&WifiMac::SetEifsNoDifs,
163  MakeTimeChecker ())
164  .AddAttribute ("Slot", "The duration of a Slot.",
166  MakeTimeAccessor (&WifiMac::SetSlot,
168  MakeTimeChecker ())
169  .AddAttribute ("Pifs", "The value of the PIFS constant.",
171  MakeTimeAccessor (&WifiMac::SetPifs,
173  MakeTimeChecker ())
174  .AddAttribute ("MaxPropagationDelay", "The maximum propagation delay. Unused for now.",
176  MakeTimeAccessor (&WifiMac::m_maxPropagationDelay),
177  MakeTimeChecker ())
178  .AddAttribute ("Ssid", "The ssid we want to belong to.",
179  SsidValue (Ssid ("default")),
180  MakeSsidAccessor (&WifiMac::GetSsid,
182  MakeSsidChecker ())
183  .AddTraceSource ("MacTx",
184  "A packet has been received from higher layers and is being processed in preparation for "
185  "queueing for transmission.",
187  .AddTraceSource ("MacTxDrop",
188  "A packet has been dropped in the MAC layer before being queued for transmission.",
190  .AddTraceSource ("MacPromiscRx",
191  "A packet has been received by this device, has been passed up from the physical layer "
192  "and is being forwarded up the local protocol stack. This is a promiscuous trace,",
194  .AddTraceSource ("MacRx",
195  "A packet has been received by this device, has been passed up from the physical layer "
196  "and is being forwarded up the local protocol stack. This is a non-promiscuous trace,",
198  .AddTraceSource ("MacRxDrop",
199  "A packet has been dropped in the MAC layer after it has been passed up from the physical "
200  "layer.",
202 #if 0
203  // Not currently implemented in this device
204  .AddTraceSource ("Sniffer",
205  "Trace source simulating a non-promiscuous packet sniffer attached to the device",
206  MakeTraceSourceAccessor (&WifiMac::m_snifferTrace))
207 #endif
208  ;
209 
210  return tid;
211 }
212 
213 void
215 {
216  m_maxPropagationDelay = delay;
217 }
218 
219 Time
221 {
222  return Seconds (10);
223 }
224 Time
226 {
227  return m_maxPropagationDelay;
228 }
229 
230 void
232 {
233  m_macTxTrace (packet);
234 }
235 
236 void
238 {
239  m_macTxDropTrace (packet);
240 }
241 
242 void
244 {
245  m_macRxTrace (packet);
246 }
247 
248 void
250 {
251  m_macPromiscRxTrace (packet);
252 }
253 
254 void
256 {
257  m_macRxDropTrace (packet);
258 }
259 
260 void
262 {
263  switch (standard)
264  {
266  Configure80211a ();
267  break;
269  Configure80211b ();
270  break;
272  Configure80211g ();
273  break;
276  break;
279  break;
281  Configure80211a ();
282  break;
285  break;
288  break;
289  default:
290  NS_ASSERT (false);
291  break;
292  }
293  FinishConfigureStandard (standard);
294 }
295 
296 void
298 {
299  SetSifs (MicroSeconds (16));
300  SetSlot (MicroSeconds (9));
301  SetEifsNoDifs (MicroSeconds (16 + 44));
302  SetPifs (MicroSeconds (16 + 9));
303  SetCtsTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
304  SetAckTimeout (MicroSeconds (16 + 44 + 9 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
305 }
306 
307 void
309 {
310  SetSifs (MicroSeconds (10));
311  SetSlot (MicroSeconds (20));
312  SetEifsNoDifs (MicroSeconds (10 + 304));
313  SetPifs (MicroSeconds (10 + 20));
314  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
315  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
316 }
317 
318 void
320 {
321  SetSifs (MicroSeconds (10));
322  // Note no support for Short Slot Time as yet
323  SetSlot (MicroSeconds (20));
324  SetEifsNoDifs (MicroSeconds (10 + 304));
325  SetPifs (MicroSeconds (10 + 20));
326  SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
327  SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
328 }
329 
330 void
332 {
333  SetSifs (MicroSeconds (32));
334  SetSlot (MicroSeconds (13));
335  SetEifsNoDifs (MicroSeconds (32 + 88));
336  SetPifs (MicroSeconds (32 + 13));
337  SetCtsTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
338  SetAckTimeout (MicroSeconds (32 + 88 + 13 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
339 }
340 
341 void
343 {
344  SetSifs (MicroSeconds (64));
345  SetSlot (MicroSeconds (21));
346  SetEifsNoDifs (MicroSeconds (64 + 176));
347  SetPifs (MicroSeconds (64 + 21));
348  SetCtsTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
349  SetAckTimeout (MicroSeconds (64 + 176 + 21 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
350 }
351 
352 void
354 {
356 }
357 
358 void
360 {
362 }
363 
364 void
365 WifiMac::ConfigureDcf (Ptr<Dcf> dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
366 {
367  /* see IEE802.11 section 7.3.2.29 */
368  switch (ac)
369  {
370  case AC_VO:
371  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
372  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
373  dcf->SetAifsn (2);
374  break;
375  case AC_VI:
376  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
377  dcf->SetMaxCw (cwmin);
378  dcf->SetAifsn (2);
379  break;
380  case AC_BE:
381  dcf->SetMinCw (cwmin);
382  dcf->SetMaxCw (cwmax);
383  dcf->SetAifsn (3);
384  break;
385  case AC_BK:
386  dcf->SetMinCw (cwmin);
387  dcf->SetMaxCw (cwmax);
388  dcf->SetAifsn (7);
389  break;
390  case AC_BE_NQOS:
391  dcf->SetMinCw (cwmin);
392  dcf->SetMaxCw (cwmax);
393  dcf->SetAifsn (2);
394  break;
395  case AC_UNDEF:
396  NS_FATAL_ERROR ("I don't know what to do with this");
397  break;
398  }
399 }
400 
401 void
402 WifiMac::ConfigureCCHDcf (Ptr<Dcf> dcf, uint32_t cwmin, uint32_t cwmax, enum AcIndex ac)
403 {
404  /* see IEEE 1609.4-2006 section 6.3.1, Table 1 */
405  switch (ac)
406  {
407  case AC_VO:
408  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
409  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
410  dcf->SetAifsn (2);
411  break;
412  case AC_VI:
413  dcf->SetMinCw ((cwmin + 1) / 4 - 1);
414  dcf->SetMaxCw ((cwmin + 1) / 2 - 1);
415  dcf->SetAifsn (3);
416  break;
417  case AC_BE:
418  dcf->SetMinCw ((cwmin + 1) / 2 - 1);
419  dcf->SetMaxCw (cwmin);
420  dcf->SetAifsn (6);
421  break;
422  case AC_BK:
423  dcf->SetMinCw (cwmin);
424  dcf->SetMaxCw (cwmax);
425  dcf->SetAifsn (9);
426  break;
427  case AC_BE_NQOS:
428  dcf->SetMinCw (cwmin);
429  dcf->SetMaxCw (cwmax);
430  dcf->SetAifsn (2);
431  break;
432  case AC_UNDEF:
433  NS_FATAL_ERROR ("I don't know what to do with this");
434  break;
435  }
436 }
437 } // namespace ns3