A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
power-save-manager.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Universita' degli Studi di Napoli Federico II
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8
9#ifndef POWER_SAVE_MANAGER_H
10#define POWER_SAVE_MANAGER_H
11
12#include "txop.h"
13#include "wifi-types.h"
14#include "wifi-utils.h"
15
16#include "ns3/nstime.h"
17#include "ns3/object.h"
18#include "ns3/traced-callback.h"
19
20#include <map>
21#include <optional>
22
23namespace ns3
24{
25
26class StaWifiMac;
27class MgtBeaconHeader;
28class WifiMpdu;
29enum WifiMacDropReason : uint8_t;
30enum WifiPowerManagementMode : uint8_t;
31
32/**
33 * @ingroup wifi
34 *
35 * PowerSaveManager is an abstract base class. Each subclass defines a logic
36 * to switch a STA in powersave mode between active state and doze state.
37 */
39{
40 public:
41 /**
42 * @brief Get the type ID.
43 * @return the object TypeId
44 */
45 static TypeId GetTypeId();
46 ~PowerSaveManager() override;
47
48 /**
49 * Set the MAC which is using this Power Save Manager
50 *
51 * @param mac a pointer to the MAC
52 */
54
55 /**
56 * Enable or disable Power Save mode on a given set of links. If this object is not initialized
57 * yet, the settings are recorded and notified to the STA wifi MAC upon initialization.
58 *
59 * @param linkIdEnableMap a link ID-indexed map indicating whether to enable or not power save
60 * mode on the link with the given ID
61 */
62 void SetPowerSaveMode(const std::map<linkId_t, bool>& linkIdEnableMap);
63
64 /// @return the Listen interval
66
67 /**
68 * This function is normally used to notify the Beacon interval and timestamp included in the
69 * last Beacon frame advertised by the AP this device is going to associate with. The purpose is
70 * to be able to put the PHY operating on the given link to sleep (if needed) right after
71 * association is completed.
72 *
73 * @param beaconInterval the Beacon interval
74 * @param timestamp the timestamp included in the Beacon frame
75 * @param linkId the ID of the link on which the Beacon frame was sent
76 */
77 void NotifyBeaconIntervalAndTimestamp(const Time& beaconInterval,
78 const Time& timestamp,
79 linkId_t linkId);
80
81 /**
82 * @param linkId the ID of the given link
83 * @return the remaining time until the next Target Beacon Transmission Time (TBTT) on the given
84 * link, if known
85 */
86 std::optional<Time> GetTimeUntilNextTbtt(linkId_t linkId) const;
87
88 /**
89 * Notify that the non-AP STA/MLD has completed association with an AP.
90 */
92
93 /**
94 * Notify that the non-AP STA/MLD has disassociated.
95 */
97
98 /**
99 * Notify that the Power Management mode of the non-AP STA operating on the given link
100 * has changed.
101 *
102 * @param pmMode the new PM mode
103 * @param linkId the ID of the given link
104 */
106
107 /**
108 * Notify that a Beacon frame has been received from the associated AP on the given link.
109 *
110 * @param mpdu the MPDU carrying the Beacon frame
111 * @param linkId the ID of the given link
112 */
114
115 /**
116 * Notify the reception of a frame in response to a PS-Poll frame on the given link.
117 *
118 * @param mpdu the received MPDU
119 * @param linkId the ID of the given link
120 */
122
123 /**
124 * Notify the reception of a groupcast frame (possibly after a DTIM) on the given link.
125 *
126 * @param mpdu the received MPDU
127 * @param linkId the ID of the given link
128 */
130
131 /**
132 * Notify that the given TXOP is requesting channel access on the given link.
133 *
134 * @param txop the DCF/EDCAF requesting channel access
135 * @param linkId the ID of the given link
136 */
137 void NotifyRequestAccess(Ptr<Txop> txop, linkId_t linkId);
138
139 /**
140 * Notify that the given TXOP has released the channel on the given link.
141 *
142 * @param txop the DCF/EDCAF releasing the channel
143 * @param linkId the ID of the given link
144 */
145 void NotifyChannelReleased(Ptr<Txop> txop, linkId_t linkId);
146
147 /**
148 * Notify that the given MPDU has been discarded for the given reason.
149 *
150 * @param reason the reason why the MPDU was dropped
151 * @param mpdu the dropped MPDU
152 */
154
155 protected:
156 void DoInitialize() override;
157 void DoDispose() override;
158
159 /**
160 * Information about each STA operating on a given link.
161 */
162 struct StaInfo
163 {
164 Time beaconInterval{0}; ///< Beacon interval advertised by the AP
165 Time lastBeaconTimestamp{0}; ///< last time a Beacon was received from the AP
166 bool pendingUnicast{false}; ///< AP has buffered unicast frame(s) (set from last TIM and
167 ///< updated as frames are received from the AP)
168 bool pendingGroupcast{false}; ///< AP has buffered groupcast frame(s) (set from last TIM
169 ///< and updated as frames are received from the AP)
170 };
171
172 /**
173 * @return the MAC of the non-AP MLD managed by this Power Save Manager.
174 */
176
177 /**
178 * Get the information about the STA operating on the given link.
179 *
180 * @param linkId the ID of the given link
181 * @return the information about the STA operating on the given link
182 */
183 StaInfo& GetStaInfo(linkId_t linkId);
184
185 /**
186 * Get whether any Access Category has requested (or gained) the channel on the given link.
187 *
188 * @param linkId the ID of the given link
189 * @return whether any AC has requested (or gained) the channel on the given link
190 */
191 bool HasRequestedOrGainedChannel(linkId_t linkId) const;
192
193 /**
194 * Notify subclasses that the non-AP STA/MLD has completed association with an AP.
195 */
196 virtual void DoNotifyAssocCompleted() = 0;
197
198 /**
199 * Notify subclasses that the non-AP STA/MLD has disassociated.
200 */
201 virtual void DoNotifyDisassociation() = 0;
202
203 /**
204 * Notify subclasses that the Power Management mode of the non-AP STA operating on the given
205 * link has changed.
206 *
207 * @param pmMode the new PM mode
208 * @param linkId the ID of the given link
209 */
211
212 /**
213 * Notify subclasses that a Beacon frame has been received from the associated AP on the given
214 * link.
215 *
216 * @param beacon the Beacon frame
217 * @param linkId the ID of the given link
218 */
219 virtual void DoNotifyReceivedBeacon(const MgtBeaconHeader& beacon, linkId_t linkId) = 0;
220
221 /**
222 * Notify subclasses of the reception of a frame in response to a PS-Poll frame on the given
223 * link. The notification is sent a SIFS after the reception of the frame.
224 *
225 * @param mpdu the received MPDU
226 * @param linkId the ID of the given link
227 */
229
230 /**
231 * Notify subclasses of the reception of a groupcast frame (possibly after a DTIM) on the given
232 * link.
233 *
234 * @param mpdu the received MPDU
235 * @param linkId the ID of the given link
236 */
238
239 /**
240 * Notify subclasses that the given TXOP is requesting channel access on the given link.
241 *
242 * @param txop the DCF/EDCAF requesting channel access
243 * @param linkId the ID of the given link
244 */
245 virtual void DoNotifyRequestAccess(Ptr<Txop> txop, linkId_t linkId) = 0;
246
247 /**
248 * Notify subclasses that the given TXOP is releasing the channel on the given link.
249 *
250 * @param txop the DCF/EDCAF releasing the channel
251 * @param linkId the ID of the given link
252 */
253 virtual void DoNotifyChannelReleased(Ptr<Txop> txop, linkId_t linkId) = 0;
254
255 /**
256 * Notify subclasses that the given MPDU has been discarded for the given reason.
257 *
258 * @param reason the reason why the MPDU was dropped
259 * @param mpdu the dropped MPDU
260 */
261 virtual void DoTxDropped(WifiMacDropReason reason, Ptr<const WifiMpdu> mpdu) = 0;
262
263 private:
264 Ptr<StaWifiMac> m_staMac; //!< MAC which is using this Power Save Manager
265 std::map<linkId_t, StaInfo> m_staInfo; ///< link ID-indexed map of STA infos
266 std::map<linkId_t, bool>
267 m_linkIdEnableMap; ///< a link ID-indexed map indicating whether to enable or not power save
268 ///< mode on the link with the given ID (used before initialization)
269 uint32_t m_listenInterval; ///< beacon listen interval
271 m_pmModeLogger; ///< link ID-indexed power management mode logger
272
273 /// TracedCallback signature for power management mode change events
275};
276
277} // namespace ns3
278
279#endif /* POWER_SAVE_MANAGER_H */
Implement the header for management frames of type beacon.
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
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.
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 &timestamp, linkId_t linkId)
This function is normally used to notify the Beacon interval and timestamp included in the last Beaco...
void(*)(linkId_t, WifiPowerManagementMode) PmModeChangeCallback
TracedCallback signature for power management mode change events.
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.
Definition ptr.h:70
The Wifi MAC high model for a non-AP STA in a BSS.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:50
WifiMpdu stores a (const) packet along with a MAC header.
Definition wifi-mpdu.h:51
WifiMacDropReason
The reason why an MPDU was dropped.
Definition wifi-mac.h:71
WifiPowerManagementMode
Enumeration for power management modes.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t linkId_t
IEEE 802.11be D7.0 Figure 9-207e—Link ID Info field format.
Definition wifi-utils.h:74
Information about each STA operating on a given link.
bool pendingUnicast
AP has buffered unicast frame(s) (set from last TIM and updated as frames are received from the AP).
Time beaconInterval
Beacon interval advertised by the AP.
bool pendingGroupcast
AP has buffered groupcast frame(s) (set from last TIM and updated as frames are received from the AP)...
Time lastBeaconTimestamp
last time a Beacon was received from the AP