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
cara-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) 2004,2005,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: Federico Maguolo <maguolof@dei.unipd.it>
19
*/
20
21
#include "
cara-wifi-manager.h
"
22
#include "ns3/assert.h"
23
#include "ns3/log.h"
24
#include "ns3/double.h"
25
#include "ns3/uinteger.h"
26
#include "ns3/simulator.h"
27
28
#define Min(a,b) ((a < b) ? a : b)
29
30
NS_LOG_COMPONENT_DEFINE
(
"Cara"
);
31
32
33
namespace
ns3 {
34
35
struct
CaraWifiRemoteStation
:
public
WifiRemoteStation
36
{
37
uint32_t
m_timer
;
38
uint32_t
m_success
;
39
uint32_t
m_failed
;
40
uint32_t
m_rate
;
41
};
42
43
NS_OBJECT_ENSURE_REGISTERED
(
CaraWifiManager
);
44
45
TypeId
46
CaraWifiManager::GetTypeId
(
void
)
47
{
48
static
TypeId
tid =
TypeId
(
"ns3::CaraWifiManager"
)
49
.
SetParent
<
WifiRemoteStationManager
> ()
50
.AddConstructor<CaraWifiManager> ()
51
.AddAttribute (
"ProbeThreshold"
,
52
"The number of consecutive transmissions failure to activate the RTS probe."
,
53
UintegerValue
(1),
54
MakeUintegerAccessor (&
CaraWifiManager::m_probeThreshold
),
55
MakeUintegerChecker<uint32_t> ())
56
.AddAttribute (
"FailureThreshold"
,
57
"The number of consecutive transmissions failure to decrease the rate."
,
58
UintegerValue
(2),
59
MakeUintegerAccessor (&
CaraWifiManager::m_failureThreshold
),
60
MakeUintegerChecker<uint32_t> ())
61
.AddAttribute (
"SuccessThreshold"
,
62
"The minimum number of sucessfull transmissions to try a new rate."
,
63
UintegerValue
(10),
64
MakeUintegerAccessor (&
CaraWifiManager::m_successThreshold
),
65
MakeUintegerChecker<uint32_t> ())
66
.AddAttribute (
"Timeout"
,
67
"The 'timer' in the CARA algorithm"
,
68
UintegerValue
(15),
69
MakeUintegerAccessor (&
CaraWifiManager::m_timerTimeout
),
70
MakeUintegerChecker<uint32_t> ())
71
;
72
return
tid;
73
}
74
75
CaraWifiManager::CaraWifiManager
()
76
:
WifiRemoteStationManager
()
77
{
78
NS_LOG_FUNCTION
(
this
);
79
}
80
CaraWifiManager::~CaraWifiManager
()
81
{
82
NS_LOG_FUNCTION
(
this
);
83
}
84
85
WifiRemoteStation
*
86
CaraWifiManager::DoCreateStation
(
void
)
const
87
{
88
NS_LOG_FUNCTION
(
this
);
89
CaraWifiRemoteStation
*station =
new
CaraWifiRemoteStation
();
90
station->
m_rate
= 0;
91
station->
m_success
= 0;
92
station->
m_failed
= 0;
93
station->
m_timer
= 0;
94
return
station;
95
}
96
97
void
98
CaraWifiManager::DoReportRtsFailed
(
WifiRemoteStation
*st)
99
{
100
NS_LOG_FUNCTION
(
this
<< st);
101
}
102
103
void
104
CaraWifiManager::DoReportDataFailed
(
WifiRemoteStation
*st)
105
{
106
NS_LOG_FUNCTION
(
this
<< st);
107
CaraWifiRemoteStation
*station = (
CaraWifiRemoteStation
*) st;
108
station->
m_timer
++;
109
station->
m_failed
++;
110
station->
m_success
= 0;
111
if
(station->
m_failed
>=
m_failureThreshold
)
112
{
113
NS_LOG_DEBUG
(
"self="
<< station <<
" dec rate"
);
114
if
(station->
m_rate
!= 0)
115
{
116
station->
m_rate
--;
117
}
118
station->
m_failed
= 0;
119
station->
m_timer
= 0;
120
}
121
}
122
void
123
CaraWifiManager::DoReportRxOk
(
WifiRemoteStation
*st,
124
double
rxSnr,
WifiMode
txMode)
125
{
126
NS_LOG_FUNCTION
(
this
<< st << rxSnr << txMode);
127
}
128
void
129
CaraWifiManager::DoReportRtsOk
(
WifiRemoteStation
*st,
130
double
ctsSnr,
WifiMode
ctsMode,
double
rtsSnr)
131
{
132
NS_LOG_FUNCTION
(
this
<< st << ctsSnr << ctsMode << rtsSnr);
133
NS_LOG_DEBUG
(
"self="
<< st <<
" rts ok"
);
134
}
135
void
136
CaraWifiManager::DoReportDataOk
(
WifiRemoteStation
*st,
137
double
ackSnr,
WifiMode
ackMode,
double
dataSnr)
138
{
139
NS_LOG_FUNCTION
(
this
<< st << ackSnr << ackMode << dataSnr);
140
CaraWifiRemoteStation
*station = (
CaraWifiRemoteStation
*) st;
141
station->
m_timer
++;
142
station->
m_success
++;
143
station->
m_failed
= 0;
144
NS_LOG_DEBUG
(
"self="
<< station <<
" data ok success="
<< station->
m_success
<<
", timer="
<< station->
m_timer
);
145
if
((station->
m_success
==
m_successThreshold
146
|| station->
m_timer
>=
m_timerTimeout
))
147
{
148
if
(station->
m_rate
<
GetNSupported
(station) - 1)
149
{
150
station->
m_rate
++;
151
}
152
NS_LOG_DEBUG
(
"self="
<< station <<
" inc rate="
<< station->
m_rate
);
153
station->
m_timer
= 0;
154
station->
m_success
= 0;
155
}
156
}
157
void
158
CaraWifiManager::DoReportFinalRtsFailed
(
WifiRemoteStation
*st)
159
{
160
NS_LOG_FUNCTION
(
this
<< st);
161
}
162
void
163
CaraWifiManager::DoReportFinalDataFailed
(
WifiRemoteStation
*st)
164
{
165
NS_LOG_FUNCTION
(
this
<< st);
166
}
167
168
WifiTxVector
169
CaraWifiManager::DoGetDataTxVector
(
WifiRemoteStation
*st,
170
uint32_t size)
171
{
172
NS_LOG_FUNCTION
(
this
<< st << size);
173
CaraWifiRemoteStation
*station = (
CaraWifiRemoteStation
*) st;
174
return
WifiTxVector
(
GetSupported
(station, station->
m_rate
),
GetDefaultTxPowerLevel
(),
GetLongRetryCount
(station),
GetShortGuardInterval
(station),
Min
(
GetNumberOfReceiveAntennas
(station),
GetNumberOfTransmitAntennas
()),
GetNumberOfTransmitAntennas
(station),
GetStbc
(station));
175
}
176
WifiTxVector
177
CaraWifiManager::DoGetRtsTxVector
(
WifiRemoteStation
*st)
178
{
179
NS_LOG_FUNCTION
(
this
<< st);
182
return
WifiTxVector
(
GetSupported
(st, 0),
GetDefaultTxPowerLevel
(),
GetLongRetryCount
(st),
GetShortGuardInterval
(st),
Min
(
GetNumberOfReceiveAntennas
(st),
GetNumberOfTransmitAntennas
()),
GetNumberOfTransmitAntennas
(st),
GetStbc
(st));
183
}
184
185
bool
186
CaraWifiManager::DoNeedRts
(
WifiRemoteStation
*st,
187
Ptr<const Packet>
packet,
bool
normally)
188
{
189
NS_LOG_FUNCTION
(
this
<< st << normally);
190
CaraWifiRemoteStation
*station = (
CaraWifiRemoteStation
*) st;
191
return
normally || station->
m_failed
>=
m_probeThreshold
;
192
}
193
194
bool
195
CaraWifiManager::IsLowLatency
(
void
)
const
196
{
197
NS_LOG_FUNCTION
(
this
);
198
return
true
;
199
}
200
201
}
// namespace ns3
src
wifi
model
cara-wifi-manager.cc
Generated on Fri Aug 30 2013 01:43:04 for ns-3 by
1.8.1.2