A Discrete-Event Network Simulator
API
sta-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) 2006, 2009 INRIA
4  * Copyright (c) 2009 MIRKO BANCHI
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Mirko Banchi <mk.banchi@gmail.com>
21  */
22 
23 #include "sta-wifi-mac.h"
24 #include "ns3/log.h"
25 #include "ns3/simulator.h"
26 #include "ns3/string.h"
27 #include "ns3/pointer.h"
28 #include "ns3/boolean.h"
29 #include "ns3/trace-source-accessor.h"
30 #include "mac-low.h"
31 #include "dcf-manager.h"
32 #include "mac-rx-middle.h"
33 #include "mac-tx-middle.h"
34 #include "wifi-mac-header.h"
35 #include "msdu-aggregator.h"
36 #include "amsdu-subframe-header.h"
37 #include "mgt-headers.h"
38 #include "ht-capabilities.h"
39 #include "ht-operations.h"
40 #include "vht-capabilities.h"
41 
42 /*
43  * The state machine for this STA is:
44  -------------- -----------
45  | Associated | <-------------------- -------> | Refused |
46  -------------- \ / -----------
47  \ \ /
48  \ ----------------- -----------------------------
49  \-> | Beacon Missed | --> | Wait Association Response |
50  ----------------- -----------------------------
51  \ ^
52  \ |
53  \ -----------------------
54  \-> | Wait Probe Response |
55  -----------------------
56  */
57 
58 namespace ns3 {
59 
60 NS_LOG_COMPONENT_DEFINE ("StaWifiMac");
61 
62 NS_OBJECT_ENSURE_REGISTERED (StaWifiMac);
63 
64 TypeId
66 {
67  static TypeId tid = TypeId ("ns3::StaWifiMac")
69  .SetGroupName ("Wifi")
70  .AddConstructor<StaWifiMac> ()
71  .AddAttribute ("ProbeRequestTimeout", "The interval between two consecutive probe request attempts.",
72  TimeValue (Seconds (0.05)),
74  MakeTimeChecker ())
75  .AddAttribute ("AssocRequestTimeout", "The interval between two consecutive assoc request attempts.",
76  TimeValue (Seconds (0.5)),
78  MakeTimeChecker ())
79  .AddAttribute ("MaxMissedBeacons",
80  "Number of beacons which much be consecutively missed before "
81  "we attempt to restart association.",
82  UintegerValue (10),
84  MakeUintegerChecker<uint32_t> ())
85  .AddAttribute ("ActiveProbing",
86  "If true, we send probe requests. If false, we don't."
87  "NOTE: if more than one STA in your simulation is using active probing, "
88  "you should enable it at a different simulation time for each STA, "
89  "otherwise all the STAs will start sending probes at the same time resulting in collisions. "
90  "See bug 1060 for more info.",
91  BooleanValue (false),
94  .AddTraceSource ("Assoc", "Associated with an access point.",
96  "ns3::Mac48Address::TracedCallback")
97  .AddTraceSource ("DeAssoc", "Association with an access point lost.",
99  "ns3::Mac48Address::TracedCallback")
100  ;
101  return tid;
102 }
103 
105  : m_state (BEACON_MISSED),
106  m_probeRequestEvent (),
107  m_assocRequestEvent (),
108  m_beaconWatchdogEnd (Seconds (0.0))
109 {
110  NS_LOG_FUNCTION (this);
111 
112  //Let the lower layers know that we are acting as a non-AP STA in
113  //an infrastructure BSS.
115 }
116 
118 {
119  NS_LOG_FUNCTION (this);
120 }
121 
122 void
124 {
125  NS_LOG_FUNCTION (this << missed);
126  m_maxMissedBeacons = missed;
127 }
128 
129 void
131 {
132  NS_LOG_FUNCTION (this << timeout);
134 }
135 
136 void
138 {
139  NS_LOG_FUNCTION (this << timeout);
141 }
142 
143 void
145 {
146  NS_LOG_FUNCTION (this);
148 }
149 
150 void
152 {
153  NS_LOG_FUNCTION (this << enable);
154  if (enable)
155  {
157  }
158  else
159  {
161  }
162  m_activeProbing = enable;
163 }
164 
166 {
167  return m_activeProbing;
168 }
169 
170 void
172 {
173  NS_LOG_FUNCTION (this);
174  WifiMacHeader hdr;
175  hdr.SetProbeReq ();
177  hdr.SetAddr2 (GetAddress ());
179  hdr.SetDsNotFrom ();
180  hdr.SetDsNotTo ();
181  Ptr<Packet> packet = Create<Packet> ();
182  MgtProbeRequestHeader probe;
183  probe.SetSsid (GetSsid ());
184  probe.SetSupportedRates (GetSupportedRates ());
186  {
187  probe.SetHtCapabilities (GetHtCapabilities ());
188  hdr.SetNoOrder ();
189  }
190  if (m_vhtSupported)
191  {
192  probe.SetVhtCapabilities (GetVhtCapabilities ());
193  }
194  packet->AddHeader (probe);
195 
196  //The standard is not clear on the correct queue for management
197  //frames if we are a QoS AP. The approach taken here is to always
198  //use the DCF for these regardless of whether we have a QoS
199  //association or not.
200  m_dca->Queue (packet, hdr);
201 
203  {
205  }
208 }
209 
210 void
212 {
213  NS_LOG_FUNCTION (this << GetBssid ());
214  WifiMacHeader hdr;
215  hdr.SetAssocReq ();
216  hdr.SetAddr1 (GetBssid ());
217  hdr.SetAddr2 (GetAddress ());
218  hdr.SetAddr3 (GetBssid ());
219  hdr.SetDsNotFrom ();
220  hdr.SetDsNotTo ();
221  Ptr<Packet> packet = Create<Packet> ();
222  MgtAssocRequestHeader assoc;
223  assoc.SetSsid (GetSsid ());
224  assoc.SetSupportedRates (GetSupportedRates ());
225  assoc.SetCapabilities (GetCapabilities ());
227  {
228  assoc.SetHtCapabilities (GetHtCapabilities ());
229  hdr.SetNoOrder ();
230  }
231  if (m_vhtSupported)
232  {
233  assoc.SetVhtCapabilities (GetVhtCapabilities ());
234  }
235  packet->AddHeader (assoc);
236 
237  //The standard is not clear on the correct queue for management
238  //frames if we are a QoS AP. The approach taken here is to always
239  //use the DCF for these regardless of whether we have a QoS
240  //association or not.
241  m_dca->Queue (packet, hdr);
242 
244  {
246  }
249 }
250 
251 void
253 {
254  NS_LOG_FUNCTION (this);
255  switch (m_state)
256  {
257  case ASSOCIATED:
258  return;
259  break;
260  case WAIT_PROBE_RESP:
261  /* we have sent a probe request earlier so we
262  do not need to re-send a probe request immediately.
263  We just need to wait until probe-request-timeout
264  or until we get a probe response
265  */
266  break;
267  case BEACON_MISSED:
268  /* we were associated but we missed a bunch of beacons
269  * so we should assume we are not associated anymore.
270  * We try to initiate a probe request now.
271  */
272  m_linkDown ();
273  if (m_activeProbing)
274  {
276  SendProbeRequest ();
277  }
278  break;
279  case WAIT_ASSOC_RESP:
280  /* we have sent an assoc request so we do not need to
281  re-send an assoc request right now. We just need to
282  wait until either assoc-request-timeout or until
283  we get an assoc response.
284  */
285  break;
286  case REFUSED:
287  /* we have sent an assoc request and received a negative
288  assoc resp. We wait until someone restarts an
289  association with a given ssid.
290  */
291  break;
292  }
293 }
294 
295 void
297 {
298  NS_LOG_FUNCTION (this);
301 }
302 
303 void
305 {
306  NS_LOG_FUNCTION (this);
308  SendProbeRequest ();
309 }
310 
311 void
313 {
314  NS_LOG_FUNCTION (this);
316  {
318  {
320  }
323  return;
324  }
325  NS_LOG_DEBUG ("beacon missed");
328 }
329 
330 void
332 {
333  NS_LOG_FUNCTION (this << delay);
337  {
338  NS_LOG_DEBUG ("really restart watchdog.");
340  }
341 }
342 
343 bool
345 {
346  return m_state == ASSOCIATED;
347 }
348 
349 bool
351 {
352  return m_state == WAIT_ASSOC_RESP;
353 }
354 
355 void
357 {
358  NS_LOG_FUNCTION (this << packet << to);
359  if (!IsAssociated ())
360  {
361  NotifyTxDrop (packet);
363  return;
364  }
365  WifiMacHeader hdr;
366 
367  //If we are not a QoS AP then we definitely want to use AC_BE to
368  //transmit the packet. A TID of zero will map to AC_BE (through \c
369  //QosUtilsMapTidToAc()), so we use that as our default here.
370  uint8_t tid = 0;
371 
372  //For now, an AP that supports QoS does not support non-QoS
373  //associations, and vice versa. In future the AP model should
374  //support simultaneously associated QoS and non-QoS STAs, at which
375  //point there will need to be per-association QoS state maintained
376  //by the association state machine, and consulted here.
377  if (m_qosSupported)
378  {
381  hdr.SetQosNoEosp ();
382  hdr.SetQosNoAmsdu ();
383  //Transmission of multiple frames in the same TXOP is not
384  //supported for now
385  hdr.SetQosTxopLimit (0);
386 
387  //Fill in the QoS control field in the MAC header
388  tid = QosUtilsGetTidForPacket (packet);
389  //Any value greater than 7 is invalid and likely indicates that
390  //the packet had no QoS tag, so we revert to zero, which'll
391  //mean that AC_BE is used.
392  if (tid > 7)
393  {
394  tid = 0;
395  }
396  hdr.SetQosTid (tid);
397  }
398  else
399  {
400  hdr.SetTypeData ();
401  }
403  {
404  hdr.SetNoOrder ();
405  }
406 
407  hdr.SetAddr1 (GetBssid ());
408  hdr.SetAddr2 (m_low->GetAddress ());
409  hdr.SetAddr3 (to);
410  hdr.SetDsNotFrom ();
411  hdr.SetDsTo ();
412 
413  if (m_qosSupported)
414  {
415  //Sanity check that the TID is valid
416  NS_ASSERT (tid < 8);
417  m_edca[QosUtilsMapTidToAc (tid)]->Queue (packet, hdr);
418  }
419  else
420  {
421  m_dca->Queue (packet, hdr);
422  }
423 }
424 
425 void
427 {
428  NS_LOG_FUNCTION (this << packet << hdr);
429  NS_ASSERT (!hdr->IsCtl ());
430  if (hdr->GetAddr3 () == GetAddress ())
431  {
432  NS_LOG_LOGIC ("packet sent by us.");
433  return;
434  }
435  else if (hdr->GetAddr1 () != GetAddress ()
436  && !hdr->GetAddr1 ().IsGroup ())
437  {
438  NS_LOG_LOGIC ("packet is not for us");
439  NotifyRxDrop (packet);
440  return;
441  }
442  else if (hdr->IsData ())
443  {
444  if (!IsAssociated ())
445  {
446  NS_LOG_LOGIC ("Received data frame while not associated: ignore");
447  NotifyRxDrop (packet);
448  return;
449  }
450  if (!(hdr->IsFromDs () && !hdr->IsToDs ()))
451  {
452  NS_LOG_LOGIC ("Received data frame not from the DS: ignore");
453  NotifyRxDrop (packet);
454  return;
455  }
456  if (hdr->GetAddr2 () != GetBssid ())
457  {
458  NS_LOG_LOGIC ("Received data frame not from the BSS we are associated with: ignore");
459  NotifyRxDrop (packet);
460  return;
461  }
462  if (hdr->IsQosData ())
463  {
464  if (hdr->IsQosAmsdu ())
465  {
466  NS_ASSERT (hdr->GetAddr3 () == GetBssid ());
467  DeaggregateAmsduAndForward (packet, hdr);
468  packet = 0;
469  }
470  else
471  {
472  ForwardUp (packet, hdr->GetAddr3 (), hdr->GetAddr1 ());
473  }
474  }
475  else
476  {
477  ForwardUp (packet, hdr->GetAddr3 (), hdr->GetAddr1 ());
478  }
479  return;
480  }
481  else if (hdr->IsProbeReq ()
482  || hdr->IsAssocReq ())
483  {
484  //This is a frame aimed at an AP, so we can safely ignore it.
485  NotifyRxDrop (packet);
486  return;
487  }
488  else if (hdr->IsBeacon ())
489  {
490  MgtBeaconHeader beacon;
491  packet->RemoveHeader (beacon);
492  CapabilityInformation capabilities = beacon.GetCapabilities ();
493  bool goodBeacon = false;
494  if (GetSsid ().IsBroadcast ()
495  || beacon.GetSsid ().IsEqual (GetSsid ()))
496  {
497  NS_LOG_LOGIC ("Beacon is for our SSID");
498  goodBeacon = true;
499  }
500  SupportedRates rates = beacon.GetSupportedRates ();
501  bool bssMembershipSelectorMatch = false;
502  for (uint32_t i = 0; i < m_phy->GetNBssMembershipSelectors (); i++)
503  {
504  uint32_t selector = m_phy->GetBssMembershipSelector (i);
505  if (rates.IsBssMembershipSelectorRate (selector))
506  {
507  NS_LOG_LOGIC ("Beacon is matched to our BSS membership selector");
508  bssMembershipSelectorMatch = true;
509  }
510  }
511  if (m_phy->GetNBssMembershipSelectors () > 0 && bssMembershipSelectorMatch == false)
512  {
513  NS_LOG_LOGIC ("No match for BSS membership selector");
514  goodBeacon = false;
515  }
516  if ((IsWaitAssocResp () || IsAssociated ()) && hdr->GetAddr3 () != GetBssid ())
517  {
518  NS_LOG_LOGIC ("Beacon is not for us");
519  goodBeacon = false;
520  }
521  if (goodBeacon)
522  {
524  RestartBeaconWatchdog (delay);
525  SetBssid (hdr->GetAddr3 ());
526  bool isShortPreambleEnabled = capabilities.IsShortPreamble ();
527  if (m_erpSupported)
528  {
529  ErpInformation erpInformation = beacon.GetErpInformation ();
530  isShortPreambleEnabled &= !erpInformation.GetBarkerPreambleMode ();
531  if (erpInformation.GetUseProtection() == true)
532  {
534  }
535  else
536  {
538  }
539  if (capabilities.IsShortSlotTime () == true)
540  {
541  //enable short slot time
542  SetSlot (MicroSeconds (9));
543  }
544  else
545  {
546  //disable short slot time
547  SetSlot (MicroSeconds (20));
548  }
549  }
550  if (m_qosSupported)
551  {
552  EdcaParameterSet edcaParameters = beacon.GetEdcaParameterSet ();
553  //The value of the TXOP Limit field is specified as an unsigned integer, with the least significant octet transmitted first, in units of 32 μs.
554  SetEdcaParameters (AC_BE, edcaParameters.GetBeCWmin(), edcaParameters.GetBeCWmax(), edcaParameters.GetBeAifsn(), 32 * MicroSeconds (edcaParameters.GetBeTXOPLimit()));
555  SetEdcaParameters (AC_BK, edcaParameters.GetBkCWmin(), edcaParameters.GetBkCWmax(), edcaParameters.GetBkAifsn(), 32 * MicroSeconds (edcaParameters.GetBkTXOPLimit()));
556  SetEdcaParameters (AC_VI, edcaParameters.GetViCWmin(), edcaParameters.GetViCWmax(), edcaParameters.GetViAifsn(), 32 * MicroSeconds (edcaParameters.GetViTXOPLimit()));
557  SetEdcaParameters (AC_VO, edcaParameters.GetVoCWmin(), edcaParameters.GetVoCWmax(), edcaParameters.GetVoAifsn(), 32 * MicroSeconds (edcaParameters.GetVoTXOPLimit()));
558  }
559  m_stationManager->SetShortPreambleEnabled (isShortPreambleEnabled);
561  }
562  if (goodBeacon && m_state == BEACON_MISSED)
563  {
566  }
567  return;
568  }
569  else if (hdr->IsProbeResp ())
570  {
571  if (m_state == WAIT_PROBE_RESP)
572  {
573  MgtProbeResponseHeader probeResp;
574  packet->RemoveHeader (probeResp);
575  CapabilityInformation capabilities = probeResp.GetCapabilities ();
576  if (!probeResp.GetSsid ().IsEqual (GetSsid ()))
577  {
578  //not a probe resp for our ssid.
579  return;
580  }
581  SupportedRates rates = probeResp.GetSupportedRates ();
582  for (uint32_t i = 0; i < m_phy->GetNBssMembershipSelectors (); i++)
583  {
584  uint32_t selector = m_phy->GetBssMembershipSelector (i);
585  if (!rates.IsSupportedRate (selector))
586  {
587  return;
588  }
589  }
590  for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
591  {
592  WifiMode mode = m_phy->GetMode (i);
593  uint8_t nss = 1; // Assume 1 spatial stream
594  if (rates.IsSupportedRate (mode.GetDataRate (m_phy->GetChannelWidth (), false, nss)))
595  {
596  m_stationManager->AddSupportedMode (hdr->GetAddr2 (), mode);
597  if (rates.IsBasicRate (mode.GetDataRate (m_phy->GetChannelWidth (), false, nss)))
598  {
600  }
601  }
602  }
603 
604  bool isShortPreambleEnabled = capabilities.IsShortPreamble ();
605  if (m_erpSupported)
606  {
607  bool isErpAllowed = false;
608  for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
609  {
610  WifiMode mode = m_phy->GetMode (i);
611  if (mode.GetModulationClass () == WIFI_MOD_CLASS_ERP_OFDM && rates.IsSupportedRate (mode.GetDataRate (m_phy->GetChannelWidth (), false, 1)))
612  {
613  isErpAllowed = true;
614  break;
615  }
616  }
617  if (!isErpAllowed)
618  {
619  //disable short slot time and set cwMin to 31
620  SetSlot (MicroSeconds (20));
621  ConfigureContentionWindow (31, 1023);
622  }
623  else
624  {
625  ErpInformation erpInformation = probeResp.GetErpInformation ();
626  isShortPreambleEnabled &= !erpInformation.GetBarkerPreambleMode ();
628  {
629  //enable short slot time
630  SetSlot (MicroSeconds (9));
631  }
632  else
633  {
634  //disable short slot time
635  SetSlot (MicroSeconds (20));
636  }
637  ConfigureContentionWindow (15, 1023);
638  }
639  }
640  m_stationManager->SetShortPreambleEnabled (isShortPreambleEnabled);
642  SetBssid (hdr->GetAddr3 ());
643  Time delay = MicroSeconds (probeResp.GetBeaconIntervalUs () * m_maxMissedBeacons);
644  RestartBeaconWatchdog (delay);
646  {
648  }
651  }
652  return;
653  }
654  else if (hdr->IsAssocResp ())
655  {
656  if (m_state == WAIT_ASSOC_RESP)
657  {
658  MgtAssocResponseHeader assocResp;
659  packet->RemoveHeader (assocResp);
661  {
663  }
664  if (assocResp.GetStatusCode ().IsSuccess ())
665  {
667  NS_LOG_DEBUG ("assoc completed");
668  CapabilityInformation capabilities = assocResp.GetCapabilities ();
669  SupportedRates rates = assocResp.GetSupportedRates ();
670  bool isShortPreambleEnabled = capabilities.IsShortPreamble ();
671  if (m_erpSupported)
672  {
673  bool isErpAllowed = false;
674  for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
675  {
676  WifiMode mode = m_phy->GetMode (i);
677  if (mode.GetModulationClass () == WIFI_MOD_CLASS_ERP_OFDM && rates.IsSupportedRate (mode.GetDataRate (m_phy->GetChannelWidth (), false, 1)))
678  {
679  isErpAllowed = true;
680  break;
681  }
682  }
683  if (!isErpAllowed)
684  {
685  //disable short slot time and set cwMin to 31
686  SetSlot (MicroSeconds (20));
687  ConfigureContentionWindow (31, 1023);
688  }
689  else
690  {
691  ErpInformation erpInformation = assocResp.GetErpInformation ();
692  isShortPreambleEnabled &= !erpInformation.GetBarkerPreambleMode ();
694  {
695  //enable short slot time
696  SetSlot (MicroSeconds (9));
697  }
698  else
699  {
700  //disable short slot time
701  SetSlot (MicroSeconds (20));
702  }
703  ConfigureContentionWindow (15, 1023);
704  }
705  }
706  m_stationManager->SetShortPreambleEnabled (isShortPreambleEnabled);
708  if (m_qosSupported)
709  {
710  EdcaParameterSet edcaParameters = assocResp.GetEdcaParameterSet ();
711  //The value of the TXOP Limit field is specified as an unsigned integer, with the least significant octet transmitted first, in units of 32 μs.
712  SetEdcaParameters (AC_BE, edcaParameters.GetBeCWmin(), edcaParameters.GetBeCWmax(), edcaParameters.GetBeAifsn(), 32 * MicroSeconds (edcaParameters.GetBeTXOPLimit()));
713  SetEdcaParameters (AC_BK, edcaParameters.GetBkCWmin(), edcaParameters.GetBkCWmax(), edcaParameters.GetBkAifsn(), 32 * MicroSeconds (edcaParameters.GetBkTXOPLimit()));
714  SetEdcaParameters (AC_VI, edcaParameters.GetViCWmin(), edcaParameters.GetViCWmax(), edcaParameters.GetViAifsn(), 32 * MicroSeconds (edcaParameters.GetViTXOPLimit()));
715  SetEdcaParameters (AC_VO, edcaParameters.GetVoCWmin(), edcaParameters.GetVoCWmax(), edcaParameters.GetVoAifsn(), 32 * MicroSeconds (edcaParameters.GetVoTXOPLimit()));
716  }
717  if (m_htSupported)
718  {
719  HtCapabilities htcapabilities = assocResp.GetHtCapabilities ();
720  HtOperations htOperations = assocResp.GetHtOperations ();
721  m_stationManager->AddStationHtCapabilities (hdr->GetAddr2 (), htcapabilities);
722  }
723  if (m_vhtSupported)
724  {
725  VhtCapabilities vhtcapabilities = assocResp.GetVhtCapabilities ();
726  m_stationManager->AddStationVhtCapabilities (hdr->GetAddr2 (), vhtcapabilities);
727  }
728 
729  for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
730  {
731  WifiMode mode = m_phy->GetMode (i);
732  uint8_t nss = 1; // Assume 1 spatial stream
733  if (rates.IsSupportedRate (mode.GetDataRate (m_phy->GetChannelWidth (), false, nss)))
734  {
735  m_stationManager->AddSupportedMode (hdr->GetAddr2 (), mode);
736  if (rates.IsBasicRate (mode.GetDataRate (m_phy->GetChannelWidth (), false, nss)))
737  {
739  }
740  }
741  }
742  if (m_htSupported)
743  {
744  HtCapabilities htcapabilities = assocResp.GetHtCapabilities ();
745  for (uint32_t i = 0; i < m_phy->GetNMcs (); i++)
746  {
747  WifiMode mcs = m_phy->GetMcs (i);
748  if (mcs.GetModulationClass () == WIFI_MOD_CLASS_HT && htcapabilities.IsSupportedMcs (mcs.GetMcsValue ()))
749  {
750  m_stationManager->AddSupportedMcs (hdr->GetAddr2 (), mcs);
751  //here should add a control to add basic MCS when it is implemented
752  }
753  }
754  }
755  if (m_vhtSupported)
756  {
757  VhtCapabilities vhtcapabilities = assocResp.GetVhtCapabilities ();
758  for (uint32_t i = 0; i < m_phy->GetNMcs (); i++)
759  {
760  WifiMode mcs = m_phy->GetMcs (i);
761  if (mcs.GetModulationClass () == WIFI_MOD_CLASS_VHT && vhtcapabilities.IsSupportedTxMcs (mcs.GetMcsValue ()))
762  {
763  m_stationManager->AddSupportedMcs (hdr->GetAddr2 (), mcs);
764  //here should add a control to add basic MCS when it is implemented
765  }
766  }
767  }
768  if (!m_linkUp.IsNull ())
769  {
770  m_linkUp ();
771  }
772  }
773  else
774  {
775  NS_LOG_DEBUG ("assoc refused");
776  SetState (REFUSED);
777  }
778  }
779  return;
780  }
781 
782  //Invoke the receive handler of our parent class to deal with any
783  //other frames. Specifically, this will handle Block Ack-related
784  //Management Action frames.
785  RegularWifiMac::Receive (packet, hdr);
786 }
787 
790 {
791  SupportedRates rates;
792  uint8_t nss = 1; // Number of spatial streams is 1 for non-MIMO modes
794  {
795  for (uint32_t i = 0; i < m_phy->GetNBssMembershipSelectors (); i++)
796  {
798  }
799  }
800  for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
801  {
802  WifiMode mode = m_phy->GetMode (i);
803  uint64_t modeDataRate = mode.GetDataRate (m_phy->GetChannelWidth (), false, nss);
804  NS_LOG_DEBUG ("Adding supported rate of " << modeDataRate);
805  rates.AddSupportedRate (modeDataRate);
806  }
807  return rates;
808 }
809 
812 {
813  CapabilityInformation capabilities;
816  return capabilities;
817 }
818 
819 void
821 {
822  if (value == ASSOCIATED
823  && m_state != ASSOCIATED)
824  {
825  m_assocLogger (GetBssid ());
826  }
827  else if (value != ASSOCIATED
828  && m_state == ASSOCIATED)
829  {
831  }
832  m_state = value;
833 }
834 
835 void
836 StaWifiMac::SetEdcaParameters (AcIndex ac, uint8_t cwMin, uint8_t cwMax, uint8_t aifsn, Time txopLimit)
837 {
838  Ptr<EdcaTxopN> edca = m_edca.find (ac)->second;
839  edca->SetMinCw (cwMin);
840  edca->SetMaxCw (cwMax);
841  edca->SetAifsn (aifsn);
842  edca->SetTxopLimit (txopLimit);
843 }
844 
845 } //namespace ns3
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
Definition: simulator.cc:233
bool IsWaitAssocResp(void) const
Return whether we are waiting for an association response from an AP.
bool IsBeacon(void) const
Return true if the header is a Beacon header.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
The HT Operations Information ElementThis class knows how to serialise and deserialise the HT Operati...
Definition: ht-operations.h:54
virtual void SetMaxCw(uint32_t maxCw)
Set the maximum contention window size.
Definition: edca-txop-n.cc:399
TracedCallback< Mac48Address > m_deAssocLogger
Definition: sta-wifi-mac.h:202
void AddSupportedRate(uint32_t bs)
Add the given rate to the supported rates.
SupportedRates GetSupportedRates(void) const
Return an instance of SupportedRates that contains all rates that we support including HT rates...
virtual uint32_t GetNBssMembershipSelectors(void) const
The WifiPhy::NBssMembershipSelectors() method is used (e.g., by a WifiRemoteStationManager) to determ...
Definition: wifi-phy.cc:1200
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
bool IsSupportedTxMcs(uint8_t mcs) const
Time m_assocRequestTimeout
Definition: sta-wifi-mac.h:193
void AddSupportedMcs(Mac48Address address, WifiMode mcs)
Record the MCS index supported by the station.
SupportedRates GetSupportedRates(void) const
Return the supported rates.
Definition: mgt-headers.cc:183
bool GetShortSlotTimeEnabled(void) const
Return whether the device uses short slot time.
virtual void Receive(Ptr< Packet > packet, const WifiMacHeader *hdr)
This method acts as the MacRxMiddle receive callback and is invoked to notify us that a frame has bee...
Implement the header for management frames of type association request.
Definition: mgt-headers.h:46
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetQosAckPolicy(enum QosAckPolicy policy)
Set the QoS ACK policy in the QoS control field.
ERP-OFDM PHY (19.5)
Definition: wifi-mode.h:58
AttributeValue implementation for Boolean.
Definition: boolean.h:34
void SendAssociationRequest(void)
Forward an association request packet to the DCF.
CapabilityInformation GetCapabilities(void) const
Return the Capability information.
Definition: mgt-headers.cc:606
Ssid GetSsid(void) const
Return the Service Set Identifier (SSID).
Definition: mgt-headers.cc:171
HtOperations GetHtOperations(void) const
Return the HT operations.
Definition: mgt-headers.cc:630
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
void SetProbeReq(void)
Set Type/Subtype values for a probe request header.
uint64_t GetBeaconIntervalUs(void) const
Return the beacon interval in microseconds unit.
Definition: mgt-headers.cc:177
void AssocRequestTimeout(void)
This method is called after the association timeout occurred.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: boolean.h:81
Time m_probeRequestTimeout
Definition: sta-wifi-mac.h:192
void SetProbeRequestTimeout(Time timeout)
EdcaQueues m_edca
This is a map from Access Category index to the corresponding channel access function.
Mac48Address GetAddr3(void) const
Return the address in the Address 3 field.
enum WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:379
uint8_t GetViCWmax(void) const
uint8_t GetVoAifsn(void) const
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1270
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
Callback< void > m_linkUp
Callback when a link is up.
void ConfigureContentionWindow(uint32_t cwMin, uint32_t cwMax)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
The HT Capabilities Information ElementThis class knows how to serialise and deserialise the HT Capab...
bool IsAssocReq(void) const
Return true if the header is an Association Request header.
void SetSsid(Ssid ssid)
Set the Service Set Identifier (SSID).
Definition: mgt-headers.cc:421
void SetSlot(Time slotTime)
void NotifyRxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:284
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:65
VhtCapabilities GetVhtCapabilities(void) const
Return the VHT capabilities.
Definition: mgt-headers.cc:642
virtual void DeaggregateAmsduAndForward(Ptr< Packet > aggregatedPacket, const WifiMacHeader *hdr)
This method can be called to de-aggregate an A-MSDU and forward the constituent packets up the stack...
virtual uint8_t GetNMcs(void) const
The WifiPhy::GetNMcs() method is used (e.g., by a WifiRemoteStationManager) to determine the set of t...
Definition: wifi-phy.cc:2862
TracedCallback< Mac48Address > m_assocLogger
Definition: sta-wifi-mac.h:201
EventId m_assocRequestEvent
Definition: sta-wifi-mac.h:195
bool IsAssocResp(void) const
Return true if the header is an Association Response header.
VHT PHY (Clause 22)
Definition: wifi-mode.h:64
Ptr< WifiPhy > m_phy
Wifi PHY.
bool IsCtl(void) const
Return true if the Type is Control.
ns3::Time timeout
bool IsEqual(const Ssid &o) const
Check if the two SSIDs are equal.
Definition: ssid.cc:73
uint8_t GetVoCWmin(void) const
virtual Ssid GetSsid(void) const
Video.
Definition: qos-utils.h:43
The Supported Rates Information ElementThis class knows how to serialise and deserialise the Supporte...
Voice.
Definition: qos-utils.h:45
Best Effort.
Definition: qos-utils.h:39
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:99
bool IsQosAmsdu(void) const
Check if the A-MSDU present bit is set in the QoS control field.
VhtCapabilities GetVhtCapabilities(void) const
Return the VHT capability of the device.
bool IsProbeResp(void) const
Return true if the header is a Probe Response header.
Capability information.
virtual uint32_t GetBssMembershipSelector(uint32_t selector) const
The WifiPhy::BssMembershipSelector() method is used (e.g., by a WifiRemoteStationManager) to determin...
Definition: wifi-phy.cc:1206
void SetAssocRequestTimeout(Time timeout)
virtual void Receive(Ptr< Packet > packet, const WifiMacHeader *hdr)
This method acts as the MacRxMiddle receive callback and is invoked to notify us that a frame has bee...
ErpInformation GetErpInformation(void) const
Return the ERP information.
Definition: mgt-headers.cc:654
uint8_t QosUtilsGetTidForPacket(Ptr< const Packet > packet)
If a qos tag is attached to the packet, returns a value < 8.
Definition: qos-utils.cc:62
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:446
uint16_t GetBeTXOPLimit(void) const
uint8_t GetViCWmin(void) const
void SetShortSlotTimeEnabled(bool enable)
Enable or disable short slot time.
virtual void SetBssid(Mac48Address bssid)
void SendProbeRequest(void)
Forward a probe request packet to the DCF.
Background.
Definition: qos-utils.h:41
void ForwardUp(Ptr< Packet > packet, Mac48Address from, Mac48Address to)
Forward the packet up to the device.
base class for all MAC-level wifi objects.
void ProbeRequestTimeout(void)
This method is called after the probe request timeout occurred.
bool m_qosSupported
This Boolean is set true iff this WifiMac is to model 802.11e/WMM style Quality of Service...
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1238
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
void SetTypeOfStation(TypeOfStation type)
This method is invoked by a subclass to specify what type of station it is implementing.
#define max(a, b)
Definition: 80211b.c:45
uint16_t GetBkTXOPLimit(void) const
AttributeValue implementation for Time.
Definition: nstime.h:957
void SetDsNotTo(void)
Un-set the To DS bit in the Frame Control field.
uint8_t GetBeCWmin(void) const
MacState
The current MAC state of the STA.
Definition: sta-wifi-mac.h:90
Ptr< DcaTxop > m_dca
This holds a pointer to the DCF instance for this WifiMac - used for transmission of frames to non-Qo...
ErpInformation GetErpInformation(void) const
Return the ERP information.
Definition: mgt-headers.cc:273
void SetAddr3(Mac48Address address)
Fill the Address 3 field with the given address.
virtual void SetMinCw(uint32_t minCw)
Set the minimum contention window size.
Definition: edca-txop-n.cc:392
The IEEE 802.11ac VHT Capabilities.
void NotifyTxDrop(Ptr< const Packet > packet)
Definition: wifi-mac.cc:266
bool IsProbeReq(void) const
Return true if the header is a Probe Request header.
Hold an unsigned integer type.
Definition: uinteger.h:44
void MissedBeacons(void)
This method is called after we have not received a beacon from the AP.
uint8_t GetBarkerPreambleMode(void) const
void AddStationHtCapabilities(Mac48Address from, HtCapabilities htcapabilities)
Records HT capabilities of the remote station.
bool m_vhtSupported
This Boolean is set true iff this WifiMac is to model 802.11ac.
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition: qos-utils.cc:28
uint16_t GetVoTXOPLimit(void) const
HT PHY (Clause 20)
Definition: wifi-mode.h:62
uint8_t GetMcsValue(void) const
Definition: wifi-mode.cc:357
static Mac48Address GetBroadcast(void)
Mac48Address GetAddress(void) const
Return the MAC address of this MacLow.
Definition: mac-low.cc:627
uint8_t GetVoCWmax(void) const
bool GetActiveProbing(void) const
Return whether active probing is enabled.
virtual uint32_t GetNModes(void) const
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
Definition: wifi-phy.cc:2850
void SetState(enum MacState value)
Set the current MAC state.
void SetAssocReq(void)
Set Type/Subtype values for an association request header.
EdcaParameterSet GetEdcaParameterSet(void) const
Return the EDCA Parameter Set.
Definition: mgt-headers.cc:666
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
Ptr< MacLow > m_low
MacLow (RTS, CTS, DATA, ACK etc.)
SupportedRates GetSupportedRates(void)
Return the supported rates.
Definition: mgt-headers.cc:582
HtCapabilities GetHtCapabilities(void) const
Return the HT capability of the device.
Callback< void > m_linkDown
Callback when a link is down.
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
bool IsBasicRate(uint32_t bs) const
Check if the given rate is a basic rate.
uint32_t m_maxMissedBeacons
Definition: sta-wifi-mac.h:198
void StartActiveAssociation(void)
Start an active association sequence immediately.
virtual WifiMode GetMcs(uint8_t mcs) const
The WifiPhy::GetMcs() method is used (e.g., by a WifiRemoteStationManager) to determine the set of tr...
Definition: wifi-phy.cc:2868
void SetMaxMissedBeacons(uint32_t missed)
virtual uint32_t GetChannelWidth(void) const
Definition: wifi-phy.cc:1157
EventId m_beaconWatchdog
Definition: sta-wifi-mac.h:196
void AddBssMembershipSelectorRate(uint32_t bs)
Add a special value to the supported rate set, corresponding to a BSS membership selector.
virtual ~StaWifiMac()
bool IsToDs(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t GetBeCWmax(void) const
The EDCA Parameter SetThis class knows how to serialise and deserialise the EDCA Parameter Set...
uint8_t GetBkCWmax(void) const
void AddSupportedMode(Mac48Address address, WifiMode mode)
Invoked in a STA or AP to store the set of modes supported by a destination which is also supported l...
bool IsGroup(void) const
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
bool IsSupportedMcs(uint8_t mcs) const
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
static TypeId GetTypeId(void)
Definition: sta-wifi-mac.cc:65
void AddBasicMode(WifiMode mode)
Invoked in a STA upon association to store the set of rates which belong to the BSSBasicRateSet of th...
void SetUseNonErpProtection(bool enable)
Enable or disable protection for non-ERP stations.
an EUI-48 address
Definition: mac48-address.h:43
uint8_t GetBkCWmin(void) const
uint64_t GetDataRate(uint32_t channelWidth, bool isShortGuardInterval, uint8_t nss) const
Definition: wifi-mode.cc:109
uint16_t GetViTXOPLimit(void) const
uint8_t GetViAifsn(void) const
void RestartBeaconWatchdog(Time delay)
Restarts the beacon timer.
CapabilityInformation GetCapabilities(void) const
Return the Capability information of the current STA.
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
Definition: simulator.h:1401
void TryToEnsureAssociated(void)
Try to ensure that we are associated with an AP by taking an appropriate action depending on the curr...
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:958
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
void SetShortPreamble(bool shortPreamble)
Set the short preamble bit in the capability information field.
Implement the header for management frames of type probe request.
Definition: mgt-headers.h:283
bool m_htSupported
This Boolean is set true iff this WifiMac is to model 802.11n.
void SetActiveProbing(bool enable)
Enable or disable active probing.
Implement the header for management frames of type association response.
Definition: mgt-headers.h:151
virtual Mac48Address GetBssid(void) const
bool IsShortSlotTime(void) const
Check if the short slot time in the capability information field is set to 1.
void SetQosTxopLimit(uint8_t txop)
Set TXOP limit in the QoS control field.
bool IsData(void) const
Return true if the Type is DATA.
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS DATA...
EdcaParameterSet GetEdcaParameterSet(void) const
Return the EDCA Parameter Set.
Definition: mgt-headers.cc:285
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
virtual Mac48Address GetAddress(void) const
void SetTypeData(void)
Set Type/Subtype values for a data packet with no subtype equal to 0.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void SetQosNoAmsdu(void)
Set that A-MSDU is not present.
bool IsSuccess(void) const
Return whether the status code is success.
Definition: status-code.cc:44
virtual void Enqueue(Ptr< const Packet > packet, Mac48Address to)
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
void SetDsTo(void)
Set the To DS bit in the Frame Control field.
bool IsFromDs(void) const
uint8_t GetBeAifsn(void) const
bool IsSupportedRate(uint32_t bs) const
Check if the given rate is supported.
uint8_t GetBkAifsn(void) const
void SetNoOrder(void)
Unset order bit in the frame control field.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:911
The ErpInformation Information ElementThis class knows how to serialise and deserialise the ErpInform...
CapabilityInformation GetCapabilities(void) const
Return the Capability information.
Definition: mgt-headers.cc:195
void SetSsid(Ssid ssid)
Set the Service Set Identifier (SSID).
Definition: mgt-headers.cc:41
void SetType(enum WifiMacType type)
Set Type/Subtype values with the correct values depending on the given type.
enum MacState m_state
Definition: sta-wifi-mac.h:191
virtual bool GetShortSlotTimeSupported(void) const
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
Time m_beaconWatchdogEnd
Definition: sta-wifi-mac.h:197
bool m_erpSupported
This Boolean is set true iff this WifiMac is to model 802.11g.
virtual void SetTxopLimit(Time txopLimit)
Definition: edca-txop-n.cc:413
void SetShortSlotTime(bool shortSlotTime)
Set the short slot time bit in the capability information field.
EventId m_probeRequestEvent
Definition: sta-wifi-mac.h:194
void SetShortPreambleEnabled(bool enable)
Enable or disable short PLCP preambles.
Implement the header for management frames of type probe response.
Definition: mgt-headers.h:361
Ptr< WifiRemoteStationManager > m_stationManager
Remote station manager (rate control, RTS/CTS/fragmentation thresholds etc.)
virtual bool GetShortPlcpPreambleSupported(void) const
Return whether short PLCP preamble is supported.
Definition: wifi-phy.cc:592
void SetQosNoEosp()
Un-set the end of service period (EOSP) bit in the QoS control field.
uint8_t GetUseProtection(void) const
bool IsAssociated(void) const
Return whether we are associated with an AP.
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:59
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:58
void SetEdcaParameters(AcIndex ac, uint8_t cwMin, uint8_t cwMax, uint8_t aifsn, Time txopLimit)
Set the EDCA parameters.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:36
Implement the header for management frames of type beacon.
Definition: mgt-headers.h:525
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:257
void AddStationVhtCapabilities(Mac48Address from, VhtCapabilities vhtcapabilities)
Records VHT capabilities of the remote station.
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
virtual void SetAifsn(uint32_t aifsn)
Definition: edca-txop-n.cc:406
StatusCode GetStatusCode(void)
Return the status code.
Definition: mgt-headers.cc:576
virtual WifiMode GetMode(uint32_t mode) const
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
Definition: wifi-phy.cc:2856
void SetDsNotFrom(void)
Un-set the From DS bit in the Frame Control field.
bool IsBssMembershipSelectorRate(uint32_t bs) const
Check if the given rate is a BSS membership selector value.
HtCapabilities GetHtCapabilities(void) const
Return the HT capabilities.
Definition: mgt-headers.cc:618
The Wifi MAC high model for a non-AP STA in a BSS.
Definition: sta-wifi-mac.h:42
bool IsShortPreamble(void) const
Check if the short preamble bit in the capability information field is set to 1.