src/wifi/model/cara-wifi-manager.cc
changeset 7141 072fb225b714
parent 6852 8f1a53d3f6ca
child 7385 10beb0e53130
equal deleted inserted replaced
7140:d203296efb63 7141:072fb225b714
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     2 /*
     3  * Copyright (c) 2004,2005,2006 INRIA
     3  * Copyright (c) 2004,2005,2006 INRIA
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as 
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     7  * published by the Free Software Foundation;
     8  *
     8  *
     9  * This program is distributed in the hope that it will be useful,
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    32 
    32 
    33 struct CaraWifiRemoteStation : public WifiRemoteStation
    33 struct CaraWifiRemoteStation : public WifiRemoteStation
    34 {
    34 {
    35   uint32_t m_timer;
    35   uint32_t m_timer;
    36   uint32_t m_success;
    36   uint32_t m_success;
    37   uint32_t m_failed;  
    37   uint32_t m_failed;
    38   uint32_t m_rate;
    38   uint32_t m_rate;
    39 };
    39 };
    40 
    40 
    41 NS_OBJECT_ENSURE_REGISTERED(CaraWifiManager);
    41 NS_OBJECT_ENSURE_REGISTERED (CaraWifiManager);
    42 
    42 
    43 TypeId 
    43 TypeId
    44 CaraWifiManager::GetTypeId (void)
    44 CaraWifiManager::GetTypeId (void)
    45 {
    45 {
    46  static TypeId tid = TypeId ("ns3::CaraWifiManager")
    46   static TypeId tid = TypeId ("ns3::CaraWifiManager")
    47    .SetParent<WifiRemoteStationManager> ()
    47     .SetParent<WifiRemoteStationManager> ()
    48    .AddConstructor<CaraWifiManager> ()
    48     .AddConstructor<CaraWifiManager> ()
    49    .AddAttribute ("ProbeThreshold",
    49     .AddAttribute ("ProbeThreshold",
    50                   "The number of consecutive transmissions failure to activate the RTS probe.",
    50                    "The number of consecutive transmissions failure to activate the RTS probe.",
    51                   UintegerValue (1),
    51                    UintegerValue (1),
    52                   MakeUintegerAccessor (&CaraWifiManager::m_probeThreshold),
    52                    MakeUintegerAccessor (&CaraWifiManager::m_probeThreshold),
    53                   MakeUintegerChecker<uint32_t> ())
    53                    MakeUintegerChecker<uint32_t> ())
    54    .AddAttribute ("FailureThreshold",
    54     .AddAttribute ("FailureThreshold",
    55                   "The number of consecutive transmissions failure to decrease the rate.",
    55                    "The number of consecutive transmissions failure to decrease the rate.",
    56                   UintegerValue (2),
    56                    UintegerValue (2),
    57                   MakeUintegerAccessor (&CaraWifiManager::m_failureThreshold),
    57                    MakeUintegerAccessor (&CaraWifiManager::m_failureThreshold),
    58                   MakeUintegerChecker<uint32_t> ())
    58                    MakeUintegerChecker<uint32_t> ())
    59    .AddAttribute ("SuccessThreshold",
    59     .AddAttribute ("SuccessThreshold",
    60                   "The minimum number of sucessfull transmissions to try a new rate.",
    60                    "The minimum number of sucessfull transmissions to try a new rate.",
    61                   UintegerValue (10),
    61                    UintegerValue (10),
    62                   MakeUintegerAccessor (&CaraWifiManager::m_successThreshold),
    62                    MakeUintegerAccessor (&CaraWifiManager::m_successThreshold),
    63                   MakeUintegerChecker<uint32_t> ())
    63                    MakeUintegerChecker<uint32_t> ())
    64    .AddAttribute ("Timeout",
    64     .AddAttribute ("Timeout",
    65                   "The 'timer' in the CARA algorithm",
    65                    "The 'timer' in the CARA algorithm",
    66                   UintegerValue (15),
    66                    UintegerValue (15),
    67                   MakeUintegerAccessor (&CaraWifiManager::m_timerTimeout),
    67                    MakeUintegerAccessor (&CaraWifiManager::m_timerTimeout),
    68                   MakeUintegerChecker<uint32_t> ())
    68                    MakeUintegerChecker<uint32_t> ())
    69  ;
    69   ;
    70  return tid;
    70   return tid;
    71 }
    71 }
    72 
    72 
    73 CaraWifiManager::CaraWifiManager ()
    73 CaraWifiManager::CaraWifiManager ()
    74   : WifiRemoteStationManager ()
    74   : WifiRemoteStationManager ()
    75 {}
    75 {
       
    76 }
    76 CaraWifiManager::~CaraWifiManager ()
    77 CaraWifiManager::~CaraWifiManager ()
    77 {}
    78 {
       
    79 }
    78 
    80 
    79 WifiRemoteStation *
    81 WifiRemoteStation *
    80 CaraWifiManager::DoCreateStation (void) const
    82 CaraWifiManager::DoCreateStation (void) const
    81 {
    83 {
    82   CaraWifiRemoteStation *station = new CaraWifiRemoteStation ();
    84   CaraWifiRemoteStation *station = new CaraWifiRemoteStation ();
    85   station->m_failed = 0;
    87   station->m_failed = 0;
    86   station->m_timer = 0;
    88   station->m_timer = 0;
    87   return station;
    89   return station;
    88 }
    90 }
    89 
    91 
    90 void 
    92 void
    91 CaraWifiManager::DoReportRtsFailed (WifiRemoteStation *st)
    93 CaraWifiManager::DoReportRtsFailed (WifiRemoteStation *st)
    92 {}
    94 {
       
    95 }
    93 
    96 
    94 void 
    97 void
    95 CaraWifiManager::DoReportDataFailed (WifiRemoteStation *st)
    98 CaraWifiManager::DoReportDataFailed (WifiRemoteStation *st)
    96 {
    99 {
    97   CaraWifiRemoteStation *station = (CaraWifiRemoteStation *) st;
   100   CaraWifiRemoteStation *station = (CaraWifiRemoteStation *) st;
    98   NS_LOG_FUNCTION (station);
   101   NS_LOG_FUNCTION (station);
    99   station->m_timer++;
   102   station->m_timer++;
   100   station->m_failed++;
   103   station->m_failed++;
   101   station->m_success = 0;
   104   station->m_success = 0;
   102   if (station->m_failed >= m_failureThreshold) 
   105   if (station->m_failed >= m_failureThreshold)
   103     {
   106     {
   104       NS_LOG_DEBUG ("self="<<station<<" dec rate");
   107       NS_LOG_DEBUG ("self=" << station << " dec rate");
   105       if (station->m_rate != 0)
   108       if (station->m_rate != 0)
   106         {
   109         {
   107           station->m_rate--;
   110           station->m_rate--;
   108         }
   111         }
   109       station->m_failed = 0;
   112       station->m_failed = 0;
   110       station->m_timer = 0;
   113       station->m_timer = 0;
   111     }
   114     }
   112 }
   115 }
   113 void 
   116 void
   114 CaraWifiManager::DoReportRxOk (WifiRemoteStation *st,
   117 CaraWifiManager::DoReportRxOk (WifiRemoteStation *st,
   115                                      double rxSnr, WifiMode txMode)
   118                                double rxSnr, WifiMode txMode)
   116 {}
   119 {
   117 void 
   120 }
       
   121 void
   118 CaraWifiManager::DoReportRtsOk (WifiRemoteStation *st,
   122 CaraWifiManager::DoReportRtsOk (WifiRemoteStation *st,
   119                                       double ctsSnr, WifiMode ctsMode, double rtsSnr)
   123                                 double ctsSnr, WifiMode ctsMode, double rtsSnr)
   120 {
   124 {
   121   NS_LOG_DEBUG ("self="<<st<<" rts ok");
   125   NS_LOG_DEBUG ("self=" << st << " rts ok");
   122 }
   126 }
   123 void 
   127 void
   124 CaraWifiManager::DoReportDataOk (WifiRemoteStation *st,
   128 CaraWifiManager::DoReportDataOk (WifiRemoteStation *st,
   125                                        double ackSnr, WifiMode ackMode, double dataSnr)
   129                                  double ackSnr, WifiMode ackMode, double dataSnr)
   126 {
   130 {
   127   CaraWifiRemoteStation *station = (CaraWifiRemoteStation *) st;
   131   CaraWifiRemoteStation *station = (CaraWifiRemoteStation *) st;
   128   station->m_timer++;
   132   station->m_timer++;
   129   station->m_success++;
   133   station->m_success++;
   130   station->m_failed = 0;
   134   station->m_failed = 0;
   131   NS_LOG_DEBUG ("self="<<station<<" data ok success="<<station->m_success<<", timer="<<station->m_timer);
   135   NS_LOG_DEBUG ("self=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
   132   if ((station->m_success == m_successThreshold ||
   136   if ((station->m_success == m_successThreshold
   133        station->m_timer >= m_timerTimeout))
   137        || station->m_timer >= m_timerTimeout))
   134     {
   138     {
   135       if (station->m_rate < GetNSupported (station) - 1)
   139       if (station->m_rate < GetNSupported (station) - 1)
   136         {
   140         {
   137           station->m_rate++;
   141           station->m_rate++;
   138         }
   142         }
   139       NS_LOG_DEBUG ("self="<<station<<" inc rate=" << station->m_rate);
   143       NS_LOG_DEBUG ("self=" << station << " inc rate=" << station->m_rate);
   140       station->m_timer = 0;
   144       station->m_timer = 0;
   141       station->m_success = 0;
   145       station->m_success = 0;
   142     }
   146     }
   143 }
   147 }
   144 void 
   148 void
   145 CaraWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *st)
   149 CaraWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *st)
   146 {}
   150 {
   147 void 
   151 }
       
   152 void
   148 CaraWifiManager::DoReportFinalDataFailed (WifiRemoteStation *st)
   153 CaraWifiManager::DoReportFinalDataFailed (WifiRemoteStation *st)
   149 {}
   154 {
       
   155 }
   150 
   156 
   151 WifiMode
   157 WifiMode
   152 CaraWifiManager::DoGetDataMode (WifiRemoteStation *st,
   158 CaraWifiManager::DoGetDataMode (WifiRemoteStation *st,
   153                                       uint32_t size)
   159                                 uint32_t size)
   154 {
   160 {
   155   CaraWifiRemoteStation *station = (CaraWifiRemoteStation *) st;
   161   CaraWifiRemoteStation *station = (CaraWifiRemoteStation *) st;
   156   return GetSupported (station, station->m_rate);
   162   return GetSupported (station, station->m_rate);
   157 }
   163 }
   158 WifiMode
   164 WifiMode
   163   return GetSupported (st, 0);
   169   return GetSupported (st, 0);
   164 }
   170 }
   165 
   171 
   166 bool
   172 bool
   167 CaraWifiManager::DoNeedRts (WifiRemoteStation *st,
   173 CaraWifiManager::DoNeedRts (WifiRemoteStation *st,
   168                                   Ptr<const Packet> packet, bool normally)
   174                             Ptr<const Packet> packet, bool normally)
   169 {
   175 {
   170   CaraWifiRemoteStation *station = (CaraWifiRemoteStation *) st;
   176   CaraWifiRemoteStation *station = (CaraWifiRemoteStation *) st;
   171   return normally || station->m_failed >= m_probeThreshold;
   177   return normally || station->m_failed >= m_probeThreshold;
   172 }
   178 }
   173 
   179 
   174 bool 
   180 bool
   175 CaraWifiManager::IsLowLatency (void) const
   181 CaraWifiManager::IsLowLatency (void) const
   176 {
   182 {
   177   return true;
   183   return true;
   178 }
   184 }
   179 
   185