25 |
25 |
26 NS_LOG_COMPONENT_DEFINE ("ns3::ArfWifiManager"); |
26 NS_LOG_COMPONENT_DEFINE ("ns3::ArfWifiManager"); |
27 |
27 |
28 |
28 |
29 namespace ns3 { |
29 namespace ns3 { |
|
30 |
|
31 struct ArfWifiRemoteStation : public WifiRemoteStation |
|
32 { |
|
33 uint32_t m_timer; |
|
34 uint32_t m_success; |
|
35 uint32_t m_failed; |
|
36 bool m_recovery; |
|
37 uint32_t m_retry; |
30 |
38 |
31 ArfWifiRemoteStation::ArfWifiRemoteStation (Ptr<ArfWifiManager> manager) |
39 uint32_t m_timerTimeout; |
32 : m_manager (manager) |
40 uint32_t m_successThreshold; |
33 { |
|
34 m_successThreshold = m_manager->m_successThreshold; |
|
35 m_timerTimeout = m_manager->m_timerThreshold; |
|
36 m_rate = GetMinRate (); |
|
37 |
41 |
38 m_success = 0; |
42 uint32_t m_rate; |
39 m_failed = 0; |
43 }; |
40 m_recovery = false; |
|
41 m_retry = 0; |
|
42 m_timer = 0; |
|
43 } |
|
44 ArfWifiRemoteStation::~ArfWifiRemoteStation () |
|
45 {} |
|
46 |
|
47 uint32_t |
|
48 ArfWifiRemoteStation::GetMaxRate (void) |
|
49 { |
|
50 return GetNSupportedModes (); |
|
51 } |
|
52 uint32_t |
|
53 ArfWifiRemoteStation::GetMinRate (void) |
|
54 { |
|
55 return 0; |
|
56 } |
|
57 |
|
58 bool |
|
59 ArfWifiRemoteStation::NeedRecoveryFallback (void) |
|
60 { |
|
61 if (m_retry == 1) |
|
62 { |
|
63 return true; |
|
64 } |
|
65 else |
|
66 { |
|
67 return false; |
|
68 } |
|
69 } |
|
70 bool |
|
71 ArfWifiRemoteStation::NeedNormalFallback (void) |
|
72 { |
|
73 int retryMod = (m_retry - 1) % 2; |
|
74 if (retryMod == 1) |
|
75 { |
|
76 return true; |
|
77 } |
|
78 else |
|
79 { |
|
80 return false; |
|
81 } |
|
82 } |
|
83 |
|
84 |
|
85 |
|
86 void |
|
87 ArfWifiRemoteStation::DoReportRtsFailed (void) |
|
88 {} |
|
89 /** |
|
90 * It is important to realize that "recovery" mode starts after failure of |
|
91 * the first transmission after a rate increase and ends at the first successful |
|
92 * transmission. Specifically, recovery mode transcends retransmissions boundaries. |
|
93 * Fundamentally, ARF handles each data transmission independently, whether it |
|
94 * is the initial transmission of a packet or the retransmission of a packet. |
|
95 * The fundamental reason for this is that there is a backoff between each data |
|
96 * transmission, be it an initial transmission or a retransmission. |
|
97 */ |
|
98 void |
|
99 ArfWifiRemoteStation::DoReportDataFailed (void) |
|
100 { |
|
101 m_timer++; |
|
102 m_failed++; |
|
103 m_retry++; |
|
104 m_success = 0; |
|
105 |
|
106 if (m_recovery) |
|
107 { |
|
108 NS_ASSERT (m_retry >= 1); |
|
109 if (NeedRecoveryFallback ()) |
|
110 { |
|
111 ReportRecoveryFailure (); |
|
112 if (m_rate != GetMinRate ()) |
|
113 { |
|
114 m_rate--; |
|
115 } |
|
116 } |
|
117 m_timer = 0; |
|
118 } |
|
119 else |
|
120 { |
|
121 NS_ASSERT (m_retry >= 1); |
|
122 if (NeedNormalFallback ()) |
|
123 { |
|
124 ReportFailure (); |
|
125 if (m_rate != GetMinRate ()) |
|
126 { |
|
127 m_rate--; |
|
128 } |
|
129 } |
|
130 if (m_retry >= 2) |
|
131 { |
|
132 m_timer = 0; |
|
133 } |
|
134 } |
|
135 } |
|
136 void |
|
137 ArfWifiRemoteStation::DoReportRxOk (double rxSnr, WifiMode txMode) |
|
138 {} |
|
139 void ArfWifiRemoteStation::DoReportRtsOk (double ctsSnr, WifiMode ctsMode, double rtsSnr) |
|
140 { |
|
141 NS_LOG_DEBUG ("self="<<this<<" rts ok"); |
|
142 } |
|
143 void ArfWifiRemoteStation::DoReportDataOk (double ackSnr, WifiMode ackMode, double dataSnr) |
|
144 { |
|
145 m_timer++; |
|
146 m_success++; |
|
147 m_failed = 0; |
|
148 m_recovery = false; |
|
149 m_retry = 0; |
|
150 NS_LOG_DEBUG ("self="<<this<<" data ok success="<<m_success<<", timer="<<m_timer); |
|
151 if ((m_success == GetSuccessThreshold () || |
|
152 m_timer == GetTimerTimeout ()) && |
|
153 (m_rate < (GetMaxRate () - 1))) |
|
154 { |
|
155 NS_LOG_DEBUG ("self="<<this<<" inc rate"); |
|
156 m_rate++; |
|
157 m_timer = 0; |
|
158 m_success = 0; |
|
159 m_recovery = true; |
|
160 } |
|
161 } |
|
162 void |
|
163 ArfWifiRemoteStation::DoReportFinalRtsFailed (void) |
|
164 {} |
|
165 void |
|
166 ArfWifiRemoteStation::DoReportFinalDataFailed (void) |
|
167 {} |
|
168 |
|
169 WifiMode |
|
170 ArfWifiRemoteStation::DoGetDataMode (uint32_t size) |
|
171 { |
|
172 return GetSupportedMode (m_rate); |
|
173 } |
|
174 WifiMode |
|
175 ArfWifiRemoteStation::DoGetRtsMode (void) |
|
176 { |
|
177 // XXX: we could/should implement the Arf algorithm for |
|
178 // RTS only by picking a single rate within the BasicRateSet. |
|
179 return GetSupportedMode (0); |
|
180 } |
|
181 |
|
182 void ArfWifiRemoteStation::ReportRecoveryFailure (void) |
|
183 {} |
|
184 void ArfWifiRemoteStation::ReportFailure (void) |
|
185 {} |
|
186 uint32_t ArfWifiRemoteStation::GetMinTimerTimeout (void) |
|
187 { |
|
188 return m_manager->m_timerThreshold; |
|
189 } |
|
190 uint32_t ArfWifiRemoteStation::GetMinSuccessThreshold (void) |
|
191 { |
|
192 return m_manager->m_successThreshold; |
|
193 } |
|
194 uint32_t ArfWifiRemoteStation::GetTimerTimeout (void) |
|
195 { |
|
196 return m_timerTimeout; |
|
197 } |
|
198 uint32_t ArfWifiRemoteStation::GetSuccessThreshold (void) |
|
199 { |
|
200 return m_successThreshold; |
|
201 } |
|
202 void ArfWifiRemoteStation::SetTimerTimeout (uint32_t timerTimeout) |
|
203 { |
|
204 NS_ASSERT (timerTimeout >= m_manager->m_timerThreshold); |
|
205 m_timerTimeout = timerTimeout; |
|
206 } |
|
207 void ArfWifiRemoteStation::SetSuccessThreshold (uint32_t successThreshold) |
|
208 { |
|
209 NS_ASSERT (successThreshold >= m_manager->m_successThreshold); |
|
210 m_successThreshold = successThreshold; |
|
211 } |
|
212 Ptr<WifiRemoteStationManager> |
|
213 ArfWifiRemoteStation::GetManager (void) const |
|
214 { |
|
215 return m_manager; |
|
216 } |
|
217 |
44 |
218 NS_OBJECT_ENSURE_REGISTERED (ArfWifiManager); |
45 NS_OBJECT_ENSURE_REGISTERED (ArfWifiManager); |
219 |
46 |
220 TypeId |
47 TypeId |
221 ArfWifiManager::GetTypeId (void) |
48 ArfWifiManager::GetTypeId (void) |
239 ArfWifiManager::ArfWifiManager () |
66 ArfWifiManager::ArfWifiManager () |
240 {} |
67 {} |
241 ArfWifiManager::~ArfWifiManager () |
68 ArfWifiManager::~ArfWifiManager () |
242 {} |
69 {} |
243 WifiRemoteStation * |
70 WifiRemoteStation * |
244 ArfWifiManager::CreateStation (void) |
71 ArfWifiManager::DoCreateStation (void) const |
245 { |
72 { |
246 return new ArfWifiRemoteStation (this); |
73 ArfWifiRemoteStation *station = new ArfWifiRemoteStation (); |
|
74 |
|
75 station->m_successThreshold = m_successThreshold; |
|
76 station->m_timerTimeout = m_timerThreshold; |
|
77 station->m_rate = 0; |
|
78 station->m_success = 0; |
|
79 station->m_failed = 0; |
|
80 station->m_recovery = false; |
|
81 station->m_retry = 0; |
|
82 station->m_timer = 0; |
|
83 |
|
84 return station; |
|
85 } |
|
86 |
|
87 void |
|
88 ArfWifiManager::DoReportRtsFailed (WifiRemoteStation *station) |
|
89 {} |
|
90 /** |
|
91 * It is important to realize that "recovery" mode starts after failure of |
|
92 * the first transmission after a rate increase and ends at the first successful |
|
93 * transmission. Specifically, recovery mode transcends retransmissions boundaries. |
|
94 * Fundamentally, ARF handles each data transmission independently, whether it |
|
95 * is the initial transmission of a packet or the retransmission of a packet. |
|
96 * The fundamental reason for this is that there is a backoff between each data |
|
97 * transmission, be it an initial transmission or a retransmission. |
|
98 */ |
|
99 void |
|
100 ArfWifiManager::DoReportDataFailed (WifiRemoteStation *st) |
|
101 { |
|
102 ArfWifiRemoteStation *station = (ArfWifiRemoteStation *)st; |
|
103 station->m_timer++; |
|
104 station->m_failed++; |
|
105 station->m_retry++; |
|
106 station->m_success = 0; |
|
107 |
|
108 if (station->m_recovery) |
|
109 { |
|
110 NS_ASSERT (station->m_retry >= 1); |
|
111 if (station->m_retry == 1) |
|
112 { |
|
113 // need recovery fallback |
|
114 if (station->m_rate != 0) |
|
115 { |
|
116 station->m_rate--; |
|
117 } |
|
118 } |
|
119 station->m_timer = 0; |
|
120 } |
|
121 else |
|
122 { |
|
123 NS_ASSERT (station->m_retry >= 1); |
|
124 if (((station->m_retry - 1) % 2) == 1) |
|
125 { |
|
126 // need normal fallback |
|
127 if (station->m_rate != 0) |
|
128 { |
|
129 station->m_rate--; |
|
130 } |
|
131 } |
|
132 if (station->m_retry >= 2) |
|
133 { |
|
134 station->m_timer = 0; |
|
135 } |
|
136 } |
|
137 } |
|
138 void |
|
139 ArfWifiManager::DoReportRxOk (WifiRemoteStation *station, |
|
140 double rxSnr, WifiMode txMode) |
|
141 {} |
|
142 void ArfWifiManager::DoReportRtsOk (WifiRemoteStation *station, |
|
143 double ctsSnr, WifiMode ctsMode, double rtsSnr) |
|
144 { |
|
145 NS_LOG_DEBUG ("station="<<station<<" rts ok"); |
|
146 } |
|
147 void ArfWifiManager::DoReportDataOk (WifiRemoteStation *st, |
|
148 double ackSnr, WifiMode ackMode, double dataSnr) |
|
149 { |
|
150 ArfWifiRemoteStation *station = (ArfWifiRemoteStation *) st; |
|
151 station->m_timer++; |
|
152 station->m_success++; |
|
153 station->m_failed = 0; |
|
154 station->m_recovery = false; |
|
155 station->m_retry = 0; |
|
156 NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer); |
|
157 if ((station->m_success == m_successThreshold || |
|
158 station->m_timer == m_timerThreshold) && |
|
159 (station->m_rate < (station->m_state->m_modes.size () - 1))) |
|
160 { |
|
161 NS_LOG_DEBUG ("station="<<station<<" inc rate"); |
|
162 station->m_rate++; |
|
163 station->m_timer = 0; |
|
164 station->m_success = 0; |
|
165 station->m_recovery = true; |
|
166 } |
|
167 } |
|
168 void |
|
169 ArfWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *station) |
|
170 {} |
|
171 void |
|
172 ArfWifiManager::DoReportFinalDataFailed (WifiRemoteStation *station) |
|
173 {} |
|
174 |
|
175 WifiMode |
|
176 ArfWifiManager::DoGetDataMode (WifiRemoteStation *st, uint32_t size) |
|
177 { |
|
178 ArfWifiRemoteStation *station = (ArfWifiRemoteStation *) st; |
|
179 return GetSupported (station, station->m_rate); |
|
180 } |
|
181 WifiMode |
|
182 ArfWifiManager::DoGetRtsMode (WifiRemoteStation *st) |
|
183 { |
|
184 // XXX: we could/should implement the Arf algorithm for |
|
185 // RTS only by picking a single rate within the BasicRateSet. |
|
186 ArfWifiRemoteStation *station = (ArfWifiRemoteStation *) st; |
|
187 return GetSupported (station, 0); |
|
188 } |
|
189 |
|
190 bool |
|
191 ArfWifiManager::IsLowLatency (void) const |
|
192 { |
|
193 return true; |
247 } |
194 } |
248 |
195 |
249 } // namespace ns3 |
196 } // namespace ns3 |