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 "qos-txop.h"
13#include "wifi-mac-queue.h"
14#include "wifi-mac-trailer.h"
15#include "wifi-mac.h"
17#include "wifi-tx-parameters.h"
18
19#include "ns3/ht-capabilities.h"
20#include "ns3/ht-frame-exchange-manager.h"
21#include "ns3/log.h"
22#include "ns3/packet.h"
23
24#include <algorithm>
25
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE("MsduAggregator");
30
31NS_OBJECT_ENSURE_REGISTERED(MsduAggregator);
32
33TypeId
35{
36 static TypeId tid = TypeId("ns3::MsduAggregator")
38 .SetGroupName("Wifi")
39 .AddConstructor<MsduAggregator>();
40 return tid;
41}
42
43void
45{
46 m_mac = nullptr;
47 m_htFem = nullptr;
49}
50
51void
53{
54 NS_LOG_FUNCTION(this << mac);
55 m_mac = mac;
56 m_htFem = DynamicCast<HtFrameExchangeManager>(m_mac->GetFrameExchangeManager(m_linkId));
57}
58
59void
61{
62 NS_LOG_FUNCTION(this << +linkId);
63 m_linkId = linkId;
64 if (m_mac)
65 {
66 m_htFem = DynamicCast<HtFrameExchangeManager>(m_mac->GetFrameExchangeManager(m_linkId));
67 }
68}
69
70uint16_t
71MsduAggregator::GetSizeIfAggregated(uint16_t msduSize, uint16_t amsduSize)
72{
73 NS_LOG_FUNCTION(msduSize << amsduSize);
74
75 // the size of the A-MSDU subframe header is 14 bytes: DA (6), SA (6) and Length (2)
76 return amsduSize + CalculatePadding(amsduSize) + 14 + msduSize;
77}
78
81 WifiTxParameters& txParams,
82 Time availableTime) const
83{
84 NS_LOG_FUNCTION(this << *peekedItem << &txParams << availableTime);
85
86 Ptr<WifiMacQueue> queue = m_mac->GetTxopQueue(peekedItem->GetQueueAc());
87
88 uint8_t tid = peekedItem->GetHeader().GetQosTid();
89 auto recipient = peekedItem->GetOriginal()->GetHeader().GetAddr1();
90
91 /* "The Address 1 field of an MPDU carrying an A-MSDU shall be set to an
92 * individual address or to the GCR concealment address" (Section 10.12
93 * of 802.11-2016)
94 */
95 NS_ABORT_MSG_IF(recipient.IsBroadcast(), "Recipient address is broadcast");
96
97 /* "A STA shall not transmit an A-MSDU within a QoS Data frame under a block
98 * ack agreement unless the recipient indicates support for A-MSDU by setting
99 * the A-MSDU Supported field to 1 in its BlockAck Parameter Set field of the
100 * ADDBA Response frame" (Section 10.12 of 802.11-2016)
101 */
102 // No check required for now, as we always set the A-MSDU Supported field to 1
103
104 // TODO Add support for the Max Number Of MSDUs In A-MSDU field in the Extended
105 // Capabilities element sent by the recipient
106
108
109 if (GetMaxAmsduSize(recipient, tid, txParams.m_txVector.GetModulationClass()) == 0)
110 {
111 NS_LOG_DEBUG("A-MSDU aggregation disabled");
112 return nullptr;
113 }
114
115 Ptr<WifiMpdu> amsdu = queue->GetOriginal(peekedItem);
116 uint8_t nMsdu = 1;
117 peekedItem = queue->PeekByTidAndAddress(tid, recipient, peekedItem->GetOriginal());
118
119 // stop aggregation if we find an A-MSDU in the queue. This likely happens when an A-MSDU is
120 // prepared but not transmitted due to RTS/CTS failure
121 while (peekedItem && !peekedItem->GetHeader().IsQosAmsdu() &&
122 m_htFem->TryAggregateMsdu(peekedItem = m_htFem->CreateAliasIfNeeded(peekedItem),
123 txParams,
124 availableTime))
125 {
126 NS_ASSERT_MSG(!peekedItem->HasSeqNoAssigned(),
127 "Found item with sequence number assignment after one without: perhaps "
128 "sequence numbers were not released correctly?");
129 // find the next MPDU before dequeuing the current one
130 Ptr<const WifiMpdu> msdu = peekedItem->GetOriginal();
131 peekedItem = queue->PeekByTidAndAddress(tid, recipient, msdu);
132 queue->DequeueIfQueued({amsdu});
133 // perform A-MSDU aggregation
134 amsdu->Aggregate(msdu);
135 queue->Replace(msdu, amsdu);
136
137 nMsdu++;
138 }
139
140 if (nMsdu == 1)
141 {
142 NS_LOG_DEBUG("Aggregation failed (could not aggregate at least two MSDUs)");
143 return nullptr;
144 }
145
146 // Aggregation succeeded
147 return m_htFem->CreateAliasIfNeeded(amsdu);
148}
149
150uint8_t
152{
153 return (4 - (amsduSize % 4)) % 4;
154}
155
156uint16_t
158 uint8_t tid,
159 WifiModulationClass modulation) const
160{
161 NS_LOG_FUNCTION(this << recipient << +tid << modulation);
162
163 AcIndex ac = QosUtilsMapTidToAc(tid);
164
165 // Find the A-MSDU max size configured on this device
166 uint16_t maxAmsduSize = m_mac->GetMaxAmsduSize(ac);
167
168 if (maxAmsduSize == 0)
169 {
170 NS_LOG_DEBUG("A-MSDU Aggregation is disabled on this station for AC " << ac);
171 return 0;
172 }
173
174 Ptr<WifiRemoteStationManager> stationManager = m_mac->GetWifiRemoteStationManager(m_linkId);
175 NS_ASSERT(stationManager);
176
177 // Retrieve the Capabilities elements advertised by the recipient
178 auto ehtCapabilities = stationManager->GetStationEhtCapabilities(recipient);
179 auto he6GhzCapabilities = stationManager->GetStationHe6GhzCapabilities(recipient);
180 auto vhtCapabilities = stationManager->GetStationVhtCapabilities(recipient);
181 auto htCapabilities = stationManager->GetStationHtCapabilities(recipient);
182
183 // Determine the maximum MPDU size, which is used to indirectly constrain the maximum
184 // A-MSDU size in some cases (see below). The maximum MPDU size is advertised
185 // in the EHT Capabilities element, for the 2.4 GHz band, or in the VHT Capabilities
186 // element, otherwise.
187 uint16_t maxMpduSize = 0;
188 if (ehtCapabilities && m_mac->GetWifiPhy(m_linkId)->GetPhyBand() == WIFI_PHY_BAND_2_4GHZ)
189 {
190 maxMpduSize = ehtCapabilities->GetMaxMpduLength();
191 }
192 else if (he6GhzCapabilities && m_mac->Is6GhzBand(m_linkId))
193 {
194 maxMpduSize = he6GhzCapabilities->GetMaxMpduLength();
195 }
196 else if (vhtCapabilities && m_mac->GetWifiPhy(m_linkId)->GetPhyBand() != WIFI_PHY_BAND_2_4GHZ)
197 {
198 maxMpduSize = vhtCapabilities->GetMaxMpduLength();
199 }
200
201 if (!htCapabilities && !he6GhzCapabilities)
202 {
203 /* "A non-DMG STA shall not transmit an A-MSDU to a STA from which it has
204 * not received a frame containing an HT Capabilities element" (Section
205 * 10.12 of 802.11-2016)
206 */
207 NS_LOG_DEBUG("A-MSDU Aggregation disabled because the recipient did not"
208 " send an HT Capabilities element");
209 return 0;
210 }
211
212 // Determine the constraint imposed by the recipient based on the PPDU
213 // format used to transmit the A-MSDU
214 if (modulation >= WIFI_MOD_CLASS_EHT)
215 {
216 // the maximum A-MSDU size is indirectly constrained by the maximum MPDU size
217 // supported by the recipient (see Table 9-34 of 802.11be D2.0)
218 NS_ABORT_MSG_IF(maxMpduSize == 0, "Max MPDU size not advertised");
219 maxAmsduSize = std::min(maxAmsduSize, static_cast<uint16_t>(maxMpduSize - 56));
220 }
221 else if (modulation == WIFI_MOD_CLASS_HE)
222 {
223 // for a non-EHT STA operating in the 2.4 GHz band, the maximum A-MSDU size is
224 // advertised in the HT Capabilities element. Otherwise, the maximum A-MSDU size is
225 // indirectly constrained by the maximum MPDU size supported by the recipient
226 // (see Table 9-34 of 802.11be D2.0)
227 if (m_mac->GetWifiPhy(m_linkId)->GetStandard() < WIFI_STANDARD_80211be &&
228 m_mac->GetWifiPhy(m_linkId)->GetPhyBand() == WIFI_PHY_BAND_2_4GHZ)
229 {
230 maxAmsduSize = std::min(maxAmsduSize, htCapabilities->GetMaxAmsduLength());
231 }
232 else
233 {
234 NS_ABORT_MSG_IF(maxMpduSize == 0, "Max MPDU size not advertised");
235 maxAmsduSize = std::min(maxAmsduSize, static_cast<uint16_t>(maxMpduSize - 56));
236 }
237 }
238 else if (modulation == WIFI_MOD_CLASS_VHT)
239 {
240 // the maximum A-MSDU size is indirectly constrained by the maximum MPDU
241 // size supported by the recipient and advertised in the VHT Capabilities
242 // element (see Table 9-25 of 802.11-2020)
243 NS_ABORT_MSG_IF(maxMpduSize == 0, "Max MPDU size not advertised");
244 maxAmsduSize = std::min(maxAmsduSize, static_cast<uint16_t>(maxMpduSize - 56));
245 }
246 else if (modulation >= WIFI_MOD_CLASS_HT)
247 {
248 // the maximum A-MSDU size is constrained by the maximum A-MSDU size
249 // supported by the recipient and advertised in the HT Capabilities
250 // element (see Table 9-19 of 802.11-2016)
251 maxAmsduSize = std::min(maxAmsduSize, htCapabilities->GetMaxAmsduLength());
252 }
253 else // non-HT PPDU
254 {
255 // the maximum A-MSDU size is indirectly constrained by the maximum PSDU size
256 // supported by the recipient (see Table 9-19 of 802.11-2016)
257 maxAmsduSize = std::min(maxAmsduSize, static_cast<uint16_t>(3839));
258 }
259
260 return maxAmsduSize;
261}
262
265{
268
270 Ptr<Packet> extractedMsdu = Create<Packet>();
271 uint32_t maxSize = aggregatedPacket->GetSize();
272 uint16_t extractedLength;
273 uint8_t padding;
274 uint32_t deserialized = 0;
275
276 while (deserialized < maxSize)
277 {
278 deserialized += aggregatedPacket->RemoveHeader(hdr);
279 extractedLength = hdr.GetLength();
280 extractedMsdu = aggregatedPacket->CreateFragment(0, static_cast<uint32_t>(extractedLength));
281 aggregatedPacket->RemoveAtStart(extractedLength);
282 deserialized += extractedLength;
283
284 padding = (4 - ((extractedLength + 14) % 4)) % 4;
285
286 if (padding > 0 && deserialized < maxSize)
287 {
288 aggregatedPacket->RemoveAtStart(padding);
289 deserialized += padding;
290 }
291
292 std::pair<Ptr<const Packet>, AmsduSubframeHeader> packetHdr(extractedMsdu, hdr);
293 set.push_back(packetHdr);
294 }
295 NS_LOG_INFO("Deaggreated A-MSDU: extracted " << set.size() << " MSDUs");
296 return set;
297}
298
299} // 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:48
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