AMRR rate control algorithm
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 13 Dec 2007 13:00:02 +0100
changeset 2273 0bfe240ec168
parent 2272 ae2bbdbfc161
child 2274 406712a0c6ef
AMRR rate control algorithm
src/devices/wifi/amrr-mac-stations.cc
src/devices/wifi/amrr-mac-stations.h
src/devices/wifi/wifi-default-parameters.cc
src/devices/wifi/wifi-default-parameters.h
src/devices/wifi/wifi-net-device.cc
src/devices/wifi/wscript
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/wifi/amrr-mac-stations.cc	Thu Dec 13 13:00:02 2007 +0100
@@ -0,0 +1,129 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2003,2007 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#include "amrr-mac-stations.h"
+#include "ns3/default-value.h"
+#include "ns3/time-default-value.h"
+#include "ns3/simulator.h"
+#include "ns3/log.h"
+
+NS_LOG_COMPONENT_DEFINE ("AmrrMacStation");
+
+namespace ns3 {
+
+static TimeDefaultValue g_updatePeriod
+("WifiAmrrUpdatePeriod",
+ "The interval between decisions about rate control changes",
+ Seconds (1.0));
+
+AmrrMacStations::AmrrMacStations (WifiMode defaultTxMode)
+  : MacStations (defaultTxMode),
+    m_updatePeriod (g_updatePeriod.GetValue ())
+{}
+MacStation *
+AmrrMacStations::CreateStation (void)
+{
+  return new AmrrMacStation (this);
+}
+
+AmrrMacStation::AmrrMacStation (AmrrMacStations *stations)
+  : m_stations (stations),
+    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)
+{}
+AmrrMacStation::~AmrrMacStation ()
+{}
+
+void 
+AmrrMacStation::ReportRxOk (double rxSnr, WifiMode txMode)
+{}
+void 
+AmrrMacStation::ReportRtsFailed (void)
+{
+  m_shortRetry++;
+}
+void 
+AmrrMacStation::ReportDataFailed (void)
+{
+  m_longRetry++;
+}
+void 
+AmrrMacStation::ReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr)
+{}
+void 
+AmrrMacStation::ReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr)
+{
+  UpdateRetry ();
+  m_tx_ok++;
+}
+void 
+AmrrMacStation::ReportFinalRtsFailed (void)
+{
+  UpdateRetry ();
+  m_tx_err++;
+}
+void 
+AmrrMacStation::ReportFinalDataFailed (void)
+{
+  UpdateRetry ();
+  m_tx_err++;
+}
+void
+AmrrMacStation::UpdateRetry (void)
+{
+  m_tx_retr += m_shortRetry + m_longRetry;
+  m_shortRetry = 0;
+  m_longRetry = 0;
+}
+void
+AmrrMacStation::UpdateMode (void)
+{
+  if (Simulator::Now () < m_nextModeUpdate)
+    {
+      return;
+    }
+}
+
+AmrrMacStations *
+AmrrMacStation::GetStations (void) const
+{
+  return m_stations;
+}
+WifiMode 
+AmrrMacStation::DoGetDataMode (uint32_t size)
+{
+  UpdateMode ();
+  //XXX
+  return GetSupportedMode (0);
+}
+WifiMode 
+AmrrMacStation::DoGetRtsMode (void)
+{
+  UpdateMode ();
+  // XXX: can we implement something smarter ?
+  return GetSupportedMode (0);
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/wifi/amrr-mac-stations.h	Thu Dec 13 13:00:02 2007 +0100
@@ -0,0 +1,78 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2003,2007 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef AMRR_MAC_STATIONS_H
+#define AMRR_MAC_STATIONS_H
+
+#include "mac-stations.h"
+#include "ns3/nstime.h"
+
+namespace ns3 {
+
+class AmrrMacStations : public MacStations
+{
+public:
+  AmrrMacStations (WifiMode defaultTxMode);
+
+private:
+  friend class AmrrMacStation;
+  virtual MacStation *CreateStation (void);
+
+  Time m_updatePeriod;
+};
+
+/**
+ */
+class AmrrMacStation : public MacStation
+{
+public:
+  AmrrMacStation (AmrrMacStations *stations);
+
+  virtual ~AmrrMacStation ();
+
+  virtual void ReportRxOk (double rxSnr, WifiMode txMode);
+  virtual void ReportRtsFailed (void);
+  virtual void ReportDataFailed (void);
+  virtual void ReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr);
+  virtual void ReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr);
+  virtual void ReportFinalRtsFailed (void);
+  virtual void ReportFinalDataFailed (void);
+
+private:
+  virtual AmrrMacStations *GetStations (void) const;
+  virtual WifiMode DoGetDataMode (uint32_t size);
+  virtual WifiMode DoGetRtsMode (void);
+
+  void UpdateRetry (void);
+  void UpdateMode (void);
+
+  AmrrMacStations *m_stations;
+  Time m_nextModeUpdate;
+  uint32_t m_shortRetry;
+  uint32_t m_longRetry;
+  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
+
+#endif /* AMRR_MAC_STATIONS_H */
--- a/src/devices/wifi/wifi-default-parameters.cc	Thu Dec 13 09:26:20 2007 +0100
+++ b/src/devices/wifi/wifi-default-parameters.cc	Thu Dec 13 13:00:02 2007 +0100
@@ -65,6 +65,7 @@
  AARF, "Aarf",
  IDEAL, "Ideal",
  ONOE, "Onoe",
+ AMRR, "Amrr",
  0, (void *)0);
 
 static NumericDefaultValue<uint32_t> g_arfSuccessThreshold
--- a/src/devices/wifi/wifi-default-parameters.h	Thu Dec 13 09:26:20 2007 +0100
+++ b/src/devices/wifi/wifi-default-parameters.h	Thu Dec 13 13:00:02 2007 +0100
@@ -35,6 +35,7 @@
   ARF,
   AARF,
   ONOE,
+  AMRR,
   IDEAL
 };
 enum PhyModeParameter {
--- a/src/devices/wifi/wifi-net-device.cc	Thu Dec 13 09:26:20 2007 +0100
+++ b/src/devices/wifi/wifi-net-device.cc	Thu Dec 13 13:00:02 2007 +0100
@@ -41,6 +41,7 @@
 #include "ideal-mac-stations.h"
 #include "cr-mac-stations.h"
 #include "onoe-mac-stations.h"
+#include "amrr-mac-stations.h"
 
 namespace ns3 {
 
@@ -215,6 +216,9 @@
   case WifiDefaultParameters::ONOE: {
     m_stations = new OnoeMacStations (m_phy->GetMode (0));
   } break;
+  case WifiDefaultParameters::AMRR: {
+    m_stations = new AmrrMacStations (m_phy->GetMode (0));
+  } break;
   default:
     // NOTREACHED
     NS_ASSERT (false);
--- a/src/devices/wifi/wscript	Thu Dec 13 09:26:20 2007 +0100
+++ b/src/devices/wifi/wscript	Thu Dec 13 13:00:02 2007 +0100
@@ -35,6 +35,7 @@
         'dcf-manager.cc',
         'dcf-manager-test.cc',
         'onoe-mac-stations.cc',
+        'amrr-mac-stations.cc',
         ]
     headers = bld.create_obj('ns3header')
     headers.source = [