A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-acknowledgment.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Stefano Avallone <stavallo@unina.it>
18 */
19
20#include "wifi-acknowledgment.h"
21
22#include "wifi-utils.h"
23
24#include "ns3/mac48-address.h"
25
26namespace ns3
27{
28
29/*
30 * WifiAcknowledgment
31 */
32
34 : method(m)
35{
36}
37
39{
40}
41
44{
45 auto it = m_ackPolicy.find({receiver, tid});
46 NS_ASSERT(it != m_ackPolicy.end());
47 return it->second;
48}
49
50void
52 uint8_t tid,
54{
55 NS_ABORT_MSG_IF(!CheckQosAckPolicy(receiver, tid, ackPolicy), "QoS Ack policy not admitted");
56 m_ackPolicy[{receiver, tid}] = ackPolicy;
57}
58
59/*
60 * WifiNoAck
61 */
62
64 : WifiAcknowledgment(NONE)
65{
67}
68
69std::unique_ptr<WifiAcknowledgment>
71{
72 return std::make_unique<WifiNoAck>(*this);
73}
74
75bool
77 uint8_t tid,
78 WifiMacHeader::QosAckPolicy ackPolicy) const
79{
80 return ackPolicy == WifiMacHeader::NO_ACK || ackPolicy == WifiMacHeader::BLOCK_ACK;
81}
82
83void
84WifiNoAck::Print(std::ostream& os) const
85{
86 os << "NONE";
87}
88
89/*
90 * WifiNormalAck
91 */
92
94 : WifiAcknowledgment(NORMAL_ACK)
95{
96}
97
98std::unique_ptr<WifiAcknowledgment>
100{
101 return std::make_unique<WifiNormalAck>(*this);
102}
103
104bool
106 uint8_t tid,
107 WifiMacHeader::QosAckPolicy ackPolicy) const
108{
109 return ackPolicy == WifiMacHeader::NORMAL_ACK;
110}
111
112void
113WifiNormalAck::Print(std::ostream& os) const
114{
115 os << "NORMAL_ACK";
116}
117
118/*
119 * WifiBlockAck
120 */
121
123 : WifiAcknowledgment(BLOCK_ACK)
124{
125}
126
127std::unique_ptr<WifiAcknowledgment>
129{
130 return std::make_unique<WifiBlockAck>(*this);
131}
132
133bool
135 uint8_t tid,
136 WifiMacHeader::QosAckPolicy ackPolicy) const
137{
138 return ackPolicy == WifiMacHeader::NORMAL_ACK;
139}
140
141void
142WifiBlockAck::Print(std::ostream& os) const
143{
144 os << "BLOCK_ACK";
145}
146
147/*
148 * WifiBarBlockAck
149 */
150
152 : WifiAcknowledgment(BAR_BLOCK_ACK)
153{
154}
155
156std::unique_ptr<WifiAcknowledgment>
158{
159 return std::make_unique<WifiBarBlockAck>(*this);
160}
161
162bool
164 uint8_t tid,
165 WifiMacHeader::QosAckPolicy ackPolicy) const
166{
167 return ackPolicy == WifiMacHeader::BLOCK_ACK;
168}
169
170void
171WifiBarBlockAck::Print(std::ostream& os) const
172{
173 os << "BAR_BLOCK_ACK";
174}
175
176/*
177 * WifiDlMuBarBaSequence
178 */
179
182{
183}
184
185std::unique_ptr<WifiAcknowledgment>
187{
188 return std::make_unique<WifiDlMuBarBaSequence>(*this);
189}
190
191bool
193 uint8_t tid,
194 WifiMacHeader::QosAckPolicy ackPolicy) const
195{
196 if (ackPolicy == WifiMacHeader::NORMAL_ACK)
197 {
198 // The given receiver must be the only one to send an immediate reply
199 if (stationsReplyingWithNormalAck.size() == 1 &&
200 stationsReplyingWithNormalAck.begin()->first == receiver)
201 {
202 return true;
203 }
204
205 if (stationsReplyingWithBlockAck.size() == 1 &&
206 stationsReplyingWithBlockAck.begin()->first == receiver)
207 {
208 return true;
209 }
210
211 return false;
212 }
213
214 return ackPolicy == WifiMacHeader::BLOCK_ACK;
215}
216
217void
218WifiDlMuBarBaSequence::Print(std::ostream& os) const
219{
220 os << "DL_MU_BAR_BA_SEQUENCE [";
221 for (const auto& sta : stationsReplyingWithNormalAck)
222 {
223 os << " (ACK) " << sta.first;
224 }
225 for (const auto& sta : stationsReplyingWithBlockAck)
226 {
227 os << " (BA) " << sta.first;
228 }
229 for (const auto& sta : stationsSendBlockAckReqTo)
230 {
231 os << " (BAR+BA) " << sta.first;
232 }
233 os << "]";
234}
235
236/*
237 * WifiDlMuTfMuBar
238 */
239
241 : WifiAcknowledgment(DL_MU_TF_MU_BAR),
242 ulLength(0)
243{
244}
245
246std::unique_ptr<WifiAcknowledgment>
248{
249 return std::make_unique<WifiDlMuTfMuBar>(*this);
250}
251
252bool
254 uint8_t tid,
255 WifiMacHeader::QosAckPolicy ackPolicy) const
256{
257 // the only admitted ack policy is Block Ack because stations need to wait for a MU-BAR
258 return ackPolicy == WifiMacHeader::BLOCK_ACK;
259}
260
261void
262WifiDlMuTfMuBar::Print(std::ostream& os) const
263{
264 os << "DL_MU_TF_MU_BAR [";
265 for (const auto& sta : stationsReplyingWithBlockAck)
266 {
267 os << " (BA) " << sta.first;
268 }
269 os << "]";
270}
271
272/*
273 * WifiDlMuAggregateTf
274 */
275
277 : WifiAcknowledgment(DL_MU_AGGREGATE_TF),
278 ulLength(0)
279{
280}
281
282std::unique_ptr<WifiAcknowledgment>
284{
285 return std::make_unique<WifiDlMuAggregateTf>(*this);
286}
287
288bool
290 uint8_t tid,
291 WifiMacHeader::QosAckPolicy ackPolicy) const
292{
293 // the only admitted ack policy is No explicit acknowledgment or TB PPDU Ack policy
294 return ackPolicy == WifiMacHeader::NO_EXPLICIT_ACK;
295}
296
297void
298WifiDlMuAggregateTf::Print(std::ostream& os) const
299{
300 os << "DL_MU_AGGREGATE_TF [";
301 for (const auto& sta : stationsReplyingWithBlockAck)
302 {
303 os << " (BA) " << sta.first;
304 }
305 os << "]";
306}
307
308/*
309 * WifiUlMuMultiStaBa
310 */
311
313 : WifiAcknowledgment(UL_MU_MULTI_STA_BA),
314 baType(BlockAckType::MULTI_STA)
315{
316}
317
318std::unique_ptr<WifiAcknowledgment>
320{
321 return std::make_unique<WifiUlMuMultiStaBa>(*this);
322}
323
324bool
326 uint8_t tid,
327 WifiMacHeader::QosAckPolicy ackPolicy) const
328{
329 // a Basic Trigger Frame has no QoS ack policy
330 return true;
331}
332
333void
334WifiUlMuMultiStaBa::Print(std::ostream& os) const
335{
336 os << "UL_MU_MULTI_STA_BA [";
337 for (const auto& sta : stationsReceivingMultiStaBa)
338 {
339 os << "(" << sta.first.first << "," << +sta.first.second << ") ";
340 }
341 os << "]";
342}
343
344/*
345 * WifiAckAfterTbPpdu
346 */
347
349 : WifiAcknowledgment(ACK_AFTER_TB_PPDU)
350{
351}
352
353std::unique_ptr<WifiAcknowledgment>
355{
356 return std::make_unique<WifiAckAfterTbPpdu>(*this);
357}
358
359bool
361 uint8_t tid,
362 WifiMacHeader::QosAckPolicy ackPolicy) const
363{
364 return ackPolicy == WifiMacHeader::NORMAL_ACK;
365}
366
367void
368WifiAckAfterTbPpdu::Print(std::ostream& os) const
369{
370 os << "ACK_AFTER_TB_PPDU";
371}
372
373std::ostream&
374operator<<(std::ostream& os, const WifiAcknowledgment* acknowledgment)
375{
376 acknowledgment->Print(os);
377 return os;
378}
379
380} // namespace ns3
an EUI-48 address
Definition: mac48-address.h:46
QosAckPolicy
Ack policy for QoS frames.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
The different BlockAck variants.
void Print(std::ostream &os) const override
Print the object contents.
std::unique_ptr< WifiAcknowledgment > Copy() 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 ...
WifiAcknowledgment is an abstract base struct.
WifiAcknowledgment(Method m)
Constructor.
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.
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...
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...
virtual void Print(std::ostream &os) const =0
Print the object contents.
Method
Available acknowledgment methods.
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 ...
std::optional< Time > acknowledgmentTime
time required by the acknowledgment method
void Print(std::ostream &os) const override
Print the object contents.
std::unique_ptr< WifiAcknowledgment > Copy() 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() const override
Clone this object.
void Print(std::ostream &os) const override
Print the object contents.
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() const override
Clone this object.
void Print(std::ostream &os) const override
Print the object contents.
std::map< Mac48Address, BlockAckInfo > stationsReplyingWithBlockAck
Set of stations replying with a BlockAck frame.
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.
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, BlockAckReqInfo > stationsSendBlockAckReqTo
Set of stations receiving a BlockAckReq frame and replying with a BlockAck frame.
std::map< Mac48Address, BlockAckInfo > stationsReplyingWithBlockAck
Set of stations replying with a BlockAck frame (no more than one)
std::unique_ptr< WifiAcknowledgment > Copy() const override
Clone this object.
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::map< Mac48Address, BlockAckInfo > stationsReplyingWithBlockAck
Set of stations replying with a BlockAck frame.
std::unique_ptr< WifiAcknowledgment > Copy() const override
Clone this object.
void Print(std::ostream &os) const override
Print the object contents.
std::unique_ptr< WifiAcknowledgment > Copy() 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 ...
void Print(std::ostream &os) const override
Print the object contents.
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.
std::unique_ptr< WifiAcknowledgment > Copy() const override
Clone this object.
std::unique_ptr< WifiAcknowledgment > Copy() const override
Clone this object.
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.
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 ...