A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
29
struct
IdealWifiRemoteStation
:
public
WifiRemoteStation
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"
)
40
.
SetParent
<
WifiRemoteStationManager
> ()
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
*
92
IdealWifiManager::DoCreateStation
(
void
)
const
93
{
94
IdealWifiRemoteStation
*station =
new
IdealWifiRemoteStation
();
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
137
IdealWifiManager::DoGetDataMode
(
WifiRemoteStation
*st, uint32_t size)
138
{
139
IdealWifiRemoteStation
*station = (
IdealWifiRemoteStation
*)st;
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
159
IdealWifiManager::DoGetRtsMode
(
WifiRemoteStation
*st)
160
{
161
IdealWifiRemoteStation
*station = (
IdealWifiRemoteStation
*)st;
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
182
IdealWifiManager::IsLowLatency
(
void
)
const
183
{
184
return
true
;
185
}
186
187
}
// namespace ns3
src
wifi
model
ideal-wifi-manager.cc
Generated on Tue May 14 2013 11:08:35 for ns-3 by
1.8.1.2