src/devices/wifi/aarfcd-wifi-manager.cc
changeset 4336 6886a39dfc47
parent 4334 12b3fcf84fc5
child 4337 a74d21ce3298
equal deleted inserted replaced
4335:33cf509840d3 4336:6886a39dfc47
    23 #include "ns3/log.h"
    23 #include "ns3/log.h"
    24 #include "ns3/simulator.h"
    24 #include "ns3/simulator.h"
    25 #include "ns3/boolean.h"
    25 #include "ns3/boolean.h"
    26 #include <algorithm>
    26 #include <algorithm>
    27 
    27 
    28 NS_LOG_COMPONENT_DEFINE ("Maarf");
    28 NS_LOG_COMPONENT_DEFINE ("Aarfcd");
    29 
    29 
    30 namespace ns3 {
    30 namespace ns3 {
    31 
    31 
    32 NS_OBJECT_ENSURE_REGISTERED(AarfcdWifiManager);
    32 NS_OBJECT_ENSURE_REGISTERED(AarfcdWifiManager);
    33 
    33 
   165   m_timer++;
   165   m_timer++;
   166   m_failed++;
   166   m_failed++;
   167   m_retry++;
   167   m_retry++;
   168   m_success = 0;
   168   m_success = 0;
   169   //printf ("%.9f %p Fail %d %d %d\n",Simulator::Now ().GetSeconds (),this,m_rate,m_timer,m_retry);
   169   //printf ("%.9f %p Fail %d %d %d\n",Simulator::Now ().GetSeconds (),this,m_rate,m_timer,m_retry);
   170   if (!m_rtsOn) {
   170   if (!m_rtsOn) 
   171     TurnOnRts ();
   171     {
   172     if (!m_justModifyRate && !m_haveASuccess) {
   172       TurnOnRts ();
   173       //printf ("%p Increase RTS Windows\n",this);
   173       if (!m_justModifyRate && !m_haveASuccess) 
   174       IncreaseRtsWnd ();
   174         {
   175     }
   175           //printf ("%p Increase RTS Windows\n",this);
   176     else {
   176           IncreaseRtsWnd ();
   177       //printf ("%p Reset RTS Window\n",this);
   177         }
   178       ResetRtsWnd ();
   178       else 
   179     }
   179         {
   180     m_rtsCounter = m_rtsWnd;
   180           //printf ("%p Reset RTS Window\n",this);
   181     if (m_retry >= 2) {
   181           ResetRtsWnd ();
       
   182         }
       
   183       m_rtsCounter = m_rtsWnd;
       
   184       if (m_retry >= 2) 
       
   185         {
       
   186           m_timer = 0;
       
   187         }
       
   188       //printf ("%.9f %p AtcivateRTS %d %d\n",Simulator::Now ().GetSeconds (),this, m_rate, m_rtsCounter);
       
   189     }
       
   190   else if (m_recovery) 
       
   191     {
       
   192       NS_ASSERT (m_retry >= 1);
       
   193       m_justModifyRate = false;
       
   194       m_rtsCounter = m_rtsWnd;
       
   195       if (NeedRecoveryFallback ()) 
       
   196         {
       
   197           if (m_turnOffRtsAfterRateDecrease) 
       
   198             {
       
   199               TurnOffRts ();
       
   200             }
       
   201           m_justModifyRate = true;
       
   202           ReportRecoveryFailure ();
       
   203           if (m_rate != GetMinRate ()) 
       
   204             {
       
   205               m_rate--;
       
   206             }
       
   207           NS_LOG_INFO ("" << this << " JD rate=" << m_rate << " Sthr=" << GetSuccessThreshold ());
       
   208           //printf ("%.9f %p DecreaseRateRecovery %d\n", Simulator::Now ().GetSeconds (),this, m_rate);
       
   209         }
   182       m_timer = 0;
   210       m_timer = 0;
   183     }
   211     } 
   184     //printf ("%.9f %p AtcivateRTS %d %d\n",Simulator::Now ().GetSeconds (),this, m_rate, m_rtsCounter);
   212   else 
   185   }
   213     {
   186   else if (m_recovery) {
   214       NS_ASSERT (m_retry >= 1);
   187     NS_ASSERT (m_retry >= 1);
   215       m_justModifyRate = false;
   188     m_justModifyRate = false;
   216       m_rtsCounter = m_rtsWnd;
   189     m_rtsCounter = m_rtsWnd;
   217       if (NeedNormalFallback ()) 
   190     if (NeedRecoveryFallback ()) {
   218         {
   191       if (m_turnOffRtsAfterRateDecrease) {
   219           if (m_turnOffRtsAfterRateDecrease) 
   192         TurnOffRts ();
   220             {
   193       }
   221               TurnOffRts ();
   194       m_justModifyRate = true;
   222             }
   195       ReportRecoveryFailure ();
   223           m_justModifyRate = true;
   196       if (m_rate != GetMinRate ()) {
   224           ReportFailure ();
   197         m_rate--;
   225           if (m_rate != GetMinRate ()) 
   198       }
   226             {
   199       NS_LOG_INFO ("" << this << " JD rate=" << m_rate << " Sthr=" << GetSuccessThreshold ());
   227               m_rate--;
   200       //printf ("%.9f %p DecreaseRateRecovery %d\n", Simulator::Now ().GetSeconds (),this, m_rate);
   228             }
   201     }
   229           NS_LOG_INFO ("" << this << " JD rate=" << m_rate << " Sthr=" << GetSuccessThreshold ());
   202     m_timer = 0;
   230           //printf ("%.9f %p DecreaseRate %d\n", Simulator::Now ().GetSeconds (),this,m_rate);
   203   } 
   231         }
   204   else {
   232       if (m_retry >= 2) 
   205     NS_ASSERT (m_retry >= 1);
   233         {
   206     m_justModifyRate = false;
   234           m_timer = 0;
   207     m_rtsCounter = m_rtsWnd;
   235         }
   208     if (NeedNormalFallback ()) {
   236     }
   209       if (m_turnOffRtsAfterRateDecrease) {
       
   210         TurnOffRts ();
       
   211       }
       
   212       m_justModifyRate = true;
       
   213       ReportFailure ();
       
   214       if (m_rate != GetMinRate ()) {
       
   215         m_rate--;
       
   216       }
       
   217       NS_LOG_INFO ("" << this << " JD rate=" << m_rate << " Sthr=" << GetSuccessThreshold ());
       
   218       //printf ("%.9f %p DecreaseRate %d\n", Simulator::Now ().GetSeconds (),this,m_rate);
       
   219     }
       
   220     if (m_retry >= 2) {
       
   221       m_timer = 0;
       
   222     }
       
   223   }
       
   224   CheckRts ();
   237   CheckRts ();
   225 }
   238 }
   226 void 
   239 void 
   227 AarfcdWifiRemoteStation::DoReportRxOk (double rxSnr, WifiMode txMode)
   240 AarfcdWifiRemoteStation::DoReportRxOk (double rxSnr, WifiMode txMode)
   228 {}
   241 {}
   248   //printf ("%p OK (m_success=%d, th=%d, m_rate=%d, maxRate=%d)\n",this,m_success,GetSuccessThreshold (), m_rate, GetMaxRate ());
   261   //printf ("%p OK (m_success=%d, th=%d, m_rate=%d, maxRate=%d)\n",this,m_success,GetSuccessThreshold (), m_rate, GetMaxRate ());
   249   NS_LOG_DEBUG ("self="<<this<<" data ok success="<<m_success<<", timer="<<m_timer);
   262   NS_LOG_DEBUG ("self="<<this<<" data ok success="<<m_success<<", timer="<<m_timer);
   250   if ((m_success == GetSuccessThreshold () ||
   263   if ((m_success == GetSuccessThreshold () ||
   251        m_timer >= GetTimerTimeout ()) &&
   264        m_timer >= GetTimerTimeout ()) &&
   252       (m_rate < GetMaxRate ())) 
   265       (m_rate < GetMaxRate ())) 
   253   {
   266     {
   254     NS_LOG_DEBUG ("self="<<this<<" inc rate");
   267       NS_LOG_DEBUG ("self="<<this<<" inc rate");
   255     m_rate++;
   268       m_rate++;
   256     NS_LOG_INFO ("" << this << " JI rate=" << m_rate << " Sthr=" << GetSuccessThreshold ());
   269       NS_LOG_INFO ("" << this << " JI rate=" << m_rate << " Sthr=" << GetSuccessThreshold ());
   257     m_timer = 0;
   270       m_timer = 0;
   258     m_success = 0;
   271       m_success = 0;
   259     m_recovery = true;
   272       m_recovery = true;
   260     m_justModifyRate = true;
   273       m_justModifyRate = true;
   261     if (m_turnOnRtsAfterRateIncrease) {
   274       if (m_turnOnRtsAfterRateIncrease) 
   262       TurnOnRts ();
   275         {
   263       ResetRtsWnd ();
   276           TurnOnRts ();
   264       m_rtsCounter = m_rtsWnd;
   277           ResetRtsWnd ();
   265     }
   278           m_rtsCounter = m_rtsWnd;
   266     //printf ("%.9f %p IncreaseRate %d %d\n", Simulator::Now ().GetSeconds (),this,m_rate,(m_rtsOn?1:0));
   279         }
   267   }
   280       //printf ("%.9f %p IncreaseRate %d %d\n", Simulator::Now ().GetSeconds (),this,m_rate,(m_rtsOn?1:0));
       
   281     }
   268   else if (m_success == GetSuccessThreshold () ||
   282   else if (m_success == GetSuccessThreshold () ||
   269            m_timer >= GetTimerTimeout ()) {
   283            m_timer >= GetTimerTimeout ()) 
   270     NS_LOG_INFO ("" << this << " JI rate=" << m_rate << " Sthr=" << GetSuccessThreshold ());
   284     {
   271   }
   285       NS_LOG_INFO ("" << this << " JI rate=" << m_rate << " Sthr=" << GetSuccessThreshold ());
       
   286     }
   272   CheckRts ();
   287   CheckRts ();
   273 }
   288 }
   274 void 
   289 void 
   275 AarfcdWifiRemoteStation::DoReportFinalRtsFailed (void)
   290 AarfcdWifiRemoteStation::DoReportFinalRtsFailed (void)
   276 {}
   291 {}
   318 }
   333 }
   319 
   334 
   320 void
   335 void
   321 AarfcdWifiRemoteStation::CheckRts (void)
   336 AarfcdWifiRemoteStation::CheckRts (void)
   322 {
   337 {
   323   if (m_rtsCounter == 0 && m_rtsOn) {
   338   if (m_rtsCounter == 0 && m_rtsOn) 
   324     //printf ("%p Turn off RTS\n",this);
   339     {
   325     TurnOffRts ();
   340       //printf ("%p Turn off RTS\n",this);
   326   }
   341       TurnOffRts ();
       
   342     }
   327 }
   343 }
   328 
   344 
   329 void
   345 void
   330 AarfcdWifiRemoteStation::TurnOffRts (void)
   346 AarfcdWifiRemoteStation::TurnOffRts (void)
   331 {
   347 {
   342 
   358 
   343 void
   359 void
   344 AarfcdWifiRemoteStation::IncreaseRtsWnd (void)
   360 AarfcdWifiRemoteStation::IncreaseRtsWnd (void)
   345 {
   361 {
   346   if (m_rtsWnd == m_maxRtsWnd)
   362   if (m_rtsWnd == m_maxRtsWnd)
   347     return;
   363     {
       
   364       return;
       
   365     }
   348 
   366 
   349   m_rtsWnd *= 2;
   367   m_rtsWnd *= 2;
   350   if (m_rtsWnd > m_maxRtsWnd)
   368   if (m_rtsWnd > m_maxRtsWnd)
   351     m_rtsWnd = m_maxRtsWnd;
   369     {
       
   370       m_rtsWnd = m_maxRtsWnd;
       
   371     }
   352 }
   372 }
   353 
   373 
   354 void
   374 void
   355 AarfcdWifiRemoteStation::ResetRtsWnd (void)
   375 AarfcdWifiRemoteStation::ResetRtsWnd (void)
   356 {
   376 {