A Discrete-Event Network Simulator
API
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  * 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 #ifndef FRAME_EXCHANGE_MANAGER_H
21 #define FRAME_EXCHANGE_MANAGER_H
22 
23 #include "mac-rx-middle.h"
24 #include "mac-tx-middle.h"
25 #include "qos-txop.h"
26 #include "wifi-mac.h"
27 #include "wifi-phy.h"
28 #include "wifi-psdu.h"
29 #include "wifi-tx-parameters.h"
30 #include "wifi-tx-timer.h"
31 #include "wifi-tx-vector.h"
32 
33 // Needed to compile wave bindings
34 #include "channel-access-manager.h"
35 #include "wifi-ack-manager.h"
37 
38 #include "ns3/object.h"
39 
40 namespace ns3
41 {
42 
43 struct RxSignalInfo;
44 struct WifiProtection;
45 struct WifiAcknowledgment;
46 
54 {
55  public:
60  static TypeId GetTypeId();
62  ~FrameExchangeManager() override;
63 
72 
81  virtual bool StartTransmission(Ptr<Txop> dcf, uint16_t allowedWidth);
82 
94  void Receive(Ptr<const WifiPsdu> psdu,
95  RxSignalInfo rxSignalInfo,
96  WifiTxVector txVector,
97  std::vector<bool> perMpduStatus);
98 
104  virtual void SetLinkId(uint8_t linkId);
110  virtual void SetWifiMac(const Ptr<WifiMac> mac);
116  virtual void SetMacTxMiddle(const Ptr<MacTxMiddle> txMiddle);
122  virtual void SetMacRxMiddle(const Ptr<MacRxMiddle> rxMiddle);
128  virtual void SetChannelAccessManager(const Ptr<ChannelAccessManager> channelAccessManager);
134  virtual void SetWifiPhy(const Ptr<WifiPhy> phy);
138  virtual void ResetPhy();
144  virtual void SetProtectionManager(Ptr<WifiProtectionManager> protectionManager);
150  virtual void SetAckManager(Ptr<WifiAckManager> ackManager);
156  virtual void SetAddress(Mac48Address address);
162  Mac48Address GetAddress() const;
168  virtual void SetBssid(Mac48Address bssid);
174  Mac48Address GetBssid() const;
180  virtual void SetDroppedMpduCallback(DroppedMpdu callback);
186  void SetAckedMpduCallback(AckedMpdu callback);
190  void SetPromisc();
197  bool IsPromisc() const;
198 
204  const WifiTxTimer& GetWifiTxTimer() const;
205 
212 
220  virtual void CalculateProtectionTime(WifiProtection* protection) const;
221 
228 
236  virtual void CalculateAcknowledgmentTime(WifiAcknowledgment* acknowledgment) const;
237 
241  virtual bool VirtualCsMediumIdle() const;
242 
246  const std::set<Mac48Address>& GetProtectedStas() const;
247 
253  virtual void NotifyInternalCollision(Ptr<Txop> txop);
254 
262  virtual void NotifySwitchingStartNow(Time duration);
263 
269  void NotifySleepNow();
270 
276  void NotifyOffNow();
277 
278  protected:
279  void DoDispose() override;
280 
285 
296 
306 
312  virtual void StartProtection(const WifiTxParameters& txParams);
313 
317  virtual void ProtectionCompleted();
318 
325  virtual void UpdateNav(Ptr<const WifiPsdu> psdu, const WifiTxVector& txVector);
326 
330  virtual void NavResetTimeout();
331 
340  virtual void ReceiveMpdu(Ptr<const WifiMpdu> mpdu,
341  RxSignalInfo rxSignalInfo,
342  const WifiTxVector& txVector,
343  bool inAmpdu);
344 
354  virtual void EndReceiveAmpdu(Ptr<const WifiPsdu> psdu,
355  const RxSignalInfo& rxSignalInfo,
356  const WifiTxVector& txVector,
357  const std::vector<bool>& perMpduStatus);
358 
368  virtual void ReceivedNormalAck(Ptr<WifiMpdu> mpdu,
369  const WifiTxVector& txVector,
370  const WifiTxVector& ackTxVector,
371  const RxSignalInfo& rxInfo,
372  double snr);
373 
379  virtual void NotifyReceivedNormalAck(Ptr<WifiMpdu> mpdu);
380 
386  virtual void RetransmitMpduAfterMissedAck(Ptr<WifiMpdu> mpdu) const;
387 
394  virtual void ReleaseSequenceNumbers(Ptr<const WifiPsdu> psdu) const;
395 
402  virtual void NotifyPacketDiscarded(Ptr<const WifiMpdu> mpdu);
403 
412  virtual void PreProcessFrame(Ptr<const WifiPsdu> psdu, const WifiTxVector& txVector);
413 
422  virtual void PostProcessFrame(Ptr<const WifiPsdu> psdu, const WifiTxVector& txVector);
423 
434  virtual Time GetTxDuration(uint32_t ppduPayloadSize,
435  Mac48Address receiver,
436  const WifiTxParameters& txParams) const;
437 
445  void UpdateTxDuration(Mac48Address receiver, WifiTxParameters& txParams) const;
446 
456  virtual uint32_t GetPsduSize(Ptr<const WifiMpdu> mpdu, const WifiTxVector& txVector) const;
457 
463  virtual void NotifyChannelReleased(Ptr<Txop> txop);
464 
476  std::set<Mac48Address> m_sentRtsTo;
477  std::set<Mac48Address> m_protectedStas;
478  uint8_t m_linkId;
479  uint16_t m_allowedWidth;
480  bool m_promisc;
483 
490  virtual void FinalizeMacHeader(Ptr<const WifiPsdu> psdu);
491 
498  virtual void ForwardMpduDown(Ptr<WifiMpdu> mpdu, WifiTxVector& txVector);
499 
505  virtual void DequeueMpdu(Ptr<const WifiMpdu> mpdu);
506 
518  virtual Time GetFrameDurationId(const WifiMacHeader& header,
519  uint32_t size,
520  const WifiTxParameters& txParams,
521  Ptr<Packet> fragmentedPacket) const;
522 
532  virtual Time GetRtsDurationId(const WifiTxVector& rtsTxVector,
533  Time txDuration,
534  Time response) const;
535 
541  void SendRts(const WifiTxParameters& txParams);
542 
550  void SendCtsAfterRts(const WifiMacHeader& rtsHdr, WifiMode rtsTxMode, double rtsSnr);
551 
559  void DoSendCtsAfterRts(const WifiMacHeader& rtsHdr, WifiTxVector& ctsTxVector, double rtsSnr);
560 
570  virtual Time GetCtsToSelfDurationId(const WifiTxVector& ctsTxVector,
571  Time txDuration,
572  Time response) const;
573 
579  void SendCtsToSelf(const WifiTxParameters& txParams);
580 
588  void SendNormalAck(const WifiMacHeader& hdr, const WifiTxVector& dataTxVector, double dataSnr);
589 
597 
602  virtual void TransmissionSucceeded();
603 
608  virtual void TransmissionFailed();
609 
616  virtual void NormalAckTimeout(Ptr<WifiMpdu> mpdu, const WifiTxVector& txVector);
617 
624  virtual void CtsTimeout(Ptr<WifiMpdu> rts, const WifiTxVector& txVector);
631  void DoCtsTimeout(Ptr<WifiPsdu> psdu);
632 
636  virtual void Reset();
637 
648  virtual void RxStartIndication(WifiTxVector txVector, Time psduDuration);
649 
650  private:
654  void SendMpdu();
655 
662 };
663 
664 } // namespace ns3
665 
666 #endif /* FRAME_EXCHANGE_MANAGER_H */
Callback template class.
Definition: callback.h:438
An identifier for simulation events.
Definition: event-id.h:55
FrameExchangeManager is a base class handling the basic frame exchange sequences for non-QoS stations...
std::set< Mac48Address > m_sentRtsTo
the STA(s) which we sent an RTS to (waiting for CTS)
void DoCtsTimeout(Ptr< WifiPsdu > psdu)
Take required actions when the CTS timer fired after sending an RTS to protect the given PSDU expires...
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 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
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
virtual void SetWifiMac(const Ptr< WifiMac > mac)
Set the MAC layer to use.
virtual void ResetPhy()
Remove WifiPhy associated with this FrameExchangeManager.
virtual void UpdateNav(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector)
Update the NAV, if needed, based on the Duration/ID of the given psdu.
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 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 TransmissionFailed()
Take necessary actions upon a transmission failure.
uint16_t m_allowedWidth
the allowed width in MHz for the current transmission
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...
WifiTxTimer m_txTimer
the timer set upon frame transmission
void SendCtsAfterRts(const WifiMacHeader &rtsHdr, WifiMode rtsTxMode, double rtsSnr)
Send CTS after receiving RTS.
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.
virtual void ProtectionCompleted()
Transmit prepared frame upon successful protection mechanism.
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 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.
virtual void CalculateProtectionTime(WifiProtection *protection) const
Calculate the time required to protect a frame according to the given protection method.
virtual void SetAddress(Mac48Address address)
Set the MAC address.
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.
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
Ptr< WifiPhy > m_phy
the PHY layer on this station
Ptr< WifiMpdu > GetFirstFragmentIfNeeded(Ptr< WifiMpdu > mpdu)
Fragment the given MPDU if needed.
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...
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.
void Receive(Ptr< const WifiPsdu > psdu, RxSignalInfo rxSignalInfo, WifiTxVector txVector, 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...
Mac48Address m_bssid
BSSID address (Mac48Address)
virtual void SetWifiPhy(const Ptr< WifiPhy > phy)
Set the PHY layer to use.
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 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.
bool m_moreFragments
true if a fragment has to be sent after a SIFS
void SetPromisc()
Enable promiscuous mode.
Time m_navEnd
NAV expiration time.
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.
void DoDispose() override
Destructor implementation.
WifiTxParameters m_txParams
the TX parameters for the current frame
virtual bool StartTransmission(Ptr< Txop > dcf, uint16_t allowedWidth)
Request the FrameExchangeManager to start a frame exchange sequence.
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 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
Definition: mac48-address.h:46
A base class which provides memory management and object aggregation.
Definition: object.h:89
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
Implements the IEEE 802.11 MAC header.
represent a single transmission mode
Definition: wifi-mode.h:51
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 ...
Definition: wifi-tx-timer.h:49
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mac
Definition: third.py:92
phy
Definition: third.py:89
RxSignalInfo structure containing info on the received signal.
Definition: phy-entity.h:69
WifiAcknowledgment is an abstract base struct.
WifiProtection is an abstract base struct.