00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "arf-wifi-manager.h"
00022 #include "ns3/assert.h"
00023 #include "ns3/log.h"
00024 #include "ns3/uinteger.h"
00025
00026 NS_LOG_COMPONENT_DEFINE ("ns3::ArfWifiManager");
00027
00028
00029 namespace ns3 {
00030
00031 ArfWifiRemoteStation::ArfWifiRemoteStation (Ptr<ArfWifiManager> stations,
00032 int minTimerTimeout,
00033 int minSuccessThreshold)
00034 : m_stations (stations)
00035 {
00036 m_minTimerTimeout = minTimerTimeout;
00037 m_minSuccessThreshold = minSuccessThreshold;
00038 m_successThreshold = m_minSuccessThreshold;
00039 m_timerTimeout = m_minTimerTimeout;
00040 m_rate = GetMinRate ();
00041
00042 m_success = 0;
00043 m_failed = 0;
00044 m_recovery = false;
00045 m_retry = 0;
00046 m_timer = 0;
00047 }
00048 ArfWifiRemoteStation::~ArfWifiRemoteStation ()
00049 {}
00050
00051 uint32_t
00052 ArfWifiRemoteStation::GetMaxRate (void)
00053 {
00054 return GetNSupportedModes ();
00055 }
00056 uint32_t
00057 ArfWifiRemoteStation::GetMinRate (void)
00058 {
00059 return 0;
00060 }
00061
00062 bool
00063 ArfWifiRemoteStation::NeedRecoveryFallback (void)
00064 {
00065 if (m_retry == 1)
00066 {
00067 return true;
00068 }
00069 else
00070 {
00071 return false;
00072 }
00073 }
00074 bool
00075 ArfWifiRemoteStation::NeedNormalFallback (void)
00076 {
00077 int retryMod = (m_retry - 1) % 2;
00078 if (retryMod == 1)
00079 {
00080 return true;
00081 }
00082 else
00083 {
00084 return false;
00085 }
00086 }
00087
00088
00089
00090 void
00091 ArfWifiRemoteStation::DoReportRtsFailed (void)
00092 {}
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 void
00103 ArfWifiRemoteStation::DoReportDataFailed (void)
00104 {
00105 m_timer++;
00106 m_failed++;
00107 m_retry++;
00108 m_success = 0;
00109
00110 if (m_recovery)
00111 {
00112 NS_ASSERT (m_retry >= 1);
00113 if (NeedRecoveryFallback ())
00114 {
00115 ReportRecoveryFailure ();
00116 if (m_rate != GetMinRate ())
00117 {
00118 m_rate--;
00119 }
00120 }
00121 m_timer = 0;
00122 }
00123 else
00124 {
00125 NS_ASSERT (m_retry >= 1);
00126 if (NeedNormalFallback ())
00127 {
00128 ReportFailure ();
00129 if (m_rate != GetMinRate ())
00130 {
00131 m_rate--;
00132 }
00133 }
00134 if (m_retry >= 2)
00135 {
00136 m_timer = 0;
00137 }
00138 }
00139 }
00140 void
00141 ArfWifiRemoteStation::DoReportRxOk (double rxSnr, WifiMode txMode)
00142 {}
00143 void ArfWifiRemoteStation::DoReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr)
00144 {
00145 NS_LOG_DEBUG ("self="<<this<<" rts ok");
00146 }
00147 void ArfWifiRemoteStation::DoReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr)
00148 {
00149 m_timer++;
00150 m_success++;
00151 m_failed = 0;
00152 m_recovery = false;
00153 m_retry = 0;
00154 NS_LOG_DEBUG ("self="<<this<<" data ok success="<<m_success<<", timer="<<m_timer);
00155 if ((m_success == GetSuccessThreshold () ||
00156 m_timer == GetTimerTimeout ()) &&
00157 (m_rate < (GetMaxRate () - 1)))
00158 {
00159 NS_LOG_DEBUG ("self="<<this<<" inc rate");
00160 m_rate++;
00161 m_timer = 0;
00162 m_success = 0;
00163 m_recovery = true;
00164 }
00165 }
00166 void
00167 ArfWifiRemoteStation::DoReportFinalRtsFailed (void)
00168 {}
00169 void
00170 ArfWifiRemoteStation::DoReportFinalDataFailed (void)
00171 {}
00172
00173 WifiMode
00174 ArfWifiRemoteStation::DoGetDataMode (uint32_t size)
00175 {
00176 return GetSupportedMode (m_rate);
00177 }
00178 WifiMode
00179 ArfWifiRemoteStation::DoGetRtsMode (void)
00180 {
00181
00182
00183 return GetSupportedMode (0);
00184 }
00185
00186 void ArfWifiRemoteStation::ReportRecoveryFailure (void)
00187 {}
00188 void ArfWifiRemoteStation::ReportFailure (void)
00189 {}
00190 uint32_t ArfWifiRemoteStation::GetMinTimerTimeout (void)
00191 {
00192 return m_minTimerTimeout;
00193 }
00194 uint32_t ArfWifiRemoteStation::GetMinSuccessThreshold (void)
00195 {
00196 return m_minSuccessThreshold;
00197 }
00198 uint32_t ArfWifiRemoteStation::GetTimerTimeout (void)
00199 {
00200 return m_timerTimeout;
00201 }
00202 uint32_t ArfWifiRemoteStation::GetSuccessThreshold (void)
00203 {
00204 return m_successThreshold;
00205 }
00206 void ArfWifiRemoteStation::SetTimerTimeout (uint32_t timerTimeout)
00207 {
00208 NS_ASSERT (timerTimeout >= m_minTimerTimeout);
00209 m_timerTimeout = timerTimeout;
00210 }
00211 void ArfWifiRemoteStation::SetSuccessThreshold (uint32_t successThreshold)
00212 {
00213 NS_ASSERT (successThreshold >= m_minSuccessThreshold);
00214 m_successThreshold = successThreshold;
00215 }
00216 Ptr<WifiRemoteStationManager>
00217 ArfWifiRemoteStation::GetManager (void) const
00218 {
00219 return m_stations;
00220 }
00221
00222 NS_OBJECT_ENSURE_REGISTERED (ArfWifiManager);
00223
00224 TypeId
00225 ArfWifiManager::GetTypeId (void)
00226 {
00227 static TypeId tid = TypeId ("ns3::ArfWifiManager")
00228 .SetParent<WifiRemoteStationManager> ()
00229 .AddConstructor<ArfWifiManager> ()
00230 .AddAttribute ("TimerThreshold", "The 'timer' threshold in the ARF algorithm.",
00231 UintegerValue (15),
00232 MakeUintegerAccessor (&ArfWifiManager::m_timerThreshold),
00233 MakeUintegerChecker<uint32_t> ())
00234 .AddAttribute ("SuccessThreshold",
00235 "The minimum number of sucessfull transmissions to try a new rate.",
00236 UintegerValue (10),
00237 MakeUintegerAccessor (&ArfWifiManager::m_successThreshold),
00238 MakeUintegerChecker<uint32_t> ())
00239 ;
00240 return tid;
00241 }
00242
00243 ArfWifiManager::ArfWifiManager ()
00244 {}
00245 ArfWifiManager::~ArfWifiManager ()
00246 {}
00247 WifiRemoteStation *
00248 ArfWifiManager::CreateStation (void)
00249 {
00250 return new ArfWifiRemoteStation (this, m_timerThreshold, m_successThreshold);
00251 }
00252
00253 }