A Discrete-Event Network Simulator
API
block-ack-manager.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009, 2010 MIRKO BANCHI
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mirko Banchi <mk.banchi@gmail.com>
19  */
20 
21 #ifndef BLOCK_ACK_MANAGER_H
22 #define BLOCK_ACK_MANAGER_H
23 
24 #include <map>
25 #include "ns3/nstime.h"
26 #include "ns3/traced-callback.h"
27 #include "wifi-mac-header.h"
29 #include "block-ack-type.h"
30 #include "wifi-mac-queue-item.h"
31 #include "wifi-tx-vector.h"
32 
33 namespace ns3 {
34 
35 class WifiRemoteStationManager;
36 class MgtAddBaResponseHeader;
37 class MgtAddBaRequestHeader;
38 class CtrlBAckResponseHeader;
39 class CtrlBAckRequestHeader;
40 class WifiMacQueue;
41 class WifiMode;
42 class Packet;
43 
49 struct Bar
50 {
51  Bar ();
59  Bar (Ptr<const WifiMacQueueItem> bar, uint8_t tid, bool skipIfNoDataQueued = false);
61  uint8_t tid;
63 };
64 
65 
70 class BlockAckManager : public Object
71 {
72 private:
81 
82 
83 public:
88  static TypeId GetTypeId (void);
89 
90  BlockAckManager ();
92 
108  bool ExistsAgreement (Mac48Address recipient, uint8_t tid) const;
119  bool ExistsAgreementInState (Mac48Address recipient, uint8_t tid,
128  void CreateAgreement (const MgtAddBaRequestHeader *reqHdr, Mac48Address recipient);
136  void DestroyAgreement (Mac48Address recipient, uint8_t tid);
144  void UpdateAgreement (const MgtAddBaResponseHeader *respHdr, Mac48Address recipient,
145  uint16_t startingSeq);
165  Ptr<const WifiMacQueueItem> GetBar (bool remove = true, uint8_t tid = 8,
174  bool HasPackets (void);
210  void NotifyGotBlockAck (const CtrlBAckResponseHeader& blockAck, Mac48Address recipient,
211  const std::set<uint8_t>& tids, double rxSnr, double dataSnr,
212  const WifiTxVector& dataTxVector, size_t index = 0);
221  void NotifyMissedBlockAck (Mac48Address recipient, uint8_t tid);
230  void DiscardOutstandingMpdus (Mac48Address recipient, uint8_t tid);
240  uint32_t GetNBufferedPackets (Mac48Address recipient, uint8_t tid) const;
249  void NotifyAgreementEstablished (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
258  void NotifyAgreementRejected (Mac48Address recipient, uint8_t tid);
267  void NotifyAgreementNoReply (Mac48Address recipient, uint8_t tid);
274  void NotifyAgreementReset (Mac48Address recipient, uint8_t tid);
281  void SetBlockAckThreshold (uint8_t nPackets);
288 
292  void SetQueue (const Ptr<WifiMacQueue> queue);
293 
309 
323  bool SwitchToBlockAckIfNeeded (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
334  bool NeedBarRetransmission (uint8_t tid, Mac48Address recipient);
343  uint16_t GetRecipientBufferSize (Mac48Address recipient, uint8_t tid) const;
352  BlockAckReqType GetBlockAckReqType (Mac48Address recipient, uint8_t tid) const;
361  BlockAckType GetBlockAckType (Mac48Address recipient, uint8_t tid) const;
370  uint16_t GetOriginatorStartingSequence (Mac48Address recipient, uint8_t tid) const;
371 
384  void SetTxOkCallback (TxOk callback);
389  void SetTxFailedCallback (TxFailed callback);
390 
399  typedef void (* AgreementStateTracedCallback)(Time now, Mac48Address recipient, uint8_t tid, OriginatorBlockAckAgreement::State state);
400 
412 
421  CtrlBAckRequestHeader GetBlockAckReqHeader (Mac48Address recipient, uint8_t tid) const;
422 
432  void ScheduleBar (Ptr<const WifiMacQueueItem> bar, bool skipIfNoDataQueued = false);
433 
434 private:
440  void InactivityTimeout (Mac48Address recipient, uint8_t tid);
441 
452  void RemoveOldPackets (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
453 
457  typedef std::list<Ptr<WifiMacQueueItem>> PacketQueue;
461  typedef std::list<Ptr<WifiMacQueueItem>>::iterator PacketQueueI;
465  typedef std::list<Ptr<WifiMacQueueItem>>::const_iterator PacketQueueCI;
469  typedef std::map<std::pair<Mac48Address, uint8_t>,
470  std::pair<OriginatorBlockAckAgreement, PacketQueue> > Agreements;
474  typedef std::map<std::pair<Mac48Address, uint8_t>,
475  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::iterator AgreementsI;
479  typedef std::map<std::pair<Mac48Address, uint8_t>,
480  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::const_iterator AgreementsCI;
481 
489 
498  void RemoveFromRetryQueue (Mac48Address address, uint8_t tid, uint16_t seq);
499 
509  void RemoveFromRetryQueue (Mac48Address address, uint8_t tid, uint16_t startSeq, uint16_t endSeq);
510 
518 
525  std::list<Bar> m_bars;
526 
535 
540 };
541 
542 } //namespace ns3
543 
544 #endif /* BLOCK_ACK_MANAGER_H */
std::map< std::pair< Mac48Address, uint8_t >, std::pair< OriginatorBlockAckAgreement, PacketQueue > > Agreements
typedef for a map between MAC address and block ack agreement.
void SetUnblockDestinationCallback(Callback< void, Mac48Address, uint8_t > callback)
Set unblock destination callback.
Callback< void, Ptr< const WifiMacQueueItem > > TxOk
typedef for a callback to invoke when an MPDU is successfully ack&#39;ed.
BlockAckType GetBlockAckType(Mac48Address recipient, uint8_t tid) const
This function returns the type of Block Acks sent by the recipient.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Callback template class.
Definition: callback.h:1278
void NotifyMissedBlockAck(Mac48Address recipient, uint8_t tid)
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void RemoveOldPackets(Mac48Address recipient, uint8_t tid, uint16_t startingSeq)
Remove packets from the retransmit queue and from the queue of outstanding packets that become old af...
std::list< Ptr< WifiMacQueueItem > >::iterator PacketQueueI
typedef for an iterator for PacketQueue.
std::map< std::pair< Mac48Address, uint8_t >, std::pair< OriginatorBlockAckAgreement, PacketQueue > >::const_iterator AgreementsCI
typedef for a const iterator for Agreements.
void CreateAgreement(const MgtAddBaRequestHeader *reqHdr, Mac48Address recipient)
uint32_t GetNBufferedPackets(Mac48Address recipient, uint8_t tid) const
void ScheduleBar(Ptr< const WifiMacQueueItem > bar, bool skipIfNoDataQueued=false)
TracedCallback< Time, Mac48Address, uint8_t, OriginatorBlockAckAgreement::State > m_agreementState
The trace source fired when a state transition occurred.
uint8_t m_blockAckThreshold
block ack threshold
Agreements m_agreements
This data structure contains, for each block ack agreement (recipient, TID), a set of packets for whi...
Forward calls to a chain of Callback.
void NotifyMissedAck(Ptr< WifiMacQueueItem > mpdu)
Invoked upon missed reception of an Ack frame after the transmission of a QoS data frame sent under a...
Implement the header for management frames of type Add Block Ack request.
Definition: mgt-headers.h:990
std::map< std::pair< Mac48Address, uint8_t >, std::pair< OriginatorBlockAckAgreement, PacketQueue > >::iterator AgreementsI
typedef for an iterator for Agreements.
BlockAckReqType GetBlockAckReqType(Mac48Address recipient, uint8_t tid) const
This function returns the type of Block Acks sent to the recipient.
The different BlockAckRequest variants.
CtrlBAckRequestHeader GetBlockAckReqHeader(Mac48Address recipient, uint8_t tid) const
BlockAckRequest frame information.
TxOk m_txOkCallback
transmit OK callback
bool ExistsAgreementInState(Mac48Address recipient, uint8_t tid, OriginatorBlockAckAgreement::State state) const
void RemoveFromRetryQueue(Mac48Address address, uint8_t tid, uint16_t seq)
Remove an item from retransmission queue.
void SetTxFailedCallback(TxFailed callback)
void NotifyGotBlockAck(const CtrlBAckResponseHeader &blockAck, Mac48Address recipient, const std::set< uint8_t > &tids, double rxSnr, double dataSnr, const WifiTxVector &dataTxVector, size_t index=0)
void NotifyDiscardedMpdu(Ptr< const WifiMacQueueItem > mpdu)
Ptr< WifiMacQueue > GetRetransmitQueue(void)
void NotifyAgreementEstablished(Mac48Address recipient, uint8_t tid, uint16_t startingSeq)
void SetQueue(const Ptr< WifiMacQueue > queue)
void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > manager)
Set up WifiRemoteStationManager associated with this BlockAckManager.
static TypeId GetTypeId(void)
Get the type ID.
static Mac48Address GetBroadcast(void)
Headers for BlockAck response.
Definition: ctrl-headers.h:201
void NotifyAgreementRejected(Mac48Address recipient, uint8_t tid)
bool ExistsAgreement(Mac48Address recipient, uint8_t tid) const
std::list< Ptr< WifiMacQueueItem > >::const_iterator PacketQueueCI
typedef for a const iterator for PacketQueue.
void SetBlockDestinationCallback(Callback< void, Mac48Address, uint8_t > callback)
Set block destination callback.
bool NeedBarRetransmission(uint8_t tid, Mac48Address recipient)
This function returns true if a block ack agreement is established with the given recipient for the g...
void DestroyAgreement(Mac48Address recipient, uint8_t tid)
void SetTxOkCallback(TxOk callback)
bool HasPackets(void)
Returns true if there are packets that need of retransmission or at least a BAR is scheduled...
uint16_t GetRecipientBufferSize(Mac48Address recipient, uint8_t tid) const
This function returns the buffer size negotiated with the recipient.
void InsertInRetryQueue(Ptr< WifiMacQueueItem > mpdu)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:44
void InactivityTimeout(Mac48Address recipient, uint8_t tid)
Inactivity timeout function.
Callback< void, Mac48Address, uint8_t, bool > m_blockAckInactivityTimeout
BlockAck inactivity timeout callback.
void NotifyGotAck(Ptr< const WifiMacQueueItem > mpdu)
Invoked upon receipt of an Ack frame after the transmission of a QoS data frame sent under an establi...
void DiscardOutstandingMpdus(Mac48Address recipient, uint8_t tid)
Callback< void, Mac48Address, uint8_t > m_blockPackets
block packets callback
void StorePacket(Ptr< WifiMacQueueItem > mpdu)
an EUI-48 address
Definition: mac48-address.h:43
std::list< Ptr< WifiMacQueueItem > > PacketQueue
typedef for a list of WifiMacQueueItem.
Ptr< WifiMacQueue > m_retryPackets
This list contains all iterators to stored packets that need to be retransmitted. ...
State
Represents the state for this agreement.
void NotifyAgreementReset(Mac48Address recipient, uint8_t tid)
void SetBlockAckInactivityCallback(Callback< void, Mac48Address, uint8_t, bool > callback)
Set block ack inactivity callback.
uint16_t GetOriginatorStartingSequence(Mac48Address recipient, uint8_t tid) const
This function returns the starting sequence number of the transmit window.
bool SwitchToBlockAckIfNeeded(Mac48Address recipient, uint8_t tid, uint16_t startingSeq)
Callback< void, Mac48Address, uint8_t > m_unblockPackets
unblock packets callback
The different BlockAck variants.
std::list< Bar > m_bars
list of BARs
Ptr< const WifiMacQueueItem > bar
BlockAckRequest or MU-BAR Trigger Frame.
uint8_t tid
TID (unused if MU-BAR)
void SetBlockAckThreshold(uint8_t nPackets)
Implement the header for management frames of type Add Block Ack response.
Definition: mgt-headers.h:1122
void UpdateAgreement(const MgtAddBaResponseHeader *respHdr, Mac48Address recipient, uint16_t startingSeq)
void NotifyAgreementNoReply(Mac48Address recipient, uint8_t tid)
void(* AgreementStateTracedCallback)(Time now, Mac48Address recipient, uint8_t tid, OriginatorBlockAckAgreement::State state)
TracedCallback signature for state changes.
BlockAckManager & operator=(const BlockAckManager &block)
assignment operator
A base class which provides memory management and object aggregation.
Definition: object.h:87
Callback< void, Ptr< const WifiMacQueueItem > > TxFailed
typedef for a callback to invoke when an MPDU is negatively ack&#39;ed.
Manages all block ack agreements for an originator station.
Headers for BlockAckRequest.
Definition: ctrl-headers.h:48
TxFailed m_txFailedCallback
transmit failed callback
Ptr< const WifiMacQueueItem > GetBar(bool remove=true, uint8_t tid=8, Mac48Address recipient=Mac48Address::GetBroadcast())
Returns the next BlockAckRequest or MU-BAR Trigger Frame to send, if any.
Ptr< WifiRemoteStationManager > m_stationManager
the station manager
a unique identifier for an interface.
Definition: type-id.h:58
bool skipIfNoDataQueued
do not send if there is no data queued (unused if MU-BAR)
Ptr< WifiMacQueue > m_queue
queue