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 <cmath>
25
26
#define Min(a,b) ((a < b) ? a : b)
27
28
namespace
ns3 {
29
30
struct
IdealWifiRemoteStation
:
public
WifiRemoteStation
31
{
32
double
m_lastSnr
;
33
};
34
35
NS_OBJECT_ENSURE_REGISTERED
(
IdealWifiManager
);
36
37
TypeId
38
IdealWifiManager::GetTypeId
(
void
)
39
{
40
static
TypeId
tid =
TypeId
(
"ns3::IdealWifiManager"
)
41
.
SetParent
<
WifiRemoteStationManager
> ()
42
.AddConstructor<IdealWifiManager> ()
43
.AddAttribute (
"BerThreshold"
,
44
"The maximum Bit Error Rate acceptable at any transmission mode"
,
45
DoubleValue
(10e-6),
46
MakeDoubleAccessor (&
IdealWifiManager::m_ber
),
47
MakeDoubleChecker<double> ())
48
;
49
return
tid;
50
}
51
52
IdealWifiManager::IdealWifiManager
()
53
{
54
}
55
IdealWifiManager::~IdealWifiManager
()
56
{
57
}
58
59
void
60
IdealWifiManager::SetupPhy
(
Ptr<WifiPhy>
phy)
61
{
62
uint32_t nModes = phy->
GetNModes
();
63
for
(uint32_t i = 0; i < nModes; i++)
64
{
65
WifiMode
mode = phy->
GetMode
(i);
66
AddModeSnrThreshold
(mode, phy->
CalculateSnr
(mode,
m_ber
));
67
}
68
69
WifiRemoteStationManager::SetupPhy
(phy);
70
}
71
72
double
73
IdealWifiManager::GetSnrThreshold
(
WifiMode
mode)
const
74
{
75
for
(Thresholds::const_iterator i =
m_thresholds
.begin (); i !=
m_thresholds
.end (); i++)
76
{
77
if
(mode == i->second)
78
{
79
return
i->first;
80
}
81
}
82
NS_ASSERT
(
false
);
83
return
0.0;
84
}
85
86
void
87
IdealWifiManager::AddModeSnrThreshold
(
WifiMode
mode,
double
snr)
88
{
89
m_thresholds
.push_back (std::make_pair (snr,mode));
90
}
91
92
WifiRemoteStation
*
93
IdealWifiManager::DoCreateStation
(
void
)
const
94
{
95
IdealWifiRemoteStation
*station =
new
IdealWifiRemoteStation
();
96
station->
m_lastSnr
= 0.0;
97
return
station;
98
}
99
100
101
void
102
IdealWifiManager::DoReportRxOk
(
WifiRemoteStation
*station,
103
double
rxSnr,
WifiMode
txMode)
104
{
105
}
106
void
107
IdealWifiManager::DoReportRtsFailed
(
WifiRemoteStation
*station)
108
{
109
}
110
void
111
IdealWifiManager::DoReportDataFailed
(
WifiRemoteStation
*station)
112
{
113
}
114
void
115
IdealWifiManager::DoReportRtsOk
(
WifiRemoteStation
*st,
116
double
ctsSnr,
WifiMode
ctsMode,
double
rtsSnr)
117
{
118
IdealWifiRemoteStation
*station = (
IdealWifiRemoteStation
*)st;
119
station->
m_lastSnr
= rtsSnr;
120
}
121
void
122
IdealWifiManager::DoReportDataOk
(
WifiRemoteStation
*st,
123
double
ackSnr,
WifiMode
ackMode,
double
dataSnr)
124
{
125
IdealWifiRemoteStation
*station = (
IdealWifiRemoteStation
*)st;
126
station->
m_lastSnr
= dataSnr;
127
}
128
void
129
IdealWifiManager::DoReportFinalRtsFailed
(
WifiRemoteStation
*station)
130
{
131
}
132
void
133
IdealWifiManager::DoReportFinalDataFailed
(
WifiRemoteStation
*station)
134
{
135
}
136
137
WifiTxVector
138
IdealWifiManager::DoGetDataTxVector
(
WifiRemoteStation
*st, uint32_t size)
139
{
140
IdealWifiRemoteStation
*station = (
IdealWifiRemoteStation
*)st;
141
// We search within the Supported rate set the mode with the
142
// highest snr threshold possible which is smaller than m_lastSnr
143
// to ensure correct packet delivery.
144
double
maxThreshold = 0.0;
145
WifiMode
maxMode =
GetDefaultMode
();
146
for
(uint32_t i = 0; i <
GetNSupported
(station); i++)
147
{
148
WifiMode
mode =
GetSupported
(station, i);
149
double
threshold =
GetSnrThreshold
(mode);
150
if
(threshold > maxThreshold
151
&& threshold < station->m_lastSnr)
152
{
153
maxThreshold = threshold;
154
maxMode = mode;
155
}
156
}
157
return
WifiTxVector
(maxMode,
GetDefaultTxPowerLevel
(),
GetLongRetryCount
(station),
GetShortGuardInterval
(station),
Min
(
GetNumberOfReceiveAntennas
(station),
GetNumberOfTransmitAntennas
()),
GetNumberOfTransmitAntennas
(station),
GetStbc
(station));
158
}
159
WifiTxVector
160
IdealWifiManager::DoGetRtsTxVector
(
WifiRemoteStation
*st)
161
{
162
IdealWifiRemoteStation
*station = (
IdealWifiRemoteStation
*)st;
163
// We search within the Basic rate set the mode with the highest
164
// snr threshold possible which is smaller than m_lastSnr to
165
// ensure correct packet delivery.
166
double
maxThreshold = 0.0;
167
WifiMode
maxMode =
GetDefaultMode
();
168
for
(uint32_t i = 0; i <
GetNBasicModes
(); i++)
169
{
170
WifiMode
mode =
GetBasicMode
(i);
171
double
threshold =
GetSnrThreshold
(mode);
172
if
(threshold > maxThreshold
173
&& threshold < station->m_lastSnr)
174
{
175
maxThreshold = threshold;
176
maxMode = mode;
177
}
178
}
179
return
WifiTxVector
(maxMode,
GetDefaultTxPowerLevel
(),
GetShortRetryCount
(station),
GetShortGuardInterval
(station),
Min
(
GetNumberOfReceiveAntennas
(station),
GetNumberOfTransmitAntennas
()),
GetNumberOfTransmitAntennas
(station),
GetStbc
(station));
180
}
181
182
bool
183
IdealWifiManager::IsLowLatency
(
void
)
const
184
{
185
return
true
;
186
}
187
188
}
// namespace ns3
src
wifi
model
ideal-wifi-manager.cc
Generated on Fri Aug 30 2013 01:43:05 for ns-3 by
1.8.1.2