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 <list>
26 #include <deque>
27 #include "ns3/packet.h"
28 #include "wifi-mac-header.h"
30 #include "ctrl-headers.h"
31 #include "qos-utils.h"
32 #include "wifi-mode.h"
34 
35 namespace ns3 {
36 
37 class MgtAddBaResponseHeader;
38 class MgtAddBaRequestHeader;
39 class MgtDelBaHeader;
40 class MacTxMiddle;
41 class WifiMacQueue;
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 
76 {
77 private:
80 
81 
82 public:
83  BlockAckManager ();
85 
101  bool ExistsAgreement (Mac48Address recipient, uint8_t tid) const;
112  bool ExistsAgreementInState (Mac48Address recipient, uint8_t tid,
113  enum OriginatorBlockAckAgreement::State state) const;
121  void CreateAgreement (const MgtAddBaRequestHeader *reqHdr, Mac48Address recipient);
129  void DestroyAgreement (Mac48Address recipient, uint8_t tid);
136  void UpdateAgreement (const MgtAddBaResponseHeader *respHdr, Mac48Address recipient);
145  void StorePacket (Ptr<const Packet> packet, const WifiMacHeader &hdr, Time tStamp);
164  bool HasBar (struct Bar &bar);
172  bool HasPackets (void) const;
185  void NotifyGotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient, double rxSnr, WifiMode txMode, double dataSnr);
195  uint32_t GetNBufferedPackets (Mac48Address recipient, uint8_t tid) const;
205  uint32_t GetNRetryNeededPackets (Mac48Address recipient, uint8_t tid) const;
214  void NotifyAgreementEstablished (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
223  void NotifyAgreementUnsuccessful (Mac48Address recipient, uint8_t tid);
234  void NotifyMpduTransmission (Mac48Address recipient, uint8_t tid, uint16_t nextSeqNumber, WifiMacHeader::QosAckPolicy policy);
241  void CompleteAmpduExchange (Mac48Address recipient, uint8_t tid);
248  void SetBlockAckThreshold (uint8_t nPackets);
249 
253  void SetQueue (Ptr<WifiMacQueue> queue);
254  void SetTxMiddle (MacTxMiddle* txMiddle);
255 
261  void SetBlockAckType (enum BlockAckType bAckType);
269  void TearDownBlockAck (Mac48Address recipient, uint8_t tid);
279  bool HasOtherFragments (uint16_t sequenceNumber) const;
285  uint32_t GetNextPacketSize (void) const;
292  void SetMaxPacketDelay (Time maxDelay);
293 
297 
311  bool SwitchToBlockAckIfNeeded (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
322  uint16_t GetSeqNumOfNextRetryPacket (Mac48Address recipient, uint8_t tid) const;
326  bool AlreadyExists (uint16_t currentSeq, Mac48Address recipient, uint8_t tid);
330  bool RemovePacket (uint8_t tid, Mac48Address recipient, uint16_t seqnumber);
331  /*
332  * Peek in retransmit queue and get the next packet having address indicated
333  * by <i>type</i> equals to <i>addr</i>, and tid equals to <i>tid</i>.
334  * This method doesn't remove the packet from this queue.
335  */
336  Ptr<const Packet> PeekNextPacketByTidAndAddress (WifiMacHeader &hdr, Mac48Address recipient, uint8_t tid, Time *timestamp);
341  bool NeedBarRetransmission (uint8_t tid, uint16_t seqNumber, Mac48Address recipient);
342 
357  void SetTxOkCallback (TxOk callback);
362  void SetTxFailedCallback (TxFailed callback);
363 
364 
365 private:
377  Ptr<Packet> ScheduleBlockAckReqIfNeeded (Mac48Address recipient, uint8_t tid);
378 
382  void CleanupBuffers (void);
383  void InactivityTimeout (Mac48Address, uint8_t);
384 
385  struct Item;
389  typedef std::list<Item> PacketQueue;
393  typedef std::list<Item>::iterator PacketQueueI;
397  typedef std::list<Item>::const_iterator PacketQueueCI;
401  typedef std::map<std::pair<Mac48Address, uint8_t>,
402  std::pair<OriginatorBlockAckAgreement, PacketQueue> > Agreements;
406  typedef std::map<std::pair<Mac48Address, uint8_t>,
407  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::iterator AgreementsI;
411  typedef std::map<std::pair<Mac48Address, uint8_t>,
412  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::const_iterator AgreementsCI;
413 
418  struct Item
419  {
420  Item ();
421  Item (Ptr<const Packet> packet,
422  const WifiMacHeader &hdr,
423  Time tStamp);
427  };
434  void InsertInRetryQueue (PacketQueueI item);
435 
442  Agreements m_agreements;
443 
449  std::list<PacketQueueI> m_retryPackets;
450  std::list<Bar> m_bars;
451 
464 };
465 
466 } //namespace ns3
467 
468 #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)
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)
void StorePacket(Ptr< const Packet > packet, const WifiMacHeader &hdr, Time tStamp)
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:667
bool HasBar(struct Bar &bar)
void InactivityTimeout(Mac48Address, uint8_t)
std::map< std::pair< Mac48Address, uint8_t >, std::pair< OriginatorBlockAckAgreement, PacketQueue > >::iterator AgreementsI
typedef for an iterator for Agreements.
void SetBlockAckType(enum BlockAckType bAckType)
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:99
Handles sequence numbering of IEEE 802.11 data frames.
Definition: mac-tx-middle.h:39
void SetTxFailedCallback(TxFailed callback)
Ptr< Packet > ScheduleBlockAckReqIfNeeded(Mac48Address recipient, uint8_t tid)
void SetQueue(Ptr< WifiMacQueue > queue)
void NotifyAgreementEstablished(Mac48Address recipient, uint8_t tid, uint16_t startingSeq)
void UpdateAgreement(const MgtAddBaResponseHeader *respHdr, Mac48Address recipient)
uint32_t GetNRetryNeededPackets(Mac48Address recipient, uint8_t tid) const
uint32_t GetNextPacketSize(void) const
uint16_t GetSeqNumOfNextRetryPacket(Mac48Address recipient, uint8_t tid) const
void NotifyAgreementUnsuccessful(Mac48Address recipient, uint8_t tid)
void SetWifiRemoteStationManager(Ptr< WifiRemoteStationManager > manager)
Set up WifiRemoteStationManager associated with this BlockAckManager.
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:186
void SetTxMiddle(MacTxMiddle *txMiddle)
void SetBlockDestinationCallback(Callback< void, Mac48Address, uint8_t > callback)
void DestroyAgreement(Mac48Address recipient, uint8_t tid)
void SetTxOkCallback(TxOk callback)
Mac48Address recipient
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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
QosAckPolicy
ACK policy for QoS frames.
bool ExistsAgreementInState(Mac48Address recipient, uint8_t tid, enum OriginatorBlockAckAgreement::State state) const
Callback< void, Mac48Address, uint8_t > m_blockPackets
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.
bool AlreadyExists(uint16_t currentSeq, Mac48Address recipient, uint8_t tid)
Checks if the packet already exists in the retransmit queue or not if it does then it doesn't add it ...
Ptr< const Packet > GetNextPacket(WifiMacHeader &hdr)
void SetBlockAckInactivityCallback(Callback< void, Mac48Address, uint8_t, bool > 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.
BlockAckManager & operator=(const BlockAckManager &)
Callback< void, Mac48Address, uint8_t > m_unblockPackets
uint32_t GetNBufferedPackets(Mac48Address recipient, uint8_t tid) const
std::list< Bar > m_bars
enum BlockAckType m_blockAckType
void CleanupBuffers(void)
This method removes packets whose lifetime was exceeded.
void SetBlockAckThreshold(uint8_t nPackets)
Implement the header for management frames of type add block ack response.
Definition: mgt-headers.h:799
void CompleteAmpduExchange(Mac48Address recipient, uint8_t tid)
Ptr< const Packet > bar
State
Represents the state for this agreement.
Manages all block ack agreements for an originator station.
bool ExistsAgreement(Mac48Address recipient, uint8_t tid) const
Ptr< WifiRemoteStationManager > m_stationManager
Ptr< const Packet > packet
Implements the IEEE 802.11 MAC header.
void TearDownBlockAck(Mac48Address recipient, uint8_t tid)
Ptr< WifiMacQueue > m_queue
std::list< Item >::iterator PacketQueueI
typedef for an iterator for PacketQueue.