# HG changeset patch # User Mathieu Lacage # Date 1197534380 -3600 # Node ID ae2bbdbfc161bd9ae23d30a4710cc7968f7f107d # Parent 85724b1cbb1a22f6e732c25e043689a456953177 the meat of the onoe rate control algorithm. diff -r 85724b1cbb1a -r ae2bbdbfc161 src/devices/wifi/onoe-mac-stations.cc --- a/src/devices/wifi/onoe-mac-stations.cc Thu Dec 13 08:39:08 2007 +0100 +++ b/src/devices/wifi/onoe-mac-stations.cc Thu Dec 13 09:26:20 2007 +0100 @@ -22,6 +22,9 @@ #include "ns3/default-value.h" #include "ns3/time-default-value.h" #include "ns3/simulator.h" +#include "ns3/log.h" + +NS_LOG_COMPONENT_DEFINE ("OnoeMacStation"); namespace ns3 { @@ -52,7 +55,13 @@ OnoeMacStation::OnoeMacStation (OnoeMacStations *stations) : m_stations (stations), - m_nextModeUpdate (Simulator::Now () + stations->m_updatePeriod) + m_nextModeUpdate (Simulator::Now () + stations->m_updatePeriod), + m_shortRetry (0), + m_longRetry (0), + m_tx_ok (0), + m_tx_err (0), + m_tx_retr (0), + m_tx_upper (0) {} OnoeMacStation::~OnoeMacStation () {} @@ -105,6 +114,60 @@ { return; } + /** + * The following 20 lines of code were copied from the Onoe + * rate control kernel module used in the madwifi driver. + */ + + int dir = 0, enough; + uint32_t nrate; + enough = (m_tx_ok + m_tx_err >= 10); + + /* no packet reached -> down */ + if (m_tx_err > 0 && m_tx_ok == 0) + dir = -1; + + /* all packets needs retry in average -> down */ + if (enough && m_tx_ok < m_tx_retr) + dir = -1; + + /* no error and less than rate_raise% of packets need retry -> up */ + if (enough && m_tx_err == 0 && + m_tx_retr < (m_tx_ok * m_stations->m_addCreditThreshold) / 100) + dir = 1; + + NS_LOG_DEBUG (this << " ok " << m_tx_ok << " err " << m_tx_err << " retr " << m_tx_retr << + " upper " << m_tx_upper << " dir " << dir); + + nrate = m_txrate; + switch (dir) { + case 0: + if (enough && m_tx_upper > 0) + m_tx_upper--; + break; + case -1: + if (nrate > 0) { + nrate--; + } + m_tx_upper = 0; + break; + case 1: + /* raise rate if we hit rate_raise_threshold */ + if (++m_tx_upper < m_stations->m_raiseThreshold) + break; + m_tx_upper = 0; + if (nrate + 1 < GetNSupportedModes ()) { + nrate++; + } + break; + } + + if (nrate != m_txrate) { + m_txrate = nrate; + m_tx_ok = m_tx_err = m_tx_retr = m_tx_upper = 0; + } else if (enough) + m_tx_ok = m_tx_err = m_tx_retr = 0; + } OnoeMacStations * @@ -116,8 +179,46 @@ OnoeMacStation::DoGetDataMode (uint32_t size) { UpdateMode (); - // XXX - return GetSupportedMode (0); + NS_ASSERT (m_txrate < GetNSupportedModes ()); + uint32_t rateIndex; + if (m_longRetry < 4) + { + rateIndex = m_txrate; + } + else if (m_longRetry < 6) + { + if (m_txrate > 0) + { + rateIndex = m_txrate - 1; + } + else + { + rateIndex = m_txrate; + } + } + else if (m_longRetry < 8) + { + if (m_txrate > 1) + { + rateIndex = m_txrate - 2; + } + else + { + rateIndex = m_txrate; + } + } + else + { + if (m_txrate > 2) + { + rateIndex = m_txrate - 3; + } + else + { + rateIndex = m_txrate; + } + } + return GetSupportedMode (rateIndex); } WifiMode OnoeMacStation::DoGetRtsMode (void) diff -r 85724b1cbb1a -r ae2bbdbfc161 src/devices/wifi/onoe-mac-stations.h --- a/src/devices/wifi/onoe-mac-stations.h Thu Dec 13 08:39:08 2007 +0100 +++ b/src/devices/wifi/onoe-mac-stations.h Thu Dec 13 09:26:20 2007 +0100 @@ -72,12 +72,14 @@ void UpdateMode (void); OnoeMacStations *m_stations; + Time m_nextModeUpdate; uint32_t m_shortRetry; uint32_t m_longRetry; - Time m_nextModeUpdate; uint32_t m_tx_ok; uint32_t m_tx_err; uint32_t m_tx_retr; + uint32_t m_tx_upper; + uint32_t m_txrate; }; } // namespace ns3