A Discrete-Event Network Simulator
API
block-ack-manager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, 2010 MIRKO BANCHI
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: Mirko Banchi <mk.banchi@gmail.com>
18  */
19 
20 #ifndef BLOCK_ACK_MANAGER_H
21 #define BLOCK_ACK_MANAGER_H
22 
23 #include "block-ack-type.h"
26 #include "wifi-mac-header.h"
27 #include "wifi-mpdu.h"
28 #include "wifi-tx-vector.h"
29 
30 #include "ns3/nstime.h"
31 #include "ns3/object.h"
32 #include "ns3/traced-callback.h"
33 
34 #include <map>
35 
36 namespace ns3
37 {
38 
39 class MgtAddBaResponseHeader;
40 class MgtAddBaRequestHeader;
41 class CtrlBAckResponseHeader;
42 class CtrlBAckRequestHeader;
43 class WifiMacQueue;
44 class MacRxMiddle;
45 
50 class BlockAckManager : public Object
51 {
52  private:
56  enum MpduStatus : uint8_t
57  {
61  };
62 
63  public:
68  static TypeId GetTypeId();
69 
71  ~BlockAckManager() override;
72 
73  // Delete copy constructor and assignment operator to avoid misuse
74  BlockAckManager(const BlockAckManager&) = delete;
76 
79  std::optional<std::reference_wrapper<const OriginatorBlockAckAgreement>>;
82  std::optional<std::reference_wrapper<const RecipientBlockAckAgreement>>;
83 
93  uint8_t tid) const;
103  uint8_t tid) const;
104 
114  const Mac48Address& recipient,
115  bool htSupported = true);
123  void DestroyOriginatorAgreement(const Mac48Address& recipient, uint8_t tid);
132  const Mac48Address& recipient,
133  uint16_t startingSeq);
134 
153  const Mac48Address& originator,
154  uint16_t startingSeq,
155  bool htSupported,
156  Ptr<MacRxMiddle> rxMiddle);
163  void DestroyRecipientAgreement(const Mac48Address& originator, uint8_t tid);
164 
171  void StorePacket(Ptr<WifiMpdu> mpdu);
181  void NotifyGotAck(uint8_t linkId, Ptr<const WifiMpdu> mpdu);
191  void NotifyMissedAck(uint8_t linkId, Ptr<WifiMpdu> mpdu);
209  std::pair<uint16_t, uint16_t> NotifyGotBlockAck(uint8_t linkId,
210  const CtrlBAckResponseHeader& blockAck,
211  const Mac48Address& recipient,
212  const std::set<uint8_t>& tids,
213  size_t index = 0);
223  void NotifyMissedBlockAck(uint8_t linkId, const Mac48Address& recipient, uint8_t tid);
231  void NotifyGotBlockAckRequest(const Mac48Address& originator,
232  uint8_t tid,
233  uint16_t startingSeq);
249  uint32_t GetNBufferedPackets(const Mac48Address& recipient, uint8_t tid) const;
259  uint8_t tid,
260  uint16_t startingSeq);
269  void NotifyOriginatorAgreementRejected(const Mac48Address& recipient, uint8_t tid);
278  void NotifyOriginatorAgreementNoReply(const Mac48Address& recipient, uint8_t tid);
286  void NotifyOriginatorAgreementReset(const Mac48Address& recipient, uint8_t tid);
294  void SetBlockAckThreshold(uint8_t nPackets);
295 
299  void SetQueue(const Ptr<WifiMacQueue> queue);
300 
316 
327  bool NeedBarRetransmission(uint8_t tid, const Mac48Address& recipient);
336  uint16_t GetRecipientBufferSize(const Mac48Address& recipient, uint8_t tid) const;
345  uint16_t GetOriginatorStartingSequence(const Mac48Address& recipient, uint8_t tid) const;
346 
359 
364  void SetTxOkCallback(TxOk callback);
369  void SetTxFailedCallback(TxFailed callback);
374 
383  typedef void (*AgreementStateTracedCallback)(Time now,
384  const Mac48Address& recipient,
385  uint8_t tid,
387 
399 
408  CtrlBAckRequestHeader GetBlockAckReqHeader(const Mac48Address& recipient, uint8_t tid) const;
409 
418  void ScheduleBar(Ptr<WifiMpdu> bar);
426  void ScheduleMuBar(Ptr<WifiMpdu> muBar);
427 
429  using AgreementKey = std::pair<Mac48Address, uint8_t>;
430 
435  const std::list<AgreementKey>& GetSendBarIfDataQueuedList() const;
443  void AddToSendBarIfDataQueuedList(const Mac48Address& recipient, uint8_t tid);
451  void RemoveFromSendBarIfDataQueuedList(const Mac48Address& recipient, uint8_t tid);
452 
453  protected:
454  void DoDispose() override;
455 
456  private:
462  void InactivityTimeout(const Mac48Address& recipient, uint8_t tid);
463 
467  typedef std::list<Ptr<WifiMpdu>> PacketQueue;
471  typedef std::list<Ptr<WifiMpdu>>::iterator PacketQueueI;
472 
475  std::map<AgreementKey, std::pair<OriginatorBlockAckAgreement, PacketQueue>>;
477  using OriginatorAgreementsI = OriginatorAgreements::iterator;
478 
480  using RecipientAgreements = std::map<AgreementKey, RecipientBlockAckAgreement>;
481 
497  PacketQueueI HandleInFlightMpdu(uint8_t linkId,
498  PacketQueueI mpduIt,
499  MpduStatus status,
500  const OriginatorAgreementsI& it,
501  const Time& now);
502 
511 
512  std::list<AgreementKey> m_sendBarIfDataQueued;
514 
524 
530 };
531 
532 } // namespace ns3
533 
534 #endif /* BLOCK_ACK_MANAGER_H */
Manages all block ack agreements for an originator station.
void SetTxFailedCallback(TxFailed callback)
RecipientAgreementOptConstRef GetAgreementAsRecipient(const Mac48Address &originator, uint8_t tid) const
void NotifyOriginatorAgreementEstablished(const Mac48Address &recipient, uint8_t tid, uint16_t startingSeq)
void CreateOriginatorAgreement(const MgtAddBaRequestHeader &reqHdr, const Mac48Address &recipient, bool htSupported=true)
std::pair< Mac48Address, uint8_t > AgreementKey
agreement key typedef (MAC address and TID)
void UpdateOriginatorAgreement(const MgtAddBaResponseHeader &respHdr, const Mac48Address &recipient, uint16_t startingSeq)
Callback< void, Mac48Address, uint8_t > m_unblockPackets
unblock packets callback
OriginatorAgreements::iterator OriginatorAgreementsI
typedef for an iterator for Agreements
void SetQueue(const Ptr< WifiMacQueue > queue)
void DestroyRecipientAgreement(const Mac48Address &originator, uint8_t tid)
Destroy a recipient Block Ack agreement.
void SetTxOkCallback(TxOk callback)
void InactivityTimeout(const Mac48Address &recipient, uint8_t tid)
Inactivity timeout function.
uint8_t m_blockAckThreshold
block ack threshold
std::list< Ptr< WifiMpdu > > PacketQueue
typedef for a list of WifiMpdu.
RecipientAgreements m_recipientAgreements
Recipient Block Ack agreements.
std::optional< std::reference_wrapper< const OriginatorBlockAckAgreement > > OriginatorAgreementOptConstRef
optional const reference to OriginatorBlockAckAgreement
static TypeId GetTypeId()
Get the type ID.
TracedCallback< Time, Mac48Address, uint8_t, OriginatorBlockAckAgreement::State > m_originatorAgreementState
The trace source fired when a state transition occurred.
void SetBlockAckThreshold(uint8_t nPackets)
DroppedOldMpdu m_droppedOldMpduCallback
the dropped MPDU callback
std::map< AgreementKey, RecipientBlockAckAgreement > RecipientAgreements
AgreementKey-indexed map of recipient block ack agreements.
std::optional< std::reference_wrapper< const RecipientBlockAckAgreement > > RecipientAgreementOptConstRef
optional const reference to RecipientBlockAckAgreement
void SetDroppedOldMpduCallback(DroppedOldMpdu callback)
TxFailed m_txFailedCallback
transmit failed callback
void SetUnblockDestinationCallback(Callback< void, Mac48Address, uint8_t > callback)
Set unblock destination callback.
void NotifyOriginatorAgreementRejected(const Mac48Address &recipient, uint8_t tid)
Ptr< WifiMacQueue > m_queue
queue
uint16_t GetRecipientBufferSize(const Mac48Address &recipient, uint8_t tid) const
This function returns the buffer size negotiated with the recipient.
void CreateRecipientAgreement(const MgtAddBaResponseHeader &respHdr, const Mac48Address &originator, uint16_t startingSeq, bool htSupported, Ptr< MacRxMiddle > rxMiddle)
void ScheduleBar(Ptr< WifiMpdu > bar)
void ScheduleMuBar(Ptr< WifiMpdu > muBar)
void NotifyOriginatorAgreementNoReply(const Mac48Address &recipient, uint8_t tid)
void NotifyMissedBlockAck(uint8_t linkId, const Mac48Address &recipient, uint8_t tid)
OriginatorAgreements m_originatorAgreements
This data structure contains, for each originator block ack agreement (recipient, TID),...
void StorePacket(Ptr< WifiMpdu > mpdu)
void NotifyOriginatorAgreementReset(const Mac48Address &recipient, uint8_t tid)
void RemoveFromSendBarIfDataQueuedList(const Mac48Address &recipient, uint8_t tid)
Remove the given (recipient, TID) pair from the list of BA agreements for which a BAR shall only be s...
void NotifyGotAck(uint8_t linkId, Ptr< const WifiMpdu > mpdu)
Invoked upon receipt of an Ack frame on the given link after the transmission of a QoS data frame sen...
void AddToSendBarIfDataQueuedList(const Mac48Address &recipient, uint8_t tid)
Add the given (recipient, TID) pair to the list of BA agreements for which a BAR shall only be sent i...
void NotifyDiscardedMpdu(Ptr< const WifiMpdu > mpdu)
void NotifyGotMpdu(Ptr< const WifiMpdu > mpdu)
Callback< void, Ptr< const WifiMpdu > > TxFailed
typedef for a callback to invoke when an MPDU is negatively ack'ed.
bool NeedBarRetransmission(uint8_t tid, const Mac48Address &recipient)
This function returns true if a block ack agreement is established with the given recipient for the g...
Callback< void, Ptr< const WifiMpdu > > TxOk
typedef for a callback to invoke when an MPDU is successfully ack'ed.
void SetBlockDestinationCallback(Callback< void, Mac48Address, uint8_t > callback)
Set block destination callback.
BlockAckManager & operator=(const BlockAckManager &)=delete
std::list< AgreementKey > m_sendBarIfDataQueued
list of BA agreements for which a BAR shall only be sent if data is queued
std::list< Ptr< WifiMpdu > >::iterator PacketQueueI
typedef for an iterator for PacketQueue.
uint32_t GetNBufferedPackets(const Mac48Address &recipient, uint8_t tid) const
PacketQueueI HandleInFlightMpdu(uint8_t linkId, PacketQueueI mpduIt, MpduStatus status, const OriginatorAgreementsI &it, const Time &now)
Handle the given in flight MPDU based on its given status.
std::map< AgreementKey, std::pair< OriginatorBlockAckAgreement, PacketQueue > > OriginatorAgreements
AgreementKey-indexed map of originator block ack agreements.
void SetBlockAckInactivityCallback(Callback< void, Mac48Address, uint8_t, bool > callback)
Set block ack inactivity callback.
uint16_t GetOriginatorStartingSequence(const Mac48Address &recipient, uint8_t tid) const
This function returns the starting sequence number of the transmit window.
BlockAckManager(const BlockAckManager &)=delete
Callback< void, Mac48Address, uint8_t, bool > m_blockAckInactivityTimeout
BlockAck inactivity timeout callback.
Callback< void, Ptr< const WifiMpdu > > DroppedOldMpdu
typedef for a callback to invoke when an MPDU is dropped.
TxOk m_txOkCallback
transmit OK callback
MpduStatus
Enumeration for the statuses of a buffered MPDU.
void(* AgreementStateTracedCallback)(Time now, const Mac48Address &recipient, uint8_t tid, OriginatorBlockAckAgreement::State state)
TracedCallback signature for state changes.
std::pair< uint16_t, uint16_t > NotifyGotBlockAck(uint8_t linkId, const CtrlBAckResponseHeader &blockAck, const Mac48Address &recipient, const std::set< uint8_t > &tids, size_t index=0)
void DoDispose() override
Destructor implementation.
Callback< void, Mac48Address, uint8_t > m_blockPackets
block packets callback
void DestroyOriginatorAgreement(const Mac48Address &recipient, uint8_t tid)
OriginatorAgreementOptConstRef GetAgreementAsOriginator(const Mac48Address &recipient, uint8_t tid) const
CtrlBAckRequestHeader GetBlockAckReqHeader(const Mac48Address &recipient, uint8_t tid) const
const std::list< AgreementKey > & GetSendBarIfDataQueuedList() const
void NotifyGotBlockAckRequest(const Mac48Address &originator, uint8_t tid, uint16_t startingSeq)
void NotifyMissedAck(uint8_t linkId, Ptr< WifiMpdu > mpdu)
Invoked upon missed reception of an Ack frame on the given link after the transmission of a QoS data ...
Callback template class.
Definition: callback.h:443
Headers for BlockAckRequest.
Definition: ctrl-headers.h:52
Headers for BlockAck response.
Definition: ctrl-headers.h:203
an EUI-48 address
Definition: mac48-address.h:46
Implement the header for management frames of type Add Block Ack request.
Definition: mgt-headers.h:1511
Implement the header for management frames of type Add Block Ack response.
Definition: mgt-headers.h:1642
A base class which provides memory management and object aggregation.
Definition: object.h:89
State
Represents the state for this agreement.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:60
Every class exported by the ns3 library is enclosed in the ns3 namespace.