A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
block-ack-manager.h
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 #ifndef BLOCK_ACK_MANAGER_H
21 #define BLOCK_ACK_MANAGER_H
22 
23 #include <map>
24 #include <list>
25 #include <deque>
26 
27 #include "ns3/packet.h"
28 
29 #include "wifi-mac-header.h"
30 #include "originator-block-ack-agreement.h"
31 #include "ctrl-headers.h"
32 #include "qos-utils.h"
33 
34 namespace ns3 {
35 
36 class MgtAddBaResponseHeader;
37 class MgtAddBaRequestHeader;
38 class MgtDelBaHeader;
39 class MacTxMiddle;
40 class WifiMacQueue;
41 
47 struct Bar
48 {
49  Bar ();
50  Bar (Ptr<const Packet> packet,
51  Mac48Address recipient,
52  uint8_t tid,
53  bool immediate);
55  Mac48Address recipient;
56  uint8_t tid;
57  bool immediate;
58 };
59 
65 {
66 private:
68  BlockAckManager& operator= (const BlockAckManager&);
69 
70 public:
71  BlockAckManager ();
72  ~BlockAckManager ();
80  bool ExistsAgreement (Mac48Address recipient, uint8_t tid) const;
89  bool ExistsAgreementInState (Mac48Address recipient, uint8_t tid,
90  enum OriginatorBlockAckAgreement::State state) const;
98  void CreateAgreement (const MgtAddBaRequestHeader *reqHdr, Mac48Address recipient);
106  void DestroyAgreement (Mac48Address recipient, uint8_t tid);
113  void UpdateAgreement (const MgtAddBaResponseHeader *respHdr, Mac48Address recipient);
122  void StorePacket (Ptr<const Packet> packet, const WifiMacHeader &hdr, Time tStamp);
130  bool HasBar (struct Bar &bar);
135  bool HasPackets (void) const;
145  void NotifyGotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient);
153  uint32_t GetNBufferedPackets (Mac48Address recipient, uint8_t tid) const;
161  uint32_t GetNRetryNeededPackets (Mac48Address recipient, uint8_t tid) const;
170  void NotifyAgreementEstablished (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
179  void NotifyAgreementUnsuccessful (Mac48Address recipient, uint8_t tid);
189  void NotifyMpduTransmission (Mac48Address recipient, uint8_t tid, uint16_t nextSeqNumber);
196  void SetBlockAckThreshold (uint8_t nPackets);
200  void SetQueue (Ptr<WifiMacQueue> queue);
201  void SetTxMiddle (MacTxMiddle* txMiddle);
207  void SetBlockAckType (enum BlockAckType bAckType);
215  void TearDownBlockAck (Mac48Address recipient, uint8_t tid);
223  bool HasOtherFragments (uint16_t sequenceNumber) const;
227  uint32_t GetNextPacketSize (void) const;
234  void SetMaxPacketDelay (Time maxDelay);
237  void SetBlockAckInactivityCallback (Callback<void, Mac48Address, uint8_t, bool> callback);
238  void SetBlockDestinationCallback (Callback<void, Mac48Address, uint8_t> callback);
239  void SetUnblockDestinationCallback (Callback<void, Mac48Address, uint8_t> callback);
246  bool SwitchToBlockAckIfNeeded (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
252  uint16_t GetSeqNumOfNextRetryPacket (Mac48Address recipient, uint8_t tid) const;
253 private:
260  Ptr<Packet> ScheduleBlockAckReqIfNeeded (Mac48Address recipient, uint8_t tid);
264  void CleanupBuffers (void);
265  void InactivityTimeout (Mac48Address, uint8_t);
266 
267  struct Item;
268  typedef std::list<Item> PacketQueue;
269  typedef std::list<Item>::iterator PacketQueueI;
270  typedef std::list<Item>::const_iterator PacketQueueCI;
271 
272  typedef std::map<std::pair<Mac48Address, uint8_t>,
273  std::pair<OriginatorBlockAckAgreement, PacketQueue> > Agreements;
274  typedef std::map<std::pair<Mac48Address, uint8_t>,
275  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::iterator AgreementsI;
276  typedef std::map<std::pair<Mac48Address, uint8_t>,
277  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::const_iterator AgreementsCI;
278 
279  struct Item
280  {
281  Item ();
282  Item (Ptr<const Packet> packet,
283  const WifiMacHeader &hdr,
284  Time tStamp);
285  Ptr<const Packet> packet;
286  WifiMacHeader hdr;
287  Time timestamp;
288  };
289 
296  Agreements m_agreements;
302  std::list<PacketQueueI> m_retryPackets;
303  std::list<Bar> m_bars;
304 
305  uint8_t m_blockAckThreshold;
306  enum BlockAckType m_blockAckType;
307  Time m_maxDelay;
308  MacTxMiddle* m_txMiddle;
309  Mac48Address m_address;
310  Ptr<WifiMacQueue> m_queue;
311  Callback<void, Mac48Address, uint8_t, bool> m_blockAckInactivityTimeout;
313  Callback<void, Mac48Address, uint8_t> m_unblockPackets;
314 };
315 
316 } // namespace ns3
317 
318 #endif /* BLOCK_ACK_MANAGER_H */
keep track of time unit.
Definition: nstime.h:149
Callback template class.
Definition: callback.h:369
void NotifyGotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address recipient)
void CreateAgreement(const MgtAddBaRequestHeader *reqHdr, Mac48Address recipient)
void StorePacket(Ptr< const Packet > packet, const WifiMacHeader &hdr, Time tStamp)
void SetBlockAckType(enum BlockAckType bAckType)
bool HasPackets(void) const
Block Ack Request.
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
Headers for Block ack response.
Definition: ctrl-headers.h:102
void DestroyAgreement(Mac48Address recipient, uint8_t tid)
bool ExistsAgreementInState(Mac48Address recipient, uint8_t tid, enum OriginatorBlockAckAgreement::State state) const
an EUI-48 address
Definition: mac48-address.h:41
Ptr< const Packet > GetNextPacket(WifiMacHeader &hdr)
void SetMaxPacketDelay(Time maxDelay)
bool SwitchToBlockAckIfNeeded(Mac48Address recipient, uint8_t tid, uint16_t startingSeq)
uint32_t GetNBufferedPackets(Mac48Address recipient, uint8_t tid) const
void SetBlockAckThreshold(uint8_t nPackets)
Manages all block ack agreements for an originator station.
bool ExistsAgreement(Mac48Address recipient, uint8_t tid) const
void NotifyMpduTransmission(Mac48Address recipient, uint8_t tid, uint16_t nextSeqNumber)
void TearDownBlockAck(Mac48Address recipient, uint8_t tid)