A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #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"
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,
52  uint8_t tid,
53  bool immediate);
56  uint8_t tid;
57  bool immediate;
58 };
59 
65 {
66 private:
69 
70 public:
71  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);
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);
288  };
289 
302  std::list<PacketQueueI> m_retryPackets;
303  std::list<Bar> m_bars;
304 
314 };
315 
316 } // namespace ns3
317 
318 #endif /* BLOCK_ACK_MANAGER_H */