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 <math.h>
25 
26 namespace ns3 {
27 
29 {
30  double m_lastSnr;
31 };
32 
34 
35 TypeId
37 {
38  static TypeId tid = TypeId ("ns3::IdealWifiManager")
40  .AddConstructor<IdealWifiManager> ()
41  .AddAttribute ("BerThreshold",
42  "The maximum Bit Error Rate acceptable at any transmission mode",
43  DoubleValue (10e-6),
44  MakeDoubleAccessor (&IdealWifiManager::m_ber),
45  MakeDoubleChecker<double> ())
46  ;
47  return tid;
48 }
49 
51 {
52 }
54 {
55 }
56 
57 void
59 {
60  uint32_t nModes = phy->GetNModes ();
61  for (uint32_t i = 0; i < nModes; i++)
62  {
63  WifiMode mode = phy->GetMode (i);
64  AddModeSnrThreshold (mode, phy->CalculateSnr (mode, m_ber));
65  }
66 
68 }
69 
70 double
72 {
73  for (Thresholds::const_iterator i = m_thresholds.begin (); i != m_thresholds.end (); i++)
74  {
75  if (mode == i->second)
76  {
77  return i->first;
78  }
79  }
80  NS_ASSERT (false);
81  return 0.0;
82 }
83 
84 void
86 {
87  m_thresholds.push_back (std::make_pair (snr,mode));
88 }
89 
92 {
94  station->m_lastSnr = 0.0;
95  return station;
96 }
97 
98 
99 void
101  double rxSnr, WifiMode txMode)
102 {
103 }
104 void
106 {
107 }
108 void
110 {
111 }
112 void
114  double ctsSnr, WifiMode ctsMode, double rtsSnr)
115 {
117  station->m_lastSnr = rtsSnr;
118 }
119 void
121  double ackSnr, WifiMode ackMode, double dataSnr)
122 {
124  station->m_lastSnr = dataSnr;
125 }
126 void
128 {
129 }
130 void
132 {
133 }
134 
135 WifiMode
137 {
139  // We search within the Supported rate set the mode with the
140  // highest snr threshold possible which is smaller than m_lastSnr
141  // to ensure correct packet delivery.
142  double maxThreshold = 0.0;
143  WifiMode maxMode = GetDefaultMode ();
144  for (uint32_t i = 0; i < GetNSupported (station); i++)
145  {
146  WifiMode mode = GetSupported (station, i);
147  double threshold = GetSnrThreshold (mode);
148  if (threshold > maxThreshold
149  && threshold < station->m_lastSnr)
150  {
151  maxThreshold = threshold;
152  maxMode = mode;
153  }
154  }
155  return maxMode;
156 }
157 WifiMode
159 {
161  // We search within the Basic rate set the mode with the highest
162  // snr threshold possible which is smaller than m_lastSnr to
163  // ensure correct packet delivery.
164  double maxThreshold = 0.0;
165  WifiMode maxMode = GetDefaultMode ();
166  for (uint32_t i = 0; i < GetNBasicModes (); i++)
167  {
168  WifiMode mode = GetBasicMode (i);
169  double threshold = GetSnrThreshold (mode);
170  if (threshold > maxThreshold
171  && threshold < station->m_lastSnr)
172  {
173  maxThreshold = threshold;
174  maxMode = mode;
175  }
176  }
177  return maxMode;
178 }
179 
180 bool
182 {
183  return true;
184 }
185 
186 } // namespace ns3