From 0d39d4643ef8e33d9fddf63042ada981ba34d7d2 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Wed, 6 Sep 2023 15:50:51 +0200 Subject: [PATCH] wifi: Non-AP MLDs use a single beacon watchdog --- src/wifi/model/sta-wifi-mac.cc | 51 ++++++++++++++++------------------ src/wifi/model/sta-wifi-mac.h | 16 ++++------- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/src/wifi/model/sta-wifi-mac.cc b/src/wifi/model/sta-wifi-mac.cc index 3dc12e7ad..cfab2983b 100644 --- a/src/wifi/model/sta-wifi-mac.cc +++ b/src/wifi/model/sta-wifi-mac.cc @@ -814,14 +814,9 @@ StaWifiMac::ScanningTimeout(const std::optional& bestAp) }; Time beaconInterval = std::visit(getBeaconInterval, bestAp->m_frame); Time delay = beaconInterval * m_maxMissedBeacons; - // restart beacon watchdog for all links to setup - for (const auto& [id, link] : GetLinks()) - { - if (GetStaLink(link).bssid.has_value() || GetNLinks() == 1) - { - RestartBeaconWatchdog(delay, id); - } - } + // restart beacon watchdog + RestartBeaconWatchdog(delay); + SetState(WAIT_ASSOC_RESP); SendAssociationRequest(false); } @@ -835,20 +830,19 @@ StaWifiMac::AssocRequestTimeout() } void -StaWifiMac::MissedBeacons(uint8_t linkId) +StaWifiMac::MissedBeacons() { - NS_LOG_FUNCTION(this << +linkId); - auto& link = GetLink(linkId); - if (link.beaconWatchdogEnd > Simulator::Now()) + NS_LOG_FUNCTION(this); + + if (m_beaconWatchdogEnd > Simulator::Now()) { - if (link.beaconWatchdog.IsRunning()) + if (m_beaconWatchdog.IsRunning()) { - link.beaconWatchdog.Cancel(); + m_beaconWatchdog.Cancel(); } - link.beaconWatchdog = Simulator::Schedule(link.beaconWatchdogEnd - Simulator::Now(), - &StaWifiMac::MissedBeacons, - this, - linkId); + m_beaconWatchdog = Simulator::Schedule(m_beaconWatchdogEnd - Simulator::Now(), + &StaWifiMac::MissedBeacons, + this); return; } NS_LOG_DEBUG("beacon missed"); @@ -856,9 +850,12 @@ StaWifiMac::MissedBeacons(uint8_t linkId) // a frame, wait until the RX is completed (otherwise, crashes may occur if // we are receiving a MU frame because its reception requires the STA-ID) Time delay = Seconds(0); - if (GetWifiPhy(linkId)->IsStateRx()) + for (const auto& [id, link] : GetLinks()) { - delay = GetWifiPhy(linkId)->GetDelayUntilIdle(); + if (link->phy->IsStateRx()) + { + delay = std::max(delay, link->phy->GetDelayUntilIdle()); + } } Simulator::Schedule(delay, &StaWifiMac::Disassociated, this); } @@ -890,15 +887,15 @@ StaWifiMac::Disassociated() } void -StaWifiMac::RestartBeaconWatchdog(Time delay, uint8_t linkId) +StaWifiMac::RestartBeaconWatchdog(Time delay) { - NS_LOG_FUNCTION(this << delay << +linkId); - auto& link = GetLink(linkId); - link.beaconWatchdogEnd = std::max(Simulator::Now() + delay, link.beaconWatchdogEnd); - if (Simulator::GetDelayLeft(link.beaconWatchdog) < delay && link.beaconWatchdog.IsExpired()) + NS_LOG_FUNCTION(this << delay); + + m_beaconWatchdogEnd = std::max(Simulator::Now() + delay, m_beaconWatchdogEnd); + if (Simulator::GetDelayLeft(m_beaconWatchdog) < delay && m_beaconWatchdog.IsExpired()) { NS_LOG_DEBUG("really restart watchdog."); - link.beaconWatchdog = Simulator::Schedule(delay, &StaWifiMac::MissedBeacons, this, linkId); + m_beaconWatchdog = Simulator::Schedule(delay, &StaWifiMac::MissedBeacons, this); } } @@ -1246,7 +1243,7 @@ StaWifiMac::ReceiveBeacon(Ptr mpdu, uint8_t linkId) m_beaconArrival(Simulator::Now()); Time delay = MicroSeconds(std::get(apInfo.m_frame).GetBeaconIntervalUs() * m_maxMissedBeacons); - RestartBeaconWatchdog(delay, linkId); + RestartBeaconWatchdog(delay); UpdateApInfo(apInfo.m_frame, hdr.GetAddr2(), hdr.GetAddr3(), linkId); } else diff --git a/src/wifi/model/sta-wifi-mac.h b/src/wifi/model/sta-wifi-mac.h index 5a32fff75..858889958 100644 --- a/src/wifi/model/sta-wifi-mac.h +++ b/src/wifi/model/sta-wifi-mac.h @@ -357,8 +357,6 @@ class StaWifiMac : public WifiMac bool sendAssocReq; //!< whether this link is used to send the //!< Association Request frame std::optional bssid; //!< BSSID of the AP to associate with over this link - EventId beaconWatchdog; //!< beacon watchdog - Time beaconWatchdogEnd{0}; //!< beacon watchdog end WifiPowerManagementMode pmMode{WIFI_PM_ACTIVE}; /**< the current PM mode, if the STA is associated, or the PM mode to switch to upon association, otherwise */ @@ -506,19 +504,15 @@ class StaWifiMac : public WifiMac */ bool IsWaitAssocResp() const; /** - * This method is called after we have not received a beacon from the AP - * on the given link. - * - * \param linkId the ID of the given link + * This method is called after we have not received a beacon from the AP on any link. */ - void MissedBeacons(uint8_t linkId); + void MissedBeacons(); /** - * Restarts the beacon timer for the given link. + * Restarts the beacon timer. * * \param delay the delay before the watchdog fires - * \param linkId the ID of the given link */ - void RestartBeaconWatchdog(Time delay, uint8_t linkId); + void RestartBeaconWatchdog(Time delay); /** * Set the state to unassociated and try to associate again. */ @@ -628,6 +622,8 @@ class StaWifiMac : public WifiMac Time m_assocRequestTimeout; ///< association request timeout EventId m_assocRequestEvent; ///< association request event uint32_t m_maxMissedBeacons; ///< maximum missed beacons + EventId m_beaconWatchdog; //!< beacon watchdog + Time m_beaconWatchdogEnd{0}; //!< beacon watchdog end bool m_activeProbing; ///< active probing Ptr m_probeDelay; ///< RandomVariable used to randomize the time ///< of the first Probe Response on each channel