00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "onoe-wifi-manager.h"
00022 #include "ns3/simulator.h"
00023 #include "ns3/log.h"
00024 #include "ns3/uinteger.h"
00025
00026 NS_LOG_COMPONENT_DEFINE ("OnoeWifiRemoteStation");
00027
00028 namespace ns3 {
00029
00030 NS_OBJECT_ENSURE_REGISTERED (OnoeWifiManager);
00031
00032 TypeId
00033 OnoeWifiManager::GetTypeId (void)
00034 {
00035 static TypeId tid = TypeId ("ns3::OnoeWifiManager")
00036 .SetParent<WifiRemoteStationManager> ()
00037 .AddConstructor<OnoeWifiManager> ()
00038 .AddAttribute ("UpdatePeriod",
00039 "The interval between decisions about rate control changes",
00040 TimeValue (Seconds (1.0)),
00041 MakeTimeAccessor (&OnoeWifiManager::m_updatePeriod),
00042 MakeTimeChecker ())
00043 .AddAttribute ("RaiseThreshold", "Attempt to raise the rate if we hit that threshold",
00044 UintegerValue (10),
00045 MakeUintegerAccessor (&OnoeWifiManager::m_raiseThreshold),
00046 MakeUintegerChecker<uint32_t> ())
00047 .AddAttribute ("AddCreditThreshold", "Add credit threshold",
00048 UintegerValue (10),
00049 MakeUintegerAccessor (&OnoeWifiManager::m_addCreditThreshold),
00050 MakeUintegerChecker<uint32_t> ())
00051 ;
00052 return tid;
00053 }
00054
00055 OnoeWifiManager::OnoeWifiManager ()
00056 {}
00057 WifiRemoteStation *
00058 OnoeWifiManager::CreateStation (void)
00059 {
00060 return new OnoeWifiRemoteStation (this);
00061 }
00062
00063 OnoeWifiRemoteStation::OnoeWifiRemoteStation (Ptr<OnoeWifiManager> stations)
00064 : m_stations (stations),
00065 m_nextModeUpdate (Simulator::Now () + stations->m_updatePeriod),
00066 m_shortRetry (0),
00067 m_longRetry (0),
00068 m_tx_ok (0),
00069 m_tx_err (0),
00070 m_tx_retr (0),
00071 m_tx_upper (0),
00072 m_txrate (0)
00073 {}
00074 OnoeWifiRemoteStation::~OnoeWifiRemoteStation ()
00075 {}
00076
00077 void
00078 OnoeWifiRemoteStation::DoReportRxOk (double rxSnr, WifiMode txMode)
00079 {}
00080 void
00081 OnoeWifiRemoteStation::DoReportRtsFailed (void)
00082 {
00083 m_shortRetry++;
00084 }
00085 void
00086 OnoeWifiRemoteStation::DoReportDataFailed (void)
00087 {
00088 m_longRetry++;
00089 }
00090 void
00091 OnoeWifiRemoteStation::DoReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr)
00092 {}
00093 void
00094 OnoeWifiRemoteStation::DoReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr)
00095 {
00096 UpdateRetry ();
00097 m_tx_ok++;
00098 }
00099 void
00100 OnoeWifiRemoteStation::DoReportFinalRtsFailed (void)
00101 {
00102 UpdateRetry ();
00103 m_tx_err++;
00104 }
00105 void
00106 OnoeWifiRemoteStation::DoReportFinalDataFailed (void)
00107 {
00108 UpdateRetry ();
00109 m_tx_err++;
00110 }
00111 void
00112 OnoeWifiRemoteStation::UpdateRetry (void)
00113 {
00114 m_tx_retr += m_shortRetry + m_longRetry;
00115 m_shortRetry = 0;
00116 m_longRetry = 0;
00117 }
00118 void
00119 OnoeWifiRemoteStation::UpdateMode (void)
00120 {
00121 if (Simulator::Now () < m_nextModeUpdate)
00122 {
00123 return;
00124 }
00125 m_nextModeUpdate = Simulator::Now () + m_stations->m_updatePeriod;
00126
00127
00128
00129
00130
00131 int dir = 0, enough;
00132 uint32_t nrate;
00133 enough = (m_tx_ok + m_tx_err >= 10);
00134
00135
00136 if (m_tx_err > 0 && m_tx_ok == 0)
00137 dir = -1;
00138
00139
00140 if (enough && m_tx_ok < m_tx_retr)
00141 dir = -1;
00142
00143
00144 if (enough && m_tx_err == 0 &&
00145 m_tx_retr < (m_tx_ok * m_stations->m_addCreditThreshold) / 100)
00146 dir = 1;
00147
00148 NS_LOG_DEBUG (this << " ok " << m_tx_ok << " err " << m_tx_err << " retr " << m_tx_retr <<
00149 " upper " << m_tx_upper << " dir " << dir);
00150
00151 nrate = m_txrate;
00152 switch (dir) {
00153 case 0:
00154 if (enough && m_tx_upper > 0)
00155 m_tx_upper--;
00156 break;
00157 case -1:
00158 if (nrate > 0) {
00159 nrate--;
00160 }
00161 m_tx_upper = 0;
00162 break;
00163 case 1:
00164
00165 if (++m_tx_upper < m_stations->m_raiseThreshold)
00166 break;
00167 m_tx_upper = 0;
00168 if (nrate + 1 < GetNSupportedModes ()) {
00169 nrate++;
00170 }
00171 break;
00172 }
00173
00174 if (nrate != m_txrate) {
00175 NS_ASSERT (nrate < GetNSupportedModes ());
00176 m_txrate = nrate;
00177 m_tx_ok = m_tx_err = m_tx_retr = m_tx_upper = 0;
00178 } else if (enough)
00179 m_tx_ok = m_tx_err = m_tx_retr = 0;
00180
00181 }
00182
00183 Ptr<WifiRemoteStationManager>
00184 OnoeWifiRemoteStation::GetManager (void) const
00185 {
00186 return m_stations;
00187 }
00188 WifiMode
00189 OnoeWifiRemoteStation::DoGetDataMode (uint32_t size)
00190 {
00191 UpdateMode ();
00192 NS_ASSERT (m_txrate < GetNSupportedModes ());
00193 uint32_t rateIndex;
00194 if (m_longRetry < 4)
00195 {
00196 rateIndex = m_txrate;
00197 }
00198 else if (m_longRetry < 6)
00199 {
00200 if (m_txrate > 0)
00201 {
00202 rateIndex = m_txrate - 1;
00203 }
00204 else
00205 {
00206 rateIndex = m_txrate;
00207 }
00208 }
00209 else if (m_longRetry < 8)
00210 {
00211 if (m_txrate > 1)
00212 {
00213 rateIndex = m_txrate - 2;
00214 }
00215 else
00216 {
00217 rateIndex = m_txrate;
00218 }
00219 }
00220 else
00221 {
00222 if (m_txrate > 2)
00223 {
00224 rateIndex = m_txrate - 3;
00225 }
00226 else
00227 {
00228 rateIndex = m_txrate;
00229 }
00230 }
00231 return GetSupportedMode (rateIndex);
00232 }
00233 WifiMode
00234 OnoeWifiRemoteStation::DoGetRtsMode (void)
00235 {
00236 UpdateMode ();
00237
00238 return GetSupportedMode (0);
00239 }
00240
00241 }