A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
frame-exchange-manager.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8
9#ifndef FRAME_EXCHANGE_MANAGER_H
10#define FRAME_EXCHANGE_MANAGER_H
11
12#include "mac-rx-middle.h"
13#include "mac-tx-middle.h"
14#include "qos-txop.h"
15#include "wifi-mac.h"
16#include "wifi-phy.h"
17#include "wifi-psdu.h"
18#include "wifi-tx-parameters.h"
19#include "wifi-tx-timer.h"
20#include "wifi-tx-vector.h"
21
22// Needed to compile wave bindings
24#include "wifi-ack-manager.h"
26
27#include "ns3/object.h"
28
29#include <functional>
30#include <optional>
31
32#define WIFI_FEM_NS_LOG_APPEND_CONTEXT \
33 std::clog << "[link=" << +m_linkId << "][mac=" << m_self << "] "
34
35namespace ns3
36{
37
38class ApWifiMac;
39class StaWifiMac;
40
41struct RxSignalInfo;
42struct WifiProtection;
43struct WifiAcknowledgment;
44
45/**
46 * @ingroup wifi
47 *
48 * FrameExchangeManager is a base class handling the basic frame exchange
49 * sequences for non-QoS stations.
50 *
51 * The fragmentation policy implemented uses a simple fragmentation
52 * threshold: any packet bigger than this threshold is fragmented
53 * in fragments whose size is smaller than the threshold.
54 *
55 * The retransmission policy is also very simple: every packet is
56 * retransmitted until it is either successfully transmitted or
57 * it has been retransmitted up until the SSRC or SLRC thresholds.
58 */
60{
61 public:
62 /**
63 * @brief Get the type ID.
64 * @return the object TypeId
65 */
66 static TypeId GetTypeId();
68 ~FrameExchangeManager() override;
69
70 /**
71 * typedef for a callback to invoke when an MPDU is dropped.
72 */
74 /**
75 * typedef for a callback to invoke when an MPDU is successfully acknowledged.
76 */
78
79 /**
80 * Request the FrameExchangeManager to start a frame exchange sequence.
81 *
82 * @param dcf the channel access function that gained channel access. It is
83 * the DCF on non-QoS stations and an EDCA on QoS stations.
84 * @param allowedWidth the allowed width for the frame exchange sequence
85 * @return true if a frame exchange sequence was started, false otherwise
86 */
87 virtual bool StartTransmission(Ptr<Txop> dcf, MHz_u allowedWidth);
88
89 /**
90 * This method is intended to be called by the PHY layer every time an MPDU
91 * is received and also when the reception of an A-MPDU is completed. In case
92 * the PSDU contains multiple MPDUs, the <i>perMpduStatus</i> vector is empty
93 * when receiving the individual MPDUs.
94 *
95 * @param psdu the received PSDU
96 * @param rxSignalInfo the info on the received signal (\see RxSignalInfo)
97 * @param txVector TxVector of the received PSDU
98 * @param perMpduStatus per MPDU reception status
99 */
101 RxSignalInfo rxSignalInfo,
102 const WifiTxVector& txVector,
103 const std::vector<bool>& perMpduStatus);
104
105 /**
106 * Information about the MPDU being received. The TXVECTOR is populated upon
107 * PHY-RXSTART indication; the MAC header is populated when notified by the PHY.
108 */
110 {
111 std::optional<WifiMacHeader> macHdr; //!< MAC header of the MPDU being received
112 WifiTxVector txVector; //!< TXVECTOR of the MPDU being received
113 Time endOfPsduRx; //!< time when reception of PSDU ends
114 };
115
116 /**
117 * @return the information about the MPDU being received by the PHY, if any. This information
118 * is available from the time the PHY-RXSTART.indication is received until the end
119 * of PSDU reception
120 */
121 std::optional<std::reference_wrapper<const OngoingRxInfo>> GetOngoingRxInfo() const;
122
123 /**
124 * @return the information about the MAC header of the MPDU being received by the PHY, if any.
125 * The MAC header is available from the time its reception is completed until the end
126 * of PSDU reception
127 */
128 std::optional<std::reference_wrapper<const WifiMacHeader>> GetReceivedMacHdr() const;
129
130 /**
131 * Set the ID of the link this Frame Exchange Manager is associated with.
132 *
133 * @param linkId the ID of the link this Frame Exchange Manager is associated with
134 */
135 virtual void SetLinkId(uint8_t linkId);
136 /**
137 * Set the MAC layer to use.
138 *
139 * @param mac the MAC layer to use
140 */
141 virtual void SetWifiMac(const Ptr<WifiMac> mac);
142 /**
143 * Set the MAC TX Middle to use.
144 *
145 * @param txMiddle the MAC TX Middle to use
146 */
147 virtual void SetMacTxMiddle(const Ptr<MacTxMiddle> txMiddle);
148 /**
149 * Set the MAC RX Middle to use.
150 *
151 * @param rxMiddle the MAC RX Middle to use
152 */
153 virtual void SetMacRxMiddle(const Ptr<MacRxMiddle> rxMiddle);
154 /**
155 * Set the channel access manager to use
156 *
157 * @param channelAccessManager the channel access manager to use
158 */
159 virtual void SetChannelAccessManager(const Ptr<ChannelAccessManager> channelAccessManager);
160 /**
161 * Set the PHY layer to use.
162 *
163 * @param phy the PHY layer to use
164 */
165 virtual void SetWifiPhy(const Ptr<WifiPhy> phy);
166 /**
167 * Remove WifiPhy associated with this FrameExchangeManager.
168 */
169 virtual void ResetPhy();
170 /**
171 * Set the Protection Manager to use
172 *
173 * @param protectionManager the Protection Manager to use
174 */
175 virtual void SetProtectionManager(Ptr<WifiProtectionManager> protectionManager);
176 /**
177 * Set the Acknowledgment Manager to use
178 *
179 * @param ackManager the Acknowledgment Manager to use
180 */
181 virtual void SetAckManager(Ptr<WifiAckManager> ackManager);
182 /**
183 * Set the MAC address.
184 *
185 * @param address the MAC address
186 */
187 virtual void SetAddress(Mac48Address address);
188 /**
189 * Get the MAC address.
190 *
191 * @return the MAC address
192 */
193 Mac48Address GetAddress() const;
194 /**
195 * Set the Basic Service Set Identification.
196 *
197 * @param bssid the BSSID
198 */
199 virtual void SetBssid(Mac48Address bssid);
200 /**
201 * Get the Basic Service Set Identification.
202 *
203 * @return the BSSID
204 */
205 Mac48Address GetBssid() const;
206 /**
207 * @return the width of the channel that the FEM is allowed to use for the current transmission
208 */
209 MHz_u GetAllowedWidth() const;
210 /**
211 * Set the callback to invoke when an MPDU is dropped.
212 *
213 * @param callback the callback to invoke when an MPDU is dropped
214 */
215 virtual void SetDroppedMpduCallback(DroppedMpdu callback);
216 /**
217 * Set the callback to invoke when an MPDU is successfully acked.
218 *
219 * @param callback the callback to invoke when an MPDU is successfully acked
220 */
221 void SetAckedMpduCallback(AckedMpdu callback);
222 /**
223 * Enable promiscuous mode.
224 */
225 void SetPromisc();
226 /**
227 * Check if the device is operating in promiscuous mode.
228 *
229 * @return true if the device is operating in promiscuous mode,
230 * false otherwise
231 */
232 bool IsPromisc() const;
233
234 /**
235 * Get a const reference to the WifiTxTimer object.
236 *
237 * @return a const reference to the WifiTxTimer object
238 */
239 const WifiTxTimer& GetWifiTxTimer() const;
240
241 /**
242 * Get the Protection Manager used by this node.
243 *
244 * @return the Protection Manager used by this node
245 */
247
248 /**
249 * Calculate the time required to protect a frame according to the given
250 * protection method. The protection time is stored in the protection
251 * object itself.
252 *
253 * @param protection the protection method
254 */
255 virtual void CalculateProtectionTime(WifiProtection* protection) const;
256
257 /**
258 * Get the Acknowledgment Manager used by this node.
259 *
260 * @return the Acknowledgment Manager used by this node
261 */
263
264 /**
265 * Calculate the time required to acknowledge a frame according to the given
266 * acknowledgment method. The acknowledgment time is stored in the acknowledgment
267 * object itself.
268 *
269 * @param acknowledgment the acknowledgment method
270 */
271 virtual void CalculateAcknowledgmentTime(WifiAcknowledgment* acknowledgment) const;
272
273 /**
274 * @return true if the virtual CS indication is that the medium is idle
275 */
276 virtual bool VirtualCsMediumIdle() const;
277
278 /**
279 * @return the set of stations that have successfully received an RTS in this TXOP.
280 */
281 const std::set<Mac48Address>& GetProtectedStas() const;
282
283 /**
284 * Notify that an internal collision has occurred for the given Txop
285 *
286 * @param txop the Txop for which an internal collision has occurred
287 */
288 virtual void NotifyInternalCollision(Ptr<Txop> txop);
289
290 /**
291 * @param duration switching delay duration.
292 *
293 * This method is typically invoked by the PhyListener to notify
294 * the MAC layer that a channel switching occurred. When a channel switching
295 * occurs, pending MAC transmissions (RTS, CTS, Data and Ack) are cancelled.
296 */
297 virtual void NotifySwitchingStartNow(Time duration);
298
299 /**
300 * This method is typically invoked by the PhyListener to notify
301 * the MAC layer that the device has been put into sleep mode. When the device is put
302 * into sleep mode, pending MAC transmissions (RTS, CTS, Data and Ack) are cancelled.
303 */
304 void NotifySleepNow();
305
306 /**
307 * This method is typically invoked by the PhyListener to notify
308 * the MAC layer that the device has been put into off mode. When the device is put
309 * into off mode, pending MAC transmissions (RTS, CTS, Data and Ack) are cancelled.
310 */
311 void NotifyOffNow();
312
313 protected:
314 void DoDispose() override;
315
316 /**
317 * @return the remote station manager operating on our link
318 * @hidecaller
319 */
321
322 /**
323 * Fragment the given MPDU if needed. If fragmentation is needed, return the
324 * first fragment; otherwise, return the given MPDU. Note that, if fragmentation
325 * is applied, the given MPDU is dequeued from the MAC queue and the first
326 * fragment is enqueued in its place.
327 *
328 * @param mpdu the given MPDU
329 * @return the first fragment if fragmentation is needed, the given MPDU otherwise
330 */
332
333 /**
334 * Set the sequence number, determine the transmission parameters and transmit the given MPDU,
335 * which has been likely peeked from a TXOP queue.
336 *
337 * @param peekedItem the MPDU to transmit
338 */
339 virtual void PrepareFrameToSend(Ptr<WifiMpdu> peekedItem);
340
341 /**
342 * Send a buffered unit to the given sender, if any. Note that the sender must be a STA in
343 * powersave mode.
344 *
345 * @param sender the (link) address of the sender
346 * @return true if a buffered unit is sent, false otherwise
347 */
348 virtual bool SendBufferedUnit(Mac48Address sender);
349
350 /**
351 * Send an MPDU with the given TX parameters (with the specified protection).
352 * Note that <i>txParams</i> is moved to m_txParams and hence is left in an
353 * undefined state.
354 *
355 * @param mpdu the MPDU to send
356 * @param txParams the TX parameters to use to transmit the MPDU
357 */
359
360 /**
361 * Start the protection mechanism indicated by the given TX parameters
362 *
363 * @param txParams the TX parameters
364 */
365 virtual void StartProtection(const WifiTxParameters& txParams);
366
367 /**
368 * Transmit prepared frame immediately, if no protection was used, or in a SIFS, if protection
369 * was completed successfully.
370 */
371 virtual void ProtectionCompleted();
372
373 /**
374 * Update the NAV, if needed, based on the Duration/ID of the given MAC header and the given
375 * surplus.
376 *
377 * @param hdr the given MAC header
378 * @param txVector TxVector of the PSDU containing the MAC header
379 * @param surplus the surplus to add to the Duration/ID value. This is needed, e.g., when
380 * setting the NAV at the end of the reception of the MAC header
381 */
382 virtual void UpdateNav(const WifiMacHeader& hdr,
383 const WifiTxVector& txVector,
384 const Time& surplus = Time{0});
385
386 /**
387 * Reset the NAV upon expiration of the NAV reset timer.
388 */
389 virtual void NavResetTimeout();
390
391 /**
392 * Set the TXNAV upon sending an MPDU.
393 *
394 * @param mpdu the MPDU being sent
395 * @param txDuration the TX duration of the MPDU
396 */
397 void SetTxNav(Ptr<const WifiMpdu> mpdu, const Time& txDuration);
398
399 /// Reset the TXNAV
400 void ResetTxNav();
401
402 /**
403 * This method is called when the reception of a PSDU fails.
404 *
405 * @param psdu the PSDU whose reception failed
406 */
407 virtual void PsduRxError(Ptr<const WifiPsdu> psdu);
408
409 /**
410 * This method handles the reception of an MPDU (possibly included in an A-MPDU)
411 *
412 * @param mpdu the received MPDU
413 * @param rxSignalInfo the info on the received signal (\see RxSignalInfo)
414 * @param txVector TxVector of the received PSDU
415 * @param inAmpdu true if the MPDU is part of an A-MPDU
416 */
417 virtual void ReceiveMpdu(Ptr<const WifiMpdu> mpdu,
418 RxSignalInfo rxSignalInfo,
419 const WifiTxVector& txVector,
420 bool inAmpdu);
421
422 /**
423 * This method is called when the reception of an A-MPDU including multiple
424 * MPDUs is completed.
425 *
426 * @param psdu the received PSDU
427 * @param rxSignalInfo the info on the received signal (\see RxSignalInfo)
428 * @param txVector TxVector of the received PSDU
429 * @param perMpduStatus per MPDU reception status
430 */
431 virtual void EndReceiveAmpdu(Ptr<const WifiPsdu> psdu,
432 const RxSignalInfo& rxSignalInfo,
433 const WifiTxVector& txVector,
434 const std::vector<bool>& perMpduStatus);
435
436 /**
437 * Perform the actions needed when a Normal Ack is received.
438 *
439 * @param mpdu the MPDU that was acknowledged
440 * @param txVector the TXVECTOR used to transmit the MPDU that was acknowledged
441 * @param ackTxVector the TXVECTOR used to transmit the Normal Ack frame
442 * @param rxInfo the info on the received signal (\see RxSignalInfo)
443 * @param snr the SNR at the receiver for the MPDU that was acknowledged
444 */
445 virtual void ReceivedNormalAck(Ptr<WifiMpdu> mpdu,
446 const WifiTxVector& txVector,
447 const WifiTxVector& ackTxVector,
448 const RxSignalInfo& rxInfo,
449 double snr);
450
451 /**
452 * Notify other components that an MPDU was acknowledged.
453 *
454 * @param mpdu the MPDU that was acknowledged
455 */
456 virtual void NotifyReceivedNormalAck(Ptr<WifiMpdu> mpdu);
457
458 /**
459 * Take actions required when a frame is received from the associated AP after sending a
460 * PS-Poll frame.
461 */
463
464 /**
465 * Retransmit an MPDU that was not acknowledged.
466 *
467 * @param mpdu the MPDU to retransmit
468 */
469 virtual void RetransmitMpduAfterMissedAck(Ptr<WifiMpdu> mpdu) const;
470
471 /**
472 * Make the sequence numbers of MPDUs included in the given PSDU available again
473 * if the MPDUs have never been transmitted.
474 *
475 * @param psdu the given PSDU
476 */
477 virtual void ReleaseSequenceNumbers(Ptr<const WifiPsdu> psdu) const;
478
479 /**
480 * Pass the given MPDU, discarded because of the max retry limit was reached,
481 * to the MPDU dropped callback.
482 *
483 * @param mpdu the discarded MPDU
484 */
486
487 /**
488 * Perform actions that are possibly needed when receiving any frame,
489 * independently of whether the frame is addressed to this station
490 * (e.g., storing buffer status reports).
491 *
492 * @param psdu the received PSDU
493 * @param txVector TX vector of the received PSDU
494 */
495 virtual void PreProcessFrame(Ptr<const WifiPsdu> psdu, const WifiTxVector& txVector);
496
497 /**
498 * Perform actions that are possibly needed after receiving any frame,
499 * independently of whether the frame is addressed to this station
500 * (e.g., setting the NAV or the TXOP holder).
501 *
502 * @param psdu the received PSDU
503 * @param txVector TX vector of the received PSDU
504 */
505 virtual void PostProcessFrame(Ptr<const WifiPsdu> psdu, const WifiTxVector& txVector);
506
507 /**
508 * Get the updated TX duration of the frame associated with the given TX
509 * parameters if the size of the PSDU addressed to the given receiver
510 * becomes <i>ppduPayloadSize</i>.
511 *
512 * @param ppduPayloadSize the new PSDU size
513 * @param receiver the MAC address of the receiver of the PSDU
514 * @param txParams the TX parameters
515 * @return the updated TX duration
516 */
517 virtual Time GetTxDuration(uint32_t ppduPayloadSize,
518 Mac48Address receiver,
519 const WifiTxParameters& txParams) const;
520
521 /**
522 * Update the TX duration field of the given TX parameters after that the PSDU
523 * addressed to the given receiver has changed.
524 *
525 * @param receiver the MAC address of the receiver of the PSDU
526 * @param txParams the TX parameters
527 */
528 void UpdateTxDuration(Mac48Address receiver, WifiTxParameters& txParams) const;
529
530 /**
531 * Get the size in bytes of the given MPDU, which is to be transmitted with the
532 * given TXVECTOR. The purpose of this method is that it can be overridden to
533 * compute the size of an S-MPDU.
534 *
535 * @param mpdu the given MPDU
536 * @param txVector the given TXVECTOR
537 * @return the size of the MPDU
538 */
539 virtual uint32_t GetPsduSize(Ptr<const WifiMpdu> mpdu, const WifiTxVector& txVector) const;
540
541 /**
542 * Notify the given Txop that channel has been released.
543 *
544 * @param txop the given Txop
545 */
546 virtual void NotifyChannelReleased(Ptr<Txop> txop);
547
548 Ptr<Txop> m_dcf; //!< the DCF/EDCAF that gained channel access
549 WifiTxTimer m_txTimer; //!< the timer set upon frame transmission
550 EventId m_navResetEvent; //!< the event to reset the NAV after an RTS
551 EventId m_sendCtsEvent; //!< the event to send a CTS after an (MU-)RTS
552 Ptr<WifiMac> m_mac; //!< the MAC layer on this station
553 Ptr<ApWifiMac> m_apMac; //!< AP MAC layer pointer (null if not an AP)
554 Ptr<StaWifiMac> m_staMac; //!< STA MAC layer pointer (null if not a STA)
555 Ptr<MacTxMiddle> m_txMiddle; //!< the MAC TX Middle on this station
556 Ptr<MacRxMiddle> m_rxMiddle; //!< the MAC RX Middle on this station
557 Ptr<ChannelAccessManager> m_channelAccessManager; //!< the channel access manager
558 Ptr<WifiPhy> m_phy; //!< the PHY layer on this station
559 Mac48Address m_self; //!< the MAC address of this device
560 Mac48Address m_bssid; //!< BSSID address (Mac48Address)
561 Time m_navEnd; //!< NAV expiration time
562 Time m_txNav; //!< the TXNAV timer
563 std::set<Mac48Address> m_sentRtsTo; //!< the STA(s) which we sent an RTS to (waiting for CTS)
564 std::set<Mac48Address>
565 m_sentFrameTo; //!< the STA(s) to which we sent a frame requesting a response
566 std::set<Mac48Address> m_protectedStas; //!< STAs that have replied to an RTS in this TXOP
567 bool m_protectedIfResponded; //!< whether a STA is assumed to be protected if replied to a
568 //!< frame requiring acknowledgment
569 uint8_t m_linkId; //!< the ID of the link this object is associated with
570 MHz_u m_allowedWidth; //!< the allowed width for the current transmission
571 bool m_promisc; //!< Flag if the device is operating in promiscuous mode
572 DroppedMpdu m_droppedMpduCallback; //!< the dropped MPDU callback
573 AckedMpdu m_ackedMpduCallback; //!< the acknowledged MPDU callback
574
575 /**
576 * Finalize the MAC header of the MPDUs in the given PSDU before transmission. Tasks
577 * performed by this method include setting the Power Management flag in the MAC header.
578 *
579 * @param psdu the given PSDU
580 */
581 virtual void FinalizeMacHeader(Ptr<const WifiPsdu> psdu);
582
583 /**
584 * Forward an MPDU down to the PHY layer.
585 *
586 * @param mpdu the MPDU to forward down
587 * @param txVector the TXVECTOR used to transmit the MPDU
588 */
589 virtual void ForwardMpduDown(Ptr<WifiMpdu> mpdu, WifiTxVector& txVector);
590
591 /**
592 * Dequeue the given MPDU from the queue in which it is stored.
593 *
594 * @param mpdu the given MPDU
595 */
596 virtual void DequeueMpdu(Ptr<const WifiMpdu> mpdu);
597
598 /**
599 * Compute how to set the Duration/ID field of a frame being transmitted with
600 * the given TX parameters
601 *
602 * @param header the MAC header of the frame
603 * @param size the size of the frame in bytes
604 * @param txParams the TX parameters used to send the frame
605 * @param fragmentedPacket the packet that originated the frame to transmit, in case
606 * the latter is a fragment
607 * @return the computed Duration/ID value
608 */
609 virtual Time GetFrameDurationId(const WifiMacHeader& header,
610 uint32_t size,
611 const WifiTxParameters& txParams,
612 Ptr<Packet> fragmentedPacket) const;
613
614 /**
615 * Compute how to set the Duration/ID field of an RTS frame to send to protect
616 * a frame transmitted with the given TX vector.
617 *
618 * @param rtsTxVector the TX vector used to send the RTS frame
619 * @param txDuration the TX duration of the data frame
620 * @param response the time taken by the response (acknowledgment) to the data frame
621 * @return the computed Duration/ID value for the RTS frame
622 */
623 virtual Time GetRtsDurationId(const WifiTxVector& rtsTxVector,
624 Time txDuration,
625 Time response) const;
626
627 /**
628 * Send RTS to begin RTS-CTS-Data-Ack transaction.
629 *
630 * @param txParams the TX parameters for the data frame
631 */
632 void SendRts(const WifiTxParameters& txParams);
633
634 /**
635 * Send CTS after receiving RTS.
636 *
637 * @param rtsHdr the header of the received RTS
638 * @param rtsTxVector the TXVECTOR used to transmit the RTS
639 * @param rtsSnr the SNR of the RTS in linear scale
640 */
641 virtual void SendCtsAfterRts(const WifiMacHeader& rtsHdr,
642 const WifiTxVector& rtsTxVector,
643 double rtsSnr);
644
645 /**
646 * Send CTS after receiving RTS.
647 *
648 * @param rtsHdr the header of the received RTS
649 * @param ctsTxVector the TXVECTOR to use to transmit the CTS
650 * @param rtsSnr the SNR of the RTS in linear scale
651 */
652 void DoSendCtsAfterRts(const WifiMacHeader& rtsHdr, WifiTxVector& ctsTxVector, double rtsSnr);
653
654 /**
655 * Compute how to set the Duration/ID field of a CTS-to-self frame to send to
656 * protect a frame transmitted with the given TX vector.
657 *
658 * @param ctsTxVector the TX vector used to send the CTS-to-self frame
659 * @param txDuration the TX duration of the data frame
660 * @param response the time taken by the response (acknowledgment) to the data frame
661 * @return the computed Duration/ID value for the CTS-to-self frame
662 */
663 virtual Time GetCtsToSelfDurationId(const WifiTxVector& ctsTxVector,
664 Time txDuration,
665 Time response) const;
666
667 /**
668 * Send CTS for a CTS-to-self mechanism.
669 *
670 * @param txParams the TX parameters for the data frame
671 */
672 void SendCtsToSelf(const WifiTxParameters& txParams);
673
674 /**
675 * Send Normal Ack.
676 *
677 * @param hdr the header of the frame soliciting the Normal Ack
678 * @param dataTxVector the TXVECTOR used to transmit the frame soliciting the Normal Ack
679 * @param dataSnr the SNR of the frame soliciting the Normal Ack in linear scale
680 */
681 void SendNormalAck(const WifiMacHeader& hdr, const WifiTxVector& dataTxVector, double dataSnr);
682
683 /**
684 * Get the next fragment of the current MSDU.
685 * Only called for fragmented MSDUs.
686 *
687 * @return the next fragment of the current MSDU.
688 */
690
691 /**
692 * Take necessary actions upon a transmission success. A non-QoS station
693 * transmits the next fragment, if any, or releases the channel, otherwise.
694 */
695 virtual void TransmissionSucceeded();
696
697 /**
698 * Take necessary actions upon a transmission failure. A non-QoS station
699 * releases the channel when this method is called.
700 *
701 * @param forceCurrentCw whether to force the contention window to stay equal to the current
702 * value (normally, contention window is updated upon TX failure)
703 */
704 virtual void TransmissionFailed(bool forceCurrentCw = false);
705
706 /**
707 * Wrapper for the GetMpdusToDropOnTxFailure function of the remote station manager that
708 * additionally drops the MPDUs in the given PSDU that the remote station manager requested
709 * to drop.
710 *
711 * @param psdu the given PSDU
712 * @return an MPDU that has been dropped, if any, to be notified to the remote station manager
713 * through the appropriate function
714 */
716
717 /**
718 * Called when the Ack timeout expires.
719 *
720 * @param mpdu the MPDU that solicited a Normal Ack response
721 * @param txVector the TXVECTOR used to transmit the frame soliciting the Normal Ack
722 */
723 virtual void NormalAckTimeout(Ptr<WifiMpdu> mpdu, const WifiTxVector& txVector);
724
725 /**
726 * Called when the CTS timeout expires.
727 *
728 * @param rts the RTS that solicited a CTS response
729 * @param txVector the TXVECTOR used to transmit the RTS frame
730 */
731 virtual void CtsTimeout(Ptr<WifiMpdu> rts, const WifiTxVector& txVector);
732 /**
733 * Take required actions when the CTS timer fired after sending an (MU-)RTS to
734 * protect the given PSDU map expires.
735 *
736 * @param psduMap the PSDU map protected by the failed (MU-)RTS
737 */
738 void DoCtsTimeout(const WifiPsduMap& psduMap);
739
740 /**
741 * @return whether CW shall be updated on CTS timeout
742 */
743 virtual bool GetUpdateCwOnCtsTimeout() const;
744
745 /**
746 * @return whether an (MU-)RTS failure shall be reported to the remote station manager
747 */
748 virtual bool GetReportRtsFailed() const;
749
750 /**
751 * Reset this frame exchange manager.
752 */
753 virtual void Reset();
754
755 /**
756 * @param txVector the TXVECTOR decoded from PHY header.
757 * @param psduDuration the duration of the PSDU that is about to be received.
758 *
759 * This method is typically invoked by the lower PHY layer to notify
760 * the MAC layer that the reception of a PSDU is starting.
761 * This is equivalent to the PHY-RXSTART primitive.
762 * If the reception is correct for at least one MPDU of the PSDU
763 * the Receive method will be called after \p psduDuration.
764 */
765 virtual void RxStartIndication(WifiTxVector txVector, Time psduDuration);
766
767 /**
768 * Store information about the MAC header of the MPDU being received.
769 *
770 * @param macHdr the MAC header of the MPDU being received
771 * @param txVector the TXVECTOR used to transmit the PSDU
772 * @param psduDuration the remaining duration of the PSDU
773 */
774 virtual void ReceivedMacHdr(const WifiMacHeader& macHdr,
775 const WifiTxVector& txVector,
776 Time psduDuration);
777
778 /**
779 * Notify the last (re)transmission of a groupcast MPDU using the GCR-UR service.
780 *
781 * @param mpdu the groupcast MPDU
782 */
783 virtual void NotifyLastGcrUrTx(Ptr<const WifiMpdu> mpdu);
784
785 private:
786 /**
787 * Send the current MPDU, which can be acknowledged by a Normal Ack.
788 */
789 void SendMpdu();
790
791 Ptr<WifiMpdu> m_mpdu; //!< the MPDU being transmitted
792 WifiTxParameters m_txParams; //!< the TX parameters for the current frame
793 Ptr<Packet> m_fragmentedPacket; //!< the MSDU being fragmented
794 bool m_moreFragments; //!< true if a fragment has to be sent after a SIFS
796 Ptr<WifiAckManager> m_ackManager; //!< Acknowledgment manager
797
799 m_ongoingRxInfo{}; //!< information about the MAC header of the MPDU being received
800};
801
802} // namespace ns3
803
804#endif /* FRAME_EXCHANGE_MANAGER_H */
Callback template class.
Definition callback.h:428
An identifier for simulation events.
Definition event-id.h:45
std::set< Mac48Address > m_sentRtsTo
the STA(s) which we sent an RTS to (waiting for CTS)
Ptr< WifiMpdu > m_mpdu
the MPDU being transmitted
virtual void SetAckManager(Ptr< WifiAckManager > ackManager)
Set the Acknowledgment Manager to use.
void NotifyOffNow()
This method is typically invoked by the PhyListener to notify the MAC layer that the device has been ...
virtual void NotifyLastGcrUrTx(Ptr< const WifiMpdu > mpdu)
Notify the last (re)transmission of a groupcast MPDU using the GCR-UR service.
virtual void NotifyInternalCollision(Ptr< Txop > txop)
Notify that an internal collision has occurred for the given Txop.
static TypeId GetTypeId()
Get the type ID.
uint8_t m_linkId
the ID of the link this object is associated with
Ptr< WifiMac > m_mac
the MAC layer on this station
void SetTxNav(Ptr< const WifiMpdu > mpdu, const Time &txDuration)
Set the TXNAV upon sending an MPDU.
Callback< void, WifiMacDropReason, Ptr< const WifiMpdu > > DroppedMpdu
typedef for a callback to invoke when an MPDU is dropped.
DroppedMpdu m_droppedMpduCallback
the dropped MPDU callback
bool m_protectedIfResponded
whether a STA is assumed to be protected if replied to a frame requiring acknowledgment
virtual void SetWifiMac(const Ptr< WifiMac > mac)
Set the MAC layer to use.
virtual void ResetPhy()
Remove WifiPhy associated with this FrameExchangeManager.
void SendMpduWithProtection(Ptr< WifiMpdu > mpdu, WifiTxParameters &txParams)
Send an MPDU with the given TX parameters (with the specified protection).
Ptr< WifiAckManager > m_ackManager
Acknowledgment manager.
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager() const
void UpdateTxDuration(Mac48Address receiver, WifiTxParameters &txParams) const
Update the TX duration field of the given TX parameters after that the PSDU addressed to the given re...
virtual void CalculateAcknowledgmentTime(WifiAcknowledgment *acknowledgment) const
Calculate the time required to acknowledge a frame according to the given acknowledgment method.
Ptr< MacTxMiddle > m_txMiddle
the MAC TX Middle on this station
void SendNormalAck(const WifiMacHeader &hdr, const WifiTxVector &dataTxVector, double dataSnr)
Send Normal Ack.
Ptr< Packet > m_fragmentedPacket
the MSDU being fragmented
virtual void SetDroppedMpduCallback(DroppedMpdu callback)
Set the callback to invoke when an MPDU is dropped.
virtual bool GetReportRtsFailed() const
virtual void Reset()
Reset this frame exchange manager.
Callback< void, Ptr< const WifiMpdu > > AckedMpdu
typedef for a callback to invoke when an MPDU is successfully acknowledged.
Mac48Address m_self
the MAC address of this device
virtual void StartProtection(const WifiTxParameters &txParams)
Start the protection mechanism indicated by the given TX parameters.
virtual void NotifyPacketDiscarded(Ptr< const WifiMpdu > mpdu)
Pass the given MPDU, discarded because of the max retry limit was reached, to the MPDU dropped callba...
std::optional< std::reference_wrapper< const WifiMacHeader > > GetReceivedMacHdr() const
WifiTxTimer m_txTimer
the timer set upon frame transmission
std::set< Mac48Address > m_protectedStas
STAs that have replied to an RTS in this TXOP.
virtual Time GetRtsDurationId(const WifiTxVector &rtsTxVector, Time txDuration, Time response) const
Compute how to set the Duration/ID field of an RTS frame to send to protect a frame transmitted with ...
virtual void RetransmitMpduAfterMissedAck(Ptr< WifiMpdu > mpdu) const
Retransmit an MPDU that was not acknowledged.
Mac48Address GetAddress() const
Get the MAC address.
Ptr< WifiProtectionManager > m_protectionManager
Protection manager.
OngoingRxInfo m_ongoingRxInfo
information about the MAC header of the MPDU being received
virtual void ProtectionCompleted()
Transmit prepared frame immediately, if no protection was used, or in a SIFS, if protection was compl...
virtual void ForwardMpduDown(Ptr< WifiMpdu > mpdu, WifiTxVector &txVector)
Forward an MPDU down to the PHY layer.
virtual void SetLinkId(uint8_t linkId)
Set the ID of the link this Frame Exchange Manager is associated with.
virtual bool VirtualCsMediumIdle() const
void SendRts(const WifiTxParameters &txParams)
Send RTS to begin RTS-CTS-Data-Ack transaction.
virtual void NotifyReceivedNormalAck(Ptr< WifiMpdu > mpdu)
Notify other components that an MPDU was acknowledged.
virtual void NotifyChannelReleased(Ptr< Txop > txop)
Notify the given Txop that channel has been released.
virtual void NormalAckTimeout(Ptr< WifiMpdu > mpdu, const WifiTxVector &txVector)
Called when the Ack timeout expires.
virtual bool SendBufferedUnit(Mac48Address sender)
Send a buffered unit to the given sender, if any.
virtual void NotifySwitchingStartNow(Time duration)
virtual void SetBssid(Mac48Address bssid)
Set the Basic Service Set Identification.
void SendCtsToSelf(const WifiTxParameters &txParams)
Send CTS for a CTS-to-self mechanism.
virtual void CtsTimeout(Ptr< WifiMpdu > rts, const WifiTxVector &txVector)
Called when the CTS timeout expires.
void DoCtsTimeout(const WifiPsduMap &psduMap)
Take required actions when the CTS timer fired after sending an (MU-)RTS to protect the given PSDU ma...
virtual void ReceivedMacHdr(const WifiMacHeader &macHdr, const WifiTxVector &txVector, Time psduDuration)
Store information about the MAC header of the MPDU being received.
virtual void CalculateProtectionTime(WifiProtection *protection) const
Calculate the time required to protect a frame according to the given protection method.
std::optional< std::reference_wrapper< const OngoingRxInfo > > GetOngoingRxInfo() const
virtual void SetAddress(Mac48Address address)
Set the MAC address.
virtual void SendCtsAfterRts(const WifiMacHeader &rtsHdr, const WifiTxVector &rtsTxVector, double rtsSnr)
Send CTS after receiving RTS.
Ptr< WifiAckManager > GetAckManager() const
Get the Acknowledgment Manager used by this node.
virtual void DequeueMpdu(Ptr< const WifiMpdu > mpdu)
Dequeue the given MPDU from the queue in which it is stored.
virtual void NavResetTimeout()
Reset the NAV upon expiration of the NAV reset timer.
const std::set< Mac48Address > & GetProtectedStas() const
Ptr< WifiProtectionManager > GetProtectionManager() const
Get the Protection Manager used by this node.
void ReceiveFrameAfterPsPoll()
Take actions required when a frame is received from the associated AP after sending a PS-Poll frame.
bool IsPromisc() const
Check if the device is operating in promiscuous mode.
void SendMpdu()
Send the current MPDU, which can be acknowledged by a Normal Ack.
virtual void EndReceiveAmpdu(Ptr< const WifiPsdu > psdu, const RxSignalInfo &rxSignalInfo, const WifiTxVector &txVector, const std::vector< bool > &perMpduStatus)
This method is called when the reception of an A-MPDU including multiple MPDUs is completed.
Ptr< MacRxMiddle > m_rxMiddle
the MAC RX Middle on this station
virtual void TransmissionSucceeded()
Take necessary actions upon a transmission success.
Ptr< Txop > m_dcf
the DCF/EDCAF that gained channel access
EventId m_sendCtsEvent
the event to send a CTS after an (MU-)RTS
Ptr< WifiPhy > m_phy
the PHY layer on this station
Ptr< WifiMpdu > GetFirstFragmentIfNeeded(Ptr< WifiMpdu > mpdu)
Fragment the given MPDU if needed.
Ptr< WifiMpdu > DropMpduIfRetryLimitReached(Ptr< WifiPsdu > psdu)
Wrapper for the GetMpdusToDropOnTxFailure function of the remote station manager that additionally dr...
Ptr< WifiMpdu > GetNextFragment()
Get the next fragment of the current MSDU.
virtual void ReleaseSequenceNumbers(Ptr< const WifiPsdu > psdu) const
Make the sequence numbers of MPDUs included in the given PSDU available again if the MPDUs have never...
std::set< Mac48Address > m_sentFrameTo
the STA(s) to which we sent a frame requesting a response
void SetAckedMpduCallback(AckedMpdu callback)
Set the callback to invoke when an MPDU is successfully acked.
virtual void PreProcessFrame(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector)
Perform actions that are possibly needed when receiving any frame, independently of whether the frame...
virtual Time GetFrameDurationId(const WifiMacHeader &header, uint32_t size, const WifiTxParameters &txParams, Ptr< Packet > fragmentedPacket) const
Compute how to set the Duration/ID field of a frame being transmitted with the given TX parameters.
virtual Time GetCtsToSelfDurationId(const WifiTxVector &ctsTxVector, Time txDuration, Time response) const
Compute how to set the Duration/ID field of a CTS-to-self frame to send to protect a frame transmitte...
void DoSendCtsAfterRts(const WifiMacHeader &rtsHdr, WifiTxVector &ctsTxVector, double rtsSnr)
Send CTS after receiving RTS.
Ptr< ApWifiMac > m_apMac
AP MAC layer pointer (null if not an AP).
Mac48Address m_bssid
BSSID address (Mac48Address).
virtual void SetWifiPhy(const Ptr< WifiPhy > phy)
Set the PHY layer to use.
void Receive(Ptr< const WifiPsdu > psdu, RxSignalInfo rxSignalInfo, const WifiTxVector &txVector, const std::vector< bool > &perMpduStatus)
This method is intended to be called by the PHY layer every time an MPDU is received and also when th...
virtual void TransmissionFailed(bool forceCurrentCw=false)
Take necessary actions upon a transmission failure.
AckedMpdu m_ackedMpduCallback
the acknowledged MPDU callback
virtual void FinalizeMacHeader(Ptr< const WifiPsdu > psdu)
Finalize the MAC header of the MPDUs in the given PSDU before transmission.
virtual void PostProcessFrame(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector)
Perform actions that are possibly needed after receiving any frame, independently of whether the fram...
virtual uint32_t GetPsduSize(Ptr< const WifiMpdu > mpdu, const WifiTxVector &txVector) const
Get the size in bytes of the given MPDU, which is to be transmitted with the given TXVECTOR.
Ptr< ChannelAccessManager > m_channelAccessManager
the channel access manager
virtual void ReceivedNormalAck(Ptr< WifiMpdu > mpdu, const WifiTxVector &txVector, const WifiTxVector &ackTxVector, const RxSignalInfo &rxInfo, double snr)
Perform the actions needed when a Normal Ack is received.
bool m_promisc
Flag if the device is operating in promiscuous mode.
void NotifySleepNow()
This method is typically invoked by the PhyListener to notify the MAC layer that the device has been ...
virtual void PrepareFrameToSend(Ptr< WifiMpdu > peekedItem)
Set the sequence number, determine the transmission parameters and transmit the given MPDU,...
virtual void ReceiveMpdu(Ptr< const WifiMpdu > mpdu, RxSignalInfo rxSignalInfo, const WifiTxVector &txVector, bool inAmpdu)
This method handles the reception of an MPDU (possibly included in an A-MPDU).
virtual void SetChannelAccessManager(const Ptr< ChannelAccessManager > channelAccessManager)
Set the channel access manager to use.
virtual bool StartTransmission(Ptr< Txop > dcf, MHz_u allowedWidth)
Request the FrameExchangeManager to start a frame exchange sequence.
bool m_moreFragments
true if a fragment has to be sent after a SIFS
void SetPromisc()
Enable promiscuous mode.
MHz_u m_allowedWidth
the allowed width for the current transmission
virtual void PsduRxError(Ptr< const WifiPsdu > psdu)
This method is called when the reception of a PSDU fails.
Time m_navEnd
NAV expiration time.
virtual void UpdateNav(const WifiMacHeader &hdr, const WifiTxVector &txVector, const Time &surplus=Time{0})
Update the NAV, if needed, based on the Duration/ID of the given MAC header and the given surplus.
virtual void SetMacTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set the MAC TX Middle to use.
virtual void SetMacRxMiddle(const Ptr< MacRxMiddle > rxMiddle)
Set the MAC RX Middle to use.
virtual void SetProtectionManager(Ptr< WifiProtectionManager > protectionManager)
Set the Protection Manager to use.
Mac48Address GetBssid() const
Get the Basic Service Set Identification.
Ptr< StaWifiMac > m_staMac
STA MAC layer pointer (null if not a STA).
void DoDispose() override
Destructor implementation.
WifiTxParameters m_txParams
the TX parameters for the current frame
virtual void RxStartIndication(WifiTxVector txVector, Time psduDuration)
EventId m_navResetEvent
the event to reset the NAV after an RTS
const WifiTxTimer & GetWifiTxTimer() const
Get a const reference to the WifiTxTimer object.
virtual bool GetUpdateCwOnCtsTimeout() const
virtual Time GetTxDuration(uint32_t ppduPayloadSize, Mac48Address receiver, const WifiTxParameters &txParams) const
Get the updated TX duration of the frame associated with the given TX parameters if the size of the P...
an EUI-48 address
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
a unique identifier for an interface.
Definition type-id.h:50
Implements the IEEE 802.11 MAC header.
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
This class is used to handle the timer that a station starts when transmitting a frame that solicits ...
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double MHz_u
MHz weak type.
Definition wifi-units.h:31
std::unordered_map< uint16_t, Ptr< WifiPsdu > > WifiPsduMap
Map of PSDUs indexed by STA-ID.
Definition wifi-mac.h:78
Information about the MPDU being received.
Time endOfPsduRx
time when reception of PSDU ends
std::optional< WifiMacHeader > macHdr
MAC header of the MPDU being received.
WifiTxVector txVector
TXVECTOR of the MPDU being received.
RxSignalInfo structure containing info on the received signal.
Definition wifi-types.h:84
WifiAcknowledgment is an abstract base struct.
WifiProtection is an abstract base struct.