LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2005,2006 INRIA | 3 * Copyright (c) 2005,2006 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> | 18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
19 */ | 19 */ |
20 | 20 |
21 #include "ns3/log.h" | 21 #include "ns3/log.h" |
| 22 #include "ns3/simulator.h" |
22 #include "dcf-manager.h" | 23 #include "dcf-manager.h" |
23 #include "dcf-state.h" | 24 #include "dca-txop.h" |
| 25 #include "wifi-phy-listener.h" |
| 26 #include "wifi-phy.h" |
| 27 #include "mac-low.h" |
24 | 28 |
25 namespace ns3 { | 29 namespace ns3 { |
26 | 30 |
27 NS_LOG_COMPONENT_DEFINE ("DcfManager"); | 31 NS_LOG_COMPONENT_DEFINE ("DcfManager"); |
28 | 32 |
29 /** | 33 /** |
30 * Listener for PHY events. Forwards to DcfManager | 34 * Listener for PHY events. Forwards to DcfManager |
31 */ | 35 */ |
32 class PhyListener : public ns3::WifiPhyListener | 36 class PhyListener : public ns3::WifiPhyListener |
33 { | 37 { |
(...skipping 17 matching lines...) Expand all Loading... |
51 void NotifyRxEndOk (void) | 55 void NotifyRxEndOk (void) |
52 { | 56 { |
53 m_dcf->NotifyRxEndOkNow (); | 57 m_dcf->NotifyRxEndOkNow (); |
54 } | 58 } |
55 void NotifyRxEndError (void) | 59 void NotifyRxEndError (void) |
56 { | 60 { |
57 m_dcf->NotifyRxEndErrorNow (); | 61 m_dcf->NotifyRxEndErrorNow (); |
58 } | 62 } |
59 void NotifyTxStart (Time duration, double txPowerDbm) | 63 void NotifyTxStart (Time duration, double txPowerDbm) |
60 { | 64 { |
61 NS_UNUSED(txPowerDbm); | |
62 m_dcf->NotifyTxStartNow (duration); | 65 m_dcf->NotifyTxStartNow (duration); |
63 } | 66 } |
64 void NotifyMaybeCcaBusyStart (Time duration) | 67 void NotifyMaybeCcaBusyStart (Time duration) |
65 { | 68 { |
66 m_dcf->NotifyMaybeCcaBusyStartNow (duration); | 69 m_dcf->NotifyMaybeCcaBusyStartNow (duration); |
67 } | 70 } |
68 void NotifySwitchingStart (Time duration) | 71 void NotifySwitchingStart (Time duration) |
69 { | 72 { |
70 m_dcf->NotifySwitchingStartNow (duration); | 73 m_dcf->NotifySwitchingStartNow (duration); |
71 } | 74 } |
72 void NotifySleep (void) | 75 void NotifySleep (void) |
73 { | 76 { |
74 m_dcf->NotifySleepNow (); | 77 m_dcf->NotifySleepNow (); |
75 } | 78 } |
76 void NotifyOff (void) | 79 void NotifyOff (void) |
77 { | 80 { |
78 m_dcf->NotifyOffNow (); | 81 m_dcf->NotifyOffNow (); |
79 } | 82 } |
80 void NotifyWakeup (void) | 83 void NotifyWakeup (void) |
81 { | 84 { |
82 m_dcf->NotifyWakeupNow (); | 85 m_dcf->NotifyWakeupNow (); |
| 86 } |
| 87 void NotifyOn (void) |
| 88 { |
| 89 m_dcf->NotifyOnNow (); |
83 } | 90 } |
84 | 91 |
85 private: | 92 private: |
86 ns3::DcfManager *m_dcf; //!< DcfManager to forward events to | 93 ns3::DcfManager *m_dcf; //!< DcfManager to forward events to |
87 }; | 94 }; |
88 | 95 |
89 | 96 |
90 /**************************************************************** | 97 /**************************************************************** |
91 * Implement the DCF manager of all DCF state holders | 98 * Implement the DCF manager of all DCF state holders |
92 ****************************************************************/ | 99 ****************************************************************/ |
(...skipping 18 matching lines...) Expand all Loading... |
111 m_off (false), | 118 m_off (false), |
112 m_slotTimeUs (0), | 119 m_slotTimeUs (0), |
113 m_sifs (Seconds (0.0)), | 120 m_sifs (Seconds (0.0)), |
114 m_phyListener (0) | 121 m_phyListener (0) |
115 { | 122 { |
116 NS_LOG_FUNCTION (this); | 123 NS_LOG_FUNCTION (this); |
117 } | 124 } |
118 | 125 |
119 DcfManager::~DcfManager () | 126 DcfManager::~DcfManager () |
120 { | 127 { |
| 128 NS_LOG_FUNCTION (this); |
121 delete m_phyListener; | 129 delete m_phyListener; |
122 m_phyListener = 0; | 130 m_phyListener = 0; |
123 } | 131 } |
124 | 132 |
125 void | 133 void |
126 DcfManager::DoDispose (void) | 134 DcfManager::DoDispose (void) |
127 { | 135 { |
128 NS_LOG_FUNCTION (this); | 136 NS_LOG_FUNCTION (this); |
129 for (Ptr<DcfState> i : m_states) | 137 for (Ptr<DcaTxop> i : m_states) |
130 { | 138 { |
131 i->Dispose (); | 139 i->Dispose (); |
132 i = 0; | 140 i = 0; |
133 } | 141 } |
134 } | 142 } |
135 | 143 |
136 void | 144 void |
137 DcfManager::SetupPhyListener (Ptr<WifiPhy> phy) | 145 DcfManager::SetupPhyListener (Ptr<WifiPhy> phy) |
138 { | 146 { |
139 NS_LOG_FUNCTION (this << phy); | 147 NS_LOG_FUNCTION (this << phy); |
140 if (m_phyListener != 0) | 148 NS_ASSERT (m_phyListener == 0); |
141 { | |
142 delete m_phyListener; | |
143 } | |
144 m_phyListener = new PhyListener (this); | 149 m_phyListener = new PhyListener (this); |
145 phy->RegisterListener (m_phyListener); | 150 phy->RegisterListener (m_phyListener); |
146 } | 151 } |
147 | 152 |
148 void | 153 void |
149 DcfManager::RemovePhyListener (Ptr<WifiPhy> phy) | 154 DcfManager::RemovePhyListener (Ptr<WifiPhy> phy) |
150 { | 155 { |
151 NS_LOG_FUNCTION (this << phy); | 156 NS_LOG_FUNCTION (this << phy); |
152 if (m_phyListener != 0) | 157 if (m_phyListener != 0) |
153 { | 158 { |
154 phy->UnregisterListener (m_phyListener); | 159 phy->UnregisterListener (m_phyListener); |
155 delete m_phyListener; | 160 delete m_phyListener; |
156 m_phyListener = 0; | 161 m_phyListener = 0; |
157 } | 162 } |
158 } | 163 } |
159 | 164 |
160 void | 165 void |
161 DcfManager::SetupLow (Ptr<MacLow> low) | 166 DcfManager::SetupLow (Ptr<MacLow> low) |
162 { | 167 { |
163 NS_LOG_FUNCTION (this << low); | 168 NS_LOG_FUNCTION (this << low); |
164 low->RegisterDcf (this); | 169 low->RegisterDcf (this); |
165 } | 170 } |
166 | 171 |
167 void | 172 void |
168 DcfManager::SetSlot (Time slotTime) | 173 DcfManager::SetSlot (Time slotTime) |
169 { | 174 { |
170 NS_LOG_FUNCTION (this << slotTime); | 175 NS_LOG_FUNCTION (this << slotTime); |
171 m_slotTimeUs = static_cast<uint32_t>(slotTime.GetMicroSeconds ()); | 176 m_slotTimeUs = static_cast<uint32_t> (slotTime.GetMicroSeconds ()); |
172 } | 177 } |
173 | 178 |
174 void | 179 void |
175 DcfManager::SetSifs (Time sifs) | 180 DcfManager::SetSifs (Time sifs) |
176 { | 181 { |
177 NS_LOG_FUNCTION (this << sifs); | 182 NS_LOG_FUNCTION (this << sifs); |
178 m_sifs = sifs; | 183 m_sifs = sifs; |
179 } | 184 } |
180 | 185 |
181 void | 186 void |
182 DcfManager::SetEifsNoDifs (Time eifsNoDifs) | 187 DcfManager::SetEifsNoDifs (Time eifsNoDifs) |
183 { | 188 { |
184 NS_LOG_FUNCTION (this << eifsNoDifs); | 189 NS_LOG_FUNCTION (this << eifsNoDifs); |
185 m_eifsNoDifs = eifsNoDifs; | 190 m_eifsNoDifs = eifsNoDifs; |
186 } | 191 } |
187 | 192 |
188 Time | 193 Time |
189 DcfManager::GetEifsNoDifs () const | 194 DcfManager::GetEifsNoDifs () const |
190 { | 195 { |
191 NS_LOG_FUNCTION (this); | 196 NS_LOG_FUNCTION (this); |
192 return m_eifsNoDifs; | 197 return m_eifsNoDifs; |
193 } | 198 } |
194 | 199 |
195 void | 200 void |
196 DcfManager::Add (Ptr<DcfState> dcf) | 201 DcfManager::Add (Ptr<DcaTxop> dcf) |
197 { | 202 { |
198 NS_LOG_FUNCTION (this << dcf); | 203 NS_LOG_FUNCTION (this << dcf); |
199 m_states.push_back (dcf); | 204 m_states.push_back (dcf); |
200 } | 205 } |
201 | 206 |
202 Time | 207 Time |
203 DcfManager::MostRecent (Time a, Time b) const | 208 DcfManager::MostRecent (Time a, Time b) const |
204 { | 209 { |
205 NS_LOG_FUNCTION (this << a << b); | |
206 return Max (a, b); | 210 return Max (a, b); |
207 } | |
208 | |
209 Time | |
210 DcfManager::MostRecent (Time a, Time b, Time c) const | |
211 { | |
212 NS_LOG_FUNCTION (this << a << b << c); | |
213 Time retval; | |
214 retval = Max (a, b); | |
215 retval = Max (retval, c); | |
216 return retval; | |
217 } | |
218 | |
219 Time | |
220 DcfManager::MostRecent (Time a, Time b, Time c, Time d) const | |
221 { | |
222 NS_LOG_FUNCTION (this << a << b << c << d); | |
223 Time e = Max (a, b); | |
224 Time f = Max (c, d); | |
225 Time retval = Max (e, f); | |
226 return retval; | |
227 } | |
228 | |
229 Time | |
230 DcfManager::MostRecent (Time a, Time b, Time c, Time d, Time e, Time f) const | |
231 { | |
232 NS_LOG_FUNCTION (this << a << b << c << d << e << f); | |
233 Time g = Max (a, b); | |
234 Time h = Max (c, d); | |
235 Time i = Max (e, f); | |
236 Time k = Max (g, h); | |
237 Time retval = Max (k, i); | |
238 return retval; | |
239 } | 211 } |
240 | 212 |
241 Time | 213 Time |
242 DcfManager::MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g)
const | 214 DcfManager::MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g)
const |
243 { | 215 { |
244 NS_LOG_FUNCTION (this << a << b << c << d << e << f << g); | 216 Time h = MostRecent (a, b); |
245 Time h = Max (a, b); | 217 Time i = MostRecent (c, d); |
246 Time i = Max (c, d); | 218 Time j = MostRecent (e, f); |
247 Time j = Max (e, f); | 219 Time k = MostRecent (h, i); |
248 Time k = Max (h, i); | 220 Time l = MostRecent (j, g); |
249 Time l = Max (j, g); | 221 Time retval = MostRecent (k, l); |
250 Time retval = Max (k, l); | |
251 return retval; | 222 return retval; |
252 } | 223 } |
253 | 224 |
254 bool | 225 bool |
255 DcfManager::IsBusy (void) const | 226 DcfManager::IsBusy (void) const |
256 { | 227 { |
257 NS_LOG_FUNCTION (this); | 228 NS_LOG_FUNCTION (this); |
258 // PHY busy | 229 // PHY busy |
259 if (m_rxing) | 230 if (m_rxing) |
260 { | 231 { |
(...skipping 13 matching lines...) Expand all Loading... |
274 // CCA busy | 245 // CCA busy |
275 Time lastCCABusyEnd = m_lastBusyStart + m_lastBusyDuration; | 246 Time lastCCABusyEnd = m_lastBusyStart + m_lastBusyDuration; |
276 if (lastCCABusyEnd > Simulator::Now ()) | 247 if (lastCCABusyEnd > Simulator::Now ()) |
277 { | 248 { |
278 return true; | 249 return true; |
279 } | 250 } |
280 return false; | 251 return false; |
281 } | 252 } |
282 | 253 |
283 bool | 254 bool |
284 DcfManager::IsWithinAifs (Ptr<DcfState> state) const | 255 DcfManager::IsWithinAifs (Ptr<DcaTxop> state) const |
285 { | 256 { |
286 NS_LOG_FUNCTION (this << state); | 257 NS_LOG_FUNCTION (this << state); |
287 Time ifsEnd = GetAccessGrantStart () + MicroSeconds (state->GetAifsn () * m_sl
otTimeUs); | 258 Time ifsEnd = GetAccessGrantStart () + MicroSeconds (state->GetAifsn () * m_sl
otTimeUs); |
288 if (ifsEnd > Simulator::Now ()) | 259 if (ifsEnd > Simulator::Now ()) |
289 { | 260 { |
290 NS_LOG_DEBUG ("IsWithinAifs () true; ifsEnd is at " << ifsEnd.GetSeconds (
)); | 261 NS_LOG_DEBUG ("IsWithinAifs () true; ifsEnd is at " << ifsEnd.GetSeconds (
)); |
291 return true; | 262 return true; |
292 } | 263 } |
293 NS_LOG_DEBUG ("IsWithinAifs () false; ifsEnd was at " << ifsEnd.GetSeconds ())
; | 264 NS_LOG_DEBUG ("IsWithinAifs () false; ifsEnd was at " << ifsEnd.GetSeconds ())
; |
294 return false; | 265 return false; |
295 } | 266 } |
296 | 267 |
297 void | 268 void |
298 DcfManager::RequestAccess (Ptr<DcfState> state) | 269 DcfManager::RequestAccess (Ptr<DcaTxop> state) |
299 { | 270 { |
300 NS_LOG_FUNCTION (this << state); | 271 NS_LOG_FUNCTION (this << state); |
301 //Deny access if in sleep mode or off | 272 //Deny access if in sleep mode or off |
302 if (m_sleeping || m_off) | 273 if (m_sleeping || m_off) |
303 { | 274 { |
304 return; | 275 return; |
305 } | 276 } |
306 UpdateBackoff (); | 277 UpdateBackoff (); |
307 NS_ASSERT (!state->IsAccessRequested ()); | 278 NS_ASSERT (!state->IsAccessRequested ()); |
308 state->NotifyAccessRequested (); | 279 state->NotifyAccessRequested (); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 DoRestartAccessTimeoutIfNeeded (); | 313 DoRestartAccessTimeoutIfNeeded (); |
343 } | 314 } |
344 | 315 |
345 void | 316 void |
346 DcfManager::DoGrantAccess (void) | 317 DcfManager::DoGrantAccess (void) |
347 { | 318 { |
348 NS_LOG_FUNCTION (this); | 319 NS_LOG_FUNCTION (this); |
349 uint32_t k = 0; | 320 uint32_t k = 0; |
350 for (States::iterator i = m_states.begin (); i != m_states.end (); k++) | 321 for (States::iterator i = m_states.begin (); i != m_states.end (); k++) |
351 { | 322 { |
352 Ptr<DcfState> state = *i; | 323 Ptr<DcaTxop> state = *i; |
353 if (state->IsAccessRequested () | 324 if (state->IsAccessRequested () |
354 && GetBackoffEndFor (state) <= Simulator::Now () ) | 325 && GetBackoffEndFor (state) <= Simulator::Now () ) |
355 { | 326 { |
356 /** | 327 /** |
357 * This is the first dcf we find with an expired backoff and which | 328 * This is the first dcf we find with an expired backoff and which |
358 * needs access to the medium. i.e., it has data to send. | 329 * needs access to the medium. i.e., it has data to send. |
359 */ | 330 */ |
360 NS_LOG_DEBUG ("dcf " << k << " needs access. backoff expired. access g
ranted. slots=" << state->GetBackoffSlots ()); | 331 NS_LOG_DEBUG ("dcf " << k << " needs access. backoff expired. access g
ranted. slots=" << state->GetBackoffSlots ()); |
361 i++; //go to the next item in the list. | 332 i++; //go to the next item in the list. |
362 k++; | 333 k++; |
363 std::vector<Ptr<DcfState> > internalCollisionStates; | 334 std::vector<Ptr<DcaTxop> > internalCollisionStates; |
364 for (States::iterator j = i; j != m_states.end (); j++, k++) | 335 for (States::iterator j = i; j != m_states.end (); j++, k++) |
365 { | 336 { |
366 Ptr<DcfState> otherState = *j; | 337 Ptr<DcaTxop> otherState = *j; |
367 if (otherState->IsAccessRequested () | 338 if (otherState->IsAccessRequested () |
368 && GetBackoffEndFor (otherState) <= Simulator::Now ()) | 339 && GetBackoffEndFor (otherState) <= Simulator::Now ()) |
369 { | 340 { |
370 NS_LOG_DEBUG ("dcf " << k << " needs access. backoff expired.
internal collision. slots=" << | 341 NS_LOG_DEBUG ("dcf " << k << " needs access. backoff expired.
internal collision. slots=" << |
371 otherState->GetBackoffSlots ()); | 342 otherState->GetBackoffSlots ()); |
372 /** | 343 /** |
373 * all other dcfs with a lower priority whose backoff | 344 * all other dcfs with a lower priority whose backoff |
374 * has expired and which needed access to the medium | 345 * has expired and which needed access to the medium |
375 * must be notified that we did get an internal collision. | 346 * must be notified that we did get an internal collision. |
376 */ | 347 */ |
377 internalCollisionStates.push_back (otherState); | 348 internalCollisionStates.push_back (otherState); |
378 } | 349 } |
379 } | 350 } |
380 | 351 |
381 /** | 352 /** |
382 * Now, we notify all of these changes in one go. It is necessary to | 353 * Now, we notify all of these changes in one go. It is necessary to |
383 * perform first the calculations of which states are colliding and th
en | 354 * perform first the calculations of which states are colliding and th
en |
384 * only apply the changes because applying the changes through notific
ation | 355 * only apply the changes because applying the changes through notific
ation |
385 * could change the global state of the manager, and, thus, could chan
ge | 356 * could change the global state of the manager, and, thus, could chan
ge |
386 * the result of the calculations. | 357 * the result of the calculations. |
387 */ | 358 */ |
388 state->NotifyAccessGranted (); | 359 state->NotifyAccessGranted (); |
389 for (std::vector<Ptr<DcfState> >::iterator l = internalCollisionStates
.begin (); | 360 for (std::vector<Ptr<DcaTxop> >::iterator l = internalCollisionStates.
begin (); |
390 l != internalCollisionStates.end (); l++) | 361 l != internalCollisionStates.end (); l++) |
391 { | 362 { |
392 (*l)->NotifyInternalCollision (); | 363 (*l)->NotifyInternalCollision (); |
393 } | 364 } |
394 break; | 365 break; |
395 } | 366 } |
396 i++; | 367 i++; |
397 } | 368 } |
398 } | 369 } |
399 | 370 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 ); | 410 ); |
440 NS_LOG_INFO ("access grant start=" << accessGrantedStart << | 411 NS_LOG_INFO ("access grant start=" << accessGrantedStart << |
441 ", rx access start=" << rxAccessStart << | 412 ", rx access start=" << rxAccessStart << |
442 ", busy access start=" << busyAccessStart << | 413 ", busy access start=" << busyAccessStart << |
443 ", tx access start=" << txAccessStart << | 414 ", tx access start=" << txAccessStart << |
444 ", nav access start=" << navAccessStart); | 415 ", nav access start=" << navAccessStart); |
445 return accessGrantedStart; | 416 return accessGrantedStart; |
446 } | 417 } |
447 | 418 |
448 Time | 419 Time |
449 DcfManager::GetBackoffStartFor (Ptr<DcfState> state) | 420 DcfManager::GetBackoffStartFor (Ptr<DcaTxop> state) |
450 { | 421 { |
451 NS_LOG_FUNCTION (this << state); | 422 NS_LOG_FUNCTION (this << state); |
452 Time mostRecentEvent = MostRecent (state->GetBackoffStart (), | 423 Time mostRecentEvent = MostRecent (state->GetBackoffStart (), |
453 GetAccessGrantStart () + MicroSeconds (stat
e->GetAifsn () * m_slotTimeUs)); | 424 GetAccessGrantStart () + MicroSeconds (stat
e->GetAifsn () * m_slotTimeUs)); |
454 | 425 |
455 return mostRecentEvent; | 426 return mostRecentEvent; |
456 } | 427 } |
457 | 428 |
458 Time | 429 Time |
459 DcfManager::GetBackoffEndFor (Ptr<DcfState> state) | 430 DcfManager::GetBackoffEndFor (Ptr<DcaTxop> state) |
460 { | 431 { |
461 NS_LOG_FUNCTION (this << state); | 432 NS_LOG_FUNCTION (this << state); |
462 NS_LOG_DEBUG ("Backoff start: " << GetBackoffStartFor (state).As (Time::US) << | 433 NS_LOG_DEBUG ("Backoff start: " << GetBackoffStartFor (state).As (Time::US) << |
463 " end: " << (GetBackoffStartFor (state) + | 434 " end: " << (GetBackoffStartFor (state) + |
464 MicroSeconds (state->GetBackoffSlots () * m_slotTim
eUs)).As (Time::US)); | 435 MicroSeconds (state->GetBackoffSlots () * m_slotTim
eUs)).As (Time::US)); |
465 return GetBackoffStartFor (state) + MicroSeconds (state->GetBackoffSlots () *
m_slotTimeUs); | 436 return GetBackoffStartFor (state) + MicroSeconds (state->GetBackoffSlots () *
m_slotTimeUs); |
466 } | 437 } |
467 | 438 |
468 void | 439 void |
469 DcfManager::UpdateBackoff (void) | 440 DcfManager::UpdateBackoff (void) |
470 { | 441 { |
471 NS_LOG_FUNCTION (this); | 442 NS_LOG_FUNCTION (this); |
472 uint32_t k = 0; | 443 uint32_t k = 0; |
473 for (States::iterator i = m_states.begin (); i != m_states.end (); i++, k++) | 444 for (States::iterator i = m_states.begin (); i != m_states.end (); i++, k++) |
474 { | 445 { |
475 Ptr<DcfState> state = *i; | 446 Ptr<DcaTxop> state = *i; |
476 | 447 |
477 Time backoffStart = GetBackoffStartFor (state); | 448 Time backoffStart = GetBackoffStartFor (state); |
478 if (backoffStart <= Simulator::Now ()) | 449 if (backoffStart <= Simulator::Now ()) |
479 { | 450 { |
480 uint32_t nus = static_cast<uint32_t>((Simulator::Now () - backoffStart
).GetMicroSeconds ()); | 451 uint32_t nus = static_cast<uint32_t> ((Simulator::Now () - backoffStar
t).GetMicroSeconds ()); |
481 uint32_t nIntSlots = nus / m_slotTimeUs; | 452 uint32_t nIntSlots = nus / m_slotTimeUs; |
482 /* | 453 /* |
483 * EDCA behaves slightly different to DCA. For EDCA we | 454 * EDCA behaves slightly different to DCA. For EDCA we |
484 * decrement once at the slot boundary at the end of AIFS as | 455 * decrement once at the slot boundary at the end of AIFS as |
485 * well as once at the end of each clear slot | 456 * well as once at the end of each clear slot |
486 * thereafter. For DCA we only decrement at the end of each | 457 * thereafter. For DCA we only decrement at the end of each |
487 * clear slot after DIFS. We account for the extra backoff | 458 * clear slot after DIFS. We account for the extra backoff |
488 * by incrementing the slot count here in the case of | 459 * by incrementing the slot count here in the case of |
489 * EDCA. The if statement whose body we are in has confirmed | 460 * EDCA. The if statement whose body we are in has confirmed |
490 * that a minimum of AIFS has elapsed since last busy | 461 * that a minimum of AIFS has elapsed since last busy |
491 * medium. | 462 * medium. |
492 */ | 463 */ |
493 if (state->IsEdca ()) | 464 if (state->IsEdca ()) |
494 { | 465 { |
495 nIntSlots++; | 466 nIntSlots++; |
496 } | 467 } |
497 uint32_t n = std::min (nIntSlots, state->GetBackoffSlots ()); | 468 uint32_t n = std::min (nIntSlots, state->GetBackoffSlots ()); |
498 NS_LOG_DEBUG ("dcf " << k << " dec backoff slots=" << n); | 469 NS_LOG_DEBUG ("dcf " << k << " dec backoff slots=" << n); |
499 Time backoffUpdateBound = backoffStart + MicroSeconds (n * m_slotTimeU
s); | 470 Time backoffUpdateBound = backoffStart + MicroSeconds (n * m_slotTimeU
s); |
500 state->UpdateBackoffSlotsNow (n, backoffUpdateBound); | 471 state->UpdateBackoffSlotsNow (n, backoffUpdateBound); |
501 } | 472 } |
502 } | 473 } |
503 } | 474 } |
504 | 475 |
505 void | 476 void |
506 DcfManager::DoRestartAccessTimeoutIfNeeded (void) | 477 DcfManager::DoRestartAccessTimeoutIfNeeded (void) |
507 { | 478 { |
508 NS_LOG_FUNCTION (this); | 479 NS_LOG_FUNCTION (this); |
509 /** | 480 /** |
510 * Is there a DcfState which needs to access the medium, and, | 481 * Is there a DcaTxop which needs to access the medium, and, |
511 * if there is one, how many slots for AIFS+backoff does it require ? | 482 * if there is one, how many slots for AIFS+backoff does it require ? |
512 */ | 483 */ |
513 bool accessTimeoutNeeded = false; | 484 bool accessTimeoutNeeded = false; |
514 Time expectedBackoffEnd = Simulator::GetMaximumSimulationTime (); | 485 Time expectedBackoffEnd = Simulator::GetMaximumSimulationTime (); |
515 for (States::iterator i = m_states.begin (); i != m_states.end (); i++) | 486 for (States::iterator i = m_states.begin (); i != m_states.end (); i++) |
516 { | 487 { |
517 Ptr<DcfState> state = *i; | 488 Ptr<DcaTxop> state = *i; |
518 if (state->IsAccessRequested ()) | 489 if (state->IsAccessRequested ()) |
519 { | 490 { |
520 Time tmp = GetBackoffEndFor (state); | 491 Time tmp = GetBackoffEndFor (state); |
521 if (tmp > Simulator::Now ()) | 492 if (tmp > Simulator::Now ()) |
522 { | 493 { |
523 accessTimeoutNeeded = true; | 494 accessTimeoutNeeded = true; |
524 expectedBackoffEnd = std::min (expectedBackoffEnd, tmp); | 495 expectedBackoffEnd = std::min (expectedBackoffEnd, tmp); |
525 } | 496 } |
526 } | 497 } |
527 } | 498 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 | 610 |
640 //Cancel timeout | 611 //Cancel timeout |
641 if (m_accessTimeout.IsRunning ()) | 612 if (m_accessTimeout.IsRunning ()) |
642 { | 613 { |
643 m_accessTimeout.Cancel (); | 614 m_accessTimeout.Cancel (); |
644 } | 615 } |
645 | 616 |
646 //Reset backoffs | 617 //Reset backoffs |
647 for (States::iterator i = m_states.begin (); i != m_states.end (); i++) | 618 for (States::iterator i = m_states.begin (); i != m_states.end (); i++) |
648 { | 619 { |
649 Ptr<DcfState> state = *i; | 620 Ptr<DcaTxop> state = *i; |
650 uint32_t remainingSlots = state->GetBackoffSlots (); | 621 uint32_t remainingSlots = state->GetBackoffSlots (); |
651 if (remainingSlots > 0) | 622 if (remainingSlots > 0) |
652 { | 623 { |
653 state->UpdateBackoffSlotsNow (remainingSlots, now); | 624 state->UpdateBackoffSlotsNow (remainingSlots, now); |
654 NS_ASSERT (state->GetBackoffSlots () == 0); | 625 NS_ASSERT (state->GetBackoffSlots () == 0); |
655 } | 626 } |
656 state->ResetCw (); | 627 state->ResetCw (); |
657 state->m_accessRequested = false; | 628 state->m_accessRequested = false; |
658 state->NotifyChannelSwitching (); | 629 state->NotifyChannelSwitching (); |
659 } | 630 } |
(...skipping 11 matching lines...) Expand all Loading... |
671 m_sleeping = true; | 642 m_sleeping = true; |
672 //Cancel timeout | 643 //Cancel timeout |
673 if (m_accessTimeout.IsRunning ()) | 644 if (m_accessTimeout.IsRunning ()) |
674 { | 645 { |
675 m_accessTimeout.Cancel (); | 646 m_accessTimeout.Cancel (); |
676 } | 647 } |
677 | 648 |
678 //Reset backoffs | 649 //Reset backoffs |
679 for (States::iterator i = m_states.begin (); i != m_states.end (); i++) | 650 for (States::iterator i = m_states.begin (); i != m_states.end (); i++) |
680 { | 651 { |
681 Ptr<DcfState> state = *i; | 652 Ptr<DcaTxop> state = *i; |
682 state->NotifySleep (); | 653 state->NotifySleep (); |
683 } | 654 } |
684 } | 655 } |
685 | 656 |
686 void | 657 void |
687 DcfManager::NotifyOffNow (void) | 658 DcfManager::NotifyOffNow (void) |
688 { | 659 { |
689 NS_LOG_FUNCTION (this); | 660 NS_LOG_FUNCTION (this); |
690 m_off = true; | 661 m_off = true; |
691 //Cancel timeout | 662 //Cancel timeout |
692 if (m_accessTimeout.IsRunning ()) | 663 if (m_accessTimeout.IsRunning ()) |
693 { | 664 { |
694 m_accessTimeout.Cancel (); | 665 m_accessTimeout.Cancel (); |
695 } | 666 } |
696 | 667 |
697 //Reset backoffs | 668 //Reset backoffs |
698 for (States::iterator i = m_states.begin (); i != m_states.end (); i++) | 669 for (States::iterator i = m_states.begin (); i != m_states.end (); i++) |
699 { | 670 { |
700 Ptr<DcfState> state = *i; | 671 Ptr<DcaTxop> state = *i; |
701 state->NotifyOff (); | 672 state->NotifyOff (); |
702 } | 673 } |
703 } | 674 } |
704 | 675 |
705 void | 676 void |
706 DcfManager::NotifyWakeupNow (void) | 677 DcfManager::NotifyWakeupNow (void) |
707 { | 678 { |
708 NS_LOG_FUNCTION (this); | 679 NS_LOG_FUNCTION (this); |
709 m_sleeping = false; | 680 m_sleeping = false; |
710 for (States::iterator i = m_states.begin (); i != m_states.end (); i++) | 681 for (States::iterator i = m_states.begin (); i != m_states.end (); i++) |
711 { | 682 { |
712 Ptr<DcfState> state = *i; | 683 Ptr<DcaTxop> state = *i; |
713 uint32_t remainingSlots = state->GetBackoffSlots (); | 684 uint32_t remainingSlots = state->GetBackoffSlots (); |
714 if (remainingSlots > 0) | 685 if (remainingSlots > 0) |
715 { | 686 { |
716 state->UpdateBackoffSlotsNow (remainingSlots, Simulator::Now ()); | 687 state->UpdateBackoffSlotsNow (remainingSlots, Simulator::Now ()); |
717 NS_ASSERT (state->GetBackoffSlots () == 0); | 688 NS_ASSERT (state->GetBackoffSlots () == 0); |
718 } | 689 } |
719 state->ResetCw (); | 690 state->ResetCw (); |
720 state->m_accessRequested = false; | 691 state->m_accessRequested = false; |
721 state->NotifyWakeUp (); | 692 state->NotifyWakeUp (); |
| 693 } |
| 694 } |
| 695 |
| 696 void |
| 697 DcfManager::NotifyOnNow (void) |
| 698 { |
| 699 NS_LOG_FUNCTION (this); |
| 700 m_off = false; |
| 701 for (States::iterator i = m_states.begin (); i != m_states.end (); i++) |
| 702 { |
| 703 Ptr<DcaTxop> state = *i; |
| 704 uint32_t remainingSlots = state->GetBackoffSlots (); |
| 705 if (remainingSlots > 0) |
| 706 { |
| 707 state->UpdateBackoffSlotsNow (remainingSlots, Simulator::Now ()); |
| 708 NS_ASSERT (state->GetBackoffSlots () == 0); |
| 709 } |
| 710 state->ResetCw (); |
| 711 state->m_accessRequested = false; |
| 712 state->NotifyOn (); |
722 } | 713 } |
723 } | 714 } |
724 | 715 |
725 void | 716 void |
726 DcfManager::NotifyNavResetNow (Time duration) | 717 DcfManager::NotifyNavResetNow (Time duration) |
727 { | 718 { |
728 NS_LOG_FUNCTION (this << duration); | 719 NS_LOG_FUNCTION (this << duration); |
729 NS_LOG_DEBUG ("nav reset for=" << duration); | 720 NS_LOG_DEBUG ("nav reset for=" << duration); |
730 UpdateBackoff (); | 721 UpdateBackoff (); |
731 m_lastNavStart = Simulator::Now (); | 722 m_lastNavStart = Simulator::Now (); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 | 771 |
781 void | 772 void |
782 DcfManager::NotifyCtsTimeoutResetNow () | 773 DcfManager::NotifyCtsTimeoutResetNow () |
783 { | 774 { |
784 NS_LOG_FUNCTION (this); | 775 NS_LOG_FUNCTION (this); |
785 m_lastCtsTimeoutEnd = Simulator::Now (); | 776 m_lastCtsTimeoutEnd = Simulator::Now (); |
786 DoRestartAccessTimeoutIfNeeded (); | 777 DoRestartAccessTimeoutIfNeeded (); |
787 } | 778 } |
788 | 779 |
789 } //namespace ns3 | 780 } //namespace ns3 |
LEFT | RIGHT |