src/devices/wifi/ideal-wifi-manager.cc
changeset 2524 db72c0e7743e
parent 2269 06c660ffc070
child 2602 d9262bff6df2
equal deleted inserted replaced
2523:58182a1561cc 2524:db72c0e7743e
       
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 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 #include "ideal-wifi-manager.h"
       
    21 #include "wifi-phy.h"
       
    22 #include "ns3/assert.h"
       
    23 #include "ns3/double.h"
       
    24 #include <math.h>
       
    25 
       
    26 #define noIDEAL_DEBUG 1
       
    27 
       
    28 #ifdef IDEAL_DEBUG
       
    29 #include <iostream>
       
    30 #  define TRACE(x) \
       
    31 std::cout << "IDEAL TRACE " << x << std::endl;
       
    32 #else
       
    33 #  define TRACE(x)
       
    34 #endif
       
    35 
       
    36 
       
    37 namespace ns3 {
       
    38 
       
    39 NS_OBJECT_ENSURE_REGISTERED (IdealWifiManager);
       
    40 
       
    41 TypeId 
       
    42 IdealWifiManager::GetTypeId (void)
       
    43 {
       
    44   static TypeId tid = TypeId ("IdealWifiManager")
       
    45     .SetParent<WifiRemoteStationManager> ()
       
    46     .AddConstructor<IdealWifiManager> ()
       
    47     .AddAttribute ("BerThreshold",
       
    48                    "The maximum Bit Error Rate acceptable at any transmission mode",
       
    49                    Double (10e-6),
       
    50                    MakeDoubleAccessor (&IdealWifiManager::m_ber),
       
    51                    MakeDoubleChecker<double> ())
       
    52     ;
       
    53   return tid;
       
    54 }
       
    55 
       
    56 IdealWifiManager::IdealWifiManager ()
       
    57 {}
       
    58 IdealWifiManager::~IdealWifiManager ()
       
    59 {}
       
    60 
       
    61 void 
       
    62 IdealWifiManager::SetupPhy (Ptr<WifiPhy> phy)
       
    63 {
       
    64   uint32_t nModes = phy->GetNModes ();
       
    65   for (uint32_t i = 0; i < nModes; i++) 
       
    66     {
       
    67       WifiMode mode = phy->GetMode (i);
       
    68       AddModeSnrThreshold (mode, phy->CalculateSnr (mode, m_ber));
       
    69     }
       
    70   
       
    71   WifiRemoteStationManager::SetupPhy (phy);
       
    72 }
       
    73 
       
    74 WifiRemoteStation *
       
    75 IdealWifiManager::CreateStation (void)
       
    76 {
       
    77   return new IdealWifiRemoteStation (this);
       
    78 }
       
    79 
       
    80 double 
       
    81 IdealWifiManager::GetSnrThreshold (WifiMode mode) const
       
    82 {
       
    83   for (Thresholds::const_iterator i = m_thresholds.begin (); i != m_thresholds.end (); i++) 
       
    84     {
       
    85       if (mode == i->second)
       
    86         {
       
    87           return i->first;
       
    88         }
       
    89     }
       
    90   NS_ASSERT (false);
       
    91   return 0.0;
       
    92 }
       
    93 
       
    94 void 
       
    95 IdealWifiManager::AddModeSnrThreshold (WifiMode mode, double snr)
       
    96 {
       
    97   m_thresholds.push_back (std::make_pair (snr,mode));
       
    98 }
       
    99 
       
   100 IdealWifiRemoteStation::IdealWifiRemoteStation (Ptr<IdealWifiManager> manager)
       
   101   : m_manager (manager),
       
   102     m_lastSnr (0.0)
       
   103 {}
       
   104 IdealWifiRemoteStation::~IdealWifiRemoteStation ()
       
   105 {}
       
   106 void 
       
   107 IdealWifiRemoteStation::ReportRxOk (double rxSnr, WifiMode txMode)
       
   108 {}
       
   109 void 
       
   110 IdealWifiRemoteStation::ReportRtsFailed (void)
       
   111 {}
       
   112 void 
       
   113 IdealWifiRemoteStation::ReportDataFailed (void)
       
   114 {}
       
   115 void 
       
   116 IdealWifiRemoteStation::ReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr)
       
   117 {
       
   118   TRACE ("got cts for rts snr="<<rtsSnr);
       
   119   m_lastSnr = rtsSnr;
       
   120 }
       
   121 void 
       
   122 IdealWifiRemoteStation::ReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr)
       
   123 {
       
   124   TRACE ("got cts for rts snr="<<dataSnr);
       
   125   m_lastSnr = dataSnr;
       
   126 }
       
   127 void 
       
   128 IdealWifiRemoteStation::ReportFinalRtsFailed (void)
       
   129 {}
       
   130 void 
       
   131 IdealWifiRemoteStation::ReportFinalDataFailed (void)
       
   132 {}
       
   133 
       
   134 WifiMode
       
   135 IdealWifiRemoteStation::DoGetDataMode (uint32_t size)
       
   136 {
       
   137   // We search within the Supported rate set the mode with the 
       
   138   // highest snr threshold possible which is smaller than m_lastSnr 
       
   139   // to ensure correct packet delivery.
       
   140   double maxThreshold = 0.0;
       
   141   WifiMode maxMode = m_manager->GetDefaultMode ();
       
   142   for (uint32_t i = 0; i < GetNSupportedModes (); i++)
       
   143     {
       
   144       WifiMode mode = GetSupportedMode (i);
       
   145       double threshold = m_manager->GetSnrThreshold (mode);
       
   146       if (threshold > maxThreshold && 
       
   147           threshold < m_lastSnr)
       
   148         {
       
   149           maxThreshold = threshold;
       
   150           maxMode = mode;
       
   151         }
       
   152     }
       
   153   return maxMode;
       
   154 }
       
   155 WifiMode
       
   156 IdealWifiRemoteStation::DoGetRtsMode (void)
       
   157 {
       
   158   // We search within the Basic rate set the mode with the highest 
       
   159   // snr threshold possible which is smaller than m_lastSnr to 
       
   160   // ensure correct packet delivery.
       
   161   double maxThreshold = 0.0;
       
   162   WifiMode maxMode = m_manager->GetDefaultMode ();
       
   163   for (uint32_t i = 0; i < m_manager->GetNBasicModes (); i++)
       
   164     {
       
   165       WifiMode mode = m_manager->GetBasicMode (i);
       
   166       double threshold = m_manager->GetSnrThreshold (mode);
       
   167       if (threshold > maxThreshold && 
       
   168           threshold < m_lastSnr)
       
   169         {
       
   170           maxThreshold = threshold;
       
   171           maxMode = mode;
       
   172         }
       
   173     }
       
   174   return maxMode;
       
   175 }
       
   176 Ptr<WifiRemoteStationManager>
       
   177 IdealWifiRemoteStation::GetManager (void) const
       
   178 {
       
   179   return m_manager;
       
   180 }
       
   181 
       
   182 } // namespace ns3