src/devices/wifi/onoe-wifi-manager.cc
changeset 6065 0f012e7d9128
parent 3212 0c00342d6a73
equal deleted inserted replaced
6064:ddec96840ebd 6065:0f012e7d9128
    24 #include "ns3/uinteger.h"
    24 #include "ns3/uinteger.h"
    25 
    25 
    26 NS_LOG_COMPONENT_DEFINE ("OnoeWifiRemoteStation");
    26 NS_LOG_COMPONENT_DEFINE ("OnoeWifiRemoteStation");
    27 
    27 
    28 namespace ns3 {
    28 namespace ns3 {
       
    29 
       
    30 struct OnoeWifiRemoteStation : public WifiRemoteStation
       
    31 {
       
    32   Time m_nextModeUpdate;
       
    33   uint32_t m_shortRetry;
       
    34   uint32_t m_longRetry;
       
    35   uint32_t m_tx_ok;
       
    36   uint32_t m_tx_err;
       
    37   uint32_t m_tx_retr;
       
    38   uint32_t m_tx_upper;
       
    39   uint32_t m_txrate;
       
    40 };
       
    41 
    29 
    42 
    30 NS_OBJECT_ENSURE_REGISTERED (OnoeWifiManager);
    43 NS_OBJECT_ENSURE_REGISTERED (OnoeWifiManager);
    31 
    44 
    32 TypeId
    45 TypeId
    33 OnoeWifiManager::GetTypeId (void)
    46 OnoeWifiManager::GetTypeId (void)
    53 }
    66 }
    54 
    67 
    55 OnoeWifiManager::OnoeWifiManager ()
    68 OnoeWifiManager::OnoeWifiManager ()
    56 {}
    69 {}
    57 WifiRemoteStation *
    70 WifiRemoteStation *
    58 OnoeWifiManager::CreateStation (void)
    71 OnoeWifiManager::DoCreateStation (void) const
    59 {
    72 {
    60   return new OnoeWifiRemoteStation (this);
    73   OnoeWifiRemoteStation *station = new OnoeWifiRemoteStation ();
    61 }
    74   station->m_nextModeUpdate = Simulator::Now () + m_updatePeriod;
    62 
    75   station->m_shortRetry = 0;
    63 OnoeWifiRemoteStation::OnoeWifiRemoteStation (Ptr<OnoeWifiManager> stations)
    76   station->m_longRetry = 0;
    64   : m_stations (stations),
    77   station->m_tx_ok = 0;
    65     m_nextModeUpdate (Simulator::Now () + stations->m_updatePeriod),
    78   station->m_tx_err = 0;
    66     m_shortRetry (0),
    79   station->m_tx_retr = 0;
    67     m_longRetry (0),
    80   station->m_tx_upper = 0;
    68     m_tx_ok (0),
    81   station->m_txrate = 0;
    69     m_tx_err (0),
    82   return station;
    70     m_tx_retr (0),
    83 }
    71     m_tx_upper (0),
    84 void 
    72     m_txrate (0)
    85 OnoeWifiManager::DoReportRxOk (WifiRemoteStation *station,
       
    86                                      double rxSnr, WifiMode txMode)
    73 {}
    87 {}
    74 OnoeWifiRemoteStation::~OnoeWifiRemoteStation ()
    88 void 
       
    89 OnoeWifiManager::DoReportRtsFailed (WifiRemoteStation *st)
       
    90 {
       
    91   OnoeWifiRemoteStation *station = (OnoeWifiRemoteStation *)st;
       
    92   station->m_shortRetry++;
       
    93 }
       
    94 void 
       
    95 OnoeWifiManager::DoReportDataFailed (WifiRemoteStation *st)
       
    96 {
       
    97   OnoeWifiRemoteStation *station = (OnoeWifiRemoteStation *)st;
       
    98   station->m_longRetry++;
       
    99 }
       
   100 void 
       
   101 OnoeWifiManager::DoReportRtsOk (WifiRemoteStation *station,
       
   102                                       double ctsSnr, WifiMode ctsMode, double rtsSnr)
    75 {}
   103 {}
    76 
   104 void 
    77 void 
   105 OnoeWifiManager::DoReportDataOk (WifiRemoteStation *st,
    78 OnoeWifiRemoteStation::DoReportRxOk (double rxSnr, WifiMode txMode)
   106                                        double ackSnr, WifiMode ackMode, double dataSnr)
    79 {}
   107 {
    80 void 
   108   OnoeWifiRemoteStation *station = (OnoeWifiRemoteStation *)st;
    81 OnoeWifiRemoteStation::DoReportRtsFailed (void)
   109   UpdateRetry (station);
    82 {
   110   station->m_tx_ok++;
    83   m_shortRetry++;
   111 }
    84 }
   112 void 
    85 void 
   113 OnoeWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *st)
    86 OnoeWifiRemoteStation::DoReportDataFailed (void)
   114 {
    87 {
   115   OnoeWifiRemoteStation *station = (OnoeWifiRemoteStation *)st;
    88   m_longRetry++;
   116   UpdateRetry (station);
    89 }
   117   station->m_tx_err++;
    90 void 
   118 }
    91 OnoeWifiRemoteStation::DoReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr)
   119 void 
    92 {}
   120 OnoeWifiManager::DoReportFinalDataFailed (WifiRemoteStation *st)
    93 void 
   121 {
    94 OnoeWifiRemoteStation::DoReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr)
   122   OnoeWifiRemoteStation *station = (OnoeWifiRemoteStation *)st;
    95 {
   123   UpdateRetry (station);
    96   UpdateRetry ();
   124   station->m_tx_err++;
    97   m_tx_ok++;
       
    98 }
       
    99 void 
       
   100 OnoeWifiRemoteStation::DoReportFinalRtsFailed (void)
       
   101 {
       
   102   UpdateRetry ();
       
   103   m_tx_err++;
       
   104 }
       
   105 void 
       
   106 OnoeWifiRemoteStation::DoReportFinalDataFailed (void)
       
   107 {
       
   108   UpdateRetry ();
       
   109   m_tx_err++;
       
   110 }
   125 }
   111 void
   126 void
   112 OnoeWifiRemoteStation::UpdateRetry (void)
   127 OnoeWifiManager::UpdateRetry (OnoeWifiRemoteStation *station)
   113 {
   128 {
   114   m_tx_retr += m_shortRetry + m_longRetry;
   129   station->m_tx_retr += station->m_shortRetry + station->m_longRetry;
   115   m_shortRetry = 0;
   130   station->m_shortRetry = 0;
   116   m_longRetry = 0;
   131   station->m_longRetry = 0;
   117 }
   132 }
   118 void
   133 void
   119 OnoeWifiRemoteStation::UpdateMode (void)
   134 OnoeWifiManager::UpdateMode (OnoeWifiRemoteStation *station)
   120 {
   135 {
   121   if (Simulator::Now () < m_nextModeUpdate)
   136   if (Simulator::Now () < station->m_nextModeUpdate)
   122     {
   137     {
   123       return;
   138       return;
   124     }
   139     }
   125   m_nextModeUpdate = Simulator::Now () + m_stations->m_updatePeriod;
   140   station->m_nextModeUpdate = Simulator::Now () + m_updatePeriod;
   126   /**
   141   /**
   127    * The following 20 lines of code were copied from the Onoe
   142    * The following 20 lines of code were copied from the Onoe
   128    * rate control kernel module used in the madwifi driver.
   143    * rate control kernel module used in the madwifi driver.
   129    */
   144    */
   130 
   145 
   131   int dir = 0, enough;
   146   int dir = 0, enough;
   132   uint32_t nrate;
   147   uint32_t nrate;
   133   enough = (m_tx_ok + m_tx_err >= 10);
   148   enough = (station->m_tx_ok + station->m_tx_err >= 10);
   134 
   149 
   135   /* no packet reached -> down */
   150   /* no packet reached -> down */
   136   if (m_tx_err > 0 && m_tx_ok == 0)
   151   if (station->m_tx_err > 0 && station->m_tx_ok == 0)
   137     dir = -1;
   152     dir = -1;
   138 
   153 
   139   /* all packets needs retry in average -> down */
   154   /* all packets needs retry in average -> down */
   140   if (enough && m_tx_ok < m_tx_retr)
   155   if (enough && station->m_tx_ok < station->m_tx_retr)
   141     dir = -1;
   156     dir = -1;
   142 
   157 
   143   /* no error and less than rate_raise% of packets need retry -> up */
   158   /* no error and less than rate_raise% of packets need retry -> up */
   144   if (enough && m_tx_err == 0 &&
   159   if (enough && station->m_tx_err == 0 &&
   145       m_tx_retr < (m_tx_ok * m_stations->m_addCreditThreshold) / 100)
   160       station->m_tx_retr < (station->m_tx_ok * m_addCreditThreshold) / 100)
   146     dir = 1;
   161     dir = 1;
   147 
   162 
   148   NS_LOG_DEBUG (this << " ok " << m_tx_ok << " err " << m_tx_err << " retr " << m_tx_retr <<
   163   NS_LOG_DEBUG (this << " ok " << station->m_tx_ok << " err " << station->m_tx_err << " retr " << station->m_tx_retr <<
   149                 " upper " << m_tx_upper << " dir " << dir);
   164                 " upper " << station->m_tx_upper << " dir " << dir);
   150 
   165 
   151   nrate = m_txrate;
   166   nrate = station->m_txrate;
   152   switch (dir) {
   167   switch (dir) {
   153   case 0:
   168   case 0:
   154     if (enough && m_tx_upper > 0)
   169     if (enough && station->m_tx_upper > 0)
   155       m_tx_upper--;
   170       station->m_tx_upper--;
   156     break;
   171     break;
   157   case -1:
   172   case -1:
   158     if (nrate > 0) {
   173     if (nrate > 0) {
   159       nrate--;
   174       nrate--;
   160     }
   175     }
   161     m_tx_upper = 0;
   176     station->m_tx_upper = 0;
   162     break;
   177     break;
   163   case 1:
   178   case 1:
   164     /* raise rate if we hit rate_raise_threshold */
   179     /* raise rate if we hit rate_raise_threshold */
   165     if (++m_tx_upper < m_stations->m_raiseThreshold)
   180     if (++station->m_tx_upper < m_raiseThreshold)
   166       break;
   181       break;
   167     m_tx_upper = 0;
   182     station->m_tx_upper = 0;
   168     if (nrate + 1 < GetNSupportedModes ()) {
   183     if (nrate + 1 < GetNSupported (station)) {
   169       nrate++;
   184       nrate++;
   170     }
   185     }
   171     break;
   186     break;
   172   }
   187   }
   173 
   188 
   174   if (nrate != m_txrate) {
   189   if (nrate != station->m_txrate) {
   175     NS_ASSERT (nrate < GetNSupportedModes ());
   190     NS_ASSERT (nrate < GetNSupported (station));
   176     m_txrate = nrate;
   191     station->m_txrate = nrate;
   177     m_tx_ok = m_tx_err = m_tx_retr = m_tx_upper = 0;
   192     station->m_tx_ok = station->m_tx_err = station->m_tx_retr = station->m_tx_upper = 0;
   178   } else if (enough)
   193   } else if (enough)
   179     m_tx_ok = m_tx_err = m_tx_retr = 0;
   194     station->m_tx_ok = station->m_tx_err = station->m_tx_retr = 0;
   180 
   195 
   181 }
   196 }
   182 
   197 
   183 Ptr<WifiRemoteStationManager>
       
   184 OnoeWifiRemoteStation::GetManager (void) const
       
   185 {
       
   186   return m_stations;
       
   187 }
       
   188 WifiMode 
   198 WifiMode 
   189 OnoeWifiRemoteStation::DoGetDataMode (uint32_t size)
   199 OnoeWifiManager::DoGetDataMode (WifiRemoteStation *st,
   190 {
   200                                       uint32_t size)
   191   UpdateMode ();
   201 {
   192   NS_ASSERT (m_txrate < GetNSupportedModes ());
   202   OnoeWifiRemoteStation *station = (OnoeWifiRemoteStation *)st;
       
   203   UpdateMode (station);
       
   204   NS_ASSERT (station->m_txrate < GetNSupported (station));
   193   uint32_t rateIndex;
   205   uint32_t rateIndex;
   194   if (m_longRetry < 4)
   206   if (station->m_longRetry < 4)
   195     {
   207     {
   196       rateIndex = m_txrate;
   208       rateIndex = station->m_txrate;
   197     }
   209     }
   198   else if (m_longRetry < 6)
   210   else if (station->m_longRetry < 6)
   199     {
   211     {
   200       if (m_txrate > 0)
   212       if (station->m_txrate > 0)
   201         {
   213         {
   202           rateIndex = m_txrate - 1;
   214           rateIndex = station->m_txrate - 1;
   203         }
   215         }
   204       else
   216       else
   205         {
   217         {
   206           rateIndex = m_txrate;
   218           rateIndex = station->m_txrate;
   207         }
   219         }
   208     }
   220     }
   209   else if (m_longRetry < 8)
   221   else if (station->m_longRetry < 8)
   210     {
   222     {
   211       if (m_txrate > 1)
   223       if (station->m_txrate > 1)
   212         {
   224         {
   213           rateIndex = m_txrate - 2;
   225           rateIndex = station->m_txrate - 2;
   214         }
   226         }
   215       else
   227       else
   216         {
   228         {
   217           rateIndex = m_txrate;
   229           rateIndex = station->m_txrate;
   218         }
   230         }
   219     }
   231     }
   220   else
   232   else
   221     {
   233     {
   222       if (m_txrate > 2)
   234       if (station->m_txrate > 2)
   223         {
   235         {
   224           rateIndex = m_txrate - 3;
   236           rateIndex = station->m_txrate - 3;
   225         }
   237         }
   226       else
   238       else
   227         {
   239         {
   228           rateIndex = m_txrate;
   240           rateIndex = station->m_txrate;
   229         }
   241         }
   230     }
   242     }
   231   return GetSupportedMode (rateIndex);
   243   return GetSupported (station, rateIndex);
   232 }
   244 }
   233 WifiMode 
   245 WifiMode 
   234 OnoeWifiRemoteStation::DoGetRtsMode (void)
   246 OnoeWifiManager::DoGetRtsMode (WifiRemoteStation *st)
   235 {
   247 {
   236   UpdateMode ();
   248   OnoeWifiRemoteStation *station = (OnoeWifiRemoteStation *)st;
       
   249   UpdateMode (station);
   237   // XXX: can we implement something smarter ?
   250   // XXX: can we implement something smarter ?
   238   return GetSupportedMode (0);
   251   return GetSupported (station, 0);
       
   252 }
       
   253 
       
   254 bool 
       
   255 OnoeWifiManager::IsLowLatency (void) const
       
   256 {
       
   257   return false;
   239 }
   258 }
   240 
   259 
   241 } // namespace ns3
   260 } // namespace ns3