A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ideal-wifi-manager.cc
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 namespace ns3 {
28 
30 {
31  double m_lastSnr;
32 };
33 
34 NS_OBJECT_ENSURE_REGISTERED (IdealWifiManager);
35 
36 TypeId
37 IdealWifiManager::GetTypeId (void)
38 {
39  static TypeId tid = TypeId ("ns3::IdealWifiManager")
41  .AddConstructor<IdealWifiManager> ()
42  .AddAttribute ("BerThreshold",
43  "The maximum Bit Error Rate acceptable at any transmission mode",
44  DoubleValue (10e-6),
45  MakeDoubleAccessor (&IdealWifiManager::m_ber),
46  MakeDoubleChecker<double> ())
47  ;
48  return tid;
49 }
50 
51 IdealWifiManager::IdealWifiManager ()
52 {
53 }
54 IdealWifiManager::~IdealWifiManager ()
55 {
56 }
57 
58 void
59 IdealWifiManager::SetupPhy (Ptr<WifiPhy> phy)
60 {
61  uint32_t nModes = phy->GetNModes ();
62  for (uint32_t i = 0; i < nModes; i++)
63  {
64  WifiMode mode = phy->GetMode (i);
65  AddModeSnrThreshold (mode, phy->CalculateSnr (mode, m_ber));
66  }
67 
68  WifiRemoteStationManager::SetupPhy (phy);
69 }
70 
71 double
72 IdealWifiManager::GetSnrThreshold (WifiMode mode) const
73 {
74  for (Thresholds::const_iterator i = m_thresholds.begin (); i != m_thresholds.end (); i++)
75  {
76  if (mode == i->second)
77  {
78  return i->first;
79  }
80  }
81  NS_ASSERT (false);
82  return 0.0;
83 }
84 
85 void
86 IdealWifiManager::AddModeSnrThreshold (WifiMode mode, double snr)
87 {
88  m_thresholds.push_back (std::make_pair (snr,mode));
89 }
90 
91 WifiRemoteStation *
93 {
95  station->m_lastSnr = 0.0;
96  return station;
97 }
98 
99 
100 void
101 IdealWifiManager::DoReportRxOk (WifiRemoteStation *station,
102  double rxSnr, WifiMode txMode)
103 {
104 }
105 void
106 IdealWifiManager::DoReportRtsFailed (WifiRemoteStation *station)
107 {
108 }
109 void
110 IdealWifiManager::DoReportDataFailed (WifiRemoteStation *station)
111 {
112 }
113 void
114 IdealWifiManager::DoReportRtsOk (WifiRemoteStation *st,
115  double ctsSnr, WifiMode ctsMode, double rtsSnr)
116 {
117  IdealWifiRemoteStation *station = (IdealWifiRemoteStation *)st;
118  station->m_lastSnr = rtsSnr;
119 }
120 void
121 IdealWifiManager::DoReportDataOk (WifiRemoteStation *st,
122  double ackSnr, WifiMode ackMode, double dataSnr)
123 {
124  IdealWifiRemoteStation *station = (IdealWifiRemoteStation *)st;
125  station->m_lastSnr = dataSnr;
126 }
127 void
128 IdealWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *station)
129 {
130 }
131 void
132 IdealWifiManager::DoReportFinalDataFailed (WifiRemoteStation *station)
133 {
134 }
135 
136 WifiMode
138 {
140  // We search within the Supported rate set the mode with the
141  // highest snr threshold possible which is smaller than m_lastSnr
142  // to ensure correct packet delivery.
143  double maxThreshold = 0.0;
144  WifiMode maxMode = GetDefaultMode ();
145  for (uint32_t i = 0; i < GetNSupported (station); i++)
146  {
147  WifiMode mode = GetSupported (station, i);
148  double threshold = GetSnrThreshold (mode);
149  if (threshold > maxThreshold
150  && threshold < station->m_lastSnr)
151  {
152  maxThreshold = threshold;
153  maxMode = mode;
154  }
155  }
156  return maxMode;
157 }
158 WifiMode
160 {
162  // We search within the Basic rate set the mode with the highest
163  // snr threshold possible which is smaller than m_lastSnr to
164  // ensure correct packet delivery.
165  double maxThreshold = 0.0;
166  WifiMode maxMode = GetDefaultMode ();
167  for (uint32_t i = 0; i < GetNBasicModes (); i++)
168  {
169  WifiMode mode = GetBasicMode (i);
170  double threshold = GetSnrThreshold (mode);
171  if (threshold > maxThreshold
172  && threshold < station->m_lastSnr)
173  {
174  maxThreshold = threshold;
175  maxMode = mode;
176  }
177  }
178  return maxMode;
179 }
180 
181 bool
183 {
184  return true;
185 }
186 
187 } // namespace ns3
virtual bool IsLowLatency(void) const
virtual WifiMode DoGetRtsMode(WifiRemoteStation *station)
#define NS_ASSERT(condition)
Definition: assert.h:64
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:88
virtual WifiMode DoGetDataMode(WifiRemoteStation *station, uint32_t size)
hold a list of per-remote-station state.
virtual WifiRemoteStation * DoCreateStation(void) const
Ideal rate control algorithmThis class implements an 'ideal' rate control algorithm similar to RBAR i...
Hold an floating point type.
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:44
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471
hold per-remote-station state.