A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mac-low.h
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"
33 #include "wifi-remote-station-manager.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 
45 namespace ns3 {
46 
47 class WifiPhy;
48 class WifiMac;
49 class EdcaTxopN;
50 
56 {
57 public:
59  virtual ~MacLowTransmissionListener ();
60 
68  virtual void GotCts (double snr, WifiMode txMode) = 0;
73  virtual void MissedCts (void) = 0;
83  virtual void GotAck (double snr, WifiMode txMode) = 0;
88  virtual void MissedAck (void) = 0;
101  virtual void GotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address source);
111  virtual void MissedBlockAck (void);
118  virtual void StartNext (void) = 0;
119 
126  virtual void Cancel (void) = 0;
127 
133  virtual void EndTxNoAck (void) = 0;
134 
135 };
136 
137 
147 {
148 public:
150  virtual ~MacLowDcfListener ();
154  virtual void NavStart (Time duration) = 0;
158  virtual void NavReset (Time duration) = 0;
159  virtual void AckTimeoutStart (Time duration) = 0;
160  virtual void AckTimeoutReset () = 0;
161  virtual void CtsTimeoutStart (Time duration) = 0;
162  virtual void CtsTimeoutReset () = 0;
163 };
164 
170 {
171 public:
173  virtual ~MacLowBlockAckEventListener ();
183  virtual void BlockAckInactivityTimeout (Mac48Address originator, uint8_t tid) = 0;
184 };
185 
195 {
196 public:
198 
204  void EnableAck (void);
218  void EnableFastAck (void);
225  void EnableSuperFastAck (void);
229  void EnableBasicBlockAck (void);
233  void EnableCompressedBlockAck (void);
237  void EnableMultiTidBlockAck (void);
244  void EnableRts (void);
254  void EnableNextData (uint32_t size);
255 
263  void EnableOverrideDurationId (Time durationId);
264 
269  void DisableAck (void);
273  void DisableRts (void);
277  void DisableNextData (void);
283  void DisableOverrideDurationId (void);
284 
292  bool MustWaitAck (void) const;
299  bool MustWaitNormalAck (void) const;
306  bool MustWaitFastAck (void) const;
313  bool MustWaitSuperFastAck (void) const;
319  bool MustWaitBasicBlockAck (void) const;
325  bool MustWaitCompressedBlockAck (void) const;
331  bool MustWaitMultiTidBlockAck (void) const;
336  bool MustSendRts (void) const;
341  bool HasDurationId (void) const;
345  Time GetDurationId (void) const;
349  bool HasNextPacket (void) const;
353  uint32_t GetNextPacketSize (void) const;
354 
355 private:
356  friend std::ostream &operator << (std::ostream &os, const MacLowTransmissionParameters &params);
357  uint32_t m_nextSize;
358  enum
359  {
360  ACK_NONE,
361  ACK_NORMAL,
362  ACK_FAST,
363  ACK_SUPER_FAST,
364  BLOCK_ACK_BASIC,
365  BLOCK_ACK_COMPRESSED,
366  BLOCK_ACK_MULTI_TID
367  } m_waitAck;
368  bool m_sendRts;
369  Time m_overrideDurationId;
370 };
371 
372 std::ostream &operator << (std::ostream &os, const MacLowTransmissionParameters &params);
373 
374 
379 class MacLow : public Object
380 {
381 public:
383 
384  MacLow ();
385  virtual ~MacLow ();
386 
387  void SetPhy (Ptr<WifiPhy> phy);
388  void SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> manager);
389 
390  void SetAddress (Mac48Address ad);
391  void SetAckTimeout (Time ackTimeout);
392  void SetBasicBlockAckTimeout (Time blockAckTimeout);
393  void SetCompressedBlockAckTimeout (Time blockAckTimeout);
394  void SetCtsTimeout (Time ctsTimeout);
395  void SetSifs (Time sifs);
396  void SetSlotTime (Time slotTime);
397  void SetPifs (Time pifs);
398  void SetBssid (Mac48Address ad);
399  void SetPromisc (void);
400  Mac48Address GetAddress (void) const;
401  Time GetAckTimeout (void) const;
402  Time GetBasicBlockAckTimeout () const;
403  Time GetCompressedBlockAckTimeout () const;
404  Time GetCtsTimeout (void) const;
405  Time GetSifs (void) const;
406  Time GetSlotTime (void) const;
407  Time GetPifs (void) const;
408  Mac48Address GetBssid (void) const;
409 
416  void SetRxCallback (Callback<void,Ptr<Packet>,const WifiMacHeader *> callback);
421  void RegisterDcfListener (MacLowDcfListener *listener);
422 
432  const WifiMacHeader* hdr,
433  const MacLowTransmissionParameters& parameters) const;
434 
445  const WifiMacHeader* hdr,
446  MacLowTransmissionParameters parameters,
447  MacLowTransmissionListener *listener);
448 
458  void ReceiveOk (Ptr<Packet> packet, double rxSnr, WifiMode txMode, WifiPreamble preamble);
466  void ReceiveError (Ptr<const Packet> packet, double rxSnr);
474  void NotifySwitchingStartNow (Time duration);
480  void NotifySensingStartNow (Time duration);
496  void CreateBlockAckAgreement (const MgtAddBaResponseHeader *respHdr,
497  Mac48Address originator,
498  uint16_t startingSeq);
507  void DestroyBlockAckAgreement (Mac48Address originator, uint8_t tid);
516  void SetTxRadio (bool isTx);
517  bool IsTxRadio (void);
518  void SetRxRadio (bool isRx);
519  bool IsRxRadio (void);
520  Ptr<WifiPhy> GetPhy (void);
521 private:
522  void CancelAllEvents (void);
523  uint32_t GetAckSize (void) const;
524  uint32_t GetBlockAckSize (enum BlockAckType type) const;
525  uint32_t GetRtsSize (void) const;
526  uint32_t GetCtsSize (void) const;
527  uint32_t GetSize (Ptr<const Packet> packet, const WifiMacHeader *hdr) const;
528  Time NowUs (void) const;
529  void ForwardDown (Ptr<const Packet> packet, const WifiMacHeader *hdr,
530  WifiMode txMode);
531  Time CalculateOverallTxTime (Ptr<const Packet> packet,
532  const WifiMacHeader* hdr,
533  const MacLowTransmissionParameters &params) const;
534  WifiMode GetRtsTxMode (Ptr<const Packet> packet, const WifiMacHeader *hdr) const;
535  WifiMode GetDataTxMode (Ptr<const Packet> packet, const WifiMacHeader *hdr) const;
536  WifiMode GetCtsTxModeForRts (Mac48Address to, WifiMode rtsTxMode) const;
537  WifiMode GetAckTxModeForData (Mac48Address to, WifiMode dataTxMode) const;
538 
539  Time GetCtsDuration (Mac48Address to, WifiMode rtsTxMode) const;
540  Time GetAckDuration (Mac48Address to, WifiMode dataTxMode) const;
541  Time GetBlockAckDuration (Mac48Address to, WifiMode blockAckReqTxMode, enum BlockAckType type) const;
542  void NotifyNav (const WifiMacHeader &hdr, WifiMode txMode, WifiPreamble preamble);
543  void DoNavResetNow (Time duration);
544  bool DoNavStartNow (Time duration);
545  bool IsNavZero (void) const;
546  void NotifyAckTimeoutStartNow (Time duration);
547  void NotifyAckTimeoutResetNow ();
548  void NotifyCtsTimeoutStartNow (Time duration);
549  void NotifyCtsTimeoutResetNow ();
550  void MaybeCancelPrevious (void);
551 
552  void NavCounterResetCtsMissed (Time rtsEndRxTime);
553  void NormalAckTimeout (void);
554  void FastAckTimeout (void);
555  void SuperFastAckTimeout (void);
556  void FastAckFailedTimeout (void);
557  void BlockAckTimeout (void);
558  void CtsTimeout (void);
559  void SendCtsAfterRts (Mac48Address source, Time duration, WifiMode txMode, double rtsSnr);
560  void SendAckAfterData (Mac48Address source, Time duration, WifiMode txMode, double rtsSnr);
561  void SendDataAfterCts (Mac48Address source, Time duration, WifiMode txMode);
562  void WaitSifsAfterEndTx (void);
563  void EndTxNoAck (void);
564 
565  void SendRtsForPacket (void);
566  void SendDataPacket (void);
567  void SendCurrentTxPacket (void);
568  void StartDataTxTimers (void);
569  virtual void DoDispose (void);
578  void RxCompleteBufferedPacketsWithSmallerSequence (uint16_t seq, Mac48Address originator, uint8_t tid);
591  void RxCompleteBufferedPacketsUntilFirstLost (Mac48Address originator, uint8_t tid);
592  /*
593  * This method checks if exists a valid established block ack agreement.
594  * If there is, store the packet without pass it up to WifiMac. The packet is buffered
595  * in order of increasing sequence control field. All comparison are performed
596  * circularly modulo 2^12.
597  */
598  bool StoreMpduIfNeeded (Ptr<Packet> packet, WifiMacHeader hdr);
599  /*
600  * Invoked after that a block ack request has been received. Looks for corresponding
601  * block ack agreement and creates block ack bitmap on a received packets basis.
602  */
603  void SendBlockAckAfterBlockAckRequest (const CtrlBAckRequestHeader reqHdr, Mac48Address originator,
604  Time duration, WifiMode blockAckReqTxMode);
605  /*
606  * This method creates block ack frame with header equals to <i>blockAck</i> and start its transmission.
607  */
608  void SendBlockAckResponse (const CtrlBAckResponseHeader* blockAck, Mac48Address originator, bool immediate,
609  Time duration, WifiMode blockAckReqTxMode);
610  /*
611  * Every time that a block ack request or a packet with ack policy equals to <i>block ack</i>
612  * are received, if a relative block ack agreement exists and the value of inactivity timeout
613  * is not 0, the timer is reset.
614  * see section 11.5.3 in IEEE802.11e for more details.
615  */
616  void ResetBlockAckInactivityTimerIfNeeded (BlockAckAgreement &agreement);
617 
618  void SetupPhyMacLowListener (Ptr<WifiPhy> phy);
619 
620  Ptr<WifiPhy> m_phy;
621  Ptr<WifiRemoteStationManager> m_stationManager;
622  MacLowRxCallback m_rxCallback;
623  typedef std::vector<MacLowDcfListener *>::const_iterator DcfListenersCI;
624  typedef std::vector<MacLowDcfListener *> DcfListeners;
625  DcfListeners m_dcfListeners;
626 
627  EventId m_normalAckTimeoutEvent;
628  EventId m_fastAckTimeoutEvent;
629  EventId m_superFastAckTimeoutEvent;
630  EventId m_fastAckFailedTimeoutEvent;
631  EventId m_blockAckTimeoutEvent;
632  EventId m_ctsTimeoutEvent;
633  EventId m_sendCtsEvent;
634  EventId m_sendAckEvent;
635  EventId m_sendDataEvent;
636  EventId m_waitSifsEvent;
637  EventId m_endTxNoAckEvent;
638  EventId m_navCounterResetCtsMissed;
639 
640  Ptr<Packet> m_currentPacket;
641  WifiMacHeader m_currentHdr;
642  MacLowTransmissionParameters m_txParams;
643  MacLowTransmissionListener *m_listener;
644  Mac48Address m_self;
645  Mac48Address m_bssid;
646  Time m_ackTimeout;
647  Time m_basicBlockAckTimeout;
648  Time m_compressedBlockAckTimeout;
649  Time m_ctsTimeout;
650  Time m_sifs;
651  Time m_slotTime;
652  Time m_pifs;
653 
654  Time m_lastNavStart;
655  Time m_lastNavDuration;
656 
657  bool m_promisc;
658  bool m_tx;
659  bool m_rx;
660 
661  // Listerner needed to monitor when a channel switching occurs.
662  class PhyMacLowListener * m_phyMacLowListener;
663 
664  /*
665  * BlockAck data structures.
666  */
667  typedef std::pair<Ptr<Packet>, WifiMacHeader> BufferedPacket;
668  typedef std::list<BufferedPacket>::iterator BufferedPacketI;
669 
670  typedef std::pair<Mac48Address, uint8_t> AgreementKey;
671  typedef std::pair<BlockAckAgreement, std::list<BufferedPacket> > AgreementValue;
672 
673  typedef std::map<AgreementKey, AgreementValue> Agreements;
674  typedef std::map<AgreementKey, AgreementValue>::iterator AgreementsI;
675 
676  typedef std::map<AgreementKey, BlockAckCache> BlockAckCaches;
677  typedef std::map<AgreementKey, BlockAckCache>::iterator BlockAckCachesI;
678 
679  Agreements m_bAckAgreements;
680  BlockAckCaches m_bAckCaches;
681 
682  typedef std::map<AcIndex, MacLowBlockAckEventListener*> QueueListeners;
683  QueueListeners m_edcaListeners;
684 };
685 
686 } // namespace ns3
687 
688 #endif /* MAC_LOW_H */
bool MustSendRts(void) const
Definition: mac-low.cc:183
keep track of time unit.
Definition: nstime.h:149
Callback template class.
Definition: callback.h:369
virtual void GotAck(double snr, WifiMode txMode)=0
virtual void MissedAck(void)=0
virtual void BlockAckInactivityTimeout(Mac48Address originator, uint8_t tid)=0
bool HasDurationId(void) const
Definition: mac-low.cc:188
void SetRxCallback(Callback< void, Ptr< Packet >, const WifiMacHeader * > callback)
Definition: mac-low.cc:529
listen to events coming from ns3::MacLow.
Definition: mac-low.h:55
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:88
bool MustWaitFastAck(void) const
Definition: mac-low.cc:158
control how a packet is transmitted.The ns3::MacLow::StartTransmission method expects an instance of ...
Definition: mac-low.h:194
WifiPreamble
Definition: wifi-preamble.h:29
void DestroyBlockAckAgreement(Mac48Address originator, uint8_t tid)
Definition: mac-low.cc:1584
void CreateBlockAckAgreement(const MgtAddBaResponseHeader *respHdr, Mac48Address originator, uint16_t startingSeq)
Definition: mac-low.cc:1542
virtual void StartNext(void)=0
virtual void EndTxNoAck(void)=0
virtual void GotCts(double snr, WifiMode txMode)=0
bool MustWaitMultiTidBlockAck(void) const
Definition: mac-low.cc:178
Headers for Block ack response.
Definition: ctrl-headers.h:102
uint32_t GetNextPacketSize(void) const
Definition: mac-low.cc:204
bool HasNextPacket(void) const
Definition: mac-low.cc:199
void RegisterDcfListener(MacLowDcfListener *listener)
Definition: mac-low.cc:534
void NotifySwitchingStartNow(Time duration)
Definition: mac-low.cc:600
void StartTransmission(Ptr< const Packet > packet, const WifiMacHeader *hdr, MacLowTransmissionParameters parameters, MacLowTransmissionListener *listener)
Definition: mac-low.cc:541
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:43
virtual void NavStart(Time duration)=0
listen for block ack events.
Definition: mac-low.h:169
Time CalculateTransmissionTime(Ptr< const Packet > packet, const WifiMacHeader *hdr, const MacLowTransmissionParameters &parameters) const
Definition: mac-low.cc:1015
bool MustWaitBasicBlockAck(void) const
Definition: mac-low.cc:168
bool MustWaitCompressedBlockAck(void) const
Definition: mac-low.cc:173
an EUI-48 address
Definition: mac48-address.h:41
virtual void Cancel(void)=0
void NotifyNav(const WifiMacHeader &hdr, WifiMode txMode, WifiPreamble preamble)
Definition: mac-low.cc:1030
listen to NAV eventsThis class is typically connected to an instance of ns3::Dcf and calls to its met...
Definition: mac-low.h:146
void RxCompleteBufferedPacketsWithSmallerSequence(uint16_t seq, Mac48Address originator, uint8_t tid)
Definition: mac-low.cc:1600
Time GetDurationId(void) const
Definition: mac-low.cc:193
virtual void MissedBlockAck(void)
Definition: mac-low.cc:58
void ReceiveError(Ptr< const Packet > packet, double rxSnr)
Definition: mac-low.cc:586
handle RTS/CTS/DATA/ACK transactions.
Definition: mac-low.h:379
virtual void MissedCts(void)=0
virtual void DoDispose(void)
Definition: mac-low.cc:326
bool MustWaitSuperFastAck(void) const
Definition: mac-low.cc:163
Maintains information for a block ack agreement.
an identifier for simulation events.
Definition: event-id.h:46
virtual void NavReset(Time duration)=0
virtual void GotBlockAck(const CtrlBAckResponseHeader *blockAck, Mac48Address source)
Definition: mac-low.cc:53
void NotifySensingStartNow(Time duration)
Definition: mac-low.cc:616
void EnableOverrideDurationId(Time durationId)
Definition: mac-low.cc:93
void EnableNextData(uint32_t size)
Definition: mac-low.cc:83
a base class which provides memory management and object aggregation
Definition: object.h:63
void ReceiveOk(Ptr< Packet > packet, double rxSnr, WifiMode txMode, WifiPreamble preamble)
Definition: mac-low.cc:632
bool MustWaitAck(void) const
Definition: mac-low.cc:148
Headers for Block ack request.
Definition: ctrl-headers.h:46
void RegisterBlockAckListenerForAc(enum AcIndex ac, MacLowBlockAckEventListener *listener)
Definition: mac-low.cc:1820
AcIndex
Definition: qos-utils.h:35
bool MustWaitNormalAck(void) const
Definition: mac-low.cc:153
void RxCompleteBufferedPacketsUntilFirstLost(Mac48Address originator, uint8_t tid)
Definition: mac-low.cc:1660