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 "ctrl-headers.h"
14#include "msdu-aggregator.h"
15#include "qos-txop.h"
16#include "wifi-mac-trailer.h"
17#include "wifi-mac.h"
18#include "wifi-mpdu.h"
19#include "wifi-net-device.h"
20#include "wifi-phy.h"
22#include "wifi-tx-parameters.h"
23#include "wifi-tx-vector.h"
24
25#include "ns3/eht-capabilities.h"
26#include "ns3/he-capabilities.h"
27#include "ns3/ht-capabilities.h"
28#include "ns3/ht-frame-exchange-manager.h"
29#include "ns3/log.h"
30#include "ns3/packet.h"
31#include "ns3/vht-capabilities.h"
32
33NS_LOG_COMPONENT_DEFINE("MpduAggregator");
34
35namespace ns3
36{
37
38NS_OBJECT_ENSURE_REGISTERED(MpduAggregator);
39
40TypeId
42{
43 static TypeId tid = TypeId("ns3::MpduAggregator")
45 .SetGroupName("Wifi")
46 .AddConstructor<MpduAggregator>();
47 return tid;
48}
49
50void
52{
53 m_mac = nullptr;
54 m_htFem = nullptr;
56}
57
58void
60{
61 NS_LOG_FUNCTION(this << mac);
62 m_mac = mac;
63 m_htFem = DynamicCast<HtFrameExchangeManager>(m_mac->GetFrameExchangeManager(m_linkId));
64}
65
66void
68{
69 NS_LOG_FUNCTION(this << +linkId);
70 m_linkId = linkId;
71 if (m_mac)
72 {
73 m_htFem = DynamicCast<HtFrameExchangeManager>(m_mac->GetFrameExchangeManager(m_linkId));
74 }
75}
76
77void
79{
80 NS_LOG_FUNCTION(mpdu << ampdu << isSingle);
81 NS_ASSERT(ampdu);
82 // if isSingle is true, then ampdu must be empty
83 NS_ASSERT(!isSingle || ampdu->GetSize() == 0);
84
85 // pad the previous A-MPDU subframe if the A-MPDU is not empty
86 if (ampdu->GetSize() > 0)
87 {
88 uint8_t padding = CalculatePadding(ampdu->GetSize());
89
90 if (padding)
91 {
92 Ptr<Packet> pad = Create<Packet>(padding);
93 ampdu->AddAtEnd(pad);
94 }
95 }
96
97 // add MPDU header and trailer
98 Ptr<Packet> tmp = mpdu->GetPacket()->Copy();
99 tmp->AddHeader(mpdu->GetHeader());
101
102 // add A-MPDU subframe header and MPDU to the A-MPDU
104 GetAmpduSubframeHeader(static_cast<uint16_t>(tmp->GetSize()), isSingle);
105
106 tmp->AddHeader(hdr);
107 ampdu->AddAtEnd(tmp);
108}
109
112{
113 NS_LOG_FUNCTION(mpduSize << ampduSize);
114
115 return ampduSize + CalculatePadding(ampduSize) + 4 + mpduSize;
116}
117
120 uint8_t tid,
121 WifiModulationClass modulation) const
122{
123 NS_LOG_FUNCTION(this << recipient << +tid << modulation);
124
125 AcIndex ac = QosUtilsMapTidToAc(tid);
126
127 // Find the A-MPDU max size configured on this device
128 uint32_t maxAmpduSize = m_mac->GetMaxAmpduSize(ac);
129
130 if (maxAmpduSize == 0)
131 {
132 NS_LOG_DEBUG("A-MPDU Aggregation is disabled on this station for " << ac);
133 return 0;
134 }
135
136 Ptr<WifiRemoteStationManager> stationManager = m_mac->GetWifiRemoteStationManager(m_linkId);
137 NS_ASSERT(stationManager);
138
139 // Retrieve the Capabilities elements advertised by the recipient
140 auto ehtCapabilities = stationManager->GetStationEhtCapabilities(recipient);
141 auto heCapabilities = stationManager->GetStationHeCapabilities(recipient);
142 auto he6GhzCapabilities = stationManager->GetStationHe6GhzCapabilities(recipient);
143 auto vhtCapabilities = stationManager->GetStationVhtCapabilities(recipient);
144 auto htCapabilities = stationManager->GetStationHtCapabilities(recipient);
145
146 // Determine the constraint imposed by the recipient based on the PPDU
147 // format used to transmit the A-MPDU
148 if (modulation >= WIFI_MOD_CLASS_EHT)
149 {
150 NS_ABORT_MSG_IF(!ehtCapabilities,
151 "EHT Capabilities element not received for " << recipient);
152
153 maxAmpduSize = std::min(maxAmpduSize, ehtCapabilities->GetMaxAmpduLength());
154 }
155 else if (modulation >= WIFI_MOD_CLASS_HE)
156 {
157 NS_ABORT_MSG_IF(!heCapabilities, "HE Capabilities element not received for " << recipient);
158
159 maxAmpduSize = std::min(maxAmpduSize, heCapabilities->GetMaxAmpduLength());
160 if (he6GhzCapabilities)
161 {
162 maxAmpduSize = std::min(maxAmpduSize, he6GhzCapabilities->GetMaxAmpduLength());
163 }
164 }
165 else if (modulation == WIFI_MOD_CLASS_VHT)
166 {
167 NS_ABORT_MSG_IF(!vhtCapabilities,
168 "VHT Capabilities element not received for " << recipient);
169
170 maxAmpduSize = std::min(maxAmpduSize, vhtCapabilities->GetMaxAmpduLength());
171 }
172 else if (modulation == WIFI_MOD_CLASS_HT)
173 {
174 NS_ABORT_MSG_IF(!htCapabilities, "HT Capabilities element not received for " << recipient);
175
176 maxAmpduSize = std::min(maxAmpduSize, htCapabilities->GetMaxAmpduLength());
177 }
178 else // non-HT PPDU
179 {
180 NS_LOG_DEBUG("A-MPDU aggregation is not available for non-HT PHYs");
181
182 maxAmpduSize = 0;
183 }
184
185 return maxAmpduSize;
186}
187
188uint8_t
190{
191 return (4 - (ampduSize % 4)) % 4;
192}
193
195MpduAggregator::GetAmpduSubframeHeader(uint16_t mpduSize, bool isSingle)
196{
198 hdr.SetLength(mpduSize);
199 if (isSingle)
200 {
201 hdr.SetEof(true);
202 }
203 return hdr;
204}
205
206std::vector<Ptr<WifiMpdu>>
208 WifiTxParameters& txParams,
209 Time availableTime) const
210{
211 NS_LOG_FUNCTION(this << *mpdu << &txParams << availableTime);
212
213 std::vector<Ptr<WifiMpdu>> mpduList;
214
215 Mac48Address recipient = mpdu->GetHeader().GetAddr1();
216 NS_ASSERT(mpdu->GetHeader().IsQosData() && !recipient.IsBroadcast());
217 uint8_t tid = mpdu->GetHeader().GetQosTid();
218 auto origRecipient = mpdu->GetOriginal()->GetHeader().GetAddr1();
219
220 Ptr<QosTxop> qosTxop = m_mac->GetQosTxop(tid);
221 NS_ASSERT(qosTxop);
222
223 // Have to make sure that the block ack agreement is established and A-MPDU is enabled
224 if (m_mac->GetBaAgreementEstablishedAsOriginator(recipient, tid) &&
225 GetMaxAmpduSize(recipient, tid, txParams.m_txVector.GetModulationClass()) > 0)
226 {
227 /* here is performed MPDU aggregation */
228 Ptr<WifiMpdu> nextMpdu = mpdu;
229
230 while (nextMpdu)
231 {
232 // if we are here, nextMpdu can be aggregated to the A-MPDU.
233 NS_LOG_DEBUG("Adding packet with sequence number "
234 << nextMpdu->GetHeader().GetSequenceNumber()
235 << " to A-MPDU, packet size = " << nextMpdu->GetSize()
236 << ", A-MPDU size = " << txParams.GetSize(recipient));
237
238 mpduList.push_back(nextMpdu);
239
240 // If allowed by the BA agreement, get the next MPDU
241 auto peekedMpdu =
242 qosTxop->PeekNextMpdu(m_linkId, tid, origRecipient, nextMpdu->GetOriginal());
243 nextMpdu = nullptr;
244
245 if (peekedMpdu)
246 {
247 // PeekNextMpdu() does not return an MPDU that is beyond the transmit window
248 NS_ASSERT(IsInWindow(peekedMpdu->GetHeader().GetSequenceNumber(),
249 qosTxop->GetBaStartingSequence(origRecipient, tid),
250 qosTxop->GetBaBufferSize(origRecipient, tid)));
251
252 peekedMpdu = m_htFem->CreateAliasIfNeeded(peekedMpdu);
253 // get the next MPDU to aggregate, provided that the constraints on size
254 // and duration limit are met. Note that the returned MPDU differs from
255 // the peeked MPDU if A-MSDU aggregation is enabled.
256 NS_LOG_DEBUG("Trying to aggregate another MPDU");
257 nextMpdu =
258 qosTxop->GetNextMpdu(m_linkId, peekedMpdu, txParams, availableTime, false);
259 }
260 }
261
262 if (mpduList.size() == 1)
263 {
264 // return an empty vector if it was not possible to aggregate at least two MPDUs
265 mpduList.clear();
266 }
267 }
268
269 return mpduList;
270}
271
272} // 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
bool IsBroadcast() const
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:48
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
@ 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
void AddWifiMacTrailer(Ptr< Packet > packet)
Add FCS trailer to a packet.
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)