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