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 #include <optional>
36 
37 namespace ns3
38 {
39 
40 class MgtAddBaResponseHeader;
41 class MgtAddBaRequestHeader;
42 class CtrlBAckResponseHeader;
43 class CtrlBAckRequestHeader;
44 class WifiMacQueue;
45 class MacRxMiddle;
46 
51 class BlockAckManager : public Object
52 {
53  private:
57  enum MpduStatus : uint8_t
58  {
62  };
63 
64  public:
69  static TypeId GetTypeId();
70 
72  ~BlockAckManager() override;
73 
74  // Delete copy constructor and assignment operator to avoid misuse
75  BlockAckManager(const BlockAckManager&) = delete;
77 
80  std::optional<std::reference_wrapper<const OriginatorBlockAckAgreement>>;
83  std::optional<std::reference_wrapper<const RecipientBlockAckAgreement>>;
84 
94  uint8_t tid) const;
104  uint8_t tid) const;
105 
115  const Mac48Address& recipient,
116  bool htSupported = true);
124  void DestroyOriginatorAgreement(const Mac48Address& recipient, uint8_t tid);
133  const Mac48Address& recipient,
134  uint16_t startingSeq);
135 
154  const Mac48Address& originator,
155  uint16_t startingSeq,
156  bool htSupported,
157  Ptr<MacRxMiddle> rxMiddle);
164  void DestroyRecipientAgreement(const Mac48Address& originator, uint8_t tid);
165 
172  void StorePacket(Ptr<WifiMpdu> mpdu);
182  void NotifyGotAck(uint8_t linkId, Ptr<const WifiMpdu> mpdu);
192  void NotifyMissedAck(uint8_t linkId, Ptr<WifiMpdu> mpdu);
210  std::pair<uint16_t, uint16_t> NotifyGotBlockAck(uint8_t linkId,
211  const CtrlBAckResponseHeader& blockAck,
212  const Mac48Address& recipient,
213  const std::set<uint8_t>& tids,
214  size_t index = 0);
224  void NotifyMissedBlockAck(uint8_t linkId, const Mac48Address& recipient, uint8_t tid);
232  void NotifyGotBlockAckRequest(const Mac48Address& originator,
233  uint8_t tid,
234  uint16_t startingSeq);
250  uint32_t GetNBufferedPackets(const Mac48Address& recipient, uint8_t tid) const;
260  uint8_t tid,
261  uint16_t startingSeq);
270  void NotifyOriginatorAgreementRejected(const Mac48Address& recipient, uint8_t tid);
279  void NotifyOriginatorAgreementNoReply(const Mac48Address& recipient, uint8_t tid);
287  void NotifyOriginatorAgreementReset(const Mac48Address& recipient, uint8_t tid);
295  void SetBlockAckThreshold(uint8_t nPackets);
296 
300  void SetQueue(const Ptr<WifiMacQueue> queue);
301 
317 
328  bool NeedBarRetransmission(uint8_t tid, const Mac48Address& recipient);
337  uint16_t GetRecipientBufferSize(const Mac48Address& recipient, uint8_t tid) const;
346  uint16_t GetOriginatorStartingSequence(const Mac48Address& recipient, uint8_t tid) const;
347 
360 
365  void SetTxOkCallback(TxOk callback);
370  void SetTxFailedCallback(TxFailed callback);
375 
384  typedef void (*AgreementStateTracedCallback)(Time now,
385  const Mac48Address& recipient,
386  uint8_t tid,
388 
400 
409  CtrlBAckRequestHeader GetBlockAckReqHeader(const Mac48Address& recipient, uint8_t tid) const;
410 
420  void ScheduleBar(const CtrlBAckRequestHeader& reqHdr, const WifiMacHeader& hdr);
421 
423  using AgreementKey = std::pair<Mac48Address, uint8_t>;
424 
429  const std::list<AgreementKey>& GetSendBarIfDataQueuedList() const;
437  void AddToSendBarIfDataQueuedList(const Mac48Address& recipient, uint8_t tid);
445  void RemoveFromSendBarIfDataQueuedList(const Mac48Address& recipient, uint8_t tid);
446 
447  protected:
448  void DoDispose() override;
449 
450  private:
456  void InactivityTimeout(const Mac48Address& recipient, uint8_t tid);
457 
461  typedef std::list<Ptr<WifiMpdu>> PacketQueue;
465  typedef std::list<Ptr<WifiMpdu>>::iterator PacketQueueI;
466 
469  std::map<AgreementKey, std::pair<OriginatorBlockAckAgreement, PacketQueue>>;
471  using OriginatorAgreementsI = OriginatorAgreements::iterator;
472 
474  using RecipientAgreements = std::map<AgreementKey, RecipientBlockAckAgreement>;
475 
491  PacketQueueI HandleInFlightMpdu(uint8_t linkId,
492  PacketQueueI mpduIt,
493  MpduStatus status,
494  const OriginatorAgreementsI& it,
495  const Time& now);
496 
505 
506  std::list<AgreementKey> m_sendBarIfDataQueued;
508 
518 
524 };
525 
526 } // namespace ns3
527 
528 #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 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.
void ScheduleBar(const CtrlBAckRequestHeader &reqHdr, const WifiMacHeader &hdr)
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:438
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.
Implement the header for management frames of type Add Block Ack response.
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:77
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:59
Implements the IEEE 802.11 MAC header.
Every class exported by the ns3 library is enclosed in the ns3 namespace.