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 
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 };
128 
129 
139 {
140 public:
142  virtual ~MacLowDcfListener ();
146  virtual void NavStart (Time duration) = 0;
150  virtual void NavReset (Time duration) = 0;
151  virtual void AckTimeoutStart (Time duration) = 0;
152  virtual void AckTimeoutReset () = 0;
153  virtual void CtsTimeoutStart (Time duration) = 0;
154  virtual void CtsTimeoutReset () = 0;
155 };
156 
162 {
163 public:
165  virtual ~MacLowBlockAckEventListener ();
175  virtual void BlockAckInactivityTimeout (Mac48Address originator, uint8_t tid) = 0;
176 };
177 
187 {
188 public:
190 
196  void EnableAck (void);
210  void EnableFastAck (void);
217  void EnableSuperFastAck (void);
221  void EnableBasicBlockAck (void);
225  void EnableCompressedBlockAck (void);
229  void EnableMultiTidBlockAck (void);
236  void EnableRts (void);
246  void EnableNextData (uint32_t size);
247 
255  void EnableOverrideDurationId (Time durationId);
256 
261  void DisableAck (void);
265  void DisableRts (void);
269  void DisableNextData (void);
275  void DisableOverrideDurationId (void);
276 
284  bool MustWaitAck (void) const;
291  bool MustWaitNormalAck (void) const;
298  bool MustWaitFastAck (void) const;
305  bool MustWaitSuperFastAck (void) const;
311  bool MustWaitBasicBlockAck (void) const;
317  bool MustWaitCompressedBlockAck (void) const;
323  bool MustWaitMultiTidBlockAck (void) const;
328  bool MustSendRts (void) const;
333  bool HasDurationId (void) const;
337  Time GetDurationId (void) const;
341  bool HasNextPacket (void) const;
345  uint32_t GetNextPacketSize (void) const;
346 
347 private:
348  friend std::ostream &operator << (std::ostream &os, const MacLowTransmissionParameters &params);
349  uint32_t m_nextSize;
350  enum
351  {
359  } m_waitAck;
360  bool m_sendRts;
362 };
363 
364 std::ostream &operator << (std::ostream &os, const MacLowTransmissionParameters &params);
365 
366 
371 class MacLow : public Object
372 {
373 public:
375 
376  MacLow ();
377  virtual ~MacLow ();
378 
379  void SetPhy (Ptr<WifiPhy> phy);
381 
382  void SetAddress (Mac48Address ad);
383  void SetAckTimeout (Time ackTimeout);
384  void SetBasicBlockAckTimeout (Time blockAckTimeout);
385  void SetCompressedBlockAckTimeout (Time blockAckTimeout);
386  void SetCtsTimeout (Time ctsTimeout);
387  void SetSifs (Time sifs);
388  void SetSlotTime (Time slotTime);
389  void SetPifs (Time pifs);
390  void SetBssid (Mac48Address ad);
391  void SetPromisc (void);
392  Mac48Address GetAddress (void) const;
393  Time GetAckTimeout (void) const;
394  Time GetBasicBlockAckTimeout () const;
396  Time GetCtsTimeout (void) const;
397  Time GetSifs (void) const;
398  Time GetSlotTime (void) const;
399  Time GetPifs (void) const;
400  Mac48Address GetBssid (void) const;
401 
408  void SetRxCallback (Callback<void,Ptr<Packet>,const WifiMacHeader *> callback);
413  void RegisterDcfListener (MacLowDcfListener *listener);
414 
424  const WifiMacHeader* hdr,
425  const MacLowTransmissionParameters& parameters) const;
426 
437  const WifiMacHeader* hdr,
438  MacLowTransmissionParameters parameters,
439  MacLowTransmissionListener *listener);
440 
450  void ReceiveOk (Ptr<Packet> packet, double rxSnr, WifiMode txMode, WifiPreamble preamble);
458  void ReceiveError (Ptr<const Packet> packet, double rxSnr);
466  void NotifySwitchingStartNow (Time duration);
482  void CreateBlockAckAgreement (const MgtAddBaResponseHeader *respHdr,
483  Mac48Address originator,
484  uint16_t startingSeq);
493  void DestroyBlockAckAgreement (Mac48Address originator, uint8_t tid);
502 private:
503  void CancelAllEvents (void);
504  uint32_t GetAckSize (void) const;
505  uint32_t GetBlockAckSize (enum BlockAckType type) const;
506  uint32_t GetRtsSize (void) const;
507  uint32_t GetCtsSize (void) const;
508  uint32_t GetSize (Ptr<const Packet> packet, const WifiMacHeader *hdr) const;
509  Time NowUs (void) const;
510  void ForwardDown (Ptr<const Packet> packet, const WifiMacHeader *hdr,
511  WifiMode txMode);
513  const WifiMacHeader* hdr,
514  const MacLowTransmissionParameters &params) const;
515  WifiMode GetRtsTxMode (Ptr<const Packet> packet, const WifiMacHeader *hdr) const;
516  WifiMode GetDataTxMode (Ptr<const Packet> packet, const WifiMacHeader *hdr) const;
517  WifiMode GetCtsTxModeForRts (Mac48Address to, WifiMode rtsTxMode) const;
518  WifiMode GetAckTxModeForData (Mac48Address to, WifiMode dataTxMode) const;
519 
520  Time GetCtsDuration (Mac48Address to, WifiMode rtsTxMode) const;
521  Time GetAckDuration (Mac48Address to, WifiMode dataTxMode) const;
522  Time GetBlockAckDuration (Mac48Address to, WifiMode blockAckReqTxMode, enum BlockAckType type) const;
523  void NotifyNav (const WifiMacHeader &hdr, WifiMode txMode, WifiPreamble preamble);
524  void DoNavResetNow (Time duration);
525  bool DoNavStartNow (Time duration);
526  bool IsNavZero (void) const;
527  void NotifyAckTimeoutStartNow (Time duration);
528  void NotifyAckTimeoutResetNow ();
529  void NotifyCtsTimeoutStartNow (Time duration);
530  void NotifyCtsTimeoutResetNow ();
531  void MaybeCancelPrevious (void);
532 
533  void NavCounterResetCtsMissed (Time rtsEndRxTime);
534  void NormalAckTimeout (void);
535  void FastAckTimeout (void);
536  void SuperFastAckTimeout (void);
537  void FastAckFailedTimeout (void);
538  void BlockAckTimeout (void);
539  void CtsTimeout (void);
540  void SendCtsAfterRts (Mac48Address source, Time duration, WifiMode txMode, double rtsSnr);
541  void SendAckAfterData (Mac48Address source, Time duration, WifiMode txMode, double rtsSnr);
542  void SendDataAfterCts (Mac48Address source, Time duration, WifiMode txMode);
543  void WaitSifsAfterEndTx (void);
544 
545  void SendRtsForPacket (void);
546  void SendDataPacket (void);
547  void SendCurrentTxPacket (void);
548  void StartDataTxTimers (void);
549  virtual void DoDispose (void);
558  void RxCompleteBufferedPacketsWithSmallerSequence (uint16_t seq, Mac48Address originator, uint8_t tid);
571  void RxCompleteBufferedPacketsUntilFirstLost (Mac48Address originator, uint8_t tid);
572  /*
573  * This method checks if exists a valid established block ack agreement.
574  * If there is, store the packet without pass it up to WifiMac. The packet is buffered
575  * in order of increasing sequence control field. All comparison are performed
576  * circularly modulo 2^12.
577  */
578  bool StoreMpduIfNeeded (Ptr<Packet> packet, WifiMacHeader hdr);
579  /*
580  * Invoked after that a block ack request has been received. Looks for corresponding
581  * block ack agreement and creates block ack bitmap on a received packets basis.
582  */
584  Time duration, WifiMode blockAckReqTxMode);
585  /*
586  * This method creates block ack frame with header equals to <i>blockAck</i> and start its transmission.
587  */
588  void SendBlockAckResponse (const CtrlBAckResponseHeader* blockAck, Mac48Address originator, bool immediate,
589  Time duration, WifiMode blockAckReqTxMode);
590  /*
591  * Every time that a block ack request or a packet with ack policy equals to <i>block ack</i>
592  * are received, if a relative block ack agreement exists and the value of inactivity timeout
593  * is not 0, the timer is reset.
594  * see section 11.5.3 in IEEE802.11e for more details.
595  */
597 
599 
603  typedef std::vector<MacLowDcfListener *>::const_iterator DcfListenersCI;
604  typedef std::vector<MacLowDcfListener *> DcfListeners;
606 
618 
632 
635 
636  bool m_promisc;
637 
638  // Listerner needed to monitor when a channel switching occurs.
640 
641  /*
642  * BlockAck data structures.
643  */
644  typedef std::pair<Ptr<Packet>, WifiMacHeader> BufferedPacket;
645  typedef std::list<BufferedPacket>::iterator BufferedPacketI;
646 
647  typedef std::pair<Mac48Address, uint8_t> AgreementKey;
648  typedef std::pair<BlockAckAgreement, std::list<BufferedPacket> > AgreementValue;
649 
650  typedef std::map<AgreementKey, AgreementValue> Agreements;
651  typedef std::map<AgreementKey, AgreementValue>::iterator AgreementsI;
652 
653  typedef std::map<AgreementKey, BlockAckCache> BlockAckCaches;
654  typedef std::map<AgreementKey, BlockAckCache>::iterator BlockAckCachesI;
655 
658 
659  typedef std::map<AcIndex, MacLowBlockAckEventListener*> QueueListeners;
661 };
662 
663 } // namespace ns3
664 
665 #endif /* MAC_LOW_H */