A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #include "ideal-wifi-manager.h"
21 #include "wifi-phy.h"
22 #include "ns3/assert.h"
23 #include "ns3/double.h"
24 #include <cmath>
25 
26 #define Min(a,b) ((a < b) ? a : b)
27 
28 namespace ns3 {
29 
37 {
38  double m_lastSnr;
39 };
40 
42 
43 TypeId
45 {
46  static TypeId tid = TypeId ("ns3::IdealWifiManager")
48  .AddConstructor<IdealWifiManager> ()
49  .AddAttribute ("BerThreshold",
50  "The maximum Bit Error Rate acceptable at any transmission mode",
51  DoubleValue (10e-6),
52  MakeDoubleAccessor (&IdealWifiManager::m_ber),
53  MakeDoubleChecker<double> ())
54  ;
55  return tid;
56 }
57 
59 {
60 }
62 {
63 }
64 
65 void
67 {
68  uint32_t nModes = phy->GetNModes ();
69  for (uint32_t i = 0; i < nModes; i++)
70  {
71  WifiMode mode = phy->GetMode (i);
72  AddModeSnrThreshold (mode, phy->CalculateSnr (mode, m_ber));
73  }
74 
76 }
77 
78 double
80 {
81  for (Thresholds::const_iterator i = m_thresholds.begin (); i != m_thresholds.end (); i++)
82  {
83  if (mode == i->second)
84  {
85  return i->first;
86  }
87  }
88  NS_ASSERT (false);
89  return 0.0;
90 }
91 
92 void
94 {
95  m_thresholds.push_back (std::make_pair (snr,mode));
96 }
97 
100 {
102  station->m_lastSnr = 0.0;
103  return station;
104 }
105 
106 
107 void
109  double rxSnr, WifiMode txMode)
110 {
111 }
112 void
114 {
115 }
116 void
118 {
119 }
120 void
122  double ctsSnr, WifiMode ctsMode, double rtsSnr)
123 {
125  station->m_lastSnr = rtsSnr;
126 }
127 void
129  double ackSnr, WifiMode ackMode, double dataSnr)
130 {
132  station->m_lastSnr = dataSnr;
133 }
134 void
136 {
137 }
138 void
140 {
141 }
142 
145 {
147  // We search within the Supported rate set the mode with the
148  // highest snr threshold possible which is smaller than m_lastSnr
149  // to ensure correct packet delivery.
150  double maxThreshold = 0.0;
151  WifiMode maxMode = GetDefaultMode ();
152  for (uint32_t i = 0; i < GetNSupported (station); i++)
153  {
154  WifiMode mode = GetSupported (station, i);
155  double threshold = GetSnrThreshold (mode);
156  if (threshold > maxThreshold
157  && threshold < station->m_lastSnr)
158  {
159  maxThreshold = threshold;
160  maxMode = mode;
161  }
162  }
164 }
167 {
169  // We search within the Basic rate set the mode with the highest
170  // snr threshold possible which is smaller than m_lastSnr to
171  // ensure correct packet delivery.
172  double maxThreshold = 0.0;
173  WifiMode maxMode = GetDefaultMode ();
174  for (uint32_t i = 0; i < GetNBasicModes (); i++)
175  {
176  WifiMode mode = GetBasicMode (i);
177  double threshold = GetSnrThreshold (mode);
178  if (threshold > maxThreshold
179  && threshold < station->m_lastSnr)
180  {
181  maxThreshold = threshold;
182  maxMode = mode;
183  }
184  }
186 }
187 
188 bool
190 {
191  return true;
192 }
193 
194 } // 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 the class in the ns-3 factory.
Definition: object-base.h:38
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:61
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:91
uint32_t GetNumberOfReceiveAntennas(const WifiRemoteStation *station) const
Return the number of receive antenna the station has.
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.
bool GetStbc(const WifiRemoteStation *station) const
Return whether the given station supports space-time block coding (STBC).
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:194
static TypeId GetTypeId(void)
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
virtual WifiMode GetMode(uint32_t mode) const =0
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
bool GetShortGuardInterval(const WifiRemoteStation *station) const
Return whether the given station supports short guard interval.
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
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 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.
Hold a floating point type.
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:49
virtual void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
hold per-remote-station state.