wifi: Non-AP MLDs use a single beacon watchdog

This commit is contained in:
Stefano Avallone
2023-09-06 15:50:51 +02:00
parent 7d660feb63
commit 0d39d4643e
2 changed files with 30 additions and 37 deletions

View File

@@ -814,14 +814,9 @@ StaWifiMac::ScanningTimeout(const std::optional<ApInfo>& 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<const WifiMpdu> mpdu, uint8_t linkId)
m_beaconArrival(Simulator::Now());
Time delay = MicroSeconds(std::get<MgtBeaconHeader>(apInfo.m_frame).GetBeaconIntervalUs() *
m_maxMissedBeacons);
RestartBeaconWatchdog(delay, linkId);
RestartBeaconWatchdog(delay);
UpdateApInfo(apInfo.m_frame, hdr.GetAddr2(), hdr.GetAddr3(), linkId);
}
else

View File

@@ -357,8 +357,6 @@ class StaWifiMac : public WifiMac
bool sendAssocReq; //!< whether this link is used to send the
//!< Association Request frame
std::optional<Mac48Address> 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<RandomVariableStream> m_probeDelay; ///< RandomVariable used to randomize the time
///< of the first Probe Response on each channel