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
#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
28
struct
IdealWifiRemoteStation
:
public
WifiRemoteStation
29
{
30
double
m_lastSnr
;
31
};
32
33
NS_OBJECT_ENSURE_REGISTERED
(
IdealWifiManager
);
34
35
TypeId
36
IdealWifiManager::GetTypeId
(
void
)
37
{
38
static
TypeId
tid =
TypeId
(
"ns3::IdealWifiManager"
)
39
.
SetParent
<
WifiRemoteStationManager
> ()
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
50
IdealWifiManager::IdealWifiManager
()
51
{
52
}
53
IdealWifiManager::~IdealWifiManager
()
54
{
55
}
56
57
void
58
IdealWifiManager::SetupPhy
(
Ptr<WifiPhy>
phy)
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
67
WifiRemoteStationManager::SetupPhy
(phy);
68
}
69
70
double
71
IdealWifiManager::GetSnrThreshold
(
WifiMode
mode)
const
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
85
IdealWifiManager::AddModeSnrThreshold
(
WifiMode
mode,
double
snr)
86
{
87
m_thresholds
.push_back (std::make_pair (snr,mode));
88
}
89
90
WifiRemoteStation
*
91
IdealWifiManager::DoCreateStation
(
void
)
const
92
{
93
IdealWifiRemoteStation
*station =
new
IdealWifiRemoteStation
();
94
station->
m_lastSnr
= 0.0;
95
return
station;
96
}
97
98
99
void
100
IdealWifiManager::DoReportRxOk
(
WifiRemoteStation
*station,
101
double
rxSnr,
WifiMode
txMode)
102
{
103
}
104
void
105
IdealWifiManager::DoReportRtsFailed
(
WifiRemoteStation
*station)
106
{
107
}
108
void
109
IdealWifiManager::DoReportDataFailed
(
WifiRemoteStation
*station)
110
{
111
}
112
void
113
IdealWifiManager::DoReportRtsOk
(
WifiRemoteStation
*st,
114
double
ctsSnr,
WifiMode
ctsMode,
double
rtsSnr)
115
{
116
IdealWifiRemoteStation
*station = (
IdealWifiRemoteStation
*)st;
117
station->
m_lastSnr
= rtsSnr;
118
}
119
void
120
IdealWifiManager::DoReportDataOk
(
WifiRemoteStation
*st,
121
double
ackSnr,
WifiMode
ackMode,
double
dataSnr)
122
{
123
IdealWifiRemoteStation
*station = (
IdealWifiRemoteStation
*)st;
124
station->
m_lastSnr
= dataSnr;
125
}
126
void
127
IdealWifiManager::DoReportFinalRtsFailed
(
WifiRemoteStation
*station)
128
{
129
}
130
void
131
IdealWifiManager::DoReportFinalDataFailed
(
WifiRemoteStation
*station)
132
{
133
}
134
135
WifiMode
136
IdealWifiManager::DoGetDataMode
(
WifiRemoteStation
*st, uint32_t size)
137
{
138
IdealWifiRemoteStation
*station = (
IdealWifiRemoteStation
*)st;
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
158
IdealWifiManager::DoGetRtsMode
(
WifiRemoteStation
*st)
159
{
160
IdealWifiRemoteStation
*station = (
IdealWifiRemoteStation
*)st;
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
181
IdealWifiManager::IsLowLatency
(
void
)
const
182
{
183
return
true
;
184
}
185
186
}
// namespace ns3
src
wifi
model
ideal-wifi-manager.cc
Generated on Tue Oct 9 2012 16:45:48 for ns-3 by
1.8.1.2