00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "ideal-wifi-manager.h"
00021 #include "wifi-phy.h"
00022 #include "ns3/assert.h"
00023 #include "ns3/double.h"
00024 #include <math.h>
00025
00026 namespace ns3 {
00027
00028 NS_OBJECT_ENSURE_REGISTERED (IdealWifiManager);
00029
00030 TypeId
00031 IdealWifiManager::GetTypeId (void)
00032 {
00033 static TypeId tid = TypeId ("ns3::IdealWifiManager")
00034 .SetParent<WifiRemoteStationManager> ()
00035 .AddConstructor<IdealWifiManager> ()
00036 .AddAttribute ("BerThreshold",
00037 "The maximum Bit Error Rate acceptable at any transmission mode",
00038 DoubleValue (10e-6),
00039 MakeDoubleAccessor (&IdealWifiManager::m_ber),
00040 MakeDoubleChecker<double> ())
00041 ;
00042 return tid;
00043 }
00044
00045 IdealWifiManager::IdealWifiManager ()
00046 {}
00047 IdealWifiManager::~IdealWifiManager ()
00048 {}
00049
00050 void
00051 IdealWifiManager::SetupPhy (Ptr<WifiPhy> phy)
00052 {
00053 uint32_t nModes = phy->GetNModes ();
00054 for (uint32_t i = 0; i < nModes; i++)
00055 {
00056 WifiMode mode = phy->GetMode (i);
00057 AddModeSnrThreshold (mode, phy->CalculateSnr (mode, m_ber));
00058 }
00059
00060 WifiRemoteStationManager::SetupPhy (phy);
00061 }
00062
00063 WifiRemoteStation *
00064 IdealWifiManager::CreateStation (void)
00065 {
00066 return new IdealWifiRemoteStation (this);
00067 }
00068
00069 double
00070 IdealWifiManager::GetSnrThreshold (WifiMode mode) const
00071 {
00072 for (Thresholds::const_iterator i = m_thresholds.begin (); i != m_thresholds.end (); i++)
00073 {
00074 if (mode == i->second)
00075 {
00076 return i->first;
00077 }
00078 }
00079 NS_ASSERT (false);
00080 return 0.0;
00081 }
00082
00083 void
00084 IdealWifiManager::AddModeSnrThreshold (WifiMode mode, double snr)
00085 {
00086 m_thresholds.push_back (std::make_pair (snr,mode));
00087 }
00088
00089 IdealWifiRemoteStation::IdealWifiRemoteStation (Ptr<IdealWifiManager> manager)
00090 : m_manager (manager),
00091 m_lastSnr (0.0)
00092 {}
00093 IdealWifiRemoteStation::~IdealWifiRemoteStation ()
00094 {}
00095 void
00096 IdealWifiRemoteStation::DoReportRxOk (double rxSnr, WifiMode txMode)
00097 {}
00098 void
00099 IdealWifiRemoteStation::DoReportRtsFailed (void)
00100 {}
00101 void
00102 IdealWifiRemoteStation::DoReportDataFailed (void)
00103 {}
00104 void
00105 IdealWifiRemoteStation::DoReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr)
00106 {
00107 m_lastSnr = rtsSnr;
00108 }
00109 void
00110 IdealWifiRemoteStation::DoReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr)
00111 {
00112 m_lastSnr = dataSnr;
00113 }
00114 void
00115 IdealWifiRemoteStation::DoReportFinalRtsFailed (void)
00116 {}
00117 void
00118 IdealWifiRemoteStation::DoReportFinalDataFailed (void)
00119 {}
00120
00121 WifiMode
00122 IdealWifiRemoteStation::DoGetDataMode (uint32_t size)
00123 {
00124
00125
00126
00127 double maxThreshold = 0.0;
00128 WifiMode maxMode = m_manager->GetDefaultMode ();
00129 for (uint32_t i = 0; i < GetNSupportedModes (); i++)
00130 {
00131 WifiMode mode = GetSupportedMode (i);
00132 double threshold = m_manager->GetSnrThreshold (mode);
00133 if (threshold > maxThreshold &&
00134 threshold < m_lastSnr)
00135 {
00136 maxThreshold = threshold;
00137 maxMode = mode;
00138 }
00139 }
00140 return maxMode;
00141 }
00142 WifiMode
00143 IdealWifiRemoteStation::DoGetRtsMode (void)
00144 {
00145
00146
00147
00148 double maxThreshold = 0.0;
00149 WifiMode maxMode = m_manager->GetDefaultMode ();
00150 for (uint32_t i = 0; i < m_manager->GetNBasicModes (); i++)
00151 {
00152 WifiMode mode = m_manager->GetBasicMode (i);
00153 double threshold = m_manager->GetSnrThreshold (mode);
00154 if (threshold > maxThreshold &&
00155 threshold < m_lastSnr)
00156 {
00157 maxThreshold = threshold;
00158 maxMode = mode;
00159 }
00160 }
00161 return maxMode;
00162 }
00163 Ptr<WifiRemoteStationManager>
00164 IdealWifiRemoteStation::GetManager (void) const
00165 {
00166 return m_manager;
00167 }
00168
00169 }