| OLD | NEW |
|---|---|
| 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 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 } | 146 } |
| 147 void | 147 void |
| 148 DcfState::NotifyCollision (void) | 148 DcfState::NotifyCollision (void) |
| 149 { | 149 { |
| 150 DoNotifyCollision (); | 150 DoNotifyCollision (); |
| 151 } | 151 } |
| 152 void | 152 void |
| 153 DcfState::NotifyInternalCollision (void) | 153 DcfState::NotifyInternalCollision (void) |
| 154 { | 154 { |
| 155 DoNotifyInternalCollision (); | 155 DoNotifyInternalCollision (); |
| 156 } | |
| 157 void | |
| 158 DcfState::NotifyChannelSwitching (void) | |
| 159 { | |
| 160 DoNotifyChannelSwitching (); | |
| 156 } | 161 } |
| 157 | 162 |
| 158 | 163 |
| 159 /*************************************************************** | 164 /*************************************************************** |
| 160 * Listener for Nav events. Forwards to DcfManager | 165 * Listener for Nav events. Forwards to DcfManager |
| 161 ***************************************************************/ | 166 ***************************************************************/ |
| 162 | 167 |
| 163 class LowDcfListener : public ns3::MacLowDcfListener { | 168 class LowDcfListener : public ns3::MacLowDcfListener { |
| 164 public: | 169 public: |
| 165 LowDcfListener (ns3::DcfManager *dcf) | 170 LowDcfListener (ns3::DcfManager *dcf) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 m_dcf->NotifyRxEndOkNow (); | 208 m_dcf->NotifyRxEndOkNow (); |
| 204 } | 209 } |
| 205 virtual void NotifyRxEndError (void) { | 210 virtual void NotifyRxEndError (void) { |
| 206 m_dcf->NotifyRxEndErrorNow (); | 211 m_dcf->NotifyRxEndErrorNow (); |
| 207 } | 212 } |
| 208 virtual void NotifyTxStart (Time duration) { | 213 virtual void NotifyTxStart (Time duration) { |
| 209 m_dcf->NotifyTxStartNow (duration); | 214 m_dcf->NotifyTxStartNow (duration); |
| 210 } | 215 } |
| 211 virtual void NotifyMaybeCcaBusyStart (Time duration) { | 216 virtual void NotifyMaybeCcaBusyStart (Time duration) { |
| 212 m_dcf->NotifyMaybeCcaBusyStartNow (duration); | 217 m_dcf->NotifyMaybeCcaBusyStartNow (duration); |
| 218 } | |
| 219 virtual void NotifySwitchingStart (Time duration) { | |
| 220 m_dcf->NotifySwitchingStartNow (duration); | |
| 213 } | 221 } |
| 214 private: | 222 private: |
| 215 ns3::DcfManager *m_dcf; | 223 ns3::DcfManager *m_dcf; |
| 216 }; | 224 }; |
| 217 | 225 |
| 218 /**************************************************************** | 226 /**************************************************************** |
| 219 * Implement the DCF manager of all DCF state holders | 227 * Implement the DCF manager of all DCF state holders |
| 220 ****************************************************************/ | 228 ****************************************************************/ |
| 221 | 229 |
| 222 DcfManager::DcfManager () | 230 DcfManager::DcfManager () |
| 223 : m_lastAckTimeoutEnd (MicroSeconds (0)), | 231 : m_lastAckTimeoutEnd (MicroSeconds (0)), |
| 224 m_lastCtsTimeoutEnd (MicroSeconds (0)), | 232 m_lastCtsTimeoutEnd (MicroSeconds (0)), |
| 225 m_lastNavStart (MicroSeconds (0)), | 233 m_lastNavStart (MicroSeconds (0)), |
| 226 m_lastNavDuration (MicroSeconds (0)), | 234 m_lastNavDuration (MicroSeconds (0)), |
| 227 m_lastRxStart (MicroSeconds (0)), | 235 m_lastRxStart (MicroSeconds (0)), |
| 228 m_lastRxDuration (MicroSeconds (0)), | 236 m_lastRxDuration (MicroSeconds (0)), |
| 229 m_lastRxReceivedOk (true), | 237 m_lastRxReceivedOk (true), |
| 230 m_lastRxEnd (MicroSeconds (0)), | 238 m_lastRxEnd (MicroSeconds (0)), |
| 231 m_lastTxStart (MicroSeconds (0)), | 239 m_lastTxStart (MicroSeconds (0)), |
| 232 m_lastTxDuration (MicroSeconds (0)), | 240 m_lastTxDuration (MicroSeconds (0)), |
| 233 m_lastBusyStart (MicroSeconds (0)), | 241 m_lastBusyStart (MicroSeconds (0)), |
| 234 m_lastBusyDuration (MicroSeconds (0)), | 242 m_lastBusyDuration (MicroSeconds (0)), |
| 243 m_lastSwitchingStart (MicroSeconds (0)), | |
| 244 m_lastSwitchingDuration (MicroSeconds (0)), | |
| 235 m_rxing (false), | 245 m_rxing (false), |
| 236 m_slotTime (Seconds (0.0)), | 246 m_slotTime (Seconds (0.0)), |
| 237 m_sifs (Seconds (0.0)), | 247 m_sifs (Seconds (0.0)), |
| 238 m_phyListener (0), | 248 m_phyListener (0), |
| 239 m_lowListener (0) | 249 m_lowListener (0) |
| 240 {} | 250 {} |
| 241 | 251 |
| 242 DcfManager::~DcfManager () | 252 DcfManager::~DcfManager () |
| 243 { | 253 { |
| 244 delete m_phyListener; | 254 delete m_phyListener; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 DcfManager::MostRecent (Time a, Time b, Time c, Time d, Time e, Time f) const | 322 DcfManager::MostRecent (Time a, Time b, Time c, Time d, Time e, Time f) const |
| 313 { | 323 { |
| 314 Time g = Max (a, b); | 324 Time g = Max (a, b); |
| 315 Time h = Max (c, d); | 325 Time h = Max (c, d); |
| 316 Time i = Max (e, f); | 326 Time i = Max (e, f); |
| 317 Time k = Max (g, h); | 327 Time k = Max (g, h); |
| 318 Time retval = Max (k, i); | 328 Time retval = Max (k, i); |
| 319 return retval; | 329 return retval; |
| 320 } | 330 } |
| 321 | 331 |
| 332 Time | |
| 333 DcfManager::MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g) const | |
| 334 { | |
| 335 Time h = Max (a, b); | |
| 336 Time i = Max (c, d); | |
| 337 Time j = Max (e, f); | |
| 338 Time k = Max (h, i); | |
| 339 Time l = Max (j, g); | |
| 340 Time retval = Max (k, l); | |
| 341 return retval; | |
| 342 } | |
| 343 | |
| 322 bool | 344 bool |
| 323 DcfManager::IsBusy (void) const | 345 DcfManager::IsBusy (void) const |
| 324 { | 346 { |
| 325 // PHY busy | 347 // PHY busy |
| 326 if (m_rxing) | 348 if (m_rxing) |
| 327 { | 349 { |
| 328 return true; | 350 return true; |
| 329 } | 351 } |
| 330 Time lastTxEnd = m_lastTxStart + m_lastTxDuration; | 352 Time lastTxEnd = m_lastTxStart + m_lastTxDuration; |
| 331 if (lastTxEnd > Simulator::Now ()) | 353 if (lastTxEnd > Simulator::Now ()) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 } | 469 } |
| 448 else | 470 else |
| 449 { | 471 { |
| 450 rxAccessStart = m_lastRxStart + m_lastRxDuration + m_sifs; | 472 rxAccessStart = m_lastRxStart + m_lastRxDuration + m_sifs; |
| 451 } | 473 } |
| 452 Time busyAccessStart = m_lastBusyStart + m_lastBusyDuration + m_sifs; | 474 Time busyAccessStart = m_lastBusyStart + m_lastBusyDuration + m_sifs; |
| 453 Time txAccessStart = m_lastTxStart + m_lastTxDuration + m_sifs; | 475 Time txAccessStart = m_lastTxStart + m_lastTxDuration + m_sifs; |
| 454 Time navAccessStart = m_lastNavStart + m_lastNavDuration + m_sifs; | 476 Time navAccessStart = m_lastNavStart + m_lastNavDuration + m_sifs; |
| 455 Time ackTimeoutAccessStart = m_lastAckTimeoutEnd + m_sifs; | 477 Time ackTimeoutAccessStart = m_lastAckTimeoutEnd + m_sifs; |
| 456 Time ctsTimeoutAccessStart = m_lastCtsTimeoutEnd + m_sifs; | 478 Time ctsTimeoutAccessStart = m_lastCtsTimeoutEnd + m_sifs; |
| 479 Time switchingAccessStart = m_lastSwitchingStart + m_lastSwitchingDuration + m _sifs; | |
| 457 Time accessGrantedStart = MostRecent (rxAccessStart, | 480 Time accessGrantedStart = MostRecent (rxAccessStart, |
| 458 busyAccessStart, | 481 busyAccessStart, |
| 459 txAccessStart, | 482 txAccessStart, |
| 460 navAccessStart, | 483 navAccessStart, |
| 461 ackTimeoutAccessStart, | 484 ackTimeoutAccessStart, |
| 462 ctsTimeoutAccessStart | 485 ctsTimeoutAccessStart, |
| 486 switchingAccessStart | |
| 463 ); | 487 ); |
| 464 NS_LOG_INFO ("access grant start=" << accessGrantedStart << | 488 NS_LOG_INFO ("access grant start=" << accessGrantedStart << |
| 465 ", rx access start=" << rxAccessStart << | 489 ", rx access start=" << rxAccessStart << |
| 466 ", busy access start=" << busyAccessStart << | 490 ", busy access start=" << busyAccessStart << |
| 467 ", tx access start=" << txAccessStart << | 491 ", tx access start=" << txAccessStart << |
| 468 ", nav access start=" << navAccessStart); | 492 ", nav access start=" << navAccessStart); |
| 469 return accessGrantedStart; | 493 return accessGrantedStart; |
| 470 } | 494 } |
| 471 | 495 |
| 472 Time | 496 Time |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 m_lastTxDuration = duration; | 613 m_lastTxDuration = duration; |
| 590 } | 614 } |
| 591 void | 615 void |
| 592 DcfManager::NotifyMaybeCcaBusyStartNow (Time duration) | 616 DcfManager::NotifyMaybeCcaBusyStartNow (Time duration) |
| 593 { | 617 { |
| 594 MY_DEBUG ("busy start for "<<duration); | 618 MY_DEBUG ("busy start for "<<duration); |
| 595 UpdateBackoff (); | 619 UpdateBackoff (); |
| 596 m_lastBusyStart = Simulator::Now (); | 620 m_lastBusyStart = Simulator::Now (); |
| 597 m_lastBusyDuration = duration; | 621 m_lastBusyDuration = duration; |
| 598 } | 622 } |
| 623 | |
| 624 | |
| 625 void | |
| 626 DcfManager::NotifySwitchingStartNow (Time duration) | |
|
Mathieu Lacage
2009/08/19 08:19:12
I would like to see an associated test in dcf-mana
Ramon Bauza
2009/09/08 11:36:08
On 2009/08/19 08:19:12, Mathieu Lacage wrote:
> I
| |
| 627 { | |
| 628 Time now = Simulator::Now (); | |
| 629 NS_ASSERT (m_lastTxStart + m_lastTxDuration < now); | |
| 630 NS_ASSERT (m_lastSwitchingStart + m_lastSwitchingDuration < now); | |
| 631 | |
| 632 if (m_rxing) | |
| 633 { | |
|
Mathieu Lacage
2009/08/19 08:19:12
indent
Ramon Bauza
2009/09/08 11:36:08
On 2009/08/19 08:19:12, Mathieu Lacage wrote:
> in
| |
| 634 // channel switching during packet reception | |
| 635 m_lastRxEnd = Simulator::Now (); | |
| 636 m_lastRxDuration = m_lastRxEnd - m_lastRxStart; | |
| 637 m_lastRxReceivedOk = true; | |
| 638 m_rxing = false; | |
| 639 } | |
| 640 if (m_lastNavStart + m_lastNavDuration > now) | |
| 641 { | |
| 642 m_lastNavDuration = now - m_lastNavStart; | |
| 643 } | |
| 644 if (m_lastBusyStart + m_lastBusyDuration > now) | |
| 645 { | |
| 646 m_lastBusyDuration = now - m_lastBusyStart; | |
| 647 } | |
| 648 if (m_lastAckTimeoutEnd > now) | |
| 649 { | |
| 650 m_lastAckTimeoutEnd = now; | |
| 651 } | |
| 652 if (m_lastCtsTimeoutEnd > now) | |
| 653 { | |
| 654 m_lastCtsTimeoutEnd = now; | |
| 655 } | |
| 656 | |
| 657 // Cancel timeout | |
| 658 if (m_accessTimeout.IsRunning ()) | |
| 659 { | |
| 660 m_accessTimeout.Cancel (); | |
| 661 } | |
| 662 | |
| 663 // Reset backoffs | |
| 664 for (States::iterator i = m_states.begin (); i != m_states.end (); i++) | |
| 665 { | |
| 666 DcfState *state = *i; | |
| 667 Time backoffEnd = GetBackoffEndFor (state); | |
| 668 if (backoffEnd >= now) | |
| 669 { | |
| 670 uint32_t remainingSlots = state->GetBackoffSlots (); | |
| 671 state->UpdateBackoffSlotsNow (remainingSlots, now); | |
| 672 NS_ASSERT(state->GetBackoffSlots()==0); | |
| 673 } | |
| 674 state->ResetCw(); | |
| 675 state->m_accessRequested = false; | |
| 676 state->NotifyChannelSwitching(); | |
| 677 } | |
| 678 | |
| 679 MY_DEBUG ("switching start for "<<duration); | |
| 680 m_lastSwitchingStart = Simulator::Now (); | |
| 681 m_lastSwitchingDuration = duration; | |
| 682 | |
| 683 } | |
| 684 | |
| 599 void | 685 void |
| 600 DcfManager::NotifyNavResetNow (Time duration) | 686 DcfManager::NotifyNavResetNow (Time duration) |
| 601 { | 687 { |
| 602 MY_DEBUG ("nav reset for="<<duration); | 688 MY_DEBUG ("nav reset for="<<duration); |
| 603 UpdateBackoff (); | 689 UpdateBackoff (); |
| 604 m_lastNavStart = Simulator::Now (); | 690 m_lastNavStart = Simulator::Now (); |
| 605 m_lastNavDuration = duration; | 691 m_lastNavDuration = duration; |
| 606 UpdateBackoff (); | 692 UpdateBackoff (); |
| 607 /** | 693 /** |
| 608 * If the nav reset indicates an end-of-nav which is earlier | 694 * If the nav reset indicates an end-of-nav which is earlier |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 { | 729 { |
| 644 m_lastCtsTimeoutEnd = Simulator::Now () + duration; | 730 m_lastCtsTimeoutEnd = Simulator::Now () + duration; |
| 645 } | 731 } |
| 646 void | 732 void |
| 647 DcfManager::NotifyCtsTimeoutResetNow () | 733 DcfManager::NotifyCtsTimeoutResetNow () |
| 648 { | 734 { |
| 649 m_lastCtsTimeoutEnd = Simulator::Now (); | 735 m_lastCtsTimeoutEnd = Simulator::Now (); |
| 650 DoRestartAccessTimeoutIfNeeded (); | 736 DoRestartAccessTimeoutIfNeeded (); |
| 651 } | 737 } |
| 652 } // namespace ns3 | 738 } // namespace ns3 |
| OLD | NEW |