A Discrete-Event Network Simulator
API
wifi-default-ack-manager.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stavallo@unina.it>
19  */
20 
21 #include "ns3/log.h"
23 #include "wifi-tx-parameters.h"
24 #include "wifi-mac-queue-item.h"
25 #include "qos-utils.h"
26 #include "wifi-mac-queue.h"
27 #include "wifi-protection.h"
28 #include "regular-wifi-mac.h"
29 #include "ctrl-headers.h"
30 #include "wifi-phy.h"
31 
32 
33 namespace ns3 {
34 
35 NS_LOG_COMPONENT_DEFINE ("WifiDefaultAckManager");
36 
37 NS_OBJECT_ENSURE_REGISTERED (WifiDefaultAckManager);
38 
39 TypeId
41 {
42  static TypeId tid = TypeId ("ns3::WifiDefaultAckManager")
44  .SetGroupName ("Wifi")
45  .AddConstructor<WifiDefaultAckManager> ()
46  .AddAttribute ("UseExplicitBar",
47  "Specify whether to send Block Ack Requests (if true) or use"
48  " Implicit Block Ack Request ack policy (if false).",
49  BooleanValue (false),
52  .AddAttribute ("BaThreshold",
53  "Immediate acknowledgment is requested upon transmission of a frame "
54  "whose sequence number is distant at least BaThreshold multiplied "
55  "by the transmit window size from the starting sequence number of "
56  "the transmit window. Set to zero to request a response for every "
57  "transmitted frame.",
58  DoubleValue (0.0),
60  MakeDoubleChecker<double> (0.0, 1.0))
61  ;
62  return tid;
63 }
64 
66 {
67  NS_LOG_FUNCTION (this);
68 }
69 
71 {
73 }
74 
75 uint16_t
77  const WifiTxParameters& txParams) const
78 {
79  NS_LOG_FUNCTION (this << *mpdu << &txParams);
80 
81  const WifiMacHeader& hdr = mpdu->GetHeader ();
82  Mac48Address receiver = hdr.GetAddr1 ();
83 
84  uint8_t tid = hdr.GetQosTid ();
85  Ptr<QosTxop> edca = m_mac->GetQosTxop (tid);
86  NS_ABORT_MSG_IF (!edca->GetBaAgreementEstablished (receiver, tid),
87  "An established Block Ack agreement is required");
88 
89  uint16_t startingSeq = edca->GetBaStartingSequence (receiver, tid);
90  uint16_t maxDistFromStartingSeq = (mpdu->GetHeader ().GetSequenceNumber () - startingSeq + SEQNO_SPACE_SIZE) % SEQNO_SPACE_SIZE;
91  NS_ABORT_MSG_IF (maxDistFromStartingSeq >= SEQNO_SPACE_HALF_SIZE,
92  "The given QoS data frame is too old");
93 
94  const WifiTxParameters::PsduInfo* psduInfo = txParams.GetPsduInfo (receiver);
95 
96  if (psduInfo == nullptr || psduInfo->seqNumbers.find (tid) == psduInfo->seqNumbers.end ())
97  {
98  // there are no aggregated MPDUs (so far)
99  return maxDistFromStartingSeq;
100  }
101 
102  for (const auto& seqNumber : psduInfo->seqNumbers.at (tid))
103  {
104  if (!QosUtilsIsOldPacket (startingSeq, seqNumber))
105  {
106  uint16_t currDistToStartingSeq = (seqNumber - startingSeq + SEQNO_SPACE_SIZE) % SEQNO_SPACE_SIZE;
107 
108  if (currDistToStartingSeq > maxDistFromStartingSeq)
109  {
110  maxDistFromStartingSeq = currDistToStartingSeq;
111  }
112  }
113  }
114 
115  NS_LOG_DEBUG ("Returning " << maxDistFromStartingSeq);
116  return maxDistFromStartingSeq;
117 }
118 
119 bool
121  const WifiTxParameters& txParams) const
122 {
123  NS_LOG_FUNCTION (this << *mpdu << &txParams);
124 
125  uint8_t tid = mpdu->GetHeader ().GetQosTid ();
126  Mac48Address receiver = mpdu->GetHeader ().GetAddr1 ();
127  Ptr<QosTxop> edca = m_mac->GetQosTxop (tid);
128 
129  // An immediate response (Ack or Block Ack) is needed if any of the following holds:
130  // * the maximum distance between the sequence number of an MPDU to transmit
131  // and the starting sequence number of the transmit window is greater than
132  // or equal to the window size multiplied by the BaThreshold
133  // * no other frame belonging to this BA agreement is queued (because, in such
134  // a case, a Block Ack is not going to be requested anytime soon)
135  // * this is the initial frame of a transmission opportunity and it is not
136  // protected by RTS/CTS (see Annex G.3 of IEEE 802.11-2016)
137  if (m_baThreshold > 0
138  && GetMaxDistFromStartingSeq (mpdu, txParams) < m_baThreshold * edca->GetBaBufferSize (receiver, tid)
139  && (edca->GetWifiMacQueue ()->GetNPackets (tid, receiver)
140  + edca->GetBaManager ()->GetRetransmitQueue ()->GetNPackets (tid, receiver) > 1)
141  && !(edca->GetTxopLimit ().IsStrictlyPositive ()
142  && edca->GetRemainingTxop () == edca->GetTxopLimit ()
143  && !(txParams.m_protection && txParams.m_protection->method == WifiProtection::RTS_CTS)))
144  {
145  return false;
146  }
147 
148  return true;
149 }
150 
151 std::unique_ptr<WifiAcknowledgment>
153  const WifiTxParameters& txParams)
154 {
155  NS_LOG_FUNCTION (this << *mpdu << &txParams);
156 
157  const WifiMacHeader& hdr = mpdu->GetHeader ();
158  Mac48Address receiver = hdr.GetAddr1 ();
159 
160  // if the current protection method (if any) is already BLOCK_ACK or BAR_BLOCK_ACK,
161  // it will not change by adding an MPDU
162  if (txParams.m_acknowledgment
163  && (txParams.m_acknowledgment->method == WifiAcknowledgment::BLOCK_ACK
164  || txParams.m_acknowledgment->method == WifiAcknowledgment::BAR_BLOCK_ACK))
165  {
166  return nullptr;
167  }
168 
169  if (receiver.IsGroup ())
170  {
171  NS_ABORT_MSG_IF (txParams.GetSize (receiver) > 0,
172  "Unicast frames only can be aggregated");
173  WifiNoAck* acknowledgment = new WifiNoAck;
174  if (hdr.IsQosData ())
175  {
176  acknowledgment->SetQosAckPolicy (receiver, hdr.GetQosTid (),
178  }
179  return std::unique_ptr<WifiAcknowledgment> (acknowledgment);
180  }
181 
182  if ((!hdr.IsQosData ()
183  || !m_mac->GetQosTxop (hdr.GetQosTid ())->GetBaAgreementEstablished (receiver, hdr.GetQosTid ()))
184  && !hdr.IsBlockAckReq ())
185  {
186  NS_LOG_DEBUG ("Non-QoS data frame or Block Ack agreement not established, request Normal Ack");
187  WifiNormalAck* acknowledgment = new WifiNormalAck;
188  acknowledgment->ackTxVector = m_mac->GetWifiRemoteStationManager ()->GetAckTxVector (receiver, txParams.m_txVector);
189  if (hdr.IsQosData ())
190  {
191  acknowledgment->SetQosAckPolicy (receiver, hdr.GetQosTid (), WifiMacHeader::NORMAL_ACK);
192  }
193  return std::unique_ptr<WifiAcknowledgment> (acknowledgment);
194  }
195 
196  // we get here if mpdu is a QoS data frame related to an established Block Ack agreement
197  // or mpdu is a BlockAckReq frame
198  if (!hdr.IsBlockAckReq () && !IsResponseNeeded (mpdu, txParams))
199  {
200  NS_LOG_DEBUG ("A response is not needed: no ack for now, use Block Ack policy");
201  if (txParams.m_acknowledgment
202  && txParams.m_acknowledgment->method == WifiAcknowledgment::NONE)
203  {
204  // no change if the ack method is already NONE
205  return nullptr;
206  }
207 
208  WifiNoAck* acknowledgment = new WifiNoAck;
209  if (hdr.IsQosData ())
210  {
211  acknowledgment->SetQosAckPolicy (receiver, hdr.GetQosTid (),
213  }
214  return std::unique_ptr<WifiAcknowledgment> (acknowledgment);
215  }
216 
217  // we get here if a response is needed
218  uint8_t tid = GetTid (mpdu->GetPacket (), hdr);
219  if (!hdr.IsBlockAckReq ()
220  && txParams.GetSize (receiver) == 0
221  && hdr.GetSequenceNumber ()
222  == m_mac->GetQosTxop (tid)->GetBaStartingSequence (receiver, tid))
223  {
224  NS_LOG_DEBUG ("Sending a single MPDU, no previous frame to ack: request Normal Ack");
225  WifiNormalAck* acknowledgment = new WifiNormalAck;
226  acknowledgment->ackTxVector = m_mac->GetWifiRemoteStationManager ()->GetAckTxVector (receiver, txParams.m_txVector);
227  acknowledgment->SetQosAckPolicy (receiver, tid, WifiMacHeader::NORMAL_ACK);
228  return std::unique_ptr<WifiAcknowledgment> (acknowledgment);
229  }
230 
231  // we get here if multiple MPDUs are being/have been sent
232  if (!hdr.IsBlockAckReq ()
233  && (txParams.GetSize (receiver) == 0 || m_useExplicitBar))
234  {
235  // in case of single MPDU, there are previous unacknowledged frames, thus
236  // we cannot use Implicit Block Ack Request policy, otherwise we get a
237  // normal ack as response
238  NS_LOG_DEBUG ("Request to schedule a Block Ack Request");
239 
240  WifiBarBlockAck* acknowledgment = new WifiBarBlockAck;
241  acknowledgment->blockAckReqTxVector = m_mac->GetWifiRemoteStationManager ()->GetBlockAckTxVector (receiver, txParams.m_txVector);
242  acknowledgment->blockAckTxVector = acknowledgment->blockAckReqTxVector;
243  acknowledgment->barType = m_mac->GetQosTxop (tid)->GetBlockAckReqType (receiver, tid);
244  acknowledgment->baType = m_mac->GetQosTxop (tid)->GetBlockAckType (receiver, tid);
245  acknowledgment->SetQosAckPolicy (receiver, tid, WifiMacHeader::BLOCK_ACK);
246  return std::unique_ptr<WifiAcknowledgment> (acknowledgment);
247  }
248 
249  NS_LOG_DEBUG ("A-MPDU using Implicit Block Ack Request policy or BlockAckReq, request Block Ack");
250  WifiBlockAck* acknowledgment = new WifiBlockAck;
251  acknowledgment->blockAckTxVector = m_mac->GetWifiRemoteStationManager ()->GetBlockAckTxVector (receiver, txParams.m_txVector);
252  acknowledgment->baType = m_mac->GetQosTxop (tid)->GetBlockAckType (receiver, tid);
253  acknowledgment->SetQosAckPolicy (receiver, tid, WifiMacHeader::NORMAL_ACK);
254  return std::unique_ptr<WifiAcknowledgment> (acknowledgment);
255 }
256 
257 std::unique_ptr<WifiAcknowledgment>
259  const WifiTxParameters& txParams)
260 {
261  NS_LOG_FUNCTION (this << *msdu << &txParams);
262 
263  // Aggregating an MSDU does not change the acknowledgment method
264  return nullptr;
265 }
266 
267 } //namespace ns3
bool m_useExplicitBar
true for sending BARs, false for using Implicit BAR policy
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
AttributeValue implementation for Boolean.
Definition: boolean.h:36
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
std::unique_ptr< WifiProtection > m_protection
protection method
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: boolean.h:85
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
const uint16_t SEQNO_SPACE_HALF_SIZE
Size of the half the space of sequence numbers (used to determine old packets)
Definition: wifi-utils.h:225
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
WifiTxVector ackTxVector
Ack TXVECTOR.
Ptr< BlockAckManager > GetBaManager(void)
Get the Block Ack Manager associated with this QosTxop.
Definition: qos-txop.cc:155
bool QosUtilsIsOldPacket(uint16_t startingSeq, uint16_t seqNumber)
This function checks if packet with sequence number seqNumber is an "old" packet. ...
Definition: qos-utils.cc:105
bool IsStrictlyPositive(void) const
Exactly equivalent to t > 0.
Definition: nstime.h:333
uint16_t GetBaStartingSequence(Mac48Address address, uint8_t tid) const
Definition: qos-txop.cc:173
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
virtual Time GetRemainingTxop(void) const
Return the remaining duration in the current TXOP.
Definition: qos-txop.cc:598
WifiTxVector blockAckReqTxVector
BlockAckReq TXVECTOR.
BlockAckType baType
BlockAck type.
bool IsBlockAckReq(void) const
Return true if the header is a BlockAckRequest header.
const PsduInfo * GetPsduInfo(Mac48Address receiver) const
Get a pointer to the information about the PSDU addressed to the given receiver, if present...
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
static TypeId GetTypeId(void)
Get the type ID.
WifiTxVector blockAckTxVector
BlockAck TXVECTOR.
WifiNoAck specifies that no acknowledgment is required.
WifiAckManager is an abstract base class.
virtual std::unique_ptr< WifiAcknowledgment > TryAddMpdu(Ptr< const WifiMacQueueItem > mpdu, const WifiTxParameters &txParams)
Determine the acknowledgment method to use if the given MPDU is added to the current frame...
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint16_t GetSequenceNumber(void) const
Return the sequence number of the header.
WifiTxVector blockAckTxVector
BlockAck TXVECTOR.
double m_baThreshold
Threshold to determine when a BlockAck must be requested.
WifiDefaultAckManager is the default ack manager.
virtual std::unique_ptr< WifiAcknowledgment > TryAggregateMsdu(Ptr< const WifiMacQueueItem > msdu, const WifiTxParameters &txParams)
Determine the acknowledgment method to use if the given MSDU is aggregated to the current frame...
WifiBarBlockAck specifies that a BlockAckReq is sent to solicit a Block Ack response.
std::map< uint8_t, std::set< uint16_t > > seqNumbers
set of the sequence numbers of the MPDUs added for each TID
an EUI-48 address
Definition: mac48-address.h:43
uint8_t GetTid(Ptr< const Packet > packet, const WifiMacHeader hdr)
Extraction operator for TypeId.
Definition: qos-utils.cc:120
WifiBlockAck specifies that acknowledgment via Block Ack is required.
information about the frame being prepared for a specific receiver
bool IsGroup(void) const
uint32_t GetSize(Mac48Address receiver) const
Get the size in bytes of the (A-)MPDU addressed to the given receiver.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: double.h:42
uint16_t GetMaxDistFromStartingSeq(Ptr< const WifiMacQueueItem > mpdu, const WifiTxParameters &txParams) const
Get the maximum distance between the starting sequence number of the Block Ack agreement which the gi...
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
Ptr< RegularWifiMac > m_mac
MAC which is using this Acknowledgment Manager.
BlockAckType baType
BlockAck type.
void SetQosAckPolicy(Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy)
Set the QoS Ack policy to use for the MPDUs addressed to the given receiver and belonging to the give...
bool GetBaAgreementEstablished(Mac48Address address, uint8_t tid) const
Definition: qos-txop.cc:161
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
Ptr< WifiMacQueue > GetWifiMacQueue() const
Return the packet queue associated with this Txop.
Definition: txop.cc:150
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism...
uint16_t GetBaBufferSize(Mac48Address address, uint8_t tid) const
Definition: qos-txop.cc:167
const uint16_t SEQNO_SPACE_SIZE
Size of the space of sequence numbers.
Definition: wifi-utils.h:222
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data...
std::unique_ptr< WifiAcknowledgment > m_acknowledgment
acknowledgment method
BlockAckReqType barType
BlockAckReq type.
WifiNormalAck specifies that acknowledgment via Normal Ack is required.
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
bool IsResponseNeeded(Ptr< const WifiMacQueueItem > mpdu, const WifiTxParameters &txParams) const
Determine whether the (A-)MPDU containing the given MPDU and the MPDUs (if any) included in the given...
Implements the IEEE 802.11 MAC header.
Time GetTxopLimit(void) const
Return the TXOP limit.
Definition: txop.cc:274