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 " << 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, "EHT Capabilities element not received");
151
152 maxAmpduSize = std::min(maxAmpduSize, ehtCapabilities->GetMaxAmpduLength());
153 }
154 else if (modulation >= WIFI_MOD_CLASS_HE)
155 {
156 NS_ABORT_MSG_IF(!heCapabilities, "HE Capabilities element not received");
157
158 maxAmpduSize = std::min(maxAmpduSize, heCapabilities->GetMaxAmpduLength());
159 if (he6GhzCapabilities)
160 {
161 maxAmpduSize = std::min(maxAmpduSize, he6GhzCapabilities->GetMaxAmpduLength());
162 }
163 }
164 else if (modulation == WIFI_MOD_CLASS_VHT)
165 {
166 NS_ABORT_MSG_IF(!vhtCapabilities, "VHT Capabilities element not received");
167
168 maxAmpduSize = std::min(maxAmpduSize, vhtCapabilities->GetMaxAmpduLength());
169 }
170 else if (modulation == WIFI_MOD_CLASS_HT)
171 {
172 NS_ABORT_MSG_IF(!htCapabilities, "HT Capabilities element not received");
173
174 maxAmpduSize = std::min(maxAmpduSize, htCapabilities->GetMaxAmpduLength());
175 }
176 else // non-HT PPDU
177 {
178 NS_LOG_DEBUG("A-MPDU aggregation is not available for non-HT PHYs");
179
180 maxAmpduSize = 0;
181 }
182
183 return maxAmpduSize;
184}
185
186uint8_t
188{
189 return (4 - (ampduSize % 4)) % 4;
190}
191
193MpduAggregator::GetAmpduSubframeHeader(uint16_t mpduSize, bool isSingle)
194{
196 hdr.SetLength(mpduSize);
197 if (isSingle)
198 {
199 hdr.SetEof(true);
200 }
201 return hdr;
202}
203
204std::vector<Ptr<WifiMpdu>>
206 WifiTxParameters& txParams,
207 Time availableTime) const
208{
209 NS_LOG_FUNCTION(this << *mpdu << &txParams << availableTime);
210
211 std::vector<Ptr<WifiMpdu>> mpduList;
212
213 Mac48Address recipient = mpdu->GetHeader().GetAddr1();
214 NS_ASSERT(mpdu->GetHeader().IsQosData() && !recipient.IsBroadcast());
215 uint8_t tid = mpdu->GetHeader().GetQosTid();
216 auto origRecipient = mpdu->GetOriginal()->GetHeader().GetAddr1();
217
218 Ptr<QosTxop> qosTxop = m_mac->GetQosTxop(tid);
219 NS_ASSERT(qosTxop);
220
221 // Have to make sure that the block ack agreement is established and A-MPDU is enabled
222 if (m_mac->GetBaAgreementEstablishedAsOriginator(recipient, tid) &&
223 GetMaxAmpduSize(recipient, tid, txParams.m_txVector.GetModulationClass()) > 0)
224 {
225 /* here is performed MPDU aggregation */
226 Ptr<WifiMpdu> nextMpdu = mpdu;
227
228 while (nextMpdu)
229 {
230 // if we are here, nextMpdu can be aggregated to the A-MPDU.
231 NS_LOG_DEBUG("Adding packet with sequence number "
232 << nextMpdu->GetHeader().GetSequenceNumber()
233 << " to A-MPDU, packet size = " << nextMpdu->GetSize()
234 << ", A-MPDU size = " << txParams.GetSize(recipient));
235
236 mpduList.push_back(nextMpdu);
237
238 // If allowed by the BA agreement, get the next MPDU
239 auto peekedMpdu =
240 qosTxop->PeekNextMpdu(m_linkId, tid, origRecipient, nextMpdu->GetOriginal());
241 nextMpdu = nullptr;
242
243 if (peekedMpdu)
244 {
245 // PeekNextMpdu() does not return an MPDU that is beyond the transmit window
246 NS_ASSERT(IsInWindow(peekedMpdu->GetHeader().GetSequenceNumber(),
247 qosTxop->GetBaStartingSequence(origRecipient, tid),
248 qosTxop->GetBaBufferSize(origRecipient, tid)));
249
250 peekedMpdu = m_htFem->CreateAliasIfNeeded(peekedMpdu);
251 // get the next MPDU to aggregate, provided that the constraints on size
252 // and duration limit are met. Note that the returned MPDU differs from
253 // the peeked MPDU if A-MSDU aggregation is enabled.
254 NS_LOG_DEBUG("Trying to aggregate another MPDU");
255 nextMpdu =
256 qosTxop->GetNextMpdu(m_linkId, peekedMpdu, txParams, availableTime, false);
257 }
258 }
259
260 if (mpduList.size() == 1)
261 {
262 // return an empty vector if it was not possible to aggregate at least two MPDUs
263 mpduList.clear();
264 }
265 }
266
267 return mpduList;
268}
269
270} // 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)