A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mac-low.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005, 2006 INRIA
4  * Copyright (c) 2009 MIRKO BANCHI
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Author: Mirko Banchi <mk.banchi@gmail.com>
21  */
22 #ifndef MAC_LOW_H
23 #define MAC_LOW_H
24 
25 #include <vector>
26 #include <stdint.h>
27 #include <ostream>
28 #include <map>
29 
30 #include "wifi-mac-header.h"
31 #include "wifi-mode.h"
32 #include "wifi-preamble.h"
34 #include "ctrl-headers.h"
35 #include "mgt-headers.h"
36 #include "block-ack-agreement.h"
37 #include "ns3/mac48-address.h"
38 #include "ns3/callback.h"
39 #include "ns3/event-id.h"
40 #include "ns3/packet.h"
41 #include "ns3/nstime.h"
42 #include "qos-utils.h"
43 #include "block-ack-cache.h"
44 #include "wifi-tx-vector.h"
45 
46 namespace ns3 {
47 
48 class WifiPhy;
49 class WifiMac;
50 class EdcaTxopN;
51 
57 {
58 public:
60  virtual ~MacLowTransmissionListener ();
61 
69  virtual void GotCts (double snr, WifiMode txMode) = 0;
74  virtual void MissedCts (void) = 0;
84  virtual void GotAck (double snr, WifiMode txMode) = 0;
89  virtual void MissedAck (void) = 0;
102  virtual void GotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address source);
112  virtual void MissedBlockAck (void);
119  virtual void StartNext (void) = 0;
120 
127  virtual void Cancel (void) = 0;
128 
134  virtual void EndTxNoAck (void) = 0;
135 
136 };
137 
138 
148 {
149 public:
151  virtual ~MacLowDcfListener ();
155  virtual void NavStart (Time duration) = 0;
159  virtual void NavReset (Time duration) = 0;
160  virtual void AckTimeoutStart (Time duration) = 0;
161  virtual void AckTimeoutReset () = 0;
162  virtual void CtsTimeoutStart (Time duration) = 0;
163  virtual void CtsTimeoutReset () = 0;
164 };
165 
171 {
172 public:
174  virtual ~MacLowBlockAckEventListener ();
184  virtual void BlockAckInactivityTimeout (Mac48Address originator, uint8_t tid) = 0;
185 };
186 
196 {
197 public:
199 
205  void EnableAck (void);
219  void EnableFastAck (void);
226  void EnableSuperFastAck (void);
230  void EnableBasicBlockAck (void);
234  void EnableCompressedBlockAck (void);
238  void EnableMultiTidBlockAck (void);
245  void EnableRts (void);
255  void EnableNextData (uint32_t size);
256 
264  void EnableOverrideDurationId (Time durationId);
265 
270  void DisableAck (void);
274  void DisableRts (void);
278  void DisableNextData (void);
284  void DisableOverrideDurationId (void);
285 
293  bool MustWaitAck (void) const;
300  bool MustWaitNormalAck (void) const;
307  bool MustWaitFastAck (void) const;
314  bool MustWaitSuperFastAck (void) const;
320  bool MustWaitBasicBlockAck (void) const;
326  bool MustWaitCompressedBlockAck (void) const;
332  bool MustWaitMultiTidBlockAck (void) const;
337  bool MustSendRts (void) const;
342  bool HasDurationId (void) const;
346  Time GetDurationId (void) const;
350  bool HasNextPacket (void) const;
354  uint32_t GetNextPacketSize (void) const;
355 
356 private:
357  friend std::ostream &operator << (std::ostream &os, const MacLowTransmissionParameters &params);
358  uint32_t m_nextSize;
359  enum
360  {
368  } m_waitAck;
369  bool m_sendRts;
371 };
372 
373 std::ostream &operator << (std::ostream &os, const MacLowTransmissionParameters &params);
374 
375 
380 class MacLow : public Object
381 {
382 public:
384 
385  MacLow ();
386  virtual ~MacLow ();
387 
388  void SetPhy (Ptr<WifiPhy> phy);
390 
391  void SetAddress (Mac48Address ad);
392  void SetAckTimeout (Time ackTimeout);
393  void SetBasicBlockAckTimeout (Time blockAckTimeout);
394  void SetCompressedBlockAckTimeout (Time blockAckTimeout);
395  void SetCtsToSelfSupported (bool enable);
396  void SetCtsTimeout (Time ctsTimeout);
397  void SetSifs (Time sifs);
398  void SetRifs (Time rifs);
399  void SetSlotTime (Time slotTime);
400  void SetPifs (Time pifs);
401  void SetBssid (Mac48Address ad);
402  void SetPromisc (void);
403  bool GetCtsToSelfSupported () const;
404  Mac48Address GetAddress (void) const;
405  Time GetAckTimeout (void) const;
406  Time GetBasicBlockAckTimeout () const;
408  Time GetCtsTimeout (void) const;
409  Time GetSifs (void) const;
410  Time GetSlotTime (void) const;
411  Time GetPifs (void) const;
412  Time GetRifs (void) const;
413  Mac48Address GetBssid (void) const;
414 
421  void SetRxCallback (Callback<void,Ptr<Packet>,const WifiMacHeader *> callback);
426  void RegisterDcfListener (MacLowDcfListener *listener);
427 
437  const WifiMacHeader* hdr,
438  const MacLowTransmissionParameters& parameters) const;
439 
450  const WifiMacHeader* hdr,
451  MacLowTransmissionParameters parameters,
452  MacLowTransmissionListener *listener);
453 
463  void ReceiveOk (Ptr<Packet> packet, double rxSnr, WifiMode txMode, WifiPreamble preamble);
471  void ReceiveError (Ptr<const Packet> packet, double rxSnr);
479  void NotifySwitchingStartNow (Time duration);
495  void CreateBlockAckAgreement (const MgtAddBaResponseHeader *respHdr,
496  Mac48Address originator,
497  uint16_t startingSeq);
506  void DestroyBlockAckAgreement (Mac48Address originator, uint8_t tid);
515 private:
516  void CancelAllEvents (void);
517  uint32_t GetAckSize (void) const;
518  uint32_t GetBlockAckSize (enum BlockAckType type) const;
519  uint32_t GetRtsSize (void) const;
520  uint32_t GetCtsSize (void) const;
521  uint32_t GetSize (Ptr<const Packet> packet, const WifiMacHeader *hdr) const;
522  Time NowUs (void) const;
523 void ForwardDown (Ptr<const Packet> packet, const WifiMacHeader *hdr,
524  WifiTxVector txVector, WifiPreamble preamble);
525  WifiTxVector GetRtsTxVector (Ptr<const Packet> packet, const WifiMacHeader *hdr) const;
526  WifiTxVector GetDataTxVector (Ptr<const Packet> packet, const WifiMacHeader *hdr) const;
527  WifiTxVector GetCtsTxVector (Mac48Address to, WifiMode rtsTxMode) const;
528  WifiTxVector GetAckTxVector (Mac48Address to, WifiMode dataTxMode) const;
529  WifiTxVector GetBlockAckTxVector (Mac48Address to, WifiMode dataTxMode) const;
530 
532 
535 
536  Time GetCtsDuration (WifiTxVector ctsTxVector) const;
537  Time GetCtsDuration (Mac48Address to, WifiTxVector rtsTxVector) const;
538  Time GetAckDuration (WifiTxVector ackTxVector) const;
539  Time GetAckDuration (Mac48Address to, WifiTxVector dataTxVector) const;
540  Time GetBlockAckDuration (Mac48Address to, WifiTxVector blockAckReqTxVector, enum BlockAckType type) const;
541 
542  bool NeedCtsToSelf (void);
543 
545  const WifiMacHeader* hdr,
546  const MacLowTransmissionParameters &params) const;
547  void NotifyNav (Ptr<const Packet> packet,const WifiMacHeader &hdr, WifiMode txMode, WifiPreamble preamble);
548  void DoNavResetNow (Time duration);
549  bool DoNavStartNow (Time duration);
550  bool IsNavZero (void) const;
551  void NotifyAckTimeoutStartNow (Time duration);
552  void NotifyAckTimeoutResetNow ();
553  void NotifyCtsTimeoutStartNow (Time duration);
554  void NotifyCtsTimeoutResetNow ();
555  void MaybeCancelPrevious (void);
556 
557  void NavCounterResetCtsMissed (Time rtsEndRxTime);
558  void NormalAckTimeout (void);
559  void FastAckTimeout (void);
560  void SuperFastAckTimeout (void);
561  void FastAckFailedTimeout (void);
562  void BlockAckTimeout (void);
563  void CtsTimeout (void);
564  void SendCtsToSelf (void);
565  void SendCtsAfterRts (Mac48Address source, Time duration, WifiMode txMode, double rtsSnr);
566  void SendAckAfterData (Mac48Address source, Time duration, WifiMode txMode, double rtsSnr);
567  void SendDataAfterCts (Mac48Address source, Time duration, WifiMode txMode);
568  void WaitSifsAfterEndTx (void);
569  void EndTxNoAck (void);
570 
571  void SendRtsForPacket (void);
572  void SendDataPacket (void);
573  void SendCurrentTxPacket (void);
574  void StartDataTxTimers (WifiTxVector dataTxVector);
575  virtual void DoDispose (void);
584  void RxCompleteBufferedPacketsWithSmallerSequence (uint16_t seq, Mac48Address originator, uint8_t tid);
597  void RxCompleteBufferedPacketsUntilFirstLost (Mac48Address originator, uint8_t tid);
598  /*
599  * This method checks if exists a valid established block ack agreement.
600  * If there is, store the packet without pass it up to WifiMac. The packet is buffered
601  * in order of increasing sequence control field. All comparison are performed
602  * circularly modulo 2^12.
603  */
604  bool StoreMpduIfNeeded (Ptr<Packet> packet, WifiMacHeader hdr);
605  /*
606  * Invoked after that a block ack request has been received. Looks for corresponding
607  * block ack agreement and creates block ack bitmap on a received packets basis.
608  */
610  Time duration, WifiMode blockAckReqTxMode);
611  /*
612  * This method creates block ack frame with header equals to <i>blockAck</i> and start its transmission.
613  */
614  void SendBlockAckResponse (const CtrlBAckResponseHeader* blockAck, Mac48Address originator, bool immediate,
615  Time duration, WifiMode blockAckReqTxMode);
616  /*
617  * Every time that a block ack request or a packet with ack policy equals to <i>block ack</i>
618  * are received, if a relative block ack agreement exists and the value of inactivity timeout
619  * is not 0, the timer is reset.
620  * see section 11.5.3 in IEEE802.11e for more details.
621  */
623 
625 
629  typedef std::vector<MacLowDcfListener *>::const_iterator DcfListenersCI;
630  typedef std::vector<MacLowDcfListener *> DcfListeners;
632 
646 
661 
664 
665  bool m_promisc;
666 
667  // Listerner needed to monitor when a channel switching occurs.
669 
670  /*
671  * BlockAck data structures.
672  */
673  typedef std::pair<Ptr<Packet>, WifiMacHeader> BufferedPacket;
674  typedef std::list<BufferedPacket>::iterator BufferedPacketI;
675 
676  typedef std::pair<Mac48Address, uint8_t> AgreementKey;
677  typedef std::pair<BlockAckAgreement, std::list<BufferedPacket> > AgreementValue;
678 
679  typedef std::map<AgreementKey, AgreementValue> Agreements;
680  typedef std::map<AgreementKey, AgreementValue>::iterator AgreementsI;
681 
682  typedef std::map<AgreementKey, BlockAckCache> BlockAckCaches;
683  typedef std::map<AgreementKey, BlockAckCache>::iterator BlockAckCachesI;
684 
687 
688  typedef std::map<AcIndex, MacLowBlockAckEventListener*> QueueListeners;
691 };
692 
693 } // namespace ns3
694 
695 #endif /* MAC_LOW_H */