A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mpdu-aggregator.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Ghada Badawy <gbadawy@gmail.com>
7 * Stefano Avallone <stavallo@unina.it>
8 */
9
10#include "mpdu-aggregator.h"
11
13#include "ap-wifi-mac.h"
14#include "ctrl-headers.h"
15#include "gcr-manager.h"
16#include "msdu-aggregator.h"
17#include "qos-txop.h"
18#include "wifi-mac-trailer.h"
19#include "wifi-mpdu.h"
20#include "wifi-net-device.h"
21#include "wifi-phy.h"
23#include "wifi-tx-parameters.h"
24#include "wifi-tx-vector.h"
25
26#include "ns3/eht-capabilities.h"
27#include "ns3/he-capabilities.h"
28#include "ns3/ht-capabilities.h"
29#include "ns3/ht-frame-exchange-manager.h"
30#include "ns3/log.h"
31#include "ns3/packet.h"
32#include "ns3/vht-capabilities.h"
33
34NS_LOG_COMPONENT_DEFINE("MpduAggregator");
35
36namespace ns3
37{
38
39NS_OBJECT_ENSURE_REGISTERED(MpduAggregator);
40
41TypeId
43{
44 static TypeId tid = TypeId("ns3::MpduAggregator")
46 .SetGroupName("Wifi")
47 .AddConstructor<MpduAggregator>();
48 return tid;
49}
50
51void
53{
54 m_mac = nullptr;
55 m_htFem = nullptr;
57}
58
59void
61{
62 NS_LOG_FUNCTION(this << mac);
63 m_mac = mac;
64 m_htFem = DynamicCast<HtFrameExchangeManager>(m_mac->GetFrameExchangeManager(m_linkId));
65}
66
67void
69{
70 NS_LOG_FUNCTION(this << +linkId);
71 m_linkId = linkId;
72 if (m_mac)
73 {
74 m_htFem = DynamicCast<HtFrameExchangeManager>(m_mac->GetFrameExchangeManager(m_linkId));
75 }
76}
77
78void
80{
81 NS_LOG_FUNCTION(mpdu << ampdu << isSingle);
82 NS_ASSERT(ampdu);
83 // if isSingle is true, then ampdu must be empty
84 NS_ASSERT(!isSingle || ampdu->GetSize() == 0);
85
86 // pad the previous A-MPDU subframe if the A-MPDU is not empty
87 if (ampdu->GetSize() > 0)
88 {
89 uint8_t padding = CalculatePadding(ampdu->GetSize());
90
91 if (padding)
92 {
93 Ptr<Packet> pad = Create<Packet>(padding);
94 ampdu->AddAtEnd(pad);
95 }
96 }
97
98 // add MPDU header and trailer
99 Ptr<Packet> tmp = mpdu->GetPacket()->Copy();
100 tmp->AddHeader(mpdu->GetHeader());
102
103 // add A-MPDU subframe header and MPDU to the A-MPDU
105 GetAmpduSubframeHeader(static_cast<uint16_t>(tmp->GetSize()), isSingle);
106
107 tmp->AddHeader(hdr);
108 ampdu->AddAtEnd(tmp);
109}
110
113{
114 NS_LOG_FUNCTION(mpduSize << ampduSize);
115
116 return ampduSize + CalculatePadding(ampduSize) + 4 + mpduSize;
117}
118
121 uint8_t tid,
122 WifiModulationClass modulation) const
123{
124 NS_LOG_FUNCTION(this << recipient << +tid << modulation);
125
126 if (auto apMac = DynamicCast<ApWifiMac>(m_mac);
127 IsGroupcast(recipient) && (m_mac->GetTypeOfStation() == AP) && apMac->GetGcrManager())
128 {
129 recipient = apMac->GetGcrManager()->GetIndividuallyAddressedRecipient(recipient);
130 }
131
132 AcIndex ac = QosUtilsMapTidToAc(tid);
133 // Find the A-MPDU max size configured on this device
134 uint32_t maxAmpduSize = m_mac->GetMaxAmpduSize(ac);
135
136 if (maxAmpduSize == 0)
137 {
138 NS_LOG_DEBUG("A-MPDU Aggregation is disabled on this station for " << ac);
139 return 0;
140 }
141
142 Ptr<WifiRemoteStationManager> stationManager = m_mac->GetWifiRemoteStationManager(m_linkId);
143 NS_ASSERT(stationManager);
144
145 // Retrieve the Capabilities elements advertised by the recipient
146 auto ehtCapabilities = stationManager->GetStationEhtCapabilities(recipient);
147 auto heCapabilities = stationManager->GetStationHeCapabilities(recipient);
148 auto he6GhzCapabilities = stationManager->GetStationHe6GhzCapabilities(recipient);
149 auto vhtCapabilities = stationManager->GetStationVhtCapabilities(recipient);
150 auto htCapabilities = stationManager->GetStationHtCapabilities(recipient);
151
152 // Determine the constraint imposed by the recipient based on the PPDU
153 // format used to transmit the A-MPDU
154 if (modulation >= WIFI_MOD_CLASS_EHT)
155 {
156 NS_ABORT_MSG_IF(!ehtCapabilities,
157 "EHT Capabilities element not received for " << recipient);
158
159 maxAmpduSize = std::min(maxAmpduSize, ehtCapabilities->GetMaxAmpduLength());
160 }
161 else if (modulation >= WIFI_MOD_CLASS_HE)
162 {
163 NS_ABORT_MSG_IF(!heCapabilities, "HE Capabilities element not received for " << recipient);
164
165 maxAmpduSize = std::min(maxAmpduSize, heCapabilities->GetMaxAmpduLength());
166 if (he6GhzCapabilities)
167 {
168 maxAmpduSize = std::min(maxAmpduSize, he6GhzCapabilities->GetMaxAmpduLength());
169 }
170 }
171 else if (modulation == WIFI_MOD_CLASS_VHT)
172 {
173 NS_ABORT_MSG_IF(!vhtCapabilities,
174 "VHT Capabilities element not received for " << recipient);
175
176 maxAmpduSize = std::min(maxAmpduSize, vhtCapabilities->GetMaxAmpduLength());
177 }
178 else if (modulation == WIFI_MOD_CLASS_HT)
179 {
180 NS_ABORT_MSG_IF(!htCapabilities, "HT Capabilities element not received for " << recipient);
181
182 maxAmpduSize = std::min(maxAmpduSize, htCapabilities->GetMaxAmpduLength());
183 }
184 else // non-HT PPDU
185 {
186 NS_LOG_DEBUG("A-MPDU aggregation is not available for non-HT PHYs");
187
188 maxAmpduSize = 0;
189 }
190
191 return maxAmpduSize;
192}
193
194uint8_t
196{
197 return (4 - (ampduSize % 4)) % 4;
198}
199
201MpduAggregator::GetAmpduSubframeHeader(uint16_t mpduSize, bool isSingle)
202{
204 hdr.SetLength(mpduSize);
205 if (isSingle)
206 {
207 hdr.SetEof(true);
208 }
209 return hdr;
210}
211
212std::vector<Ptr<WifiMpdu>>
214 WifiTxParameters& txParams,
215 Time availableTime) const
216{
217 NS_LOG_FUNCTION(this << *mpdu << &txParams << availableTime);
218
219 std::vector<Ptr<WifiMpdu>> mpduList;
220
221 const auto& header = mpdu->GetHeader();
222 const auto recipient = GetIndividuallyAddressedRecipient(m_mac, header);
223 NS_ASSERT(header.IsQosData() && !recipient.IsBroadcast());
224
225 const auto& origAddr1 = mpdu->GetOriginal()->GetHeader().GetAddr1();
226 auto origRecipient = GetIndividuallyAddressedRecipient(m_mac, mpdu->GetOriginal()->GetHeader());
227
228 const auto tid = header.GetQosTid();
229 auto qosTxop = m_mac->GetQosTxop(tid);
230 NS_ASSERT(qosTxop);
231
232 const auto isGcr = IsGcr(m_mac, header);
233 const auto bufferSize = qosTxop->GetBaBufferSize(origRecipient, tid, isGcr);
234 const auto startSeq = qosTxop->GetBaStartingSequence(origRecipient, tid, isGcr);
235
236 // Have to make sure that the block ack agreement is established and A-MPDU is enabled
237 auto apMac = DynamicCast<ApWifiMac>(m_mac);
238 const auto agreementEstablished =
239 isGcr ? apMac->IsGcrBaAgreementEstablishedWithAllMembers(header.GetAddr1(), tid)
240 : m_mac->GetBaAgreementEstablishedAsOriginator(recipient, tid).has_value();
241 if (agreementEstablished &&
242 GetMaxAmpduSize(recipient, tid, txParams.m_txVector.GetModulationClass()) > 0)
243 {
244 /* here is performed MPDU aggregation */
245 Ptr<WifiMpdu> nextMpdu = mpdu;
246
247 while (nextMpdu)
248 {
249 const auto isGcrUr = isGcr && (apMac->GetGcrManager()->GetRetransmissionPolicy() ==
251 if (isGcrUr && header.IsRetry() && !nextMpdu->GetHeader().IsRetry())
252 {
253 // if this is a retransmitted A-MPDU transmitted via GCR-UR, do not add new MPDU
254 break;
255 }
256 if (isGcr &&
257 apMac->GetGcrManager()->GetRetransmissionPolicyFor(header) !=
258 apMac->GetGcrManager()->GetRetransmissionPolicyFor(nextMpdu->GetHeader()))
259 {
260 // if an MPDU has been previously transmitted using No-Ack/No-Retry,
261 // do not add a new MPDU that still needs to be transmitted using No-Ack/No-Retry,
262 // unless No-Ack/No-Retry is the only selected retransmission policy
263 break;
264 }
265
266 // if we are here, nextMpdu can be aggregated to the A-MPDU.
267 NS_LOG_DEBUG("Adding packet with sequence number "
268 << nextMpdu->GetHeader().GetSequenceNumber()
269 << " to A-MPDU, packet size = " << nextMpdu->GetSize()
270 << ", A-MPDU size = " << txParams.GetSize(recipient));
271
272 mpduList.push_back(nextMpdu);
273
274 // If allowed by the BA agreement, get the next MPDU
275 auto peekedMpdu =
276 qosTxop->PeekNextMpdu(m_linkId, tid, origAddr1, nextMpdu->GetOriginal());
277 nextMpdu = nullptr;
278
279 if (peekedMpdu)
280 {
281 // PeekNextMpdu() does not return an MPDU that is beyond the transmit window
282 NS_ASSERT(
283 IsInWindow(peekedMpdu->GetHeader().GetSequenceNumber(), startSeq, bufferSize));
284
285 peekedMpdu = m_htFem->CreateAliasIfNeeded(peekedMpdu);
286 // get the next MPDU to aggregate, provided that the constraints on size
287 // and duration limit are met. Note that the returned MPDU differs from
288 // the peeked MPDU if A-MSDU aggregation is enabled.
289 NS_LOG_DEBUG("Trying to aggregate another MPDU");
290 nextMpdu =
291 qosTxop->GetNextMpdu(m_linkId, peekedMpdu, txParams, availableTime, false);
292 }
293 }
294
295 if (mpduList.size() == 1)
296 {
297 // return an empty vector if it was not possible to aggregate at least two MPDUs
298 mpduList.clear();
299 }
300 }
301
302 return mpduList;
303}
304
305} // namespace ns3
Headers for A-MPDU subframes.
void SetEof(bool eof)
Set the EOF field.
void SetLength(uint16_t length)
Set the length field.
an EUI-48 address
Aggregator used to construct A-MPDUs.
static uint8_t CalculatePadding(uint32_t ampduSize)
void DoDispose() override
Destructor implementation.
static void Aggregate(Ptr< const WifiMpdu > mpdu, Ptr< Packet > ampdu, bool isSingle)
Aggregate an MPDU to an A-MPDU.
Ptr< WifiMac > m_mac
the MAC of this station
Ptr< HtFrameExchangeManager > m_htFem
the HT Frame Exchange Manager of this station
uint32_t GetMaxAmpduSize(Mac48Address recipient, uint8_t tid, WifiModulationClass modulation) const
Determine the maximum size for an A-MPDU of the given TID that can be sent to the given receiver when...
static AmpduSubframeHeader GetAmpduSubframeHeader(uint16_t mpduSize, bool isSingle)
Get the A-MPDU subframe header corresponding to the MPDU size and whether the MPDU is a single MPDU.
static TypeId GetTypeId()
Get the type ID.
void SetWifiMac(const Ptr< WifiMac > mac)
Set the MAC layer to use.
static uint32_t GetSizeIfAggregated(uint32_t mpduSize, uint32_t ampduSize)
Compute the size of the A-MPDU resulting from the aggregation of an MPDU of size mpduSize and an A-MP...
std::vector< Ptr< WifiMpdu > > GetNextAmpdu(Ptr< WifiMpdu > mpdu, WifiTxParameters &txParams, Time availableTime) const
Attempt to aggregate other MPDUs to the given MPDU, while meeting the following constraints:
void SetLinkId(uint8_t linkId)
Set the ID of the link this MPDU aggregator is associated with.
uint8_t m_linkId
ID of the link this object is connected to.
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
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
uint32_t GetSize(Mac48Address receiver) const
Get the size in bytes of the (A-)MPDU addressed to the given receiver.
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_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(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: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
@ AP
Definition wifi-mac.h:60
@ 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.
void AddWifiMacTrailer(Ptr< Packet > packet)
Add FCS trailer to a packet.
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.
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)