13#include "ns3/boolean.h"
14#include "ns3/channel-access-manager.h"
16#include "ns3/qos-txop.h"
17#include "ns3/wifi-mpdu.h"
18#include "ns3/wifi-net-device.h"
19#include "ns3/wifi-phy.h"
32 TypeId(
"ns3::DefaultEmlsrManager")
36 .AddAttribute(
"SwitchAuxPhy",
37 "Whether Aux PHY should switch channel to operate on the link on which "
38 "the Main PHY was operating before moving to the link of the Aux PHY. "
39 "Note that, if the Aux PHY does not switch channel, the main PHY will "
40 "switch back to its previous link once the TXOP terminates (otherwise, "
41 "no PHY will be listening on that EMLSR link).",
69 NS_ASSERT_MSG(linkId,
"Link on which the main PHY is operating not found");
78 NS_ASSERT_MSG(linkId,
"Link on which the main PHY is operating not found");
94 NS_LOG_FUNCTION(
this << (currLinkId ? std::to_string(*currLinkId) :
"") << nextLinkId << auxPhy
111 NS_LOG_DEBUG(
"Aux PHY (" << auxPhy <<
") operating on link " << +nextLinkId
118 if (currLinkId.has_value() && currLinkId !=
GetMainPhyId())
123 "There should be an aux PHY to reconnect when the main PHY leaves an auxiliary link");
152 auto lambda = [=,
this]() {
153 if (
GetStaMac()->GetWifiPhy(currLinkId) == auxPhy)
158 if (maybeIcf && extension.IsStrictlyPositive())
160 NS_LOG_DEBUG(
"Switching aux PHY to link " << +nextLinkId <<
" is postponed by "
166 const auto isSleeping = auxPhy->IsStateSleep();
170 auxPhy->ResumeFromSleep();
176 auxPhy->SetSleepMode(
true);
192 return {
true,
Time{0}};
216 const auto delay = mainPhy->IsStateSwitching() ? mainPhy->GetDelayUntilIdle() :
Time{0};
243 if (!mainPhy->IsStateSwitching())
249 std::forward<EmlsrMainPhySwitchTrace>(traceInfo));
257 if (!GetEhtFem(linkId)->UsingOtherEmlsrLink())
259 SwitchMainPhy(GetMainPhyId(),
270DefaultEmlsrManager::SwitchMainPhyIfTxopGainedByAuxPhy(uint8_t linkId,
AcIndex aci)
277DefaultEmlsrManager::GetTimeToCtsEnd(uint8_t linkId)
const
281 const auto stationManager = GetStaMac()->GetWifiRemoteStationManager(linkId);
282 const auto bssid = GetEhtFem(linkId)->GetBssid();
283 const auto allowedWidth = GetEhtFem(linkId)->GetAllowedWidth();
285 return GetTimeToCtsEnd(linkId, stationManager->GetRtsTxVector(bssid, allowedWidth));
289DefaultEmlsrManager::GetTimeToCtsEnd(uint8_t linkId,
const WifiTxVector& rtsTxVector)
const
293 auto phy = GetStaMac()->GetWifiPhy(linkId);
296 const auto stationManager = GetStaMac()->GetWifiRemoteStationManager(linkId);
297 const auto bssid = GetEhtFem(linkId)->GetBssid();
298 const auto ctsTxVector = stationManager->GetCtsTxVector(bssid, rtsTxVector.
GetMode());
300 const auto rtsTxTime =
301 WifiPhy::CalculateTxDuration(
GetRtsSize(), rtsTxVector, phy->GetPhyBand());
302 const auto ctsTxTime =
303 WifiPhy::CalculateTxDuration(
GetCtsSize(), ctsTxVector, phy->GetPhyBand());
307 return rtsTxTime + phy->GetSifs() + ctsTxTime +
MicroSeconds(2 * MAX_PROPAGATION_DELAY_USEC);
311DefaultEmlsrManager::GetDelayUnlessMainPhyTakesOverUlTxop(uint8_t linkId)
315 auto mainPhy = GetStaMac()->GetDevice()->GetPhy(m_mainPhyId);
316 const auto timeToCtsEnd = GetTimeToCtsEnd(linkId);
317 auto switchingTime = mainPhy->GetChannelSwitchDelay();
319 switch (mainPhy->GetState()->GetState())
321 case WifiPhyState::SWITCHING:
324 switchingTime += mainPhy->GetDelayUntilIdle();
326 case WifiPhyState::RX:
327 case WifiPhyState::IDLE:
328 case WifiPhyState::CCA_BUSY:
329 if (switchingTime > timeToCtsEnd)
332 NS_LOG_DEBUG(
"Not enough time for main PHY to switch link (main PHY state: "
333 << mainPhy->GetState()->GetState() <<
")");
335 return {
false, timeToCtsEnd};
339 NS_ABORT_MSG(
"Main PHY cannot be in state " << mainPhy->GetState()->GetState());
344 m_switchMainPhyOnRtsTx[linkId] = Simulator::Now();
346 return {
true,
Time{0}};
350DefaultEmlsrManager::NotifyRtsSent(uint8_t linkId,
356 const auto it = m_switchMainPhyOnRtsTx.find(linkId);
358 if (it == m_switchMainPhyOnRtsTx.cend() || it->second != Simulator::Now())
365 auto mainPhy = GetStaMac()->GetDevice()->GetPhy(m_mainPhyId);
366 const auto delay = GetTimeToCtsEnd(linkId, txVector) - mainPhy->GetChannelSwitchDelay();
368 "RTS is being sent, but not enough time for main PHY to switch");
370 NS_LOG_DEBUG(
"Schedule main Phy switch in " << delay.As(Time::US));
371 m_ulMainPhySwitch[linkId] = Simulator::Schedule(delay, [=,
this]() {
372 SwitchMainPhy(linkId,
379 m_switchMainPhyOnRtsTx.erase(it);
DefaultEmlsrManager is the default EMLSR manager.
void DoNotifyMgtFrameReceived(Ptr< const WifiMpdu > mpdu, uint8_t linkId) override
Notify the subclass of the reception of a management frame addressed to us.
void NotifyEmlsrModeChanged() override
Notify subclass that EMLSR mode changed.
EventId m_auxPhySwitchEvent
event scheduled for an aux PHY to switch link
Ptr< WifiPhy > m_auxPhyToReconnect
Aux PHY the ChannelAccessManager of the link on which the main PHY is operating has to connect a list...
void DoNotifyUlTxopStart(uint8_t linkId) override
Notify the subclass of the start of an UL TXOP on the given link.
void NotifyMainPhySwitch(std::optional< uint8_t > currLinkId, uint8_t nextLinkId, Ptr< WifiPhy > auxPhy, Time duration) override
Notify subclass that the main PHY is switching channel to operate on another link.
bool m_switchAuxPhy
whether Aux PHY should switch channel to operate on the link on which the Main PHY was operating befo...
std::pair< bool, Time > DoGetDelayUntilAccessRequest(uint8_t linkId) override
Subclasses have to provide an implementation for this method, that is called by the base class when t...
static TypeId GetTypeId()
Get the type ID.
void DoNotifyIcfReceived(uint8_t linkId) override
Notify the subclass of the reception of an initial Control frame on the given link.
std::optional< uint8_t > ResendNotification(Ptr< const WifiMpdu > mpdu) override
A previous EML Operating Mode Notification frame was dropped.
void SwitchMainPhyBackToPreferredLink(uint8_t linkId, EmlsrMainPhySwitchTrace &&traceInfo)
This method can only be called when aux PHYs do not switch link.
void DoNotifyTxopEnd(uint8_t linkId) override
Notify the subclass of the end of a TXOP on the given link.
void SwitchAuxPhyAfterMainPhy(Ptr< WifiPhy > auxPhy, uint8_t currLinkId, uint8_t nextLinkId, Time duration)
This function shall be called when the main PHY starts switching to a link on which an aux PHY that i...
~DefaultEmlsrManager() override
uint8_t GetLinkToSendEmlOmn() override
EmlsrManager is an abstract base class defining the API that EHT non-AP MLDs with EMLSR activated can...
uint8_t m_mainPhyId
ID of main PHY (position in the vector of PHYs held by WifiNetDevice)
void SwitchAuxPhy(Ptr< WifiPhy > auxPhy, uint8_t currLinkId, uint8_t nextLinkId)
Switch channel on the Aux PHY operating on the given current link so that it operates on the given ne...
void SetCcaEdThresholdOnLinkSwitch(Ptr< WifiPhy > phy, uint8_t linkId)
Set the CCA ED threshold (if needed) on the given PHY that is switching channel to operate on the giv...
void SwitchMainPhy(uint8_t linkId, bool noSwitchDelay, bool resetBackoff, bool requestAccess, EmlsrMainPhySwitchTrace &&traceInfo)
Switch channel on the Main PHY so that it operates on the given link.
MainPhySwitchInfo m_mainPhySwitchInfo
main PHY switch info
static constexpr bool REQUEST_ACCESS
request channel access when PHY switch ends
Ptr< StaWifiMac > GetStaMac() const
uint8_t GetMainPhyId() const
std::pair< bool, Time > CheckPossiblyReceivingIcf(uint8_t linkId) const
Check whether a PPDU that may be an ICF is being received on the given link.
static constexpr bool DONT_RESET_BACKOFF
do not reset backoff on main PHY switch
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
uint32_t GetRtsSize()
Return the total RTS size (including FCS trailer).
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
uint32_t GetCtsSize()
Return the total CTS size (including FCS trailer).
Base struct for EMLSR Main PHY switch traces.
uint8_t from
ID of the link which the main PHY is/has been leaving.
Struct to trace that main PHY switched when a (DL or UL) TXOP ended.
Struct to trace that main PHY switched to start an UL TXOP after that an aux PHY transmitted an RTS.