A Discrete-Event Network Simulator
API
wifi-acknowledgment.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 "wifi-acknowledgment.h"
22 #include "wifi-utils.h"
23 #include "ns3/mac48-address.h"
24 
25 namespace ns3 {
26 
27 /*
28  * WifiAcknowledgment
29  */
30 
32  : method (m),
33  acknowledgmentTime (Time::Min ()) // uninitialized
34 {
35 }
36 
38 {
39 }
40 
43 {
44  auto it = m_ackPolicy.find ({receiver, tid});
45  NS_ASSERT (it != m_ackPolicy.end ());
46  return it->second;
47 }
48 
49 void
52 {
53  NS_ABORT_MSG_IF (!CheckQosAckPolicy (receiver, tid, ackPolicy), "QoS Ack policy not admitted");
54  m_ackPolicy[{receiver, tid}] = ackPolicy;
55 }
56 
57 /*
58  * WifiNoAck
59  */
60 
62  : WifiAcknowledgment (NONE)
63 {
65 }
66 
67 std::unique_ptr<WifiAcknowledgment>
68 WifiNoAck::Copy (void) const
69 {
70  return std::unique_ptr<WifiAcknowledgment> (new WifiNoAck (*this));
71 }
72 
73 bool
75 {
76  if (ackPolicy == WifiMacHeader::NO_ACK || ackPolicy == WifiMacHeader::BLOCK_ACK)
77  {
78  return true;
79  }
80  return false;
81 }
82 
83 void
84 WifiNoAck::Print (std::ostream &os) const
85 {
86  os << "NONE";
87 }
88 
89 
90 /*
91  * WifiNormalAck
92  */
93 
95  : WifiAcknowledgment (NORMAL_ACK)
96 {
97 }
98 
99 std::unique_ptr<WifiAcknowledgment>
101 {
102  return std::unique_ptr<WifiAcknowledgment> (new WifiNormalAck (*this));
103 }
104 
105 bool
107 {
108  if (ackPolicy == WifiMacHeader::NORMAL_ACK)
109  {
110  return true;
111  }
112  return false;
113 }
114 
115 void
116 WifiNormalAck::Print (std::ostream &os) const
117 {
118  os << "NORMAL_ACK";
119 }
120 
121 /*
122  * WifiBlockAck
123  */
124 
126  : WifiAcknowledgment (BLOCK_ACK)
127 {
128 }
129 
130 std::unique_ptr<WifiAcknowledgment>
131 WifiBlockAck::Copy (void) const
132 {
133  return std::unique_ptr<WifiAcknowledgment> (new WifiBlockAck (*this));
134 }
135 
136 bool
138 {
139  if (ackPolicy == WifiMacHeader::NORMAL_ACK)
140  {
141  return true;
142  }
143  return false;
144 }
145 
146 void
147 WifiBlockAck::Print (std::ostream &os) const
148 {
149  os << "BLOCK_ACK";
150 }
151 
152 
153 /*
154  * WifiBarBlockAck
155  */
156 
158  : WifiAcknowledgment (BAR_BLOCK_ACK)
159 {
160 }
161 
162 std::unique_ptr<WifiAcknowledgment>
164 {
165  return std::unique_ptr<WifiAcknowledgment> (new WifiBarBlockAck (*this));
166 }
167 
168 bool
170 {
171  if (ackPolicy == WifiMacHeader::BLOCK_ACK)
172  {
173  return true;
174  }
175  return false;
176 }
177 
178 void
179 WifiBarBlockAck::Print (std::ostream &os) const
180 {
181  os << "BAR_BLOCK_ACK";
182 }
183 
184 
185 /*
186  * WifiDlMuBarBaSequence
187  */
188 
190  : WifiAcknowledgment (DL_MU_BAR_BA_SEQUENCE)
191 {
192 }
193 
194 std::unique_ptr<WifiAcknowledgment>
196 {
197  return std::unique_ptr<WifiAcknowledgment> (new WifiDlMuBarBaSequence (*this));
198 }
199 
200 bool
202  WifiMacHeader::QosAckPolicy ackPolicy) const
203 {
204  if (ackPolicy == WifiMacHeader::NORMAL_ACK)
205  {
206  // The given receiver must be the only one to send an immediate reply
207  if (stationsReplyingWithNormalAck.size () == 1
208  && stationsReplyingWithNormalAck.begin ()->first == receiver)
209  {
210  return true;
211  }
212 
213  if (stationsReplyingWithBlockAck.size () == 1
214  && stationsReplyingWithBlockAck.begin ()->first == receiver)
215  {
216  return true;
217  }
218 
219  return false;
220  }
221 
222  if (ackPolicy == WifiMacHeader::BLOCK_ACK)
223  {
224  return true;
225  }
226 
227  return false;
228 }
229 
230 void
231 WifiDlMuBarBaSequence::Print (std::ostream &os) const
232 {
233  os << "DL_MU_BAR_BA_SEQUENCE [";
234  for (const auto& sta : stationsReplyingWithNormalAck)
235  {
236  os << " (ACK) " << sta.first;
237  }
238  for (const auto& sta : stationsReplyingWithBlockAck)
239  {
240  os << " (BA) " << sta.first;
241  }
242  for (const auto& sta : stationsSendBlockAckReqTo)
243  {
244  os << " (BAR+BA) " << sta.first;
245  }
246  os << "]";
247 }
248 
249 
250 /*
251  * WifiDlMuTfMuBar
252  */
253 
255  : WifiAcknowledgment (DL_MU_TF_MU_BAR),
256  ulLength (0)
257 {
258 }
259 
260 std::unique_ptr<WifiAcknowledgment>
262 {
263  return std::unique_ptr<WifiAcknowledgment> (new WifiDlMuTfMuBar (*this));
264 }
265 
266 bool
268  WifiMacHeader::QosAckPolicy ackPolicy) const
269 {
270  // the only admitted ack policy is Block Ack because stations need to wait for a MU-BAR
271  if (ackPolicy == WifiMacHeader::BLOCK_ACK)
272  {
273  return true;
274  }
275 
276  return false;
277 }
278 
279 void
280 WifiDlMuTfMuBar::Print (std::ostream &os) const
281 {
282  os << "DL_MU_TF_MU_BAR [";
283  for (const auto& sta : stationsReplyingWithBlockAck)
284  {
285  os << " (BA) " << sta.first;
286  }
287  os << "]";
288 }
289 
290 
291 /*
292  * WifiDlMuAggregateTf
293  */
294 
296  : WifiAcknowledgment (DL_MU_AGGREGATE_TF),
297  ulLength (0)
298 {
299 }
300 
301 std::unique_ptr<WifiAcknowledgment>
303 {
304  return std::unique_ptr<WifiAcknowledgment> (new WifiDlMuAggregateTf (*this));
305 }
306 
307 bool
309  WifiMacHeader::QosAckPolicy ackPolicy) const
310 {
311  // the only admitted ack policy is No explicit acknowledgment or TB PPDU Ack policy
312  if (ackPolicy == WifiMacHeader::NO_EXPLICIT_ACK)
313  {
314  return true;
315  }
316 
317  return false;
318 }
319 
320 void
321 WifiDlMuAggregateTf::Print (std::ostream &os) const
322 {
323  os << "DL_MU_AGGREGATE_TF [";
324  for (const auto& sta : stationsReplyingWithBlockAck)
325  {
326  os << " (BA) " << sta.first;
327  }
328  os << "]";
329 }
330 
331 
332 /*
333  * WifiUlMuMultiStaBa
334  */
335 
337  : WifiAcknowledgment (UL_MU_MULTI_STA_BA)
338 {
339 }
340 
341 std::unique_ptr<WifiAcknowledgment>
343 {
344  return std::unique_ptr<WifiAcknowledgment> (new WifiUlMuMultiStaBa (*this));
345 }
346 
347 bool
349  WifiMacHeader::QosAckPolicy ackPolicy) const
350 {
351  // a Basic Trigger Frame has no QoS ack policy
352  return true;
353 }
354 
355 void
356 WifiUlMuMultiStaBa::Print (std::ostream &os) const
357 {
358  os << "UL_MU_MULTI_STA_BA [";
359  for (const auto& sta : stationsReceivingMultiStaBa)
360  {
361  os << "(" << sta.first.first << "," << +sta.first.second << ") ";
362  }
363  os << "]";
364 }
365 
366 
367 /*
368  * WifiAckAfterTbPpdu
369  */
370 
372  : WifiAcknowledgment (ACK_AFTER_TB_PPDU)
373 {
374 }
375 
376 std::unique_ptr<WifiAcknowledgment>
378 {
379  return std::unique_ptr<WifiAcknowledgment> (new WifiAckAfterTbPpdu (*this));
380 }
381 
382 bool
384  WifiMacHeader::QosAckPolicy ackPolicy) const
385 {
386  if (ackPolicy == WifiMacHeader::NORMAL_ACK)
387  {
388  return true;
389  }
390 
391  return false;
392 }
393 
394 void
395 WifiAckAfterTbPpdu::Print (std::ostream &os) const
396 {
397  os << "ACK_AFTER_TB_PPDU";
398 }
399 
400 
401 std::ostream & operator << (std::ostream &os, const WifiAcknowledgment* acknowledgment)
402 {
403  acknowledgment->Print (os);
404  return os;
405 }
406 
407 } //namespace ns3
std::map< Mac48Address, BlockAckInfo > stationsReplyingWithBlockAck
Set of stations replying with a BlockAck frame.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
WifiAcknowledgment(Method m)
Constructor.
std::unique_ptr< WifiAcknowledgment > Copy(void) const override
Clone this object.
std::unique_ptr< WifiAcknowledgment > Copy(void) const override
Clone this object.
std::unique_ptr< WifiAcknowledgment > Copy(void) const override
Clone this object.
virtual void Print(std::ostream &os) const =0
Print the object contents.
std::unique_ptr< WifiAcknowledgment > Copy(void) const override
Clone this object.
void Print(std::ostream &os) const override
Print the object contents.
Time acknowledgmentTime
time required by the acknowledgment method
WifiAcknowledgment is an abstract base struct.
void Print(std::ostream &os) const override
Print the object contents.
#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
void Print(std::ostream &os) const override
Print the object contents.
std::map< Mac48Address, BlockAckInfo > stationsReplyingWithBlockAck
Set of stations replying with a BlockAck frame.
std::map< std::pair< Mac48Address, uint8_t >, WifiMacHeader::QosAckPolicy > m_ackPolicy
Qos Ack Policy to set for MPDUs addressed to a given receiver and having a given TID.
virtual bool CheckQosAckPolicy(Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const =0
Check whether the given QoS Ack policy can be used for the MPDUs addressed to the given receiver and ...
bool CheckQosAckPolicy(Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const override
Check whether the given QoS Ack policy can be used for the MPDUs addressed to the given receiver and ...
WifiMacHeader::QosAckPolicy GetQosAckPolicy(Mac48Address receiver, uint8_t tid) const
Get the QoS Ack policy to use for the MPDUs addressed to the given receiver and belonging to the give...
void Print(std::ostream &os) const override
Print the object contents.
std::map< std::pair< Mac48Address, uint8_t >, std::size_t > stationsReceivingMultiStaBa
Map (originator, tid) pairs to the their index in baType.
void Print(std::ostream &os) const override
Print the object contents.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
std::unique_ptr< WifiAcknowledgment > Copy(void) const override
Clone this object.
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:218
std::unique_ptr< WifiAcknowledgment > Copy(void) const override
Clone this object.
bool CheckQosAckPolicy(Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const override
Check whether the given QoS Ack policy can be used for the MPDUs addressed to the given receiver and ...
std::map< Mac48Address, BlockAckInfo > stationsReplyingWithBlockAck
Set of stations replying with a BlockAck frame (no more than one)
Method
Available acknowledgment methods.
bool CheckQosAckPolicy(Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const override
Check whether the given QoS Ack policy can be used for the MPDUs addressed to the given receiver and ...
bool CheckQosAckPolicy(Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const override
Check whether the given QoS Ack policy can be used for the MPDUs addressed to the given receiver and ...
void Print(std::ostream &os) const override
Print the object contents.
void Print(std::ostream &os) const override
Print the object contents.
void Print(std::ostream &os) const override
Print the object contents.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::unique_ptr< WifiAcknowledgment > Copy(void) const override
Clone this object.
bool CheckQosAckPolicy(Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const override
Check whether the given QoS Ack policy can be used for the MPDUs addressed to the given receiver and ...
std::unique_ptr< WifiAcknowledgment > Copy(void) const override
Clone this object.
bool CheckQosAckPolicy(Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const override
Check whether the given QoS Ack policy can be used for the MPDUs addressed to the given receiver and ...
an EUI-48 address
Definition: mac48-address.h:43
QosAckPolicy
Ack policy for QoS frames.
bool CheckQosAckPolicy(Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const override
Check whether the given QoS Ack policy can be used for the MPDUs addressed to the given receiver and ...
bool CheckQosAckPolicy(Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const override
Check whether the given QoS Ack policy can be used for the MPDUs addressed to the given receiver and ...
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
void Print(std::ostream &os) const override
Print the object contents.
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...
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
std::map< Mac48Address, BlockAckReqInfo > stationsSendBlockAckReqTo
Set of stations receiving a BlockAckReq frame and replying with a BlockAck frame. ...
std::map< Mac48Address, AckInfo > stationsReplyingWithNormalAck
Set of stations replying with an Ack frame (no more than one)
bool CheckQosAckPolicy(Mac48Address receiver, uint8_t tid, WifiMacHeader::QosAckPolicy ackPolicy) const override
Check whether the given QoS Ack policy can be used for the MPDUs addressed to the given receiver and ...
std::unique_ptr< WifiAcknowledgment > Copy(void) const override
Clone this object.