A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
emlsr-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Universita' degli Studi di Napoli Federico II
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Stefano Avallone <stavallo@unina.it>
18 */
19
20#include "emlsr-manager.h"
21
22#include "eht-configuration.h"
24
25#include "ns3/abort.h"
26#include "ns3/assert.h"
27#include "ns3/attribute-container.h"
28#include "ns3/log.h"
29#include "ns3/wifi-mpdu.h"
30
31namespace ns3
32{
33
34NS_LOG_COMPONENT_DEFINE("EmlsrManager");
35
36NS_OBJECT_ENSURE_REGISTERED(EmlsrManager);
37
38TypeId
40{
41 static TypeId tid =
42 TypeId("ns3::EmlsrManager")
44 .SetGroupName("Wifi")
45 .AddAttribute("EmlsrPaddingDelay",
46 "The EMLSR Paddind Delay (not used by AP MLDs). "
47 "Possible values are 0 us, 32 us, 64 us, 128 us or 256 us.",
51 .AddAttribute("EmlsrTransitionDelay",
52 "The EMLSR Transition Delay (not used by AP MLDs). "
53 "Possible values are 0 us, 16 us, 32 us, 64 us, 128 us or 256 us.",
57 .AddAttribute(
58 "EmlsrLinkSet",
59 "IDs of the links on which EMLSR mode will be enabled. An empty set "
60 "indicates to disable EMLSR.",
62 MakeAttributeContainerAccessor<UintegerValue>(&EmlsrManager::SetEmlsrLinks),
63 MakeAttributeContainerChecker<UintegerValue>(MakeUintegerChecker<uint8_t>()));
64 return tid;
65}
66
68{
69 NS_LOG_FUNCTION(this);
70}
71
73{
75}
76
77void
79{
80 NS_LOG_FUNCTION(this);
84 m_staMac = nullptr;
87}
88
89void
91{
92 NS_LOG_FUNCTION(this << mac);
93 NS_ASSERT(mac);
94 m_staMac = mac;
95
96 NS_ABORT_MSG_IF(!m_staMac->GetEhtConfiguration(), "EmlsrManager requires EHT support");
97 NS_ABORT_MSG_IF(m_staMac->GetNLinks() <= 1, "EmlsrManager can only be installed on MLDs");
99 "EmlsrManager can only be installed on non-AP MLDs");
100
104}
105
106const std::set<uint8_t>&
108{
109 return m_emlsrLinks;
110}
111
114{
115 return m_staMac;
116}
117
119EmlsrManager::GetEhtFem(uint8_t linkId) const
120{
121 return StaticCast<EhtFrameExchangeManager>(m_staMac->GetFrameExchangeManager(linkId));
122}
123
124void
126{
129}
130
131std::optional<Time>
133{
135}
136
137void
138EmlsrManager::SetEmlsrLinks(const std::set<uint8_t>& linkIds)
139{
140 NS_LOG_FUNCTION(this);
141 NS_ABORT_MSG_IF(linkIds.size() == 1, "Cannot enable EMLSR mode on a single link");
142
143 if (linkIds != m_emlsrLinks)
144 {
145 m_nextEmlsrLinks = linkIds;
146 }
147
148 if (GetStaMac() && GetStaMac()->IsAssociated() && GetTransitionTimeout() && m_nextEmlsrLinks)
149 {
150 // Request to enable EMLSR mode on the given links, provided that they have been setup
152 }
153}
154
155void
157{
158 NS_LOG_FUNCTION(this << *mpdu << linkId);
159
160 const auto& hdr = mpdu->GetHeader();
161
162 DoNotifyMgtFrameReceived(mpdu, linkId);
163
164 if (hdr.IsAssocResp() && GetStaMac()->IsAssociated() && GetTransitionTimeout() &&
166 {
167 // we just completed ML setup with an AP MLD that supports EMLSR and a non-empty
168 // set of EMLSR links have been configured, hence enable EMLSR mode on those links
170 }
171
172 if (hdr.IsAction() && hdr.GetAddr2() == m_staMac->GetBssid(linkId))
173 {
174 // this is an action frame sent by an AP of the AP MLD we are associated with
175 auto [category, action] = WifiActionHeader::Peek(mpdu->GetPacket());
176 if (category == WifiActionHeader::PROTECTED_EHT &&
177 action.protectedEhtAction ==
179 {
181 {
182 // no need to wait until the expiration of the transition timeout
185 }
186 }
187 }
188}
189
190void
192{
193 NS_LOG_FUNCTION(this);
194
196 "AP did not advertise a Transition Timeout, cannot send EML notification");
197 NS_ASSERT_MSG(m_nextEmlsrLinks, "Need to set EMLSR links before calling this method");
198
200
201 // Add the EMLSR Parameter Update field if needed
204 {
209 frame.m_emlsrParamUpdate->paddingDelay =
211 frame.m_emlsrParamUpdate->transitionDelay =
213 }
214
215 // We must verify that the links included in the given EMLSR link set (if any) have been setup.
216 auto setupLinkIds = m_staMac->GetSetupLinkIds();
217
218 for (auto emlsrLinkIt = m_nextEmlsrLinks->begin(); emlsrLinkIt != m_nextEmlsrLinks->end();)
219 {
220 if (auto setupLinkIt = setupLinkIds.find(*emlsrLinkIt); setupLinkIt != setupLinkIds.cend())
221 {
222 setupLinkIds.erase(setupLinkIt);
223 auto apLinkId = m_staMac->GetApLinkId(*emlsrLinkIt);
224 NS_ASSERT(apLinkId);
225 frame.SetLinkIdInBitmap(*apLinkId);
226 emlsrLinkIt++;
227 }
228 else
229 {
230 NS_LOG_DEBUG("Link ID " << +(*emlsrLinkIt) << " has not been setup");
231 emlsrLinkIt = m_nextEmlsrLinks->erase(emlsrLinkIt);
232 }
233 }
234
235 // EMLSR Mode is enabled if and only if the set of EMLSR links is not empty
236 frame.m_emlControl.emlsrMode = m_nextEmlsrLinks->empty() ? 0 : 1;
237
238 // TODO if this is a single radio non-AP MLD and not all setup links are in the EMLSR link
239 // set, we have to put setup links that are not included in the given EMLSR link set (i.e.,
240 // those remaining in setupLinkIds, if m_nextEmlsrLinks is not empty) in the sleep mode:
241 // For the EMLSR mode enabled in a single radio non-AP MLD, the STA(s) affiliated with
242 // the non-AP MLD that operates on the enabled link(s) that corresponds to the bit
243 // position(s) of the EMLSR Link Bitmap subfield set to 0 shall be in doze state if a
244 // non-AP STA affiliated with the non-AP MLD that operates on one of the EMLSR links is
245 // in awake state. (Sec. 35.3.17 of 802.11be D3.0)
246
247 auto linkId = GetLinkToSendEmlNotification();
248 GetEhtFem(linkId)->SendEmlOperatingModeNotification(m_staMac->GetBssid(linkId), frame);
249}
250
251void
253{
254 NS_LOG_FUNCTION(this << *mpdu);
255
256 const auto& hdr = mpdu->GetHeader();
257
258 if (hdr.IsAssocReq())
259 {
260 // store padding delay and transition delay advertised in AssocReq
261 MgtAssocRequestHeader assocReq;
262 mpdu->GetPacket()->PeekHeader(assocReq);
263 auto& mle = assocReq.Get<MultiLinkElement>();
264 NS_ASSERT_MSG(mle, "AssocReq should contain a Multi-Link Element");
265 m_lastAdvPaddingDelay = mle->GetEmlsrPaddingDelay();
266 m_lastAdvTransitionDelay = mle->GetEmlsrTransitionDelay();
267 }
268
269 if (hdr.IsMgt() && hdr.IsAction())
270 {
271 if (auto [category, action] = WifiActionHeader::Peek(mpdu->GetPacket());
273 action.protectedEhtAction ==
275 {
276 // the EML Operating Mode Notification frame that we sent has been acknowledged.
277 // Start the transition timeout to wait until the request can be made effective
278 NS_ASSERT_MSG(m_emlsrTransitionTimeout, "No transition timeout received from AP");
281 this);
282 }
283 }
284}
285
286void
288{
289 NS_LOG_FUNCTION(this << reason << *mpdu);
290
291 const auto& hdr = mpdu->GetHeader();
292
293 if (hdr.IsMgt() && hdr.IsAction())
294 {
295 auto pkt = mpdu->GetPacket()->Copy();
296 if (auto [category, action] = WifiActionHeader::Remove(pkt);
298 action.protectedEhtAction ==
300 {
301 // the EML Operating Mode Notification frame has been dropped. Ask the subclass
302 // whether the frame needs to be resent
303 auto linkId = ResendNotification(mpdu);
304 if (linkId)
305 {
307 pkt->RemoveHeader(frame);
308 GetEhtFem(*linkId)->SendEmlOperatingModeNotification(m_staMac->GetBssid(*linkId),
309 frame);
310 }
311 else
312 {
313 m_nextEmlsrLinks.reset();
314 }
315 }
316 }
317}
318
319void
321{
322 NS_LOG_FUNCTION(this);
323
324 // After the successful transmission of the EML Operating Mode Notification frame by the
325 // non-AP STA affiliated with the non-AP MLD, the non-AP MLD shall operate in the EMLSR mode
326 // and the other non-AP STAs operating on the corresponding EMLSR links shall transition to
327 // active mode after the transition delay indicated in the Transition Timeout subfield in the
328 // EML Capabilities subfield of the Basic Multi-Link element or immediately after receiving an
329 // EML Operating Mode Notification frame from one of the APs operating on the EMLSR links and
330 // affiliated with the AP MLD. (Sec. 35.3.17 of 802.11be D3.0)
331 NS_ASSERT_MSG(m_nextEmlsrLinks, "No set of EMLSR links stored");
333 m_nextEmlsrLinks.reset();
334
335 // TODO Make other non-AP STAs operating on the corresponding EMLSR links transition to
336 // active mode or passive mode (depending on whether EMLSR mode has been enabled or disabled)
337
339}
340
341} // namespace ns3
A container for one type of attribute.
void SetTransitionTimeout(Time timeout)
Set the Transition Timeout advertised by the associated AP with EMLSR activated.
virtual uint8_t GetLinkToSendEmlNotification()=0
std::optional< Time > GetTransitionTimeout() const
void ChangeEmlsrMode()
This method is called to make an EMLSR mode change effective after the transition delay has elapsed o...
Ptr< EhtFrameExchangeManager > GetEhtFem(uint8_t linkId) const
void TxDropped(WifiMacDropReason reason, Ptr< const WifiMpdu > mpdu)
Notify that the given MPDU has been discarded for the given reason.
void TxOk(Ptr< const WifiMpdu > mpdu)
Notify the acknowledgment of the given MPDU.
void SetEmlsrLinks(const std::set< uint8_t > &linkIds)
Take actions to enable EMLSR mode on the given set of links, if non-empty, or disable EMLSR mode,...
void NotifyMgtFrameReceived(Ptr< const WifiMpdu > mpdu, uint8_t linkId)
Notify the reception of a management frame addressed to us.
Ptr< StaWifiMac > m_staMac
the MAC of the managed non-AP MLD
virtual void DoNotifyMgtFrameReceived(Ptr< const WifiMpdu > mpdu, uint8_t linkId)=0
Notify the subclass of the reception of a management frame addressed to us.
Time m_emlsrPaddingDelay
EMLSR Padding delay.
void SendEmlOperatingModeNotification()
Send an EML Operating Mode Notification frame.
Time m_emlsrTransitionDelay
EMLSR Transition delay.
void SetWifiMac(Ptr< StaWifiMac > mac)
Set the wifi MAC.
const std::set< uint8_t > & GetEmlsrLinks() const
std::optional< Time > m_emlsrTransitionTimeout
Transition timeout advertised by APs with EMLSR activated.
std::optional< std::set< uint8_t > > m_nextEmlsrLinks
ID of the links that will become the EMLSR links when the pending notification frame is acknowledged.
virtual void NotifyEmlsrModeChanged()=0
Notify subclass that EMLSR mode changed.
~EmlsrManager() override
Time m_lastAdvTransitionDelay
last advertised transition delay
void DoDispose() override
Destructor implementation.
virtual std::optional< uint8_t > ResendNotification(Ptr< const WifiMpdu > mpdu)=0
A previous EML Operating Mode Notification frame was dropped.
Ptr< StaWifiMac > GetStaMac() const
Time m_lastAdvPaddingDelay
last advertised padding delay
EventId m_transitionTimeoutEvent
Timer started after the successful transmission of an EML Operating Mode Notification frame.
static TypeId GetTypeId()
Get the type ID.
std::set< uint8_t > m_emlsrLinks
ID of the EMLSR links (empty if EMLSR mode is disabled)
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
EventImpl * PeekEventImpl() const
Definition: event-id.cc:83
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:76
void Invoke()
Called by the simulation engine to notify the event that it is time to execute.
Definition: event-impl.cc:47
Implement the header for management frames of type association request.
Definition: mgt-headers.h:161
Implement the header for Action frames of type EML Operating Mode Notification.
Definition: mgt-headers.h:1113
void SetLinkIdInBitmap(uint8_t linkId)
Set the bit position in the link bitmap corresponding to the given link.
EmlControl m_emlControl
EML Control field.
Definition: mgt-headers.h:1163
std::optional< EmlsrParamUpdate > m_emlsrParamUpdate
EMLSR Parameter Update field.
Definition: mgt-headers.h:1164
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:311
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
Definition: object-base.cc:339
A base class which provides memory management and object aggregation.
Definition: object.h:89
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:353
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:568
std::set< uint8_t > GetSetupLinkIds() const
Get the IDs of the setup links (if any).
std::optional< uint8_t > GetApLinkId(uint8_t linkId) const
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:417
@ US
microsecond
Definition: nstime.h:118
AttributeValue implementation for Time.
Definition: nstime.h:1423
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
static std::pair< CategoryValue, ActionValue > Peek(Ptr< const Packet > pkt)
Peek an Action header from the given packet.
static std::pair< CategoryValue, ActionValue > Remove(Ptr< Packet > pkt)
Remove an Action header from the given packet.
@ PROTECTED_EHT_EML_OPERATING_MODE_NOTIFICATION
Definition: mgt-headers.h:714
Ptr< FrameExchangeManager > GetFrameExchangeManager(uint8_t linkId=SINGLE_LINK_OP_ID) const
Get the Frame Exchange Manager associated with the given link.
Definition: wifi-mac.cc:864
Mac48Address GetBssid(uint8_t linkId) const
Definition: wifi-mac.cc:476
TypeOfStation GetTypeOfStation() const
Return the type of station.
Definition: wifi-mac.cc:425
uint8_t GetNLinks() const
Get the number of links (can be greater than 1 for 11be devices only).
Definition: wifi-mac.cc:930
Ptr< EhtConfiguration > GetEhtConfiguration() const
Definition: wifi-mac.cc:1481
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition: nstime.h:1444
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1424
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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.
Definition: object-base.h:46
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1360
WifiMacDropReason
The reason why an MPDU was dropped.
Definition: wifi-mac.h:75
@ STA
Definition: wifi-mac.h:63
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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...
Definition: callback.h:702
ns3::Time timeout
static uint8_t EncodeEmlsrTransitionDelay(Time delay)
static uint8_t EncodeEmlsrPaddingDelay(Time delay)
uint8_t emlsrParamUpdateCtrl
EMLSR Parameter Update Control.
Definition: mgt-headers.h:1135