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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|
19 */ |
|
20 |
|
21 #include "mac-stations.h" |
|
22 #include "arf-mac-stations.h" |
|
23 #include "ns3/assert.h" |
|
24 #include "ns3/log.h" |
|
25 #include "ns3/default-value.h" |
|
26 |
|
27 NS_LOG_COMPONENT_DEFINE ("Arf"); |
|
28 |
|
29 |
|
30 namespace ns3 { |
|
31 |
|
32 ArfMacStation::ArfMacStation (ArfMacStations *stations, |
|
33 int minTimerTimeout, |
|
34 int minSuccessThreshold) |
|
35 : m_stations (stations) |
|
36 { |
|
37 m_minTimerTimeout = minTimerTimeout; |
|
38 m_minSuccessThreshold = minSuccessThreshold; |
|
39 m_successThreshold = m_minSuccessThreshold; |
|
40 m_timerTimeout = m_minTimerTimeout; |
|
41 m_rate = GetMinRate (); |
|
42 |
|
43 m_success = 0; |
|
44 m_failed = 0; |
|
45 m_recovery = false; |
|
46 m_retry = 0; |
|
47 m_timer = 0; |
|
48 } |
|
49 ArfMacStation::~ArfMacStation () |
|
50 {} |
|
51 |
|
52 uint32_t |
|
53 ArfMacStation::GetMaxRate (void) |
|
54 { |
|
55 return GetNSupportedModes (); |
|
56 } |
|
57 uint32_t |
|
58 ArfMacStation::GetMinRate (void) |
|
59 { |
|
60 return 0; |
|
61 } |
|
62 |
|
63 bool |
|
64 ArfMacStation::NeedRecoveryFallback (void) |
|
65 { |
|
66 if (m_retry == 1) |
|
67 { |
|
68 return true; |
|
69 } |
|
70 else |
|
71 { |
|
72 return false; |
|
73 } |
|
74 } |
|
75 bool |
|
76 ArfMacStation::NeedNormalFallback (void) |
|
77 { |
|
78 int retryMod = (m_retry - 1) % 2; |
|
79 if (retryMod == 1) |
|
80 { |
|
81 return true; |
|
82 } |
|
83 else |
|
84 { |
|
85 return false; |
|
86 } |
|
87 } |
|
88 |
|
89 |
|
90 |
|
91 void |
|
92 ArfMacStation::ReportRtsFailed (void) |
|
93 {} |
|
94 /** |
|
95 * It is important to realize that "recovery" mode starts after failure of |
|
96 * the first transmission after a rate increase and ends at the first successful |
|
97 * transmission. Specifically, recovery mode transcends retransmissions boundaries. |
|
98 * Fundamentally, ARF handles each data transmission independently, whether it |
|
99 * is the initial transmission of a packet or the retransmission of a packet. |
|
100 * The fundamental reason for this is that there is a backoff between each data |
|
101 * transmission, be it an initial transmission or a retransmission. |
|
102 */ |
|
103 void |
|
104 ArfMacStation::ReportDataFailed (void) |
|
105 { |
|
106 m_timer++; |
|
107 m_failed++; |
|
108 m_retry++; |
|
109 m_success = 0; |
|
110 |
|
111 if (m_recovery) |
|
112 { |
|
113 NS_ASSERT (m_retry >= 1); |
|
114 if (NeedRecoveryFallback ()) |
|
115 { |
|
116 ReportRecoveryFailure (); |
|
117 if (m_rate != GetMinRate ()) |
|
118 { |
|
119 m_rate--; |
|
120 } |
|
121 } |
|
122 m_timer = 0; |
|
123 } |
|
124 else |
|
125 { |
|
126 NS_ASSERT (m_retry >= 1); |
|
127 if (NeedNormalFallback ()) |
|
128 { |
|
129 ReportFailure (); |
|
130 if (m_rate != GetMinRate ()) |
|
131 { |
|
132 m_rate--; |
|
133 } |
|
134 } |
|
135 if (m_retry >= 2) |
|
136 { |
|
137 m_timer = 0; |
|
138 } |
|
139 } |
|
140 } |
|
141 void |
|
142 ArfMacStation::ReportRxOk (double rxSnr, WifiMode txMode) |
|
143 {} |
|
144 void ArfMacStation::ReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr) |
|
145 { |
|
146 NS_LOG_DEBUG ("self="<<this<<" rts ok"); |
|
147 } |
|
148 void ArfMacStation::ReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr) |
|
149 { |
|
150 m_timer++; |
|
151 m_success++; |
|
152 m_failed = 0; |
|
153 m_recovery = false; |
|
154 m_retry = 0; |
|
155 NS_LOG_DEBUG ("self="<<this<<" data ok success="<<m_success<<", timer="<<m_timer); |
|
156 if ((m_success == GetSuccessThreshold () || |
|
157 m_timer == GetTimerTimeout ()) && |
|
158 (m_rate < (GetMaxRate () - 1))) |
|
159 { |
|
160 NS_LOG_DEBUG ("self="<<this<<" inc rate"); |
|
161 m_rate++; |
|
162 m_timer = 0; |
|
163 m_success = 0; |
|
164 m_recovery = true; |
|
165 } |
|
166 } |
|
167 void |
|
168 ArfMacStation::ReportFinalRtsFailed (void) |
|
169 {} |
|
170 void |
|
171 ArfMacStation::ReportFinalDataFailed (void) |
|
172 {} |
|
173 |
|
174 WifiMode |
|
175 ArfMacStation::DoGetDataMode (uint32_t size) |
|
176 { |
|
177 return GetSupportedMode (m_rate); |
|
178 } |
|
179 WifiMode |
|
180 ArfMacStation::DoGetRtsMode (void) |
|
181 { |
|
182 // XXX: we could/should implement the Arf algorithm for |
|
183 // RTS only by picking a single rate within the BasicRateSet. |
|
184 return GetSupportedMode (0); |
|
185 } |
|
186 |
|
187 void ArfMacStation::ReportRecoveryFailure (void) |
|
188 {} |
|
189 void ArfMacStation::ReportFailure (void) |
|
190 {} |
|
191 uint32_t ArfMacStation::GetMinTimerTimeout (void) |
|
192 { |
|
193 return m_minTimerTimeout; |
|
194 } |
|
195 uint32_t ArfMacStation::GetMinSuccessThreshold (void) |
|
196 { |
|
197 return m_minSuccessThreshold; |
|
198 } |
|
199 uint32_t ArfMacStation::GetTimerTimeout (void) |
|
200 { |
|
201 return m_timerTimeout; |
|
202 } |
|
203 uint32_t ArfMacStation::GetSuccessThreshold (void) |
|
204 { |
|
205 return m_successThreshold; |
|
206 } |
|
207 void ArfMacStation::SetTimerTimeout (uint32_t timerTimeout) |
|
208 { |
|
209 NS_ASSERT (timerTimeout >= m_minTimerTimeout); |
|
210 m_timerTimeout = timerTimeout; |
|
211 } |
|
212 void ArfMacStation::SetSuccessThreshold (uint32_t successThreshold) |
|
213 { |
|
214 NS_ASSERT (successThreshold >= m_minSuccessThreshold); |
|
215 m_successThreshold = successThreshold; |
|
216 } |
|
217 ArfMacStations * |
|
218 ArfMacStation::GetStations (void) const |
|
219 { |
|
220 return m_stations; |
|
221 } |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 ArfMacStations::ArfMacStations (WifiMode defaultTxMode, uint32_t timerThreshold, uint32_t successThreshold) |
|
228 : MacStations (defaultTxMode), |
|
229 m_timerThreshold (timerThreshold), |
|
230 m_successThreshold (successThreshold) |
|
231 {} |
|
232 ArfMacStations::~ArfMacStations () |
|
233 {} |
|
234 MacStation * |
|
235 ArfMacStations::CreateStation (void) |
|
236 { |
|
237 return new ArfMacStation (this, m_timerThreshold, m_successThreshold); |
|
238 } |
|
239 |
|
240 } // namespace ns3 |
|