diff --git a/src/devices/wifi/amrr-mac-stations.cc b/src/devices/wifi/amrr-mac-stations.cc new file mode 100644 index 000000000..229e6bfd7 --- /dev/null +++ b/src/devices/wifi/amrr-mac-stations.cc @@ -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 + */ + +#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 diff --git a/src/devices/wifi/amrr-mac-stations.h b/src/devices/wifi/amrr-mac-stations.h new file mode 100644 index 000000000..54764e168 --- /dev/null +++ b/src/devices/wifi/amrr-mac-stations.h @@ -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 + */ +#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 */ diff --git a/src/devices/wifi/wifi-default-parameters.cc b/src/devices/wifi/wifi-default-parameters.cc index d0fd4135e..f06fec72c 100644 --- a/src/devices/wifi/wifi-default-parameters.cc +++ b/src/devices/wifi/wifi-default-parameters.cc @@ -65,6 +65,7 @@ static EnumDefaultValue g_rateControlAlgorithm AARF, "Aarf", IDEAL, "Ideal", ONOE, "Onoe", + AMRR, "Amrr", 0, (void *)0); static NumericDefaultValue g_arfSuccessThreshold diff --git a/src/devices/wifi/wifi-default-parameters.h b/src/devices/wifi/wifi-default-parameters.h index f36ac24b8..4e76e4489 100644 --- a/src/devices/wifi/wifi-default-parameters.h +++ b/src/devices/wifi/wifi-default-parameters.h @@ -35,6 +35,7 @@ enum RateControlAlgorithm { ARF, AARF, ONOE, + AMRR, IDEAL }; enum PhyModeParameter { diff --git a/src/devices/wifi/wifi-net-device.cc b/src/devices/wifi/wifi-net-device.cc index c1e85935b..b06bb2016 100644 --- a/src/devices/wifi/wifi-net-device.cc +++ b/src/devices/wifi/wifi-net-device.cc @@ -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 @@ WifiNetDevice::Construct (void) 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); diff --git a/src/devices/wifi/wscript b/src/devices/wifi/wscript index 2153b0cbd..2e84dd04b 100644 --- a/src/devices/wifi/wscript +++ b/src/devices/wifi/wscript @@ -35,6 +35,7 @@ def build(bld): 'dcf-manager.cc', 'dcf-manager-test.cc', 'onoe-mac-stations.cc', + 'amrr-mac-stations.cc', ] headers = bld.create_obj('ns3header') headers.source = [