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).",
49 : m_mainPhySwitchInfo{}
70 NS_ASSERT_MSG(linkId,
"Link on which the main PHY is operating not found");
79 NS_ASSERT_MSG(linkId,
"Link on which the main PHY is operating not found");
95 NS_LOG_FUNCTION(
this << (currLinkId ? std::to_string(*currLinkId) :
"") << nextLinkId << auxPhy
102 "No current link ID provided nor valid main PHY switch information stored");
121 NS_LOG_DEBUG(
"Aux PHY (" << auxPhy <<
") operating on link " << +nextLinkId
122 <<
" will switch to link " << +currLinkId.value() <<
" in "
129 SwitchAuxPhy(auxPhy, nextLinkId, prevLinkId);
140 if (currLinkId.has_value() && currLinkId !=
GetMainPhyId())
145 "There should be an aux PHY to reconnect when the main PHY leaves an auxiliary link");
168 return {
true,
Time{0}};
192 const auto delay = mainPhy->IsStateSwitching() ? mainPhy->GetDelayUntilIdle() :
Time{0};
219 if (!mainPhy->IsStateSwitching())
225 std::forward<EmlsrMainPhySwitchTrace>(traceInfo));
233 if (!GetEhtFem(linkId)->UsingOtherEmlsrLink())
235 SwitchMainPhy(GetMainPhyId(),
246DefaultEmlsrManager::SwitchMainPhyIfTxopGainedByAuxPhy(uint8_t linkId,
AcIndex aci)
253DefaultEmlsrManager::GetTimeToCtsEnd(uint8_t linkId)
const
257 const auto stationManager = GetStaMac()->GetWifiRemoteStationManager(linkId);
258 const auto bssid = GetEhtFem(linkId)->GetBssid();
259 const auto allowedWidth = GetEhtFem(linkId)->GetAllowedWidth();
261 return GetTimeToCtsEnd(linkId, stationManager->GetRtsTxVector(bssid, allowedWidth));
265DefaultEmlsrManager::GetTimeToCtsEnd(uint8_t linkId,
const WifiTxVector& rtsTxVector)
const
269 auto phy = GetStaMac()->GetWifiPhy(linkId);
272 const auto stationManager = GetStaMac()->GetWifiRemoteStationManager(linkId);
273 const auto bssid = GetEhtFem(linkId)->GetBssid();
274 const auto ctsTxVector = stationManager->GetCtsTxVector(bssid, rtsTxVector.
GetMode());
276 const auto rtsTxTime = phy->CalculateTxDuration(
GetRtsSize(), rtsTxVector, phy->GetPhyBand());
277 const auto ctsTxTime = phy->CalculateTxDuration(
GetCtsSize(), ctsTxVector, phy->GetPhyBand());
281 return rtsTxTime + phy->GetSifs() + ctsTxTime +
MicroSeconds(2 * MAX_PROPAGATION_DELAY_USEC);
285DefaultEmlsrManager::GetDelayUnlessMainPhyTakesOverUlTxop(uint8_t linkId)
289 auto mainPhy = GetStaMac()->GetDevice()->GetPhy(m_mainPhyId);
290 const auto timeToCtsEnd = GetTimeToCtsEnd(linkId);
291 auto switchingTime = mainPhy->GetChannelSwitchDelay();
293 switch (mainPhy->GetState()->GetState())
295 case WifiPhyState::SWITCHING:
298 switchingTime += mainPhy->GetDelayUntilIdle();
300 case WifiPhyState::RX:
301 case WifiPhyState::IDLE:
302 case WifiPhyState::CCA_BUSY:
303 if (switchingTime > timeToCtsEnd)
306 NS_LOG_DEBUG(
"Not enough time for main PHY to switch link (main PHY state: "
307 << mainPhy->GetState()->GetState() <<
")");
309 return {
false, timeToCtsEnd};
313 NS_ABORT_MSG(
"Main PHY cannot be in state " << mainPhy->GetState()->GetState());
318 m_switchMainPhyOnRtsTx[linkId] = Simulator::Now();
320 return {
true,
Time{0}};
324DefaultEmlsrManager::NotifyRtsSent(uint8_t linkId,
330 const auto it = m_switchMainPhyOnRtsTx.find(linkId);
332 if (it == m_switchMainPhyOnRtsTx.cend() || it->second != Simulator::Now())
339 auto mainPhy = GetStaMac()->GetDevice()->GetPhy(m_mainPhyId);
340 const auto delay = GetTimeToCtsEnd(linkId, txVector) - mainPhy->GetChannelSwitchDelay();
342 "RTS is being sent, but not enough time for main PHY to switch");
344 NS_LOG_DEBUG(
"Schedule main Phy switch in " << delay.As(Time::US));
345 m_ulMainPhySwitch[linkId] = Simulator::Schedule(delay, [=,
this]() {
346 SwitchMainPhy(linkId,
353 m_switchMainPhyOnRtsTx.erase(it);
AttributeValue implementation for Boolean.
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.
~DefaultEmlsrManager() override
MainPhySwitchInfo m_mainPhySwitchInfo
main PHY switch info
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.
static constexpr bool REQUEST_ACCESS
request channel access when PHY switch ends
Ptr< StaWifiMac > GetStaMac() const
uint8_t GetMainPhyId() const
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.
static Time Now()
Return the current simulation virtual time.
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...
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#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.
uint32_t GetRtsSize()
Return the total RTS size (including FCS trailer).
uint32_t GetCtsSize()
Return the total CTS size (including FCS trailer).
Time end
end of channel switching
uint8_t to
ID of the link which the main PHY is moving to.
uint8_t from
ID of the link which the main PHY is/has been leaving.
Base struct for EMLSR Main PHY switch traces.
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.