A Discrete-Event Network Simulator
API
ideal-wifi-manager.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006 INRIA
4  *
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
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ideal-wifi-manager.h"
22 #include "wifi-phy.h"
23 #include "ns3/assert.h"
24 #include "ns3/double.h"
25 #include <cmath>
26 
27 #define Min(a,b) ((a < b) ? a : b)
28 
29 namespace ns3 {
30 
38 {
39  double m_lastSnr;
40 };
41 
43 
44 TypeId
46 {
47  static TypeId tid = TypeId ("ns3::IdealWifiManager")
49  .SetGroupName ("Wifi")
50  .AddConstructor<IdealWifiManager> ()
51  .AddAttribute ("BerThreshold",
52  "The maximum Bit Error Rate acceptable at any transmission mode",
53  DoubleValue (10e-6),
55  MakeDoubleChecker<double> ())
56  ;
57  return tid;
58 }
59 
61 {
62 }
63 
65 {
66 }
67 
68 void
70 {
71  uint32_t nModes = phy->GetNModes ();
72  for (uint32_t i = 0; i < nModes; i++)
73  {
74  WifiMode mode = phy->GetMode (i);
75  AddModeSnrThreshold (mode, phy->CalculateSnr (mode, m_ber));
76  }
77 
79 }
80 
81 double
83 {
84  for (Thresholds::const_iterator i = m_thresholds.begin (); i != m_thresholds.end (); i++)
85  {
86  if (mode == i->second)
87  {
88  return i->first;
89  }
90  }
91  NS_ASSERT (false);
92  return 0.0;
93 }
94 
95 void
97 {
98  m_thresholds.push_back (std::make_pair (snr,mode));
99 }
100 
103 {
105  station->m_lastSnr = 0.0;
106  return station;
107 }
108 
109 
110 void
112  double rxSnr, WifiMode txMode)
113 {
114 }
115 
116 void
118 {
119 }
120 
121 void
123 {
124 }
125 
126 void
128  double ctsSnr, WifiMode ctsMode, double rtsSnr)
129 {
131  station->m_lastSnr = rtsSnr;
132 }
133 
134 void
136  double ackSnr, WifiMode ackMode, double dataSnr)
137 {
139  station->m_lastSnr = dataSnr;
140 }
141 
142 void
144 {
145 }
146 
147 void
149 {
150 }
151 
154 {
156  //We search within the Supported rate set the mode with the
157  //highest snr threshold possible which is smaller than m_lastSnr
158  //to ensure correct packet delivery.
159  double maxThreshold = 0.0;
160  WifiMode maxMode = GetDefaultMode ();
161  for (uint32_t i = 0; i < GetNSupported (station); i++)
162  {
163  WifiMode mode = GetSupported (station, i);
164  double threshold = GetSnrThreshold (mode);
165  if (threshold > maxThreshold
166  && threshold < station->m_lastSnr)
167  {
168  maxThreshold = threshold;
169  maxMode = mode;
170  }
171  }
172  uint32_t channelWidth = GetChannelWidth (station);
173  if (channelWidth > 20 && channelWidth != 22)
174  {
175  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
176  channelWidth = 20;
177  }
178  return WifiTxVector (maxMode, GetDefaultTxPowerLevel (), GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
179 }
180 
183 {
185  //We search within the Basic rate set the mode with the highest
186  //snr threshold possible which is smaller than m_lastSnr to
187  //ensure correct packet delivery.
188  double maxThreshold = 0.0;
189  WifiMode maxMode = GetDefaultMode ();
190  for (uint32_t i = 0; i < GetNBasicModes (); i++)
191  {
192  WifiMode mode = GetBasicMode (i);
193  double threshold = GetSnrThreshold (mode);
194  if (threshold > maxThreshold
195  && threshold < station->m_lastSnr)
196  {
197  maxThreshold = threshold;
198  maxMode = mode;
199  }
200  }
201  uint32_t channelWidth = GetChannelWidth (station);
202  if (channelWidth > 20 && channelWidth != 22)
203  {
204  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
205  channelWidth = 20;
206  }
207  return WifiTxVector (maxMode, GetDefaultTxPowerLevel (), GetShortRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
208 }
209 
210 bool
212 {
213  return true;
214 }
215 
216 } //namespace ns3
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
virtual bool IsLowLatency(void) const
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
double GetSnrThreshold(WifiMode mode) const
Return the minimum SNR needed to successfully transmit data with this mode at the specified BER...
virtual uint32_t GetNModes(void) const =0
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
virtual void SetupPhy(Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
virtual double CalculateSnr(WifiMode txMode, double ber) const =0
virtual void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr)
This method is a pure virtual method that must be implemented by the sub-class.
hold per-remote-station state for Ideal Wifi manager.
virtual void SetupPhy(Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether mode associated with the specified station at the specified index. ...
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
static TypeId GetTypeId(void)
tuple phy
Definition: third.py:86
double m_ber
The maximum Bit Error Rate acceptable at any transmission mode.
WifiMode GetBasicMode(uint32_t i) const
Return a basic mode from the set of basic modes.
Thresholds m_thresholds
List of WifiMode and the minimum SNR pair.
hold a list of per-remote-station state.
virtual void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr)
This method is a pure virtual method that must be implemented by the sub-class.
virtual WifiRemoteStation * DoCreateStation(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual WifiMode GetMode(uint32_t mode) const =0
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: double.h:42
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
uint32_t GetNBasicModes(void) const
Return the number of basic modes we support.
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
WifiMode GetDefaultMode(void) const
Return the default transmission mode.
Ideal rate control algorithmThis class implements an 'ideal' rate control algorithm similar to RBAR i...
uint32_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
Return the short retry limit of the given station.
virtual void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
double m_lastSnr
SNR of last packet sent to the remote station.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
void AddModeSnrThreshold(WifiMode mode, double snr)
Adds a pair of WifiMode and the minimum SNR for that given mode to the list.
a unique identifier for an interface.
Definition: type-id.h:58
virtual void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:826
hold per-remote-station state.