equal
deleted
inserted
replaced
22 #include "ns3/simulator.h" |
22 #include "ns3/simulator.h" |
23 #include "ns3/assert.h" |
23 #include "ns3/assert.h" |
24 #include "ns3/log.h" |
24 #include "ns3/log.h" |
25 #include "ns3/node.h" |
25 #include "ns3/node.h" |
26 #include "ns3/uinteger.h" |
26 #include "ns3/uinteger.h" |
|
27 #include "ns3/trace-source-accessor.h" |
27 |
28 |
28 #include "nqsta-wifi-mac.h" |
29 #include "nqsta-wifi-mac.h" |
29 #include "wifi-mac-header.h" |
30 #include "wifi-mac-header.h" |
30 #include "mgt-headers.h" |
31 #include "mgt-headers.h" |
31 #include "wifi-phy.h" |
32 #include "wifi-phy.h" |
87 MakeBooleanChecker ()) |
88 MakeBooleanChecker ()) |
88 .AddAttribute ("DcaTxop", "The DcaTxop object", |
89 .AddAttribute ("DcaTxop", "The DcaTxop object", |
89 PointerValue (), |
90 PointerValue (), |
90 MakePointerAccessor (&NqstaWifiMac::DoGetDcaTxop), |
91 MakePointerAccessor (&NqstaWifiMac::DoGetDcaTxop), |
91 MakePointerChecker<DcaTxop> ()) |
92 MakePointerChecker<DcaTxop> ()) |
|
93 .AddTraceSource ("Assoc", "Associated with an access point.", |
|
94 MakeTraceSourceAccessor (&NqstaWifiMac::m_assocLogger)) |
|
95 .AddTraceSource ("DeAssoc", "Association with an access point lost.", |
|
96 MakeTraceSourceAccessor (&NqstaWifiMac::m_deAssocLogger)) |
92 ; |
97 ; |
93 return tid; |
98 return tid; |
94 } |
99 } |
95 |
100 |
96 |
101 |
382 /* we were associated but we missed a bunch of beacons |
387 /* we were associated but we missed a bunch of beacons |
383 * so we should assume we are not associated anymore. |
388 * so we should assume we are not associated anymore. |
384 * We try to initiate a probe request now. |
389 * We try to initiate a probe request now. |
385 */ |
390 */ |
386 m_linkDown (); |
391 m_linkDown (); |
387 m_state = WAIT_PROBE_RESP; |
392 SetState (WAIT_PROBE_RESP); |
388 SendProbeRequest (); |
393 SendProbeRequest (); |
389 break; |
394 break; |
390 case WAIT_ASSOC_RESP: |
395 case WAIT_ASSOC_RESP: |
391 /* we have sent an assoc request so we do not need to |
396 /* we have sent an assoc request so we do not need to |
392 re-send an assoc request right now. We just need to |
397 re-send an assoc request right now. We just need to |
405 |
410 |
406 void |
411 void |
407 NqstaWifiMac::AssocRequestTimeout (void) |
412 NqstaWifiMac::AssocRequestTimeout (void) |
408 { |
413 { |
409 NS_LOG_FUNCTION (this); |
414 NS_LOG_FUNCTION (this); |
410 m_state = WAIT_ASSOC_RESP; |
415 SetState (WAIT_ASSOC_RESP); |
411 SendAssociationRequest (); |
416 SendAssociationRequest (); |
412 } |
417 } |
413 void |
418 void |
414 NqstaWifiMac::ProbeRequestTimeout (void) |
419 NqstaWifiMac::ProbeRequestTimeout (void) |
415 { |
420 { |
416 NS_LOG_FUNCTION (this); |
421 NS_LOG_FUNCTION (this); |
417 m_state = WAIT_PROBE_RESP; |
422 SetState (WAIT_PROBE_RESP); |
418 SendProbeRequest (); |
423 SendProbeRequest (); |
419 } |
424 } |
420 void |
425 void |
421 NqstaWifiMac::MissedBeacons (void) |
426 NqstaWifiMac::MissedBeacons (void) |
422 { |
427 { |
426 m_beaconWatchdog = Simulator::Schedule (m_beaconWatchdogEnd - Simulator::Now (), |
431 m_beaconWatchdog = Simulator::Schedule (m_beaconWatchdogEnd - Simulator::Now (), |
427 &NqstaWifiMac::MissedBeacons, this); |
432 &NqstaWifiMac::MissedBeacons, this); |
428 return; |
433 return; |
429 } |
434 } |
430 NS_LOG_DEBUG ("beacon missed"); |
435 NS_LOG_DEBUG ("beacon missed"); |
431 m_state = BEACON_MISSED; |
436 SetState (BEACON_MISSED); |
432 TryToEnsureAssociated (); |
437 TryToEnsureAssociated (); |
433 } |
438 } |
434 void |
439 void |
435 NqstaWifiMac::RestartBeaconWatchdog (Time delay) |
440 NqstaWifiMac::RestartBeaconWatchdog (Time delay) |
436 { |
441 { |
540 RestartBeaconWatchdog (delay); |
545 RestartBeaconWatchdog (delay); |
541 SetBssid (hdr->GetAddr3 ()); |
546 SetBssid (hdr->GetAddr3 ()); |
542 } |
547 } |
543 if (goodBeacon && m_state == BEACON_MISSED) |
548 if (goodBeacon && m_state == BEACON_MISSED) |
544 { |
549 { |
545 m_state = WAIT_ASSOC_RESP; |
550 SetState (WAIT_ASSOC_RESP); |
546 SendAssociationRequest (); |
551 SendAssociationRequest (); |
547 } |
552 } |
548 } |
553 } |
549 else if (hdr->IsProbeResp ()) |
554 else if (hdr->IsProbeResp ()) |
550 { |
555 { |
562 RestartBeaconWatchdog (delay); |
567 RestartBeaconWatchdog (delay); |
563 if (m_probeRequestEvent.IsRunning ()) |
568 if (m_probeRequestEvent.IsRunning ()) |
564 { |
569 { |
565 m_probeRequestEvent.Cancel (); |
570 m_probeRequestEvent.Cancel (); |
566 } |
571 } |
567 m_state = WAIT_ASSOC_RESP; |
572 SetState (WAIT_ASSOC_RESP); |
568 SendAssociationRequest (); |
573 SendAssociationRequest (); |
569 } |
574 } |
570 } |
575 } |
571 else if (hdr->IsAssocResp ()) |
576 else if (hdr->IsAssocResp ()) |
572 { |
577 { |
578 { |
583 { |
579 m_assocRequestEvent.Cancel (); |
584 m_assocRequestEvent.Cancel (); |
580 } |
585 } |
581 if (assocResp.GetStatusCode ().IsSuccess ()) |
586 if (assocResp.GetStatusCode ().IsSuccess ()) |
582 { |
587 { |
583 m_state = ASSOCIATED; |
588 SetState (ASSOCIATED); |
584 NS_LOG_DEBUG ("assoc completed"); |
589 NS_LOG_DEBUG ("assoc completed"); |
585 SupportedRates rates = assocResp.GetSupportedRates (); |
590 SupportedRates rates = assocResp.GetSupportedRates (); |
586 WifiRemoteStation *ap = m_stationManager->Lookup (hdr->GetAddr2 ()); |
591 WifiRemoteStation *ap = m_stationManager->Lookup (hdr->GetAddr2 ()); |
587 for (uint32_t i = 0; i < m_phy->GetNModes (); i++) |
592 for (uint32_t i = 0; i < m_phy->GetNModes (); i++) |
588 { |
593 { |
602 } |
607 } |
603 } |
608 } |
604 else |
609 else |
605 { |
610 { |
606 NS_LOG_DEBUG ("assoc refused"); |
611 NS_LOG_DEBUG ("assoc refused"); |
607 m_state = REFUSED; |
612 SetState (REFUSED); |
608 } |
613 } |
609 } |
614 } |
610 } |
615 } |
611 } |
616 } |
612 |
617 |
620 rates.AddSupportedRate (mode.GetDataRate ()); |
625 rates.AddSupportedRate (mode.GetDataRate ()); |
621 } |
626 } |
622 return rates; |
627 return rates; |
623 } |
628 } |
624 |
629 |
|
630 void |
|
631 NqstaWifiMac::SetState (MacState value) |
|
632 { |
|
633 if (value == ASSOCIATED && |
|
634 m_state != ASSOCIATED) |
|
635 { |
|
636 m_assocLogger (GetBssid ()); |
|
637 } |
|
638 else if (value != ASSOCIATED && |
|
639 m_state == ASSOCIATED) |
|
640 { |
|
641 m_deAssocLogger (GetBssid ()); |
|
642 } |
|
643 m_state = value; |
|
644 } |
|
645 |
625 } // namespace ns3 |
646 } // namespace ns3 |