A Discrete-Event Network Simulator
API
mpdu-aggregator.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013
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: Ghada Badawy <gbadawy@gmail.com>
19  * Stefano Avallone <stavallo@unina.it>
20  */
21 
22 #include "ns3/log.h"
23 #include "ns3/packet.h"
24 #include "mpdu-aggregator.h"
25 #include "ampdu-subframe-header.h"
26 #include "wifi-phy.h"
27 #include "wifi-tx-vector.h"
29 #include "wifi-mac-queue-item.h"
30 #include "wifi-mac-queue.h"
31 #include "msdu-aggregator.h"
32 #include "wifi-net-device.h"
33 #include "ns3/ht-capabilities.h"
34 #include "ns3/vht-capabilities.h"
35 #include "ns3/he-capabilities.h"
36 #include "regular-wifi-mac.h"
37 #include "ctrl-headers.h"
38 #include "wifi-mac-trailer.h"
39 #include "wifi-tx-parameters.h"
40 
41 NS_LOG_COMPONENT_DEFINE ("MpduAggregator");
42 
43 namespace ns3 {
44 
45 NS_OBJECT_ENSURE_REGISTERED (MpduAggregator);
46 
47 TypeId
49 {
50  static TypeId tid = TypeId ("ns3::MpduAggregator")
51  .SetParent<Object> ()
52  .SetGroupName ("Wifi")
53  .AddConstructor<MpduAggregator> ()
54  ;
55  return tid;
56 }
57 
59 {
60 }
61 
63 {
64 }
65 
66 void
68 {
69  m_mac = 0;
71 }
72 
73 void
75 {
76  NS_LOG_FUNCTION (this << mac);
77  m_mac = mac;
78 }
79 
80 void
82 {
83  NS_LOG_FUNCTION (mpdu << ampdu << isSingle);
84  NS_ASSERT (ampdu);
85  // if isSingle is true, then ampdu must be empty
86  NS_ASSERT (!isSingle || ampdu->GetSize () == 0);
87 
88  // pad the previous A-MPDU subframe if the A-MPDU is not empty
89  if (ampdu->GetSize () > 0)
90  {
91  uint8_t padding = CalculatePadding (ampdu->GetSize ());
92 
93  if (padding)
94  {
95  Ptr<Packet> pad = Create<Packet> (padding);
96  ampdu->AddAtEnd (pad);
97  }
98  }
99 
100  // add MPDU header and trailer
101  Ptr<Packet> tmp = mpdu->GetPacket ()->Copy ();
102  tmp->AddHeader (mpdu->GetHeader ());
103  AddWifiMacTrailer (tmp);
104 
105  // add A-MPDU subframe header and MPDU to the A-MPDU
106  AmpduSubframeHeader hdr = GetAmpduSubframeHeader (static_cast<uint16_t> (tmp->GetSize ()), isSingle);
107 
108  tmp->AddHeader (hdr);
109  ampdu->AddAtEnd (tmp);
110 }
111 
112 uint32_t
113 MpduAggregator::GetSizeIfAggregated (uint32_t mpduSize, uint32_t ampduSize)
114 {
115  NS_LOG_FUNCTION (mpduSize << ampduSize);
116 
117  return ampduSize + CalculatePadding (ampduSize) + 4 + mpduSize;
118 }
119 
120 uint32_t
122  WifiModulationClass modulation) const
123 {
124  NS_LOG_FUNCTION (this << recipient << +tid << modulation);
125 
126  AcIndex ac = QosUtilsMapTidToAc (tid);
127 
128  // Find the A-MPDU max size configured on this device
129  uint32_t maxAmpduSize = m_mac->GetMaxAmpduSize (ac);
130 
131  if (maxAmpduSize == 0)
132  {
133  NS_LOG_DEBUG ("A-MPDU Aggregation is disabled on this station for AC " << ac);
134  return 0;
135  }
136 
137  Ptr<WifiRemoteStationManager> stationManager = m_mac->GetWifiRemoteStationManager ();
138  NS_ASSERT (stationManager);
139 
140  // Retrieve the Capabilities elements advertised by the recipient
141  Ptr<const HeCapabilities> heCapabilities = stationManager->GetStationHeCapabilities (recipient);
142  Ptr<const VhtCapabilities> vhtCapabilities = stationManager->GetStationVhtCapabilities (recipient);
143  Ptr<const HtCapabilities> htCapabilities = stationManager->GetStationHtCapabilities (recipient);
144 
145  // Determine the constraint imposed by the recipient based on the PPDU
146  // format used to transmit the A-MPDU
147  if (modulation == WIFI_MOD_CLASS_HE)
148  {
149  NS_ABORT_MSG_IF (!heCapabilities, "HE Capabilities element not received");
150 
151  maxAmpduSize = std::min (maxAmpduSize, heCapabilities->GetMaxAmpduLength ());
152  }
153  else if (modulation == WIFI_MOD_CLASS_VHT)
154  {
155  NS_ABORT_MSG_IF (!vhtCapabilities, "VHT Capabilities element not received");
156 
157  maxAmpduSize = std::min (maxAmpduSize, vhtCapabilities->GetMaxAmpduLength ());
158  }
159  else if (modulation == WIFI_MOD_CLASS_HT)
160  {
161  NS_ABORT_MSG_IF (!htCapabilities, "HT Capabilities element not received");
162 
163  maxAmpduSize = std::min (maxAmpduSize, htCapabilities->GetMaxAmpduLength ());
164  }
165  else // non-HT PPDU
166  {
167  NS_LOG_DEBUG ("A-MPDU aggregation is not available for non-HT PHYs");
168 
169  maxAmpduSize = 0;
170  }
171 
172  return maxAmpduSize;
173 }
174 
175 uint8_t
177 {
178  return (4 - (ampduSize % 4 )) % 4;
179 }
180 
182 MpduAggregator::GetAmpduSubframeHeader (uint16_t mpduSize, bool isSingle)
183 {
185  hdr.SetLength (mpduSize);
186  if (isSingle)
187  {
188  hdr.SetEof (1);
189  }
190  return hdr;
191 }
192 
193 std::vector<Ptr<WifiMacQueueItem>>
195  Time availableTime, WifiMacQueueItem::QueueIteratorPair queueIt) const
196 {
197  NS_LOG_FUNCTION (this << *mpdu << &txParams << availableTime);
198 
199  std::vector<Ptr<WifiMacQueueItem>> mpduList;
200 
201  Mac48Address recipient = mpdu->GetHeader ().GetAddr1 ();
202  NS_ASSERT (mpdu->GetHeader ().IsQosData () && !recipient.IsBroadcast ());
203  uint8_t tid = mpdu->GetHeader ().GetQosTid ();
204 
205  Ptr<QosTxop> qosTxop = m_mac->GetQosTxop (tid);
206  NS_ASSERT (qosTxop != 0);
207 
208  //Have to make sure that the block ack agreement is established and A-MPDU is enabled
209  if (qosTxop->GetBaAgreementEstablished (recipient, tid)
210  && GetMaxAmpduSize (recipient, tid, txParams.m_txVector.GetModulationClass ()) > 0)
211  {
212  /* here is performed MPDU aggregation */
213  Ptr<WifiMacQueueItem> nextMpdu = mpdu;
214 
215  while (nextMpdu != 0)
216  {
217  // if we are here, nextMpdu can be aggregated to the A-MPDU.
218  NS_LOG_DEBUG ("Adding packet with sequence number " << nextMpdu->GetHeader ().GetSequenceNumber ()
219  << " to A-MPDU, packet size = " << nextMpdu->GetSize ()
220  << ", A-MPDU size = " << txParams.GetSize (recipient));
221 
222  mpduList.push_back (nextMpdu);
223 
224  // If allowed by the BA agreement, get the next MPDU
225  nextMpdu = 0;
226 
227  Ptr<const WifiMacQueueItem> peekedMpdu;
228  peekedMpdu = qosTxop->PeekNextMpdu (queueIt, tid, recipient);
229  if (peekedMpdu != 0)
230  {
231  // PeekNextMpdu() does not return an MPDU that is beyond the transmit window
232  NS_ASSERT (IsInWindow (peekedMpdu->GetHeader ().GetSequenceNumber (),
233  qosTxop->GetBaStartingSequence (recipient, tid),
234  qosTxop->GetBaBufferSize (recipient, tid)));
235 
236  // get the next MPDU to aggregate, provided that the constraints on size
237  // and duration limit are met. Note that the returned MPDU differs from
238  // the peeked MPDU if A-MSDU aggregation is enabled.
239  NS_LOG_DEBUG ("Trying to aggregate another MPDU");
240  nextMpdu = qosTxop->GetNextMpdu (peekedMpdu, txParams, availableTime, false, queueIt);
241  }
242  }
243 
244  if (mpduList.size () == 1)
245  {
246  // return an empty vector if it was not possible to aggregate at least two MPDUs
247  mpduList.clear ();
248  }
249  }
250 
251  return mpduList;
252 }
253 
254 } //namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::MpduAggregator::SetWifiMac
void SetWifiMac(const Ptr< RegularWifiMac > mac)
Set the MAC layer to use.
Definition: mpdu-aggregator.cc:74
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT
#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
min
#define min(a, b)
Definition: 80211b.c:42
regular-wifi-mac.h
ns3::Packet::GetSize
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
ns3::Packet::AddHeader
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
wifi-tx-parameters.h
ns3::QosTxop::GetBaBufferSize
uint16_t GetBaBufferSize(Mac48Address address, uint8_t tid) const
Definition: qos-txop.cc:161
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::AmpduSubframeHeader::SetLength
void SetLength(uint16_t length)
Set the length field.
Definition: ampdu-subframe-header.cc:90
ns3::WIFI_MOD_CLASS_HT
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
Definition: wifi-phy-common.h:125
ns3::WIFI_MOD_CLASS_HE
@ WIFI_MOD_CLASS_HE
HE (Clause 27)
Definition: wifi-phy-common.h:127
ns3::QosTxop::GetBaAgreementEstablished
bool GetBaAgreementEstablished(Mac48Address address, uint8_t tid) const
Definition: qos-txop.cc:155
wifi-remote-station-manager.h
ns3::WifiTxParameters::GetSize
uint32_t GetSize(Mac48Address receiver) const
Get the size in bytes of the (A-)MPDU addressed to the given receiver.
Definition: wifi-tx-parameters.cc:227
ns3::QosTxop::GetNextMpdu
Ptr< WifiMacQueueItem > GetNextMpdu(Ptr< const WifiMacQueueItem > peekedItem, WifiTxParameters &txParams, Time availableTime, bool initialFrame, WifiMacQueueItem::QueueIteratorPair &queueIt)
Prepare the frame to transmit starting from the MPDU that has been previously peeked by calling PeekN...
Definition: qos-txop.cc:345
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
ns3::QosTxop::PeekNextMpdu
Ptr< const WifiMacQueueItem > PeekNextMpdu(uint8_t tid=8, Mac48Address recipient=Mac48Address::GetBroadcast())
Peek the next frame to transmit to the given receiver and of the given TID from the block ack manager...
Definition: qos-txop.cc:263
wifi-phy.h
wifi-mac-queue-item.h
ns3::WifiMacHeader::GetAddr1
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
Definition: wifi-mac-header.cc:424
third.mac
mac
Definition: third.py:99
ns3::WifiTxParameters
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
Definition: wifi-tx-parameters.h:45
mpdu-aggregator.h
ns3::WifiMacQueueItem::GetHeader
const WifiMacHeader & GetHeader(void) const
Get the header stored in this item.
Definition: wifi-mac-queue-item.cc:63
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::MpduAggregator::GetMaxAmpduSize
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...
Definition: mpdu-aggregator.cc:121
ns3::QosTxop::GetBaStartingSequence
uint16_t GetBaStartingSequence(Mac48Address address, uint8_t tid) const
Definition: qos-txop.cc:167
ns3::MpduAggregator::GetAmpduSubframeHeader
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.
Definition: mpdu-aggregator.cc:182
wifi-mac-queue.h
ns3::MpduAggregator::m_mac
Ptr< RegularWifiMac > m_mac
the MAC of this station
Definition: mpdu-aggregator.h:161
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::WifiRemoteStationManager::GetStationHeCapabilities
Ptr< const HeCapabilities > GetStationHeCapabilities(Mac48Address from)
Return the HE capabilities sent by the remote station.
Definition: wifi-remote-station-manager.cc:1430
ns3::WifiRemoteStationManager::GetStationHtCapabilities
Ptr< const HtCapabilities > GetStationHtCapabilities(Mac48Address from)
Return the HT capabilities sent by the remote station.
Definition: wifi-remote-station-manager.cc:1418
ctrl-headers.h
ns3::WifiTxVector::GetModulationClass
WifiModulationClass GetModulationClass(void) const
Get the modulation class specified by this TXVECTOR.
Definition: wifi-tx-vector.cc:127
ns3::Object
A base class which provides memory management and object aggregation.
Definition: object.h:88
wifi-net-device.h
ns3::QosUtilsMapTidToAc
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition: qos-utils.cc:126
ns3::Mac48Address::IsBroadcast
bool IsBroadcast(void) const
Definition: mac48-address.cc:158
wifi-tx-vector.h
ns3::MpduAggregator::GetNextAmpdu
std::vector< Ptr< WifiMacQueueItem > > GetNextAmpdu(Ptr< WifiMacQueueItem > mpdu, WifiTxParameters &txParams, Time availableTime, WifiMacQueueItem::QueueIteratorPair queueIt) const
Attempt to aggregate other MPDUs to the given MPDU, while meeting the following constraints:
Definition: mpdu-aggregator.cc:194
ns3::MpduAggregator::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: mpdu-aggregator.cc:48
ns3::WifiMacHeader::IsQosData
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data.
Definition: wifi-mac-header.cc:565
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::WifiMacHeader::GetSequenceNumber
uint16_t GetSequenceNumber(void) const
Return the sequence number of the header.
Definition: wifi-mac-header.cc:777
NS_ABORT_MSG_IF
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
ns3::AmpduSubframeHeader
Headers for A-MPDU subframes.
Definition: ampdu-subframe-header.h:33
ns3::WifiRemoteStationManager::GetStationVhtCapabilities
Ptr< const VhtCapabilities > GetStationVhtCapabilities(Mac48Address from)
Return the VHT capabilities sent by the remote station.
Definition: wifi-remote-station-manager.cc:1424
msdu-aggregator.h
ns3::WifiMacQueueItem::QueueIteratorPair
Information needed to remove an MSDU from the queue.
Definition: wifi-mac-queue-item.h:147
ns3::WifiMacHeader::GetQosTid
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
Definition: wifi-mac-header.cc:862
ns3::IsInWindow
bool IsInWindow(uint16_t seq, uint16_t winstart, uint16_t winsize)
Definition: wifi-utils.cc:225
ns3::MpduAggregator::Aggregate
static void Aggregate(Ptr< const WifiMacQueueItem > mpdu, Ptr< Packet > ampdu, bool isSingle)
Aggregate an MPDU to an A-MPDU.
Definition: mpdu-aggregator.cc:81
ns3::AmpduSubframeHeader::SetEof
void SetEof(bool eof)
Set the EOF field.
Definition: ampdu-subframe-header.cc:96
ns3::Packet::AddAtEnd
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition: packet.cc:335
ns3::MpduAggregator::MpduAggregator
MpduAggregator()
Definition: mpdu-aggregator.cc:58
ns3::AddWifiMacTrailer
void AddWifiMacTrailer(Ptr< Packet > packet)
Add FCS trailer to a packet.
Definition: wifi-utils.cc:231
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::WifiTxParameters::m_txVector
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
Definition: wifi-tx-parameters.h:62
ns3::MpduAggregator::DoDispose
void DoDispose() override
Destructor implementation.
Definition: mpdu-aggregator.cc:67
ns3::MpduAggregator::CalculatePadding
static uint8_t CalculatePadding(uint32_t ampduSize)
Definition: mpdu-aggregator.cc:176
ns3::MpduAggregator::~MpduAggregator
virtual ~MpduAggregator()
Definition: mpdu-aggregator.cc:62
ns3::AcIndex
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:71
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ampdu-subframe-header.h
ns3::WIFI_MOD_CLASS_VHT
@ WIFI_MOD_CLASS_VHT
VHT (Clause 22)
Definition: wifi-phy-common.h:126
ns3::WifiMacQueueItem::GetSize
uint32_t GetSize(void) const
Return the size of the packet stored by this item, including header size and trailer size.
Definition: wifi-mac-queue-item.cc:93
ns3::MpduAggregator
Aggregator used to construct A-MPDUs.
Definition: mpdu-aggregator.h:44
wifi-mac-trailer.h
ns3::Object::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
ns3::MpduAggregator::GetSizeIfAggregated
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...
Definition: mpdu-aggregator.cc:113
ns3::WifiModulationClass
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
Definition: wifi-phy-common.h:117