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 using namespace std;
35 
36 namespace ns3 {
37 
38 class MgtAddBaResponseHeader;
39 class MgtAddBaRequestHeader;
40 class MgtDelBaHeader;
41 class MacTxMiddle;
42 class WifiMacQueue;
43 
49 struct Bar
50 {
51  Bar ();
52  Bar (Ptr<const Packet> packet,
53  Mac48Address recipient,
54  uint8_t tid,
55  bool immediate);
58  uint8_t tid;
59  bool immediate;
60 };
61 
67 {
68 private:
70  BlockAckManager& operator= (const BlockAckManager&);
71 
72 public:
73  BlockAckManager ();
74  ~BlockAckManager ();
82  bool ExistsAgreement (Mac48Address recipient, uint8_t tid) const;
91  bool ExistsAgreementInState (Mac48Address recipient, uint8_t tid,
92  enum OriginatorBlockAckAgreement::State state) const;
100  void CreateAgreement (const MgtAddBaRequestHeader *reqHdr, Mac48Address recipient);
108  void DestroyAgreement (Mac48Address recipient, uint8_t tid);
115  void UpdateAgreement (const MgtAddBaResponseHeader *respHdr, Mac48Address recipient);
124  void StorePacket (Ptr<const Packet> packet, const WifiMacHeader &hdr, Time tStamp);
131  Ptr<const Packet> GetNextPacket (WifiMacHeader &hdr);
132  bool HasBar (struct Bar &bar);
137  bool HasPackets (void) const;
147  void NotifyGotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient);
155  uint32_t GetNBufferedPackets (Mac48Address recipient, uint8_t tid) const;
163  uint32_t GetNRetryNeededPackets (Mac48Address recipient, uint8_t tid) const;
172  void NotifyAgreementEstablished (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
181  void NotifyAgreementUnsuccessful (Mac48Address recipient, uint8_t tid);
191  void NotifyMpduTransmission (Mac48Address recipient, uint8_t tid, uint16_t nextSeqNumber);
198  void SetBlockAckThreshold (uint8_t nPackets);
202  void SetQueue (Ptr<WifiMacQueue> queue);
203  void SetTxMiddle (MacTxMiddle* txMiddle);
209  void SetBlockAckType (enum BlockAckType bAckType);
217  void TearDownBlockAck (Mac48Address recipient, uint8_t tid);
225  bool HasOtherFragments (uint16_t sequenceNumber) const;
229  uint32_t GetNextPacketSize (void) const;
236  void SetMaxPacketDelay (Time maxDelay);
239  void SetBlockAckInactivityCallback (Callback<void, Mac48Address, uint8_t, bool> callback);
240  void SetBlockDestinationCallback (Callback<void, Mac48Address, uint8_t> callback);
241  void SetUnblockDestinationCallback (Callback<void, Mac48Address, uint8_t> callback);
248  bool SwitchToBlockAckIfNeeded (Mac48Address recipient, uint8_t tid, uint16_t startingSeq);
254  uint16_t GetSeqNumOfNextRetryPacket (Mac48Address recipient, uint8_t tid) const;
255 private:
262  Ptr<Packet> ScheduleBlockAckReqIfNeeded (Mac48Address recipient, uint8_t tid);
266  void CleanupBuffers (void);
267  void InactivityTimeout (Mac48Address, uint8_t);
268 
269  struct Item;
270  typedef std::list<Item> PacketQueue;
271  typedef std::list<Item>::iterator PacketQueueI;
272  typedef std::list<Item>::const_iterator PacketQueueCI;
273 
274  typedef std::map<std::pair<Mac48Address, uint8_t>,
275  std::pair<OriginatorBlockAckAgreement, PacketQueue> > Agreements;
276  typedef std::map<std::pair<Mac48Address, uint8_t>,
277  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::iterator AgreementsI;
278  typedef std::map<std::pair<Mac48Address, uint8_t>,
279  std::pair<OriginatorBlockAckAgreement, PacketQueue> >::const_iterator AgreementsCI;
280 
281  struct Item
282  {
283  Item ();
284  Item (Ptr<const Packet> packet,
285  const WifiMacHeader &hdr,
286  Time tStamp);
290  };
291 
304  std::list<PacketQueueI> m_retryPackets;
305  std::list<Bar> m_bars;
306 
316 };
317 
318 } // namespace ns3
319 
320 #endif /* BLOCK_ACK_MANAGER_H */