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 "wifi-mac-header.h"
26 #include "ctrl-headers.h"
27 #include "qos-utils.h"
29 #include <map>
30 
31 namespace ns3 {
32 
33 class MgtAddBaResponseHeader;
34 class MgtAddBaRequestHeader;
35 class MacTxMiddle;
36 class WifiMacQueue;
37 
43 struct Bar
44 {
45  Bar ();
55  Bar (Ptr<const Packet> packet,
57  uint8_t tid,
58  bool immediate);
61  uint8_t tid;
62  bool immediate;
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);
143  void UpdateAgreement (const MgtAddBaResponseHeader *respHdr, Mac48Address recipient);
152  void StorePacket (Ptr<const Packet> packet, const WifiMacHeader &hdr, Time tStamp);
178  bool HasBar (Bar &bar);
186  bool HasPackets (void) const;
199  void NotifyGotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, WifiMode txMode, double dataSnr);
209  uint32_t GetNBufferedPackets (Mac48Address recipient, uint8_t tid) const;
219  uint32_t GetNRetryNeededPackets (Mac48Address recipient, uint8_t tid) const;
228  void NotifyAgreementEstablished (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
237  void NotifyAgreementUnsuccessful (Mac48Address recipient, uint8_t tid);
248  void NotifyMpduTransmission (Mac48Address recipient, uint8_t tid, uint16_t nextSeqNumber, WifiMacHeader::QosAckPolicy policy);
255  void CompleteAmpduExchange (Mac48Address recipient, uint8_t tid);
262  void SetBlockAckThreshold (uint8_t nPackets);
263 
267  void SetQueue (const Ptr<WifiMacQueue> queue);
272  void SetTxMiddle (const Ptr<MacTxMiddle> txMiddle);
273 
279  void SetBlockAckType (BlockAckType bAckType);
287  void TearDownBlockAck (Mac48Address recipient, uint8_t tid);
297  bool HasOtherFragments (uint16_t sequenceNumber) const;
303  uint32_t GetNextPacketSize (void) const;
310  void SetMaxPacketDelay (Time maxDelay);
311 
327 
341  bool SwitchToBlockAckIfNeeded (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
352  uint16_t GetSeqNumOfNextRetryPacket (Mac48Address recipient, uint8_t tid) const;
361  bool AlreadyExists (uint16_t currentSeq, Mac48Address recipient, uint8_t tid) const;
369  bool RemovePacket (uint8_t tid, Mac48Address recipient, uint16_t seqnumber);
382  Ptr<const Packet> PeekNextPacketByTidAndAddress (WifiMacHeader &hdr, Mac48Address recipient, uint8_t tid, Time *timestamp);
393  bool NeedBarRetransmission (uint8_t tid, uint16_t seqNumber, Mac48Address recipient);
394 
409  void SetTxOkCallback (TxOk callback);
414  void SetTxFailedCallback (TxFailed callback);
415 
416 
417 private:
429  Ptr<Packet> ScheduleBlockAckReqIfNeeded (Mac48Address recipient, uint8_t tid);
430 
434  void CleanupBuffers (void);
440  void InactivityTimeout (Mac48Address recipient, uint8_t tid);
441 
442  struct Item;
446  typedef std::list<Item> PacketQueue;
450  typedef std::list<Item>::iterator PacketQueueI;
454  typedef std::list<Item>::const_iterator PacketQueueCI;
458  typedef std::map<std::pair<Mac48Address, uint8_t>,
459  std::pair<OriginatorBlockAckAgreement, PacketQueue> > Agreements;
463  typedef std::map<std::pair<Mac48Address, uint8_t>,
464  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::iterator AgreementsI;
468  typedef std::map<std::pair<Mac48Address, uint8_t>,
469  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::const_iterator AgreementsCI;
470 
475  struct Item
476  {
477  Item ();
485  Item (Ptr<const Packet> packet,
486  const WifiMacHeader &hdr,
487  Time tStamp);
491  };
498  void InsertInRetryQueue (PacketQueueI item);
499 
508  void RemoveFromRetryQueue (Mac48Address address, uint8_t tid, uint16_t seq);
509 
516  Agreements m_agreements;
517 
523  std::list<PacketQueueI> m_retryPackets;
524  std::list<Bar> m_bars;
525 
538 };
539 
540 } //namespace ns3
541 
542 #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
std::list< Item > PacketQueue
typedef for a list of Item struct.
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)
Ptr< const Packet > PeekNextPacketByTidAndAddress(WifiMacHeader &hdr, Mac48Address recipient, uint8_t tid, Time *timestamp)
Peek in retransmit queue and get the next packet having address indicated by type equals to addr...
void StorePacket(Ptr< const Packet > packet, const WifiMacHeader &hdr, Time tStamp)
uint8_t m_blockAckThreshold
bock ack threshold
Agreements m_agreements
This data structure contains, for each block ack agreement (recipient, tid), a set of packets for whi...
Implement the header for management frames of type add block ack request.
Definition: mgt-headers.h:758
std::map< std::pair< Mac48Address, uint8_t >, std::pair< OriginatorBlockAckAgreement, PacketQueue > >::iterator AgreementsI
typedef for an iterator for Agreements.
bool HasPackets(void) const
Returns true if there are packets that need of retransmission or at least a BAR is scheduled...
BlockAckType
Enumeration for different block ACK policies.
Definition: ctrl-headers.h:31
Ptr< const Packet > PeekNextPacket(WifiMacHeader &hdr)
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
void RemoveFromRetryQueue(Mac48Address address, uint8_t tid, uint16_t seq)
Remove items from retransmission queue.
void SetTxFailedCallback(TxFailed callback)
Ptr< Packet > ScheduleBlockAckReqIfNeeded(Mac48Address recipient, uint8_t tid)
WifiMacHeader hdr
header
bool AlreadyExists(uint16_t currentSeq, Mac48Address recipient, uint8_t tid) const
Checks if the packet already exists in the retransmit queue or not if it does then it doesn't add it ...
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)
uint32_t GetNRetryNeededPackets(Mac48Address recipient, uint8_t tid) const
uint32_t GetNextPacketSize(void) const
void SetBlockAckType(BlockAckType bAckType)
void SetWifiRemoteStationManager(const Ptr< WifiRemoteStationManager > manager)
Set up WifiRemoteStationManager associated with this BlockAckManager.
uint16_t GetSeqNumOfNextRetryPacket(Mac48Address recipient, uint8_t tid) const
void NotifyAgreementUnsuccessful(Mac48Address recipient, uint8_t tid)
static TypeId GetTypeId(void)
Get the type ID.
void InsertInRetryQueue(PacketQueueI item)
bool HasOtherFragments(uint16_t sequenceNumber) const
std::list< PacketQueueI > m_retryPackets
This list contains all iterators to stored packets that need to be retransmitted. ...
Headers for Block ack response.
Definition: ctrl-headers.h:190
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)
Returns true if the BAR is scheduled.
Mac48Address recipient
recipient
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void InactivityTimeout(Mac48Address recipient, uint8_t tid)
Inactivity timeout function.
bool RemovePacket(uint8_t tid, Mac48Address recipient, uint16_t seqnumber)
Remove a packet after you peek in the queue and get it.
Callback< void, Mac48Address, uint8_t, bool > m_blockAckInactivityTimeout
block ack inactivity timeout callback
QosAckPolicy
ACK policy for QoS frames.
Callback< void, Mac48Address, uint8_t > m_blockPackets
block packets callback
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
Callback< void, const WifiMacHeader & > TxFailed
typedef for a callback to invoke when a packet transmission was failed.
Ptr< const Packet > GetNextPacket(WifiMacHeader &hdr)
bool ExistsAgreementInState(Mac48Address recipient, uint8_t tid, OriginatorBlockAckAgreement::State state) const
void SetBlockAckInactivityCallback(Callback< void, Mac48Address, uint8_t, bool > callback)
Set block ack inactivity callback.
void SetMaxPacketDelay(Time maxDelay)
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't expire yet else it r...
A struct for packet, Wifi header, and timestamp.
bool SwitchToBlockAckIfNeeded(Mac48Address recipient, uint8_t tid, uint16_t startingSeq)
std::list< Item >::const_iterator PacketQueueCI
typedef for a const iterator for PacketQueue.
Callback< void, Mac48Address, uint8_t > m_unblockPackets
unblock packets callback
uint32_t GetNBufferedPackets(Mac48Address recipient, uint8_t tid) const
std::list< Bar > m_bars
list of BARs
void CleanupBuffers(void)
This method removes packets whose lifetime was exceeded.
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:890
void CompleteAmpduExchange(Mac48Address recipient, uint8_t tid)
BlockAckType m_blockAckType
bock ack type
Ptr< const Packet > bar
block ack request
State
Represents the state for this agreement.
Time m_maxDelay
maximum delay
BlockAckManager & operator=(const BlockAckManager &block)
assignment operator
A base class which provides memory management and object aggregation.
Definition: object.h:87
tuple address
Definition: first.py:37
Mac48Address m_address
address
Manages all block ack agreements for an originator station.
bool ExistsAgreement(Mac48Address recipient, uint8_t tid) const
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< const Packet > packet
packet
Implements the IEEE 802.11 MAC header.
void TearDownBlockAck(Mac48Address recipient, uint8_t tid)
Ptr< WifiMacQueue > m_queue
queue
std::list< Item >::iterator PacketQueueI
typedef for an iterator for PacketQueue.