A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
msdu-aggregator.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 MIRKO BANCHI
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mirko Banchi <mk.banchi@gmail.com>
7 * Stefano Avallone <stavallo@unina.it>
8 */
9
10#include "msdu-aggregator.h"
11
12#include "ap-wifi-mac.h"
13#include "gcr-manager.h"
14#include "qos-txop.h"
15#include "wifi-mac-queue.h"
16#include "wifi-mac-trailer.h"
18#include "wifi-tx-parameters.h"
19
20#include "ns3/ht-capabilities.h"
21#include "ns3/ht-frame-exchange-manager.h"
22#include "ns3/log.h"
23#include "ns3/packet.h"
24
25#include <algorithm>
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("MsduAggregator");
31
32NS_OBJECT_ENSURE_REGISTERED(MsduAggregator);
33
34TypeId
36{
37 static TypeId tid = TypeId("ns3::MsduAggregator")
39 .SetGroupName("Wifi")
40 .AddConstructor<MsduAggregator>();
41 return tid;
42}
43
44void
46{
47 m_mac = nullptr;
48 m_htFem = nullptr;
50}
51
52void
54{
55 NS_LOG_FUNCTION(this << mac);
56 m_mac = mac;
57 m_htFem = DynamicCast<HtFrameExchangeManager>(m_mac->GetFrameExchangeManager(m_linkId));
58}
59
60void
62{
63 NS_LOG_FUNCTION(this << +linkId);
64 m_linkId = linkId;
65 if (m_mac)
66 {
67 m_htFem = DynamicCast<HtFrameExchangeManager>(m_mac->GetFrameExchangeManager(m_linkId));
68 }
69}
70
71uint16_t
72MsduAggregator::GetSizeIfAggregated(uint16_t msduSize, uint16_t amsduSize)
73{
74 NS_LOG_FUNCTION(msduSize << amsduSize);
75
76 // the size of the A-MSDU subframe header is 14 bytes: DA (6), SA (6) and Length (2)
77 return amsduSize + CalculatePadding(amsduSize) + 14 + msduSize;
78}
79
82 WifiTxParameters& txParams,
83 Time availableTime) const
84{
85 NS_LOG_FUNCTION(this << *peekedItem << &txParams << availableTime);
86
87 /* "The Address 1 field of an MPDU carrying an A-MSDU shall be set to an
88 * individual address or to the GCR concealment address" (Section 10.12
89 * of 802.11-2016)
90 */
91 const auto& header = peekedItem->GetOriginal()->GetHeader();
92 const auto recipient = GetIndividuallyAddressedRecipient(m_mac, header);
93 NS_ABORT_MSG_IF(recipient.IsBroadcast(), "Recipient address is broadcast");
94
95 /* "A STA shall not transmit an A-MSDU within a QoS Data frame under a block
96 * ack agreement unless the recipient indicates support for A-MSDU by setting
97 * the A-MSDU Supported field to 1 in its BlockAck Parameter Set field of the
98 * ADDBA Response frame" (Section 10.12 of 802.11-2016)
99 */
100 // No check required for now, as we always set the A-MSDU Supported field to 1
101
102 // TODO Add support for the Max Number Of MSDUs In A-MSDU field in the Extended
103 // Capabilities element sent by the recipient
104
106
107 auto queue = m_mac->GetTxopQueue(peekedItem->GetQueueAc());
108
109 // if GCR, A-MSDU is always used with a single A-MSDU subframe
110 if (IsGcr(m_mac, header))
111 {
112 auto apMac = DynamicCast<ApWifiMac>(m_mac);
113 NS_ASSERT(apMac);
114 auto gcrManager = apMac->GetGcrManager();
115 if (!gcrManager->UseConcealment(peekedItem->GetHeader()))
116 {
117 return nullptr;
118 }
119 auto msdu = peekedItem->GetOriginal();
120 auto gcrAmsdu =
121 Create<WifiMpdu>(msdu->GetPacket(), msdu->GetHeader(), msdu->GetTimestamp());
122 gcrAmsdu->Aggregate(nullptr);
123 queue->Replace(msdu, gcrAmsdu);
124 if (msdu->GetHeader().IsRetry())
125 {
126 gcrAmsdu->AssignSeqNo(msdu->GetHeader().GetSequenceNumber());
127 }
128 return m_htFem->CreateAliasIfNeeded(gcrAmsdu);
129 }
130 else if (IsGroupcast(recipient))
131 {
132 NS_LOG_DEBUG("No A-MSDU aggregation for groupcast frames without GCR service");
133 return nullptr;
134 }
135
136 const auto tid = header.GetQosTid();
137 if (GetMaxAmsduSize(recipient, tid, txParams.m_txVector.GetModulationClass()) == 0)
138 {
139 NS_LOG_DEBUG("A-MSDU aggregation disabled");
140 return nullptr;
141 }
142
143 // perform A-MSDU aggregation
144 auto amsdu = queue->GetOriginal(peekedItem);
145 std::size_t nMsdu = 1;
146 peekedItem = queue->PeekByTidAndAddress(tid, recipient, peekedItem->GetOriginal());
147
148 // stop aggregation if we find an A-MSDU in the queue. This likely happens when an A-MSDU is
149 // prepared but not transmitted due to RTS/CTS failure
150 while (peekedItem && !peekedItem->GetHeader().IsQosAmsdu() &&
151 m_htFem->TryAggregateMsdu(peekedItem = m_htFem->CreateAliasIfNeeded(peekedItem),
152 txParams,
153 availableTime))
154 {
155 NS_ASSERT_MSG(!peekedItem->HasSeqNoAssigned(),
156 "Found item with sequence number assignment after one without: perhaps "
157 "sequence numbers were not released correctly?");
158 // find the next MPDU before dequeuing the current one
159 auto msdu = peekedItem->GetOriginal();
160 peekedItem = queue->PeekByTidAndAddress(tid, recipient, msdu);
161 queue->DequeueIfQueued({amsdu});
162 // perform A-MSDU aggregation
163 amsdu->Aggregate(msdu);
164 queue->Replace(msdu, amsdu);
165
166 nMsdu++;
167 }
168
169 if (nMsdu == 1)
170 {
171 NS_LOG_DEBUG("Aggregation failed (could not aggregate at least two MSDUs)");
172 return nullptr;
173 }
174
175 // Aggregation succeeded
176 return m_htFem->CreateAliasIfNeeded(amsdu);
177}
178
179uint8_t
181{
182 return (4 - (amsduSize % 4)) % 4;
183}
184
185uint16_t
187 uint8_t tid,
188 WifiModulationClass modulation) const
189{
190 NS_LOG_FUNCTION(this << recipient << +tid << modulation);
191
192 AcIndex ac = QosUtilsMapTidToAc(tid);
193
194 // Find the A-MSDU max size configured on this device
195 uint16_t maxAmsduSize = m_mac->GetMaxAmsduSize(ac);
196
197 if (maxAmsduSize == 0)
198 {
199 NS_LOG_DEBUG("A-MSDU Aggregation is disabled on this station for " << ac);
200 return 0;
201 }
202
203 Ptr<WifiRemoteStationManager> stationManager = m_mac->GetWifiRemoteStationManager(m_linkId);
204 NS_ASSERT(stationManager);
205
206 // Retrieve the Capabilities elements advertised by the recipient
207 auto ehtCapabilities = stationManager->GetStationEhtCapabilities(recipient);
208 auto he6GhzCapabilities = stationManager->GetStationHe6GhzCapabilities(recipient);
209 auto vhtCapabilities = stationManager->GetStationVhtCapabilities(recipient);
210 auto htCapabilities = stationManager->GetStationHtCapabilities(recipient);
211
212 // Determine the maximum MPDU size, which is used to indirectly constrain the maximum
213 // A-MSDU size in some cases (see below). The maximum MPDU size is advertised
214 // in the EHT Capabilities element, for the 2.4 GHz band, or in the VHT Capabilities
215 // element, otherwise.
216 uint16_t maxMpduSize = 0;
217 if (ehtCapabilities && m_mac->GetWifiPhy(m_linkId)->GetPhyBand() == WIFI_PHY_BAND_2_4GHZ)
218 {
219 maxMpduSize = ehtCapabilities->GetMaxMpduLength();
220 }
221 else if (he6GhzCapabilities && m_mac->Is6GhzBand(m_linkId))
222 {
223 maxMpduSize = he6GhzCapabilities->GetMaxMpduLength();
224 }
225 else if (vhtCapabilities && m_mac->GetWifiPhy(m_linkId)->GetPhyBand() != WIFI_PHY_BAND_2_4GHZ)
226 {
227 maxMpduSize = vhtCapabilities->GetMaxMpduLength();
228 }
229
230 if (!htCapabilities && !he6GhzCapabilities)
231 {
232 /* "A non-DMG STA shall not transmit an A-MSDU to a STA from which it has
233 * not received a frame containing an HT Capabilities element" (Section
234 * 10.12 of 802.11-2016)
235 */
236 NS_LOG_DEBUG("A-MSDU Aggregation disabled because the recipient did not"
237 " send an HT Capabilities element");
238 return 0;
239 }
240
241 // Determine the constraint imposed by the recipient based on the PPDU
242 // format used to transmit the A-MSDU
243 if (modulation >= WIFI_MOD_CLASS_EHT)
244 {
245 // the maximum A-MSDU size is indirectly constrained by the maximum MPDU size
246 // supported by the recipient (see Table 9-34 of 802.11be D2.0)
247 NS_ABORT_MSG_IF(maxMpduSize == 0, "Max MPDU size not advertised");
248 maxAmsduSize = std::min(maxAmsduSize, static_cast<uint16_t>(maxMpduSize - 56));
249 }
250 else if (modulation == WIFI_MOD_CLASS_HE)
251 {
252 // for a non-EHT STA operating in the 2.4 GHz band, the maximum A-MSDU size is
253 // advertised in the HT Capabilities element. Otherwise, the maximum A-MSDU size is
254 // indirectly constrained by the maximum MPDU size supported by the recipient
255 // (see Table 9-34 of 802.11be D2.0)
256 if (m_mac->GetWifiPhy(m_linkId)->GetStandard() < WIFI_STANDARD_80211be &&
257 m_mac->GetWifiPhy(m_linkId)->GetPhyBand() == WIFI_PHY_BAND_2_4GHZ)
258 {
259 maxAmsduSize = std::min(maxAmsduSize, htCapabilities->GetMaxAmsduLength());
260 }
261 else
262 {
263 NS_ABORT_MSG_IF(maxMpduSize == 0, "Max MPDU size not advertised");
264 maxAmsduSize = std::min(maxAmsduSize, static_cast<uint16_t>(maxMpduSize - 56));
265 }
266 }
267 else if (modulation == WIFI_MOD_CLASS_VHT)
268 {
269 // the maximum A-MSDU size is indirectly constrained by the maximum MPDU
270 // size supported by the recipient and advertised in the VHT Capabilities
271 // element (see Table 9-25 of 802.11-2020)
272 NS_ABORT_MSG_IF(maxMpduSize == 0, "Max MPDU size not advertised");
273 maxAmsduSize = std::min(maxAmsduSize, static_cast<uint16_t>(maxMpduSize - 56));
274 }
275 else if (modulation >= WIFI_MOD_CLASS_HT)
276 {
277 // the maximum A-MSDU size is constrained by the maximum A-MSDU size
278 // supported by the recipient and advertised in the HT Capabilities
279 // element (see Table 9-19 of 802.11-2016)
280 maxAmsduSize = std::min(maxAmsduSize, htCapabilities->GetMaxAmsduLength());
281 }
282 else // non-HT PPDU
283 {
284 // the maximum A-MSDU size is indirectly constrained by the maximum PSDU size
285 // supported by the recipient (see Table 9-19 of 802.11-2016)
286 maxAmsduSize = std::min(maxAmsduSize, static_cast<uint16_t>(3839));
287 }
288
289 return maxAmsduSize;
290}
291
294{
297
299 Ptr<Packet> extractedMsdu = Create<Packet>();
300 uint32_t maxSize = aggregatedPacket->GetSize();
301 uint16_t extractedLength;
302 uint8_t padding;
303 uint32_t deserialized = 0;
304
305 while (deserialized < maxSize)
306 {
307 deserialized += aggregatedPacket->RemoveHeader(hdr);
308 extractedLength = hdr.GetLength();
309 extractedMsdu = aggregatedPacket->CreateFragment(0, static_cast<uint32_t>(extractedLength));
310 aggregatedPacket->RemoveAtStart(extractedLength);
311 deserialized += extractedLength;
312
313 padding = (4 - ((extractedLength + 14) % 4)) % 4;
314
315 if (padding > 0 && deserialized < maxSize)
316 {
317 aggregatedPacket->RemoveAtStart(padding);
318 deserialized += padding;
319 }
320
321 std::pair<Ptr<const Packet>, AmsduSubframeHeader> packetHdr(extractedMsdu, hdr);
322 set.push_back(packetHdr);
323 }
324 NS_LOG_INFO("Deaggreated A-MSDU: extracted " << set.size() << " MSDUs");
325 return set;
326}
327
328} // namespace ns3
Headers for A-MSDU subframes.
uint16_t GetLength() const
Get length function.
an EUI-48 address
Aggregator used to construct A-MSDUs.
static TypeId GetTypeId()
Get the type ID.
uint16_t GetMaxAmsduSize(Mac48Address recipient, uint8_t tid, WifiModulationClass modulation) const
Determine the maximum size for an A-MSDU of the given TID that can be sent to the given receiver when...
void DoDispose() override
Destructor implementation.
Ptr< WifiMac > m_mac
the MAC of this station
uint8_t m_linkId
ID of the link this object is connected to.
static WifiMpdu::DeaggregatedMsdus Deaggregate(Ptr< Packet > aggregatedPacket)
Ptr< HtFrameExchangeManager > m_htFem
the HT Frame Exchange Manager of this station
static uint16_t GetSizeIfAggregated(uint16_t msduSize, uint16_t amsduSize)
Compute the size of the A-MSDU resulting from the aggregation of an MSDU of size msduSize and an A-MS...
Ptr< WifiMpdu > GetNextAmsdu(Ptr< WifiMpdu > peekedItem, WifiTxParameters &txParams, Time availableTime) const
Attempt to aggregate other MSDUs to the given A-MSDU while meeting the following constraints:
void SetWifiMac(const Ptr< WifiMac > mac)
Set the MAC layer to use.
static uint8_t CalculatePadding(uint16_t amsduSize)
Calculate how much padding must be added to the end of an A-MSDU of the given size if a new MSDU is a...
void SetLinkId(uint8_t linkId)
Set the ID of the link this MSDU aggregator is associated with.
A base class which provides memory management and object aggregation.
Definition object.h:78
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
std::list< std::pair< Ptr< const Packet >, AmsduSubframeHeader > > DeaggregatedMsdus
DeaggregatedMsdus typedef.
Definition wifi-mpdu.h:131
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
WifiModulationClass GetModulationClass() const
Get the modulation class specified by this TXVECTOR.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:75
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition qos-utils.cc:123
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition qos-utils.h:62
@ WIFI_STANDARD_80211be
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
@ WIFI_MOD_CLASS_EHT
EHT (Clause 36)
@ WIFI_MOD_CLASS_VHT
VHT (Clause 22)
@ WIFI_MOD_CLASS_HE
HE (Clause 27)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
bool IsGroupcast(const Mac48Address &adr)
Check whether a MAC destination address corresponds to a groupcast transmission.
bool IsGcr(Ptr< WifiMac > mac, const WifiMacHeader &hdr)
Return whether a given packet is transmitted using the GCR service.
Mac48Address GetIndividuallyAddressedRecipient(Ptr< WifiMac > mac, const WifiMacHeader &hdr)
Get the MAC address of the individually addressed recipient to use for a given packet.