src/devices/wifi/interference-helper.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu Nov 12 13:01:01 2009 +0100 (2009-11-12)
changeset 5505 c0ac392289c3
parent 5413 64931d320790
child 5819 514ec98954ab
permissions -rw-r--r--
replace RefCountBase with SimpleRefCount<> to avoid duplicate refcounting implementations.
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2005,2006 INRIA
     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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    19  */
    20 #ifndef INTERFERENCE_HELPER_H
    21 #define INTERFERENCE_HELPER_H
    22 
    23 #include <stdint.h>
    24 #include <vector>
    25 #include <list>
    26 #include "wifi-mode.h"
    27 #include "wifi-preamble.h"
    28 #include "wifi-phy-standard.h"
    29 #include "ns3/nstime.h"
    30 #include "ns3/simple-ref-count.h"
    31 
    32 namespace ns3 {
    33 
    34 class ErrorRateModel;
    35 
    36 class InterferenceHelper
    37 {
    38 public:
    39   class Event : public SimpleRefCount<InterferenceHelper::Event>
    40   {
    41   public:
    42     Event (uint32_t size, WifiMode payloadMode, 
    43 	     enum WifiPreamble preamble,
    44 	     Time duration, double rxPower);
    45     ~Event ();
    46   
    47     Time GetDuration (void) const;
    48     Time GetStartTime (void) const;
    49     Time GetEndTime (void) const;
    50     bool Overlaps (Time time) const;
    51     double GetRxPowerW (void) const;
    52     uint32_t GetSize (void) const;
    53     WifiMode GetPayloadMode (void) const;
    54     enum WifiPreamble GetPreambleType (void) const;
    55   private:
    56     uint32_t m_size;
    57     WifiMode m_payloadMode;
    58     enum WifiPreamble m_preamble;
    59     Time m_startTime;
    60     Time m_endTime;
    61     double m_rxPowerW;
    62   };
    63   struct SnrPer 
    64   {
    65     double snr;
    66     double per;
    67   };
    68 
    69   InterferenceHelper ();
    70   ~InterferenceHelper ();
    71 
    72   void SetNoiseFigure (double value);
    73   void SetErrorRateModel (Ptr<ErrorRateModel> rate);
    74 
    75   double GetNoiseFigure (void) const;
    76   Ptr<ErrorRateModel> GetErrorRateModel (void) const;
    77 
    78 
    79   /**
    80    * \param energyW the minimum energy (W) requested
    81    * \returns the expected amount of time the observed 
    82    *          energy on the medium will be higher than
    83    *          the requested threshold.
    84    */
    85   Time GetEnergyDuration (double energyW);
    86 
    87   
    88   static WifiMode GetPlcpHeaderMode (WifiMode payloadMode, WifiPreamble preamble);
    89   static uint32_t GetPlcpHeaderDurationMicroSeconds (WifiMode payloadMode, WifiPreamble preamble);
    90   static uint32_t GetPlcpPreambleDurationMicroSeconds (WifiMode mode, WifiPreamble preamble);
    91   static uint32_t GetPayloadDurationMicroSeconds (uint32_t size, WifiMode payloadMode);
    92   static Time CalculateTxDuration (uint32_t size, WifiMode payloadMode, WifiPreamble preamble);
    93   Ptr<InterferenceHelper::Event> Add (uint32_t size, WifiMode payloadMode, 
    94 				      enum WifiPreamble preamble,
    95 				      Time duration, double rxPower);
    96 
    97   struct InterferenceHelper::SnrPer CalculateSnrPer (Ptr<InterferenceHelper::Event> event);
    98   void EraseEvents (void); 
    99 private:
   100   class NiChange {
   101   public:
   102     NiChange (Time time, double delta);
   103     Time GetTime (void) const;
   104     double GetDelta (void) const;
   105     bool operator < (NiChange const &o) const;
   106   private:
   107     Time m_time;
   108     double m_delta;
   109   };
   110   typedef std::vector <NiChange> NiChanges;
   111   typedef std::list<Ptr<Event> > Events;
   112 
   113   void EraseEvents (Events::iterator start, Events::iterator end); 
   114 
   115   InterferenceHelper (const InterferenceHelper &o);
   116   InterferenceHelper &operator = (const InterferenceHelper &o);
   117   void AppendEvent (Ptr<Event> event);
   118   double CalculateNoiseInterferenceW (Ptr<Event> event, NiChanges *ni) const;
   119   double CalculateSnr (double signal, double noiseInterference, WifiMode mode) const;
   120   double CalculateChunkSuccessRate (double snir, Time delay, WifiMode mode) const;
   121   double CalculatePer (Ptr<const Event> event, NiChanges *ni) const;
   122   Time GetMaxPacketDuration (void) const;
   123 
   124   Time m_maxPacketDuration;
   125   double m_noiseFigure; /**< noise figure (linear) */
   126   Events m_events;
   127   Ptr<ErrorRateModel> m_errorRateModel;
   128 };
   129 
   130 } // namespace ns3
   131 
   132 #endif /* INTERFERENCE_HELPER_H */