author | Pavel Boyko <boyko@iitp.ru> |
Tue, 16 Jun 2009 17:58:16 +0400 | |
changeset 5074 | 355de6af8ea9 |
parent 4347 | 0b349dad4332 |
child 6065 | 0f012e7d9128 |
permissions | -rw-r--r-- |
4342 | 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/simulator.h" |
|
25 |
||
26 |
NS_LOG_COMPONENT_DEFINE ("Cara"); |
|
27 |
||
28 |
||
29 |
namespace ns3 { |
|
30 |
||
31 |
NS_OBJECT_ENSURE_REGISTERED(CaraWifiManager); |
|
32 |
||
33 |
CaraWifiRemoteStation::CaraWifiRemoteStation (Ptr<CaraWifiManager> manager) |
|
34 |
: m_manager (manager) |
|
35 |
{ |
|
36 |
m_rate = GetMinRate (); |
|
37 |
||
38 |
m_success = 0; |
|
39 |
m_failed = 0; |
|
40 |
m_timer = 0; |
|
41 |
} |
|
42 |
CaraWifiRemoteStation::~CaraWifiRemoteStation () |
|
43 |
{} |
|
44 |
||
45 |
uint32_t |
|
46 |
CaraWifiRemoteStation::GetMaxRate (void) |
|
47 |
{ |
|
48 |
return GetNSupportedModes () - 1; |
|
49 |
} |
|
50 |
uint32_t |
|
51 |
CaraWifiRemoteStation::GetMinRate (void) |
|
52 |
{ |
|
53 |
return 0; |
|
54 |
} |
|
55 |
||
56 |
bool |
|
57 |
CaraWifiRemoteStation::NeedNormalFallback (void) |
|
58 |
{ |
|
59 |
return (m_failed >= m_manager->m_failureThreshold); |
|
60 |
} |
|
61 |
||
62 |
void |
|
63 |
CaraWifiRemoteStation::DoReportRtsFailed (void) |
|
64 |
{} |
|
65 |
||
66 |
void |
|
67 |
CaraWifiRemoteStation::DoReportDataFailed (void) |
|
68 |
{ |
|
4347 | 69 |
NS_LOG_FUNCTION (this); |
4342 | 70 |
m_timer++; |
71 |
m_failed++; |
|
72 |
m_success = 0; |
|
73 |
if (NeedNormalFallback ()) |
|
74 |
{ |
|
4347 | 75 |
NS_LOG_DEBUG ("self="<<this<<" dec rate"); |
4342 | 76 |
if (m_rate != GetMinRate ()) |
77 |
{ |
|
78 |
m_rate--; |
|
79 |
} |
|
80 |
m_failed = 0; |
|
81 |
m_timer = 0; |
|
82 |
} |
|
83 |
} |
|
84 |
void |
|
85 |
CaraWifiRemoteStation::DoReportRxOk (double rxSnr, WifiMode txMode) |
|
86 |
{} |
|
87 |
void |
|
88 |
CaraWifiRemoteStation::DoReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr) |
|
89 |
{ |
|
90 |
NS_LOG_DEBUG ("self="<<this<<" rts ok"); |
|
91 |
} |
|
92 |
void |
|
93 |
CaraWifiRemoteStation::DoReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr) |
|
94 |
{ |
|
95 |
m_timer++; |
|
96 |
m_success++; |
|
97 |
m_failed = 0; |
|
98 |
NS_LOG_DEBUG ("self="<<this<<" data ok success="<<m_success<<", timer="<<m_timer); |
|
99 |
if ((m_success == m_manager->m_successThreshold || |
|
100 |
m_timer >= m_manager->m_timerTimeout)) |
|
101 |
{ |
|
102 |
if (m_rate < GetMaxRate ()) |
|
103 |
{ |
|
104 |
m_rate++; |
|
105 |
} |
|
4347 | 106 |
NS_LOG_DEBUG ("self="<<this<<" inc rate=" << m_rate); |
4342 | 107 |
m_timer = 0; |
108 |
m_success = 0; |
|
109 |
} |
|
110 |
} |
|
111 |
void |
|
112 |
CaraWifiRemoteStation::DoReportFinalRtsFailed (void) |
|
113 |
{} |
|
114 |
void |
|
115 |
CaraWifiRemoteStation::DoReportFinalDataFailed (void) |
|
116 |
{} |
|
117 |
||
118 |
WifiMode |
|
119 |
CaraWifiRemoteStation::DoGetDataMode (uint32_t size) |
|
120 |
{ |
|
121 |
return GetSupportedMode (m_rate); |
|
122 |
} |
|
123 |
WifiMode |
|
124 |
CaraWifiRemoteStation::DoGetRtsMode (void) |
|
125 |
{ |
|
126 |
// XXX: we could/should implement the Arf algorithm for |
|
127 |
// RTS only by picking a single rate within the BasicRateSet. |
|
128 |
return GetSupportedMode (0); |
|
129 |
} |
|
130 |
||
131 |
Ptr<WifiRemoteStationManager> |
|
132 |
CaraWifiRemoteStation::GetManager (void) const |
|
133 |
{ |
|
134 |
return m_manager; |
|
135 |
} |
|
136 |
||
137 |
bool |
|
4345
528d4150d2ac
handle rts somewhat better
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4342
diff
changeset
|
138 |
CaraWifiRemoteStation::NeedRts (Ptr<const Packet> packet) |
4342 | 139 |
{ |
140 |
bool rts = WifiRemoteStation::NeedRts (packet); |
|
141 |
if (rts || m_failed >= m_manager->m_probeThreshold) |
|
142 |
{ |
|
143 |
return true; |
|
144 |
} |
|
145 |
||
146 |
return false; |
|
147 |
} |
|
148 |
||
149 |
||
150 |
||
151 |
TypeId |
|
152 |
CaraWifiManager::GetTypeId (void) |
|
153 |
{ |
|
154 |
static TypeId tid = TypeId ("ns3::CaraWifiManager") |
|
155 |
.SetParent<WifiRemoteStationManager> () |
|
156 |
.AddConstructor<CaraWifiManager> () |
|
157 |
.AddAttribute ("ProbeThreshold", |
|
158 |
"The number of consecutive transmissions failure to activate the RTS probe.", |
|
159 |
UintegerValue (1), |
|
160 |
MakeUintegerAccessor (&CaraWifiManager::m_probeThreshold), |
|
161 |
MakeUintegerChecker<uint32_t> ()) |
|
162 |
.AddAttribute ("FailureThreshold", |
|
163 |
"The number of consecutive transmissions failure to decrease the rate.", |
|
164 |
UintegerValue (2), |
|
165 |
MakeUintegerAccessor (&CaraWifiManager::m_failureThreshold), |
|
166 |
MakeUintegerChecker<uint32_t> ()) |
|
167 |
.AddAttribute ("SuccessThreshold", |
|
168 |
"The minimum number of sucessfull transmissions to try a new rate.", |
|
169 |
UintegerValue (10), |
|
4347 | 170 |
MakeUintegerAccessor (&CaraWifiManager::m_successThreshold), |
4342 | 171 |
MakeUintegerChecker<uint32_t> ()) |
172 |
.AddAttribute ("Timeout", |
|
173 |
"The 'timer' in the CARA algorithm", |
|
174 |
UintegerValue (15), |
|
175 |
MakeUintegerAccessor (&CaraWifiManager::m_timerTimeout), |
|
176 |
MakeUintegerChecker<uint32_t> ()) |
|
177 |
; |
|
178 |
return tid; |
|
179 |
} |
|
180 |
||
181 |
CaraWifiManager::CaraWifiManager () |
|
182 |
: WifiRemoteStationManager () |
|
183 |
{} |
|
184 |
CaraWifiManager::~CaraWifiManager () |
|
185 |
{} |
|
186 |
||
187 |
WifiRemoteStation * |
|
188 |
CaraWifiManager::CreateStation (void) |
|
189 |
{ |
|
190 |
return new CaraWifiRemoteStation (this); |
|
191 |
} |
|
192 |
||
193 |
} // namespace ns3 |