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
33
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,
147 recipient,
148 m_htFem->GetAddress(),
149 peekedItem->GetOriginal());
150
151 // stop aggregation if we find an A-MSDU in the queue. This likely happens when an A-MSDU is
152 // prepared but not transmitted due to RTS/CTS failure
153 while (peekedItem && !peekedItem->GetHeader().IsQosAmsdu() &&
154 m_htFem->TryAggregateMsdu(peekedItem = m_htFem->CreateAliasIfNeeded(peekedItem),
155 txParams,
156 availableTime))
157 {
158 NS_ASSERT_MSG(!peekedItem->HasSeqNoAssigned(),
159 "Found item with sequence number assignment after one without: perhaps "
160 "sequence numbers were not released correctly?");
161 // find the next MPDU before dequeuing the current one
162 auto msdu = peekedItem->GetOriginal();
163 peekedItem = queue->PeekByTidAndAddress(tid, recipient, m_htFem->GetAddress(), msdu);
164 queue->DequeueIfQueued({amsdu});
165 // perform A-MSDU aggregation
166 amsdu->Aggregate(msdu);
167 queue->Replace(msdu, amsdu);
168
169 nMsdu++;
170 }
171
172 if (nMsdu == 1)
173 {
174 NS_LOG_DEBUG("Aggregation failed (could not aggregate at least two MSDUs)");
175 return nullptr;
176 }
177
178 // Aggregation succeeded
179 return m_htFem->CreateAliasIfNeeded(amsdu);
180}
181
182uint8_t
184{
185 return (4 - (amsduSize % 4)) % 4;
186}
187
188uint16_t
190 uint8_t tid,
191 WifiModulationClass modulation) const
192{
193 NS_LOG_FUNCTION(this << recipient << +tid << modulation);
194
195 AcIndex ac = QosUtilsMapTidToAc(tid);
196
197 // Find the A-MSDU max size configured on this device
198 uint16_t maxAmsduSize = m_mac->GetMaxAmsduSize(ac);
199
200 if (maxAmsduSize == 0)
201 {
202 NS_LOG_DEBUG("A-MSDU Aggregation is disabled on this station for " << ac);
203 return 0;
204 }
205
206 Ptr<WifiRemoteStationManager> stationManager = m_mac->GetWifiRemoteStationManager(m_linkId);
207 NS_ASSERT(stationManager);
208
209 // Retrieve the Capabilities elements advertised by the recipient
210 auto ehtCapabilities = stationManager->GetStationEhtCapabilities(recipient);
211 auto he6GhzCapabilities = stationManager->GetStationHe6GhzCapabilities(recipient);
212 auto vhtCapabilities = stationManager->GetStationVhtCapabilities(recipient);
213 auto htCapabilities = stationManager->GetStationHtCapabilities(recipient);
214
215 // Determine the maximum MPDU size, which is used to indirectly constrain the maximum
216 // A-MSDU size in some cases (see below). The maximum MPDU size is advertised
217 // in the EHT Capabilities element, for the 2.4 GHz band, or in the VHT Capabilities
218 // element, otherwise.
219 uint16_t maxMpduSize = 0;
220 if (ehtCapabilities && m_mac->GetWifiPhy(m_linkId)->GetPhyBand() == WIFI_PHY_BAND_2_4GHZ)
221 {
222 maxMpduSize = ehtCapabilities->GetMaxMpduLength();
223 }
224 else if (he6GhzCapabilities && m_mac->Is6GhzBand(m_linkId))
225 {
226 maxMpduSize = he6GhzCapabilities->GetMaxMpduLength();
227 }
228 else if (vhtCapabilities && m_mac->GetWifiPhy(m_linkId)->GetPhyBand() != WIFI_PHY_BAND_2_4GHZ)
229 {
230 maxMpduSize = vhtCapabilities->GetMaxMpduLength();
231 }
232
233 if (!htCapabilities && !he6GhzCapabilities)
234 {
235 /* "A non-DMG STA shall not transmit an A-MSDU to a STA from which it has
236 * not received a frame containing an HT Capabilities element" (Section
237 * 10.12 of 802.11-2016)
238 */
239 NS_LOG_DEBUG("A-MSDU Aggregation disabled because the recipient did not"
240 " send an HT Capabilities element");
241 return 0;
242 }
243
244 // Determine the constraint imposed by the recipient based on the PPDU
245 // format used to transmit the A-MSDU
246 if (modulation >= WIFI_MOD_CLASS_EHT)
247 {
248 // the maximum A-MSDU size is indirectly constrained by the maximum MPDU size
249 // supported by the recipient (see Table 9-34 of 802.11be D2.0)
250 NS_ABORT_MSG_IF(maxMpduSize == 0, "Max MPDU size not advertised");
251 maxAmsduSize = std::min(maxAmsduSize, static_cast<uint16_t>(maxMpduSize - 56));
252 }
253 else if (modulation == WIFI_MOD_CLASS_HE)
254 {
255 // for a non-EHT STA operating in the 2.4 GHz band, the maximum A-MSDU size is
256 // advertised in the HT Capabilities element. Otherwise, the maximum A-MSDU size is
257 // indirectly constrained by the maximum MPDU size supported by the recipient
258 // (see Table 9-34 of 802.11be D2.0)
259 if (m_mac->GetWifiPhy(m_linkId)->GetStandard() < WIFI_STANDARD_80211be &&
260 m_mac->GetWifiPhy(m_linkId)->GetPhyBand() == WIFI_PHY_BAND_2_4GHZ)
261 {
262 maxAmsduSize = std::min(maxAmsduSize, htCapabilities->GetMaxAmsduLength());
263 }
264 else
265 {
266 NS_ABORT_MSG_IF(maxMpduSize == 0, "Max MPDU size not advertised");
267 maxAmsduSize = std::min(maxAmsduSize, static_cast<uint16_t>(maxMpduSize - 56));
268 }
269 }
270 else if (modulation == WIFI_MOD_CLASS_VHT)
271 {
272 // the maximum A-MSDU size is indirectly constrained by the maximum MPDU
273 // size supported by the recipient and advertised in the VHT Capabilities
274 // element (see Table 9-25 of 802.11-2020)
275 NS_ABORT_MSG_IF(maxMpduSize == 0, "Max MPDU size not advertised");
276 maxAmsduSize = std::min(maxAmsduSize, static_cast<uint16_t>(maxMpduSize - 56));
277 }
278 else if (modulation >= WIFI_MOD_CLASS_HT)
279 {
280 // the maximum A-MSDU size is constrained by the maximum A-MSDU size
281 // supported by the recipient and advertised in the HT Capabilities
282 // element (see Table 9-19 of 802.11-2016)
283 maxAmsduSize = std::min(maxAmsduSize, htCapabilities->GetMaxAmsduLength());
284 }
285 else // non-HT PPDU
286 {
287 // the maximum A-MSDU size is indirectly constrained by the maximum PSDU size
288 // supported by the recipient (see Table 9-19 of 802.11-2016)
289 maxAmsduSize = std::min(maxAmsduSize, static_cast<uint16_t>(3839));
290 }
291
292 return maxAmsduSize;
293}
294
297{
300
302 Ptr<Packet> extractedMsdu = Create<Packet>();
303 uint32_t maxSize = aggregatedPacket->GetSize();
304 uint16_t extractedLength;
305 uint8_t padding;
306 uint32_t deserialized = 0;
307
308 while (deserialized < maxSize)
309 {
310 deserialized += aggregatedPacket->RemoveHeader(hdr);
311 extractedLength = hdr.GetLength();
312 extractedMsdu = aggregatedPacket->CreateFragment(0, static_cast<uint32_t>(extractedLength));
313 aggregatedPacket->RemoveAtStart(extractedLength);
314 deserialized += extractedLength;
315
316 padding = (4 - ((extractedLength + 14) % 4)) % 4;
317
318 if (padding > 0 && deserialized < maxSize)
319 {
320 aggregatedPacket->RemoveAtStart(padding);
321 deserialized += padding;
322 }
323
324 std::pair<Ptr<const Packet>, AmsduSubframeHeader> packetHdr(extractedMsdu, hdr);
325 set.push_back(packetHdr);
326 }
327 NS_LOG_INFO("Deaggreated A-MSDU: extracted " << set.size() << " MSDUs");
328 return set;
329}
330
331} // 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...
MsduAggregator()=default
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.
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
virtual void DoDispose()
Destructor implementation.
Definition object.cc:430
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
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:194
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:260
#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:267
#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:492
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:64
@ 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:643
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.