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 
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 
35 
36 TypeId
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 
52 {
53 }
55 {
56 }
57 
58 void
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 
69 }
70 
71 double
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
87 {
88  m_thresholds.push_back (std::make_pair (snr,mode));
89 }
90 
93 {
95  station->m_lastSnr = 0.0;
96  return station;
97 }
98 
99 
100 void
102  double rxSnr, WifiMode txMode)
103 {
104 }
105 void
107 {
108 }
109 void
111 {
112 }
113 void
115  double ctsSnr, WifiMode ctsMode, double rtsSnr)
116 {
118  station->m_lastSnr = rtsSnr;
119 }
120 void
122  double ackSnr, WifiMode ackMode, double dataSnr)
123 {
125  station->m_lastSnr = dataSnr;
126 }
127 void
129 {
130 }
131 void
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