18#include "ns3/attribute-container.h"
19#include "ns3/boolean.h"
22#include "ns3/uinteger.h"
35 TypeId(
"ns3::PowerSaveManager")
40 "Enable/disable power save mode on the given links. If a string is used to "
41 "set this attribute, the string must contain a comma-separated list of pairs, "
42 "where each pair is made of the link ID and a boolean value (indicating whether "
43 "to enable PS mode on that link), separated by a space. If this object is not "
44 "initialized yet when this attribute is set, the settings are stored and notified "
45 "to the STA wifi MAC upon initialization.",
52 .AddAttribute(
"ListenInterval",
53 "Interval (in beacon periods) between successive switches from sleep to "
54 "listen for a PS STAs",
60 "Traces every change in the power management mode of the STAs affiliated with this "
61 "device. Provides the ID of the link on which the STA that changed power "
62 "management mode is operating and the new power management mode of the STA.",
64 "ns3::PowerSaveManager::PmModeChangeCallback");
80 m_staMac->SetPowerSaveMode({enablePs, linkId});
89 m_staMac->TraceDisconnectWithoutContext(
"DroppedMpdu",
100 m_staMac->TraceConnectWithoutContext(
"DroppedMpdu",
129 for (
const auto aci : acList)
131 if (
const auto status =
GetStaMac()->GetTxopFor(aci)->GetAccessStatus(linkId);
143 for (
const auto& [linkId, enablePs] : linkIdEnableMap)
147 m_staMac->SetPowerSaveMode({enablePs, linkId});
158 const Time& timestamp,
162 m_staInfo[linkId] = {.beaconInterval = beaconInterval, .lastBeaconTimestamp = timestamp};
168 const auto staInfoIt =
m_staInfo.find(linkId);
170 if ((staInfoIt ==
m_staInfo.cend()) || staInfoIt->second.beaconInterval.IsZero())
175 const auto sinceLastTbtt = (
Simulator::Now() - staInfoIt->second.lastBeaconTimestamp) %
176 staInfoIt->second.beaconInterval;
178 return sinceLastTbtt.IsZero() ?
Time{0} : staInfoIt->second.beaconInterval - sinceLastTbtt;
186 const auto linkIds =
m_staMac->GetSetupLinkIds();
187 for (
const auto linkId : linkIds)
201 for (
const auto linkId :
m_staMac->GetLinkIds())
203 auto phy =
m_staMac->GetWifiPhy(linkId);
204 if (phy && phy->IsStateSleep())
206 phy->ResumeFromSleep();
220 auto phy =
m_staMac->GetWifiPhy(linkId);
221 if (phy && phy->IsStateSleep())
223 phy->ResumeFromSleep();
240 mpdu->GetPacket()->PeekHeader(beacon);
246 auto& tim = beacon.Get<
Tim>();
247 staInfo.pendingUnicast = tim->
HasAid(
m_staMac->GetAssociationId());
248 staInfo.pendingGroupcast = tim->m_hasMulticastPending;
260 if (!staInfo.pendingUnicast)
262 NS_LOG_DEBUG(
"Not expecting a buffered unit on link " << +linkId);
267 staInfo.pendingUnicast = mpdu->GetHeader().IsMoreData();
289 if (!staInfo.pendingGroupcast)
291 NS_LOG_DEBUG(
"Not expecting a group addressed frame on link " << +linkId);
296 staInfo.pendingGroupcast = mpdu->GetHeader().IsMoreData();
326 if (mpdu->GetHeader().IsPsPoll() && mpdu->IsQueued())
328 GetStaMac()->GetTxopQueue(mpdu->GetQueueAc())->DequeueIfQueued({mpdu});
Object()
Caller graph was not generated because of its size.
virtual void DoDispose()
Destructor implementation.
AttributeValue implementation for Pair.
PowerSaveManager is an abstract base class.
void NotifyPmModeChanged(WifiPowerManagementMode pmMode, linkId_t linkId)
Notify that the Power Management mode of the non-AP STA operating on the given link has changed.
Ptr< StaWifiMac > m_staMac
MAC which is using this Power Save Manager.
Ptr< StaWifiMac > GetStaMac() const
void DoDispose() override
Destructor implementation.
TracedCallback< linkId_t, WifiPowerManagementMode > m_pmModeLogger
link ID-indexed power management mode logger
virtual void DoNotifyRequestAccess(Ptr< Txop > txop, linkId_t linkId)=0
Notify subclasses that the given TXOP is requesting channel access on the given link.
~PowerSaveManager() override
uint32_t GetListenInterval() const
virtual void DoNotifyDisassociation()=0
Notify subclasses that the non-AP STA/MLD has disassociated.
StaInfo & GetStaInfo(linkId_t linkId)
Get the information about the STA operating on the given link.
std::map< linkId_t, bool > m_linkIdEnableMap
a link ID-indexed map indicating whether to enable or not power save mode on the link with the given ...
virtual void DoNotifyReceivedFrameAfterPsPoll(Ptr< const WifiMpdu > mpdu, linkId_t linkId)=0
Notify subclasses of the reception of a frame in response to a PS-Poll frame on the given link.
void NotifyAssocCompleted()
Notify that the non-AP STA/MLD has completed association with an AP.
void NotifyReceivedFrameAfterPsPoll(Ptr< const WifiMpdu > mpdu, linkId_t linkId)
Notify the reception of a frame in response to a PS-Poll frame on the given link.
void DoInitialize() override
Initialize() implementation.
virtual void DoNotifyPmModeChanged(WifiPowerManagementMode pmMode, linkId_t linkId)=0
Notify subclasses that the Power Management mode of the non-AP STA operating on the given link has ch...
bool HasRequestedOrGainedChannel(linkId_t linkId) const
Get whether any Access Category has requested (or gained) the channel on the given link.
void TxDropped(WifiMacDropReason reason, Ptr< const WifiMpdu > mpdu)
Notify that the given MPDU has been discarded for the given reason.
void NotifyReceivedGroupcast(Ptr< const WifiMpdu > mpdu, linkId_t linkId)
Notify the reception of a groupcast frame (possibly after a DTIM) on the given link.
void SetPowerSaveMode(const std::map< linkId_t, bool > &linkIdEnableMap)
Enable or disable Power Save mode on a given set of links.
void NotifyChannelReleased(Ptr< Txop > txop, linkId_t linkId)
Notify that the given TXOP has released the channel on the given link.
void NotifyRequestAccess(Ptr< Txop > txop, linkId_t linkId)
Notify that the given TXOP is requesting channel access on the given link.
uint32_t m_listenInterval
beacon listen interval
std::optional< Time > GetTimeUntilNextTbtt(linkId_t linkId) const
static TypeId GetTypeId()
Get the type ID.
virtual void DoNotifyAssocCompleted()=0
Notify subclasses that the non-AP STA/MLD has completed association with an AP.
virtual void DoNotifyReceivedBeacon(const MgtBeaconHeader &beacon, linkId_t linkId)=0
Notify subclasses that a Beacon frame has been received from the associated AP on the given link.
std::map< linkId_t, StaInfo > m_staInfo
link ID-indexed map of STA infos
virtual void DoTxDropped(WifiMacDropReason reason, Ptr< const WifiMpdu > mpdu)=0
Notify subclasses that the given MPDU has been discarded for the given reason.
virtual void DoNotifyChannelReleased(Ptr< Txop > txop, linkId_t linkId)=0
Notify subclasses that the given TXOP is releasing the channel on the given link.
virtual void DoNotifyReceivedGroupcast(Ptr< const WifiMpdu > mpdu, linkId_t linkId)=0
Notify subclasses of the reception of a groupcast frame (possibly after a DTIM) on the given link.
void NotifyBeaconIntervalAndTimestamp(const Time &beaconInterval, const Time ×tamp, linkId_t linkId)
This function is normally used to notify the Beacon interval and timestamp included in the last Beaco...
void SetWifiMac(Ptr< StaWifiMac > mac)
Set the MAC which is using this Power Save Manager.
void NotifyReceivedBeacon(Ptr< const WifiMpdu > mpdu, linkId_t linkId)
Notify that a Beacon frame has been received from the associated AP on the given link.
void NotifyDisassociation()
Notify that the non-AP STA/MLD has disassociated.
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.
Hold variables of type string.
The Traffic Indication Map Information Element.
bool HasAid(uint16_t aid) const
Check whether the bit corresponding to the provided AID is set in the Virtual Bitmap included in this...
Simulation virtual time values and global simulation resolution.
Time TimeStep(uint64_t ts)
Scheduler interface.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< AttributeChecker > MakeAttributeContainerChecker(const AttributeContainerValue< A, Sep, C > &value)
Make AttributeContainerChecker from AttributeContainerValue.
Ptr< const AttributeAccessor > MakeAttributeContainerAccessor(T1 a1)
Make AttributeContainerAccessor using explicit types.
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< AttributeChecker > MakePairChecker(const PairValue< A, B > &value)
Make a PairChecker from a PairValue.
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
#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.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
WifiMacDropReason
The reason why an MPDU was dropped.
WifiPowerManagementMode
Enumeration for power management modes.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const std::list< AcIndex > edcaAcIndices
List of the Access Categories corresponding to the four EDCA functions.
uint8_t linkId_t
IEEE 802.11be D7.0 Figure 9-207e—Link ID Info field format.
Information about each STA operating on a given link.