A Discrete-Event Network Simulator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
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  */
23 #include <map>
24 #include <list>
25 #include <deque>
27 #include "ns3/packet.h"
29 #include "wifi-mac-header.h"
31 #include "ctrl-headers.h"
32 #include "qos-utils.h"
34 namespace ns3 {
36 class MgtAddBaResponseHeader;
37 class MgtAddBaRequestHeader;
38 class MgtDelBaHeader;
39 class MacTxMiddle;
40 class WifiMacQueue;
47 struct Bar
48 {
49  Bar ();
59  Bar (Ptr<const Packet> packet,
61  uint8_t tid,
62  bool immediate);
65  uint8_t tid;
66  bool immediate;
67 };
74 {
75 private:
79 public:
80  BlockAckManager ();
90  bool ExistsAgreement (Mac48Address recipient, uint8_t tid) const;
100  bool ExistsAgreementInState (Mac48Address recipient, uint8_t tid,
101  enum OriginatorBlockAckAgreement::State state) const;
109  void CreateAgreement (const MgtAddBaRequestHeader *reqHdr, Mac48Address recipient);
117  void DestroyAgreement (Mac48Address recipient, uint8_t tid);
124  void UpdateAgreement (const MgtAddBaResponseHeader *respHdr, Mac48Address recipient);
133  void StorePacket (Ptr<const Packet> packet, const WifiMacHeader &hdr, Time tStamp);
142  bool HasBar (struct Bar &bar);
150  bool HasPackets (void) const;
160  void NotifyGotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient);
169  uint32_t GetNBufferedPackets (Mac48Address recipient, uint8_t tid) const;
178  uint32_t GetNRetryNeededPackets (Mac48Address recipient, uint8_t tid) const;
187  void NotifyAgreementEstablished (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
196  void NotifyAgreementUnsuccessful (Mac48Address recipient, uint8_t tid);
206  void NotifyMpduTransmission (Mac48Address recipient, uint8_t tid, uint16_t nextSeqNumber);
213  void SetBlockAckThreshold (uint8_t nPackets);
217  void SetQueue (Ptr<WifiMacQueue> queue);
218  void SetTxMiddle (MacTxMiddle* txMiddle);
224  void SetBlockAckType (enum BlockAckType bAckType);
232  void TearDownBlockAck (Mac48Address recipient, uint8_t tid);
242  bool HasOtherFragments (uint16_t sequenceNumber) const;
248  uint32_t GetNextPacketSize (void) const;
255  void SetMaxPacketDelay (Time maxDelay);
273  bool SwitchToBlockAckIfNeeded (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
283  uint16_t GetSeqNumOfNextRetryPacket (Mac48Address recipient, uint8_t tid) const;
284 private:
295  Ptr<Packet> ScheduleBlockAckReqIfNeeded (Mac48Address recipient, uint8_t tid);
299  void CleanupBuffers (void);
300  void InactivityTimeout (Mac48Address, uint8_t);
302  struct Item;
306  typedef std::list<Item> PacketQueue;
310  typedef std::list<Item>::iterator PacketQueueI;
314  typedef std::list<Item>::const_iterator PacketQueueCI;
319  typedef std::map<std::pair<Mac48Address, uint8_t>,
320  std::pair<OriginatorBlockAckAgreement, PacketQueue> > Agreements;
324  typedef std::map<std::pair<Mac48Address, uint8_t>,
325  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::iterator AgreementsI;
329  typedef std::map<std::pair<Mac48Address, uint8_t>,
330  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::const_iterator AgreementsCI;
336  struct Item
337  {
338  Item ();
339  Item (Ptr<const Packet> packet,
340  const WifiMacHeader &hdr,
341  Time tStamp);
345  };
359  std::list<PacketQueueI> m_retryPackets;
360  std::list<Bar> m_bars;
371 };
373 } // namespace ns3
375 #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)
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
Callback template class.
Definition: callback.h:920
std::list< Item > PacketQueue
typedef for a list of Item struct.
void NotifyGotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address recipient)
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)
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:454
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...
Enumeration for different block ACK policies.
Definition: ctrl-headers.h:30
Block Ack Request.
Handles sequence numbering of IEEE 802.11 data frames.
Definition: mac-tx-middle.h:39
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)
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:183
void SetTxMiddle(MacTxMiddle *txMiddle)
void SetBlockDestinationCallback(Callback< void, Mac48Address, uint8_t > callback)
void DestroyAgreement(Mac48Address recipient, uint8_t tid)
Mac48Address recipient
Callback< void, Mac48Address, uint8_t, bool > m_blockAckInactivityTimeout
bool ExistsAgreementInState(Mac48Address recipient, uint8_t tid, enum OriginatorBlockAckAgreement::State state) const
Callback< void, Mac48Address, uint8_t > m_blockPackets
an EUI-48 address
Definition: mac48-address.h:41
Ptr< const Packet > GetNextPacket(WifiMacHeader &hdr)
Represents the state for this agreement.
void SetBlockAckInactivityCallback(Callback< void, Mac48Address, uint8_t, bool > callback)
void SetMaxPacketDelay(Time maxDelay)
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:582
Ptr< const Packet > bar
Manages all block ack agreements for an originator station.
bool ExistsAgreement(Mac48Address recipient, uint8_t tid) const
Ptr< const Packet > packet
void NotifyMpduTransmission(Mac48Address recipient, uint8_t tid, uint16_t nextSeqNumber)
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.