A Discrete-Event Network Simulator
API
constant-wifi-ack-policy-selector.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2019 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 
24 namespace ns3 {
25 
26 NS_LOG_COMPONENT_DEFINE ("ConstantWifiAckPolicySelector");
27 
28 NS_OBJECT_ENSURE_REGISTERED (ConstantWifiAckPolicySelector);
29 
30 TypeId
32 {
33  static TypeId tid = TypeId ("ns3::ConstantWifiAckPolicySelector")
35  .AddConstructor<ConstantWifiAckPolicySelector> ()
36  .SetGroupName("Wifi")
37  .AddAttribute ("UseExplicitBar",
38  "Specify whether to send Block Ack Requests (if true) or use"
39  " Implicit Block Ack Request ack policy (if false).",
40  BooleanValue (false),
43  .AddAttribute ("BaThreshold",
44  "Immediate acknowledgment is requested upon transmission of a frame "
45  "whose sequence number is distant at least BaThreshold multiplied "
46  "by the transmit window size from the starting sequence number of "
47  "the transmit window. Set to zero to request a response for every "
48  "transmitted frame.",
49  DoubleValue (0.0),
51  MakeDoubleChecker<double> (0.0, 1.0))
52  ;
53  return tid;
54 }
55 
57 {
59 }
60 
62 {
63  NS_LOG_FUNCTION (this);
64 }
65 
66 void
68 {
69  NS_LOG_FUNCTION (this << psdu << params);
70 
71  std::set<uint8_t> tids = psdu->GetTids ();
72 
73  if (tids.empty ())
74  {
75  NS_LOG_DEBUG ("No QoS Data frame in the PSDU");
76  return;
77  }
78 
79  if (tids.size () > 1)
80  {
81  NS_LOG_DEBUG ("Multi-TID A-MPDUs not supported");
82  return;
83  }
84 
85  Mac48Address receiver = psdu->GetAddr1 ();
86  uint8_t tid = *tids.begin ();
87 
88  // Use Normal Ack if a BA agreement has not been established
89  if (!m_qosTxop->GetBaAgreementEstablished (receiver, tid))
90  {
91  params.EnableAck ();
92  return;
93  }
94 
95  // If QosTxop forced the use of Block Ack QoS policy, do not make any change
96  if (params.MustSendBlockAckRequest ())
97  {
98  NS_LOG_DEBUG ("Use Block Ack policy as requested");
99  return;
100  }
101 
102  // find the maximum distance from the sequence number of an MPDU included in the
103  // PSDU to the starting sequence number of the transmit window.
104  uint16_t maxDistToStartingSeq = psdu->GetMaxDistFromStartingSeq (m_qosTxop->GetBaStartingSequence (receiver, tid));
105 
106  // An immediate response (Ack or Block Ack) is needed if any of the following holds:
107  // * the maximum distance between the sequence number of an MPDU to transmit
108  // and the starting sequence number of the transmit window is greater than
109  // or equal to the window size multiplied by the BaThreshold
110  // * no other frame belonging to this BA agreement is queued (because, in such
111  // a case, a Block Ack is not going to be requested any time soon)
112  // * this is the initial frame of a transmission opportunity and it is not
113  // protected by RTS/CTS (see Annex G.3 of IEEE 802.11-2016)
114  bool isResponseNeeded = (maxDistToStartingSeq >= m_baThreshold * m_qosTxop->GetBaBufferSize (receiver, tid)
115  || m_qosTxop->PeekNextFrame (tid, receiver) == 0
118  && !params.MustSendRts ()));
119 
120  if (!isResponseNeeded)
121  {
122  NS_LOG_DEBUG ("A response is not needed: no ack for now, use Block Ack policy");
123  params.DisableAck ();
124  return;
125  }
126  // An immediate response is needed
127  if (maxDistToStartingSeq == 0)
128  {
129  NS_LOG_DEBUG ("Sending a single MPDU, no previous frame to ack: use Normal Ack policy");
130  NS_ASSERT (psdu->GetNMpdus () == 1);
131  params.EnableAck ();
132  return;
133  }
134  // Multiple MPDUs are being/have been sent
135  if (psdu->GetNMpdus () == 1 || m_useExplicitBar)
136  {
137  // in case of single MPDU, there are previous unacknowledged frames, thus
138  // we cannot use Implicit Block Ack Request policy, otherwise we get a
139  // normal ack as response
140  if (m_qosTxop->GetBaBufferSize (receiver, tid) > 64)
141  {
142  NS_LOG_DEBUG ("Scheduling an Extended Compressed block ack request");
144  }
145  else
146  {
147  NS_LOG_DEBUG ("Scheduling a Compressed block ack request");
149  }
150  return;
151  }
152  // Implicit Block Ack Request policy
153  if (m_qosTxop->GetBaBufferSize (receiver, tid) > 64)
154  {
155  NS_LOG_DEBUG ("Implicitly requesting an Extended Compressed block ack");
157  }
158  else
159  {
160  NS_LOG_DEBUG ("Implicitly requesting a Compressed block ack");
162  }
163 }
164 
165 } //namespace ns3
Ptr< const WifiMacQueueItem > PeekNextFrame(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:253
Time GetTxopRemaining(void) const
Return the remaining duration in the current TXOP.
Definition: qos-txop.cc:1160
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
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
#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
Ptr< QosTxop > m_qosTxop
the QoS Txop this selector is associated with
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
static TypeId GetTypeId(void)
Get the type ID.
bool IsStrictlyPositive(void) const
Exactly equivalent to t > 0.
Definition: nstime.h:332
uint16_t GetBaStartingSequence(Mac48Address address, uint8_t tid) const
Definition: qos-txop.cc:140
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
control how a packet is transmitted.
bool m_useExplicitBar
true for sending BARs, false for using Implicit BAR ack policy
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void EnableAck(void)
Wait ACKTimeout for an Ack.
an EUI-48 address
Definition: mac48-address.h:43
double m_baThreshold
Threshold to determine when a BlockAck must be requested.
virtual void UpdateTxParams(Ptr< WifiPsdu > psdu, MacLowTransmissionParameters &params)
Update the transmission parameters related to the acknowledgment policy for the given PSDU...
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
bool GetBaAgreementEstablished(Mac48Address address, uint8_t tid) const
Definition: qos-txop.cc:128
#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
uint16_t GetBaBufferSize(Mac48Address address, uint8_t tid) const
Definition: qos-txop.cc:134
void EnableBlockAck(BlockAckType type)
Wait the timeout corresponding to the given BlockAck response type.
void EnableBlockAckRequest(BlockAckType type)
Schedule the transmission of a BlockAckRequest of the given type.
WifiAckPolicySelector is in charge of selecting the acknowledgment policy for PSDUs containing QoS Da...
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
void DisableAck(void)
Do not wait for Ack after data transmission.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
Time GetTxopLimit(void) const
Return the TXOP limit.
Definition: txop.cc:303