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 
32 namespace ns3 {
33 
34 class WifiRemoteStationManager;
35 class MgtAddBaResponseHeader;
36 class MgtAddBaRequestHeader;
37 class CtrlBAckResponseHeader;
38 class MacTxMiddle;
39 class WifiMacQueue;
40 class WifiMode;
41 class Packet;
42 
48 struct Bar
49 {
50  Bar ();
60  Bar (Ptr<const Packet> packet,
62  uint8_t tid,
63  bool immediate);
66  uint8_t tid;
67  bool immediate;
68 };
69 
70 
75 class BlockAckManager : public Object
76 {
77 private:
86 
87 
88 public:
93  static TypeId GetTypeId (void);
94 
95  BlockAckManager ();
97 
113  bool ExistsAgreement (Mac48Address recipient, uint8_t tid) const;
124  bool ExistsAgreementInState (Mac48Address recipient, uint8_t tid,
133  void CreateAgreement (const MgtAddBaRequestHeader *reqHdr, Mac48Address recipient);
141  void DestroyAgreement (Mac48Address recipient, uint8_t tid);
148  void UpdateAgreement (const MgtAddBaResponseHeader *respHdr, Mac48Address recipient);
164  bool HasBar (Bar &bar, bool remove = true);
172  bool HasPackets (void) const;
203  void NotifyGotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, WifiMode txMode, double dataSnr);
212  void NotifyMissedBlockAck (Mac48Address recipient, uint8_t tid);
221  void DiscardOutstandingMpdus (Mac48Address recipient, uint8_t tid);
231  uint32_t GetNBufferedPackets (Mac48Address recipient, uint8_t tid) const;
240  void NotifyAgreementEstablished (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
249  void NotifyAgreementRejected (Mac48Address recipient, uint8_t tid);
258  void NotifyAgreementNoReply (Mac48Address recipient, uint8_t tid);
265  void NotifyAgreementReset (Mac48Address recipient, uint8_t tid);
276  void NotifyMpduTransmission (Mac48Address recipient, uint8_t tid, uint16_t nextSeqNumber, WifiMacHeader::QosAckPolicy policy);
283  void SetBlockAckThreshold (uint8_t nPackets);
290 
294  void SetQueue (const Ptr<WifiMacQueue> queue);
299  void SetTxMiddle (const Ptr<MacTxMiddle> txMiddle);
300 
306  void SetBlockAckType (BlockAckType bAckType);
307 
323 
337  bool SwitchToBlockAckIfNeeded (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
349  bool NeedBarRetransmission (uint8_t tid, uint16_t seqNumber, Mac48Address recipient);
358  uint16_t GetRecipientBufferSize (Mac48Address recipient, uint8_t tid) const;
367  uint16_t GetOriginatorStartingSequence (Mac48Address recipient, uint8_t tid) const;
368 
383  void SetTxOkCallback (TxOk callback);
388  void SetTxFailedCallback (TxFailed callback);
389 
398  typedef void (* AgreementStateTracedCallback)(Time now, Mac48Address recipient, uint8_t tid, OriginatorBlockAckAgreement::State state);
399 
411 
421  void ScheduleBlockAckReq (Mac48Address recipient, uint8_t tid);
422 
423 
424 private:
430  void InactivityTimeout (Mac48Address recipient, uint8_t tid);
431 
442  void SetStartingSequence (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
443 
447  typedef std::list<Ptr<WifiMacQueueItem>> PacketQueue;
451  typedef std::list<Ptr<WifiMacQueueItem>>::iterator PacketQueueI;
455  typedef std::list<Ptr<WifiMacQueueItem>>::const_iterator PacketQueueCI;
459  typedef std::map<std::pair<Mac48Address, uint8_t>,
460  std::pair<OriginatorBlockAckAgreement, PacketQueue> > Agreements;
464  typedef std::map<std::pair<Mac48Address, uint8_t>,
465  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::iterator AgreementsI;
469  typedef std::map<std::pair<Mac48Address, uint8_t>,
470  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::const_iterator AgreementsCI;
471 
479 
488  void RemoveFromRetryQueue (Mac48Address address, uint8_t tid, uint16_t seq);
489 
499  void RemoveFromRetryQueue (Mac48Address address, uint8_t tid, uint16_t startSeq, uint16_t endSeq);
500 
508 
515  std::list<Bar> m_bars;
516 
528 
533 };
534 
535 } //namespace ns3
536 
537 #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.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void NotifyGotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, WifiMode txMode, double dataSnr)
Callback template class.
Definition: callback.h:1176
void NotifyMissedBlockAck(Mac48Address recipient, uint8_t tid)
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
TracedCallback< Time, Mac48Address, uint8_t, OriginatorBlockAckAgreement::State > m_agreementState
The trace source fired when a state transition occured.
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:997
std::map< std::pair< Mac48Address, uint8_t >, std::pair< OriginatorBlockAckAgreement, PacketQueue > >::iterator AgreementsI
typedef for an iterator for Agreements.
void ScheduleBlockAckReq(Mac48Address recipient, uint8_t tid)
Block Ack Request.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
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 NotifyDiscardedMpdu(Ptr< const WifiMacQueueItem > mpdu)
Ptr< WifiMacQueue > GetRetransmitQueue(void)
bool immediate
immediate
void NotifyAgreementEstablished(Mac48Address recipient, uint8_t tid, uint16_t startingSeq)
void UpdateAgreement(const MgtAddBaResponseHeader *respHdr, Mac48Address recipient)
void SetQueue(const Ptr< WifiMacQueue > queue)
void SetBlockAckType(BlockAckType bAckType)
void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > manager)
Set up WifiRemoteStationManager associated with this BlockAckManager.
static TypeId GetTypeId(void)
Get the type ID.
Headers for Block ack response.
Definition: ctrl-headers.h:193
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.
Ptr< MacTxMiddle > m_txMiddle
the MacTxMiddle
void SetBlockDestinationCallback(Callback< void, Mac48Address, uint8_t > callback)
Set block destination callback.
void DestroyAgreement(Mac48Address recipient, uint8_t tid)
void SetTxOkCallback(TxOk callback)
bool HasBar(Bar &bar, bool remove=true)
Returns true if the BAR is scheduled.
uint16_t GetRecipientBufferSize(Mac48Address recipient, uint8_t tid) const
This function returns the buffer size negociated with the recipient.
void InsertInRetryQueue(Ptr< WifiMacQueueItem > mpdu)
Mac48Address recipient
recipient
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:37
void InactivityTimeout(Mac48Address recipient, uint8_t tid)
Inactivity timeout function.
Callback< void, Mac48Address, uint8_t, bool > m_blockAckInactivityTimeout
block ack 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 SetStartingSequence(Mac48Address recipient, uint8_t tid, uint16_t startingSeq)
Set the starting sequence number for the agreement with recipient equal to recipient and TID equal to...
void StorePacket(Ptr< WifiMacQueueItem > mpdu)
Callback< void, const WifiMacHeader & > TxOk
typedef for a callback to invoke when a packet transmission was completed successfully.
an EUI-48 address
Definition: mac48-address.h:43
std::list< Ptr< WifiMacQueueItem > > PacketQueue
typedef for a list of WifiMacQueueItem.
Callback< void, const WifiMacHeader & > TxFailed
typedef for a callback to invoke when a packet transmission was failed.
Ptr< WifiMacQueue > m_retryPackets
This list contains all iterators to stored packets that need to be retransmitted. ...
State
Represents the state for this agreement.
QosAckPolicy
ACK policy for QoS frames.
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.
void NotifyMpduTransmission(Mac48Address recipient, uint8_t tid, uint16_t nextSeqNumber, WifiMacHeader::QosAckPolicy policy)
bool NeedBarRetransmission(uint8_t tid, uint16_t seqNumber, Mac48Address recipient)
This function returns true if the lifetime of the packets a BAR refers to didn&#39;t expire yet otherwise...
bool SwitchToBlockAckIfNeeded(Mac48Address recipient, uint8_t tid, uint16_t startingSeq)
Callback< void, Mac48Address, uint8_t > m_unblockPackets
unblock packets callback
bool HasPackets(void) const
Returns true if there are packets that need of retransmission or at least a BAR is scheduled...
std::list< Bar > m_bars
list of BARs
void SetTxMiddle(const Ptr< MacTxMiddle > txMiddle)
Set the MacTxMiddle.
uint8_t tid
TID.
void SetBlockAckThreshold(uint8_t nPackets)
Implement the header for management frames of type add block ack response.
Definition: mgt-headers.h:1129
BlockAckType m_blockAckType
block ack type
Ptr< const Packet > bar
block ack request
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
Mac48Address m_address
address
Manages all block ack agreements for an originator station.
TxFailed m_txFailedCallback
transmit failed callback
Ptr< WifiRemoteStationManager > m_stationManager
the station manager
a unique identifier for an interface.
Definition: type-id.h:58
Ptr< WifiMacQueue > m_queue
queue
BlockAckType
The different block ACK policies.