cara rate control
authorFederico Maguolo <maguolof@dei.unipd.it>
Fri, 17 Apr 2009 10:59:51 +0200
changeset 4342 a7636758695f
parent 4341 4593d476d627
child 4343 4772bf5bc4b3
cara rate control
examples/wifi-adhoc.cc
src/devices/wifi/cara-wifi-manager.cc
src/devices/wifi/cara-wifi-manager.h
src/devices/wifi/wscript
--- a/examples/wifi-adhoc.cc	Fri Apr 17 09:59:59 2009 +0200
+++ b/examples/wifi-adhoc.cc	Fri Apr 17 10:59:51 2009 +0200
@@ -257,6 +257,12 @@
   dataset = experiment.Run (wifi, wifiPhy, wifiChannel);
   gnuplot.AddDataset (dataset);
 
+  NS_LOG_DEBUG ("cara");
+  experiment = Experiment ("cara");
+  wifi.SetRemoteStationManager ("ns3::CaraWifiManager");
+  dataset = experiment.Run (wifi, wifiPhy, wifiChannel);
+  gnuplot.AddDataset (dataset);
+
   NS_LOG_DEBUG ("ideal");
   experiment = Experiment ("ideal");
   wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/wifi/cara-wifi-manager.cc	Fri Apr 17 10:59:51 2009 +0200
@@ -0,0 +1,191 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2004,2005,2006 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as 
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Federico Maguolo <maguolof@dei.unipd.it>
+ */
+
+#include "cara-wifi-manager.h"
+#include "ns3/assert.h"
+#include "ns3/log.h"
+#include "ns3/simulator.h"
+
+NS_LOG_COMPONENT_DEFINE ("Cara");
+
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED(CaraWifiManager);
+
+CaraWifiRemoteStation::CaraWifiRemoteStation (Ptr<CaraWifiManager> manager)
+  : m_manager (manager)
+{
+  m_rate = GetMinRate ();
+
+  m_success = 0;
+  m_failed = 0;
+  m_timer = 0;
+}
+CaraWifiRemoteStation::~CaraWifiRemoteStation ()
+{}
+
+uint32_t
+CaraWifiRemoteStation::GetMaxRate (void)
+{
+  return GetNSupportedModes () - 1;
+}
+uint32_t
+CaraWifiRemoteStation::GetMinRate (void)
+{
+  return 0;
+}
+
+bool 
+CaraWifiRemoteStation::NeedNormalFallback (void)
+{
+  return (m_failed >= m_manager->m_failureThreshold);
+}
+
+void 
+CaraWifiRemoteStation::DoReportRtsFailed (void) 
+{}
+
+void 
+CaraWifiRemoteStation::DoReportDataFailed (void)
+{
+  m_timer++;
+  m_failed++;
+  m_success = 0;
+  if (NeedNormalFallback ()) 
+    {
+      if (m_rate != GetMinRate ())
+        {
+          m_rate--;
+        }
+      m_failed = 0;
+      m_timer = 0;
+    }
+}
+void 
+CaraWifiRemoteStation::DoReportRxOk (double rxSnr, WifiMode txMode)
+{}
+void 
+CaraWifiRemoteStation::DoReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr)
+{
+  NS_LOG_DEBUG ("self="<<this<<" rts ok");
+}
+void 
+CaraWifiRemoteStation::DoReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr)
+{
+  m_timer++;
+  m_success++;
+  m_failed = 0;
+  NS_LOG_DEBUG ("self="<<this<<" data ok success="<<m_success<<", timer="<<m_timer);
+  if ((m_success == m_manager->m_successThreshold ||
+       m_timer >= m_manager->m_timerTimeout))
+    {
+      NS_LOG_DEBUG ("self="<<this<<" inc rate");
+      if (m_rate < GetMaxRate ())
+        {
+          m_rate++;
+        }
+      m_timer = 0;
+      m_success = 0;
+    }
+}
+void 
+CaraWifiRemoteStation::DoReportFinalRtsFailed (void)
+{}
+void 
+CaraWifiRemoteStation::DoReportFinalDataFailed (void)
+{}
+
+WifiMode
+CaraWifiRemoteStation::DoGetDataMode (uint32_t size)
+{
+  return GetSupportedMode (m_rate);
+}
+WifiMode
+CaraWifiRemoteStation::DoGetRtsMode (void)
+{
+  // XXX: we could/should implement the Arf algorithm for
+  // RTS only by picking a single rate within the BasicRateSet.
+  return GetSupportedMode (0);
+}
+
+Ptr<WifiRemoteStationManager>
+CaraWifiRemoteStation::GetManager (void) const
+{
+  return m_manager;
+}
+
+bool
+CaraWifiRemoteStation::DoNeedRts (Ptr<const Packet> packet)
+{
+  bool rts = WifiRemoteStation::NeedRts (packet);
+  if (rts || m_failed >= m_manager->m_probeThreshold)
+    {
+      return true;
+    }
+
+  return false;
+}
+
+
+
+TypeId 
+CaraWifiManager::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::CaraWifiManager")
+   .SetParent<WifiRemoteStationManager> ()
+   .AddConstructor<CaraWifiManager> ()
+   .AddAttribute ("ProbeThreshold",
+                  "The number of consecutive transmissions failure to activate the RTS probe.",
+                  UintegerValue (1),
+                  MakeUintegerAccessor (&CaraWifiManager::m_probeThreshold),
+                  MakeUintegerChecker<uint32_t> ())
+   .AddAttribute ("FailureThreshold",
+                  "The number of consecutive transmissions failure to decrease the rate.",
+                  UintegerValue (2),
+                  MakeUintegerAccessor (&CaraWifiManager::m_failureThreshold),
+                  MakeUintegerChecker<uint32_t> ())
+   .AddAttribute ("SuccessThreshold",
+                  "The minimum number of sucessfull transmissions to try a new rate.",
+                  UintegerValue (10),
+                  MakeUintegerAccessor (&CaraWifiManager::m_failureThreshold),
+                  MakeUintegerChecker<uint32_t> ())
+   .AddAttribute ("Timeout",
+                  "The 'timer' in the CARA algorithm",
+                  UintegerValue (15),
+                  MakeUintegerAccessor (&CaraWifiManager::m_timerTimeout),
+                  MakeUintegerChecker<uint32_t> ())
+ ;
+ return tid;
+}
+
+CaraWifiManager::CaraWifiManager ()
+  : WifiRemoteStationManager ()
+{}
+CaraWifiManager::~CaraWifiManager ()
+{}
+
+WifiRemoteStation *
+CaraWifiManager::CreateStation (void)
+{
+  return new CaraWifiRemoteStation (this);
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/wifi/cara-wifi-manager.h	Fri Apr 17 10:59:51 2009 +0200
@@ -0,0 +1,90 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as 
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Federico Maguolo <maguolof@dei.unipd.it>
+ */
+#ifndef CARA_WIFI_MANAGER_H
+#define CARA_WIFI_MANAGER_H
+
+#include "wifi-remote-station-manager.h"
+
+namespace ns3 {
+
+/**
+ * \brief implement the CARA rate control algorithm
+ *
+ * Implement the CARA algorithm from:
+ * J. Kim, S. Kim, S. Choi, and D. Qiao. 
+ * "CARA: Collision-Aware Rate Adaptation for IEEE 802.11 WLANs."
+ *
+ * Originally implemented by Federico Maguolo for a very early 
+ * prototype version of ns-3.
+ */
+class CaraWifiManager : public WifiRemoteStationManager 
+{
+public:
+  static TypeId GetTypeId (void);
+  CaraWifiManager ();
+  virtual ~CaraWifiManager ();
+
+private:
+  friend class CaraWifiRemoteStation;
+  virtual class WifiRemoteStation *CreateStation (void);
+  uint32_t m_timerTimeout;
+  uint32_t m_successThreshold;
+  uint32_t m_failureThreshold;
+  uint32_t m_probeThreshold;
+};
+
+
+class CaraWifiRemoteStation : public WifiRemoteStation
+{
+public:
+  CaraWifiRemoteStation (Ptr<CaraWifiManager> manager);
+  virtual ~CaraWifiRemoteStation ();
+
+private:
+  virtual Ptr<WifiRemoteStationManager> GetManager (void) const;
+  virtual void DoReportRtsFailed (void);
+  virtual void DoReportRxOk (double rxSnr, WifiMode txMode);
+  virtual void DoReportDataFailed (void);
+  virtual void DoReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr);
+  virtual void DoReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr);
+  virtual void DoReportFinalRtsFailed (void);
+  virtual void DoReportFinalDataFailed (void);
+  virtual bool DoNeedRts (Ptr<const Packet> packet);
+  virtual WifiMode DoGetDataMode (uint32_t size);
+  virtual WifiMode DoGetRtsMode (void);
+
+  uint32_t m_timer;
+  uint32_t m_success;
+  uint32_t m_failed;
+  
+  uint32_t m_rate;
+  
+  Ptr<CaraWifiManager> m_manager;
+  
+  uint32_t GetMaxRate (void);
+  uint32_t GetMinRate (void);
+
+  bool NeedNormalFallback (void);
+  
+};
+
+} // namespace ns3
+
+#endif /* CARA_WIFI_MANAGER_H */
--- a/src/devices/wifi/wscript	Fri Apr 17 09:59:59 2009 +0200
+++ b/src/devices/wifi/wscript	Fri Apr 17 10:59:51 2009 +0200
@@ -43,6 +43,7 @@
         'onoe-wifi-manager.cc',
         'rraa-wifi-manager.cc',
         'aarfcd-wifi-manager.cc',
+        'cara-wifi-manager.cc',
         'constant-rate-wifi-manager.cc',
         'wifi-test.cc',
         ]