A Discrete-Event Network Simulator
API
msdu-aggregator.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2009 MIRKO BANCHI
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Mirko Banchi <mk.banchi@gmail.com>
19 * Stefano Avallone <stavallo@unina.it>
20 */
21
22#include "ns3/log.h"
23#include "ns3/packet.h"
24#include "msdu-aggregator.h"
25#include "qos-txop.h"
27#include "ns3/ht-capabilities.h"
28#include "wifi-mac.h"
29#include "wifi-mac-queue.h"
30#include "wifi-mac-trailer.h"
31#include "ns3/ht-frame-exchange-manager.h"
32#include "wifi-tx-parameters.h"
33#include <algorithm>
34
35namespace ns3 {
36
37NS_LOG_COMPONENT_DEFINE ("MsduAggregator");
38
39NS_OBJECT_ENSURE_REGISTERED (MsduAggregator);
40
41TypeId
43{
44 static TypeId tid = TypeId ("ns3::MsduAggregator")
45 .SetParent<Object> ()
46 .SetGroupName ("Wifi")
47 .AddConstructor<MsduAggregator> ()
48 ;
49 return tid;
50}
51
53{
54}
55
57{
58}
59
60void
62{
63 m_mac = 0;
64 m_htFem = 0;
66}
67
68void
70{
71 NS_LOG_FUNCTION (this << mac);
72 m_mac = mac;
73 m_htFem = DynamicCast<HtFrameExchangeManager> (m_mac->GetFrameExchangeManager ());
74}
75
76uint16_t
77MsduAggregator::GetSizeIfAggregated (uint16_t msduSize, uint16_t amsduSize)
78{
79 NS_LOG_FUNCTION (msduSize << amsduSize);
80
81 // the size of the A-MSDU subframe header is 14 bytes: DA (6), SA (6) and Length (2)
82 return amsduSize + CalculatePadding (amsduSize) + 14 + msduSize;
83}
84
87 Time availableTime) const
88{
89 NS_LOG_FUNCTION (this << *peekedItem << &txParams << availableTime);
90
91 Ptr<WifiMacQueue> queue = m_mac->GetTxopQueue (peekedItem->GetQueueAc ());
92
93 uint8_t tid = peekedItem->GetHeader ().GetQosTid ();
94 Mac48Address recipient = peekedItem->GetHeader ().GetAddr1 ();
95
96 /* "The Address 1 field of an MPDU carrying an A-MSDU shall be set to an
97 * individual address or to the GCR concealment address" (Section 10.12
98 * of 802.11-2016)
99 */
100 NS_ABORT_MSG_IF (recipient.IsBroadcast (), "Recipient address is broadcast");
101
102 /* "A STA shall not transmit an A-MSDU within a QoS Data frame under a block
103 * ack agreement unless the recipient indicates support for A-MSDU by setting
104 * the A-MSDU Supported field to 1 in its BlockAck Parameter Set field of the
105 * ADDBA Response frame" (Section 10.12 of 802.11-2016)
106 */
107 // No check required for now, as we always set the A-MSDU Supported field to 1
108
109 // TODO Add support for the Max Number Of MSDUs In A-MSDU field in the Extended
110 // Capabilities element sent by the recipient
111
112 NS_ASSERT (m_htFem != 0);
113
114 if (GetMaxAmsduSize (recipient, tid, txParams.m_txVector.GetModulationClass ()) == 0)
115 {
116 NS_LOG_DEBUG ("A-MSDU aggregation disabled");
117 return nullptr;
118 }
119
120 Ptr<WifiMacQueueItem> amsdu = peekedItem->GetItem (); // amsdu points to the peeked MPDU, but it's non-const
121 uint8_t nMsdu = 1;
122 peekedItem = queue->PeekByTidAndAddress (tid, recipient, peekedItem);
123
124 while (peekedItem != nullptr
125 && m_htFem->TryAggregateMsdu (peekedItem, txParams, availableTime))
126 {
127 // find the next MPDU before dequeuing the current one
128 Ptr<const WifiMacQueueItem> msdu = peekedItem;
129 peekedItem = queue->PeekByTidAndAddress (tid, recipient, peekedItem);
130 queue->DequeueIfQueued (msdu);
131
132 // perform A-MSDU aggregation
133 queue->Transform (amsdu, [&msdu](Ptr<WifiMacQueueItem> amsdu)
134 {
135 amsdu->Aggregate (msdu);
136 });
137
138 nMsdu++;
139 }
140
141 if (nMsdu == 1)
142 {
143 NS_LOG_DEBUG ("Aggregation failed (could not aggregate at least two MSDUs)");
144 return nullptr;
145 }
146
147 // Aggregation succeeded
148 return amsdu;
149}
150
151uint8_t
153{
154 return (4 - (amsduSize % 4 )) % 4;
155}
156
157uint16_t
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 ();
175 NS_ASSERT (stationManager);
176
177 // Retrieve the Capabilities elements advertised by the recipient
178 Ptr<const VhtCapabilities> vhtCapabilities = stationManager->GetStationVhtCapabilities (recipient);
179 Ptr<const HtCapabilities> htCapabilities = stationManager->GetStationHtCapabilities (recipient);
180
181 if (!htCapabilities)
182 {
183 /* "A non-DMG STA shall not transmit an A-MSDU to a STA from which it has
184 * not received a frame containing an HT Capabilities element" (Section
185 * 10.12 of 802.11-2016)
186 */
187 NS_LOG_DEBUG ("A-MSDU Aggregation disabled because the recipient did not"
188 " send an HT Capabilities element");
189 return 0;
190 }
191
192 // Determine the constraint imposed by the recipient based on the PPDU
193 // format used to transmit the A-MSDU
194 if (modulation >= WIFI_MOD_CLASS_VHT)
195 {
196 // the maximum A-MSDU size is indirectly constrained by the maximum MPDU
197 // size supported by the recipient and advertised in the VHT Capabilities
198 // element (see Table 9-19 of 802.11-2016 as amended by 802.11ax)
199 NS_ABORT_MSG_IF (!vhtCapabilities, "VHT Capabilities element not received");
200
201 maxAmsduSize = std::min (maxAmsduSize, static_cast<uint16_t>(vhtCapabilities->GetMaxMpduLength () - 56));
202 }
203 else if (modulation == WIFI_MOD_CLASS_HT)
204 {
205 // the maximum A-MSDU size is constrained by the maximum A-MSDU size
206 // supported by the recipient and advertised in the HT Capabilities
207 // element (see Table 9-19 of 802.11-2016)
208
209 maxAmsduSize = std::min (maxAmsduSize, htCapabilities->GetMaxAmsduLength ());
210 }
211 else // non-HT PPDU
212 {
213 // the maximum A-MSDU size is indirectly constrained by the maximum PSDU size
214 // supported by the recipient (see Table 9-19 of 802.11-2016)
215
216 maxAmsduSize = std::min (maxAmsduSize, static_cast<uint16_t>(3839));
217 }
218
219 return maxAmsduSize;
220}
221
224{
227
229 Ptr<Packet> extractedMsdu = Create<Packet> ();
230 uint32_t maxSize = aggregatedPacket->GetSize ();
231 uint16_t extractedLength;
232 uint8_t padding;
233 uint32_t deserialized = 0;
234
235 while (deserialized < maxSize)
236 {
237 deserialized += aggregatedPacket->RemoveHeader (hdr);
238 extractedLength = hdr.GetLength ();
239 extractedMsdu = aggregatedPacket->CreateFragment (0, static_cast<uint32_t> (extractedLength));
240 aggregatedPacket->RemoveAtStart (extractedLength);
241 deserialized += extractedLength;
242
243 padding = (4 - ((extractedLength + 14) % 4 )) % 4;
244
245 if (padding > 0 && deserialized < maxSize)
246 {
247 aggregatedPacket->RemoveAtStart (padding);
248 deserialized += padding;
249 }
250
251 std::pair<Ptr<const Packet>, AmsduSubframeHeader> packetHdr (extractedMsdu, hdr);
252 set.push_back (packetHdr);
253 }
254 NS_LOG_INFO ("Deaggreated A-MSDU: extracted " << set.size () << " MSDUs");
255 return set;
256}
257
258} //namespace ns3
#define min(a, b)
Definition: 80211b.c:42
Headers for A-MSDU subframes.
uint16_t GetLength(void) const
Get length function.
an EUI-48 address
Definition: mac48-address.h:44
bool IsBroadcast(void) const
Aggregator used to construct A-MSDUs.
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
static TypeId GetTypeId(void)
Get the type ID.
static WifiMacQueueItem::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...
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...
Ptr< WifiMacQueueItem > GetNextAmsdu(Ptr< const WifiMacQueueItem > peekedItem, WifiTxParameters &txParams, Time availableTime) const
Attempt to aggregate other MSDUs to the given A-MSDU while meeting the following constraints:
A base class which provides memory management and object aggregation.
Definition: object.h:88
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
Definition: packet.cc:362
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
Definition: packet.cc:227
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
std::list< std::pair< Ptr< const Packet >, AmsduSubframeHeader > > DeaggregatedMsdus
DeaggregatedMsdus typedef.
Ptr< const HtCapabilities > GetStationHtCapabilities(Mac48Address from)
Return the HT capabilities sent by the remote station.
Ptr< const VhtCapabilities > GetStationVhtCapabilities(Mac48Address from)
Return the VHT capabilities sent by the remote station.
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
WifiModulationClass GetModulationClass(void) 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:67
#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:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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:281
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition: qos-utils.cc:126
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:71
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
@ WIFI_MOD_CLASS_VHT
VHT (Clause 22)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mac
Definition: third.py:96