View | Details | Raw Unified | Return to bug 826
Collapse All | Expand All

(-)a/src/devices/wifi/dcf-manager.cc (-63 / +75 lines)
 Lines 228-247    Link Here 
228
 ****************************************************************/
228
 ****************************************************************/
229
229
230
DcfManager::DcfManager ()
230
DcfManager::DcfManager ()
231
  : m_lastAckTimeoutEnd (MicroSeconds (0)),
231
  : m_lastAckTimeoutEnd (0),
232
    m_lastCtsTimeoutEnd (MicroSeconds (0)),
232
    m_lastCtsTimeoutEnd (0),
233
    m_lastNavStart (MicroSeconds (0)),
233
    m_lastNavStart (0),
234
    m_lastNavDuration (MicroSeconds (0)),
234
    m_lastNavDuration (0),
235
    m_lastRxStart (MicroSeconds (0)),
235
    m_lastRxStart (0),
236
    m_lastRxDuration (MicroSeconds (0)),
236
    m_lastRxDuration (0),
237
    m_lastRxReceivedOk (true),
237
    m_lastRxReceivedOk (true),
238
    m_lastRxEnd (MicroSeconds (0)),
238
    m_lastRxEnd (0),
239
    m_lastTxStart (MicroSeconds (0)),
239
    m_lastTxStart (0),
240
    m_lastTxDuration (MicroSeconds (0)),
240
    m_lastTxDuration (0),
241
    m_lastBusyStart (MicroSeconds (0)),
241
    m_lastBusyStart (0),
242
    m_lastBusyDuration (MicroSeconds (0)),
242
    m_lastBusyDuration (0),
243
    m_lastSwitchingStart (MicroSeconds (0)), 
243
    m_lastSwitchingStart (0), 
244
    m_lastSwitchingDuration (MicroSeconds (0)), 
244
    m_lastSwitchingDuration (0), 
245
    m_rxing (false),
245
    m_rxing (false),
246
    m_slotTimeUs (0),
246
    m_slotTimeUs (0),
247
    m_sifs (Seconds (0.0)),
247
    m_sifs (Seconds (0.0)),
 Lines 340-362    Link Here 
340
  Time retval = Max (k, l);
340
  Time retval = Max (k, l);
341
  return retval;
341
  return retval;
342
}
342
}
343
uint64_t
344
DcfManager::Maximum (uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e, uint64_t f, uint64_t g) const
345
{
346
  uint64_t h = a > b ? a : b;
347
  uint64_t i = c > d ? c: d;
348
  uint64_t j = e > f ? e : f;
349
  uint64_t k = h > i ? h : i;
350
  uint64_t l = j > g ? j : g;
351
  return (k > l ? k : l);
352
}
343
353
344
bool 
354
bool 
345
DcfManager::IsBusy (void) const
355
DcfManager::IsBusy (void) const
346
{
356
{
347
  // PHY busy
357
  // PHY busy
358
  uint64_t now = Simulator::Now ().GetNanoSeconds ();
348
  if (m_rxing) 
359
  if (m_rxing) 
349
    {
360
    {
350
      return true;
361
      return true;
351
    }
362
    }
352
  Time lastTxEnd = m_lastTxStart + m_lastTxDuration;
363
  uint64_t lastTxEnd = m_lastTxStart + m_lastTxDuration;
353
  if (lastTxEnd > Simulator::Now ()) 
364
  if (lastTxEnd > now) 
354
    {
365
    {
355
      return true;
366
      return true;
356
    }
367
    }
357
  // NAV busy
368
  // NAV busy
358
  Time lastNavEnd = m_lastNavStart + m_lastNavDuration;
369
  uint64_t lastNavEnd = m_lastNavStart + m_lastNavDuration;
359
  if (lastNavEnd > Simulator::Now ())
370
  if (lastNavEnd > now)
360
    {
371
    {
361
      return true;
372
      return true;
362
    }
373
    }
 Lines 454-492    Link Here 
454
Time
465
Time
455
DcfManager::GetAccessGrantStart (void) const
466
DcfManager::GetAccessGrantStart (void) const
456
{
467
{
457
  Time rxAccessStart;
468
  uint64_t rxAccessStart;
469
  uint64_t sifsNanoSeconds = m_sifs.GetNanoSeconds ();
458
  if (!m_rxing) 
470
  if (!m_rxing) 
459
    {
471
    {
460
      rxAccessStart = m_lastRxEnd + m_sifs;
472
      rxAccessStart = m_lastRxEnd + sifsNanoSeconds;
461
      if (!m_lastRxReceivedOk)
473
      if (!m_lastRxReceivedOk)
462
        {
474
        {
463
          rxAccessStart += m_eifsNoDifs;
475
          rxAccessStart += m_eifsNoDifs.GetNanoSeconds ();
464
        }
476
        }
465
    } 
477
    } 
466
  else 
478
  else 
467
    {
479
    {
468
      rxAccessStart = m_lastRxStart + m_lastRxDuration + m_sifs;
480
      rxAccessStart = m_lastRxStart + m_lastRxDuration + m_sifs.GetNanoSeconds ();
469
    }
481
    }
470
  Time busyAccessStart = m_lastBusyStart + m_lastBusyDuration + m_sifs;
482
  uint64_t busyAccessStart = m_lastBusyStart + m_lastBusyDuration + sifsNanoSeconds;
471
  Time txAccessStart = m_lastTxStart + m_lastTxDuration + m_sifs;
483
  uint64_t txAccessStart = m_lastTxStart + m_lastTxDuration + sifsNanoSeconds;
472
  Time navAccessStart = m_lastNavStart + m_lastNavDuration + m_sifs;
484
  uint64_t navAccessStart = m_lastNavStart + m_lastNavDuration + sifsNanoSeconds;
473
  Time ackTimeoutAccessStart = m_lastAckTimeoutEnd + m_sifs;
485
  uint64_t ackTimeoutAccessStart = m_lastAckTimeoutEnd + sifsNanoSeconds;
474
  Time ctsTimeoutAccessStart = m_lastCtsTimeoutEnd + m_sifs;
486
  uint64_t ctsTimeoutAccessStart = m_lastCtsTimeoutEnd + sifsNanoSeconds;
475
  Time switchingAccessStart = m_lastSwitchingStart + m_lastSwitchingDuration + m_sifs; 
487
  uint64_t switchingAccessStart = m_lastSwitchingStart + m_lastSwitchingDuration + sifsNanoSeconds; 
476
  Time accessGrantedStart = MostRecent (rxAccessStart, 
488
  uint64_t accessGrantedStart = Maximum (rxAccessStart, 
477
                                        busyAccessStart,
489
                                          busyAccessStart,
478
                                        txAccessStart, 
490
                                          txAccessStart, 
479
                                        navAccessStart,
491
                                          navAccessStart,
480
                                        ackTimeoutAccessStart,
492
                                          ackTimeoutAccessStart,
481
                                        ctsTimeoutAccessStart,
493
                                          ctsTimeoutAccessStart,
482
                                        switchingAccessStart 
494
                                          switchingAccessStart 
483
                                        );
495
                                          );
484
  NS_LOG_INFO ("access grant start=" << accessGrantedStart <<
496
  NS_LOG_INFO ("access grant start=" << accessGrantedStart <<
485
               ", rx access start=" << rxAccessStart <<
497
               ", rx access start=" << rxAccessStart <<
486
               ", busy access start=" << busyAccessStart <<
498
               ", busy access start=" << busyAccessStart <<
487
               ", tx access start=" << txAccessStart <<
499
               ", tx access start=" << txAccessStart <<
488
               ", nav access start=" << navAccessStart);
500
               ", nav access start=" << navAccessStart);
489
  return accessGrantedStart;
501
  return NanoSeconds (accessGrantedStart);
490
}
502
}
491
503
492
Time
504
Time
 Lines 569-583    Link Here 
569
{
581
{
570
  MY_DEBUG ("rx start for="<<duration);
582
  MY_DEBUG ("rx start for="<<duration);
571
  UpdateBackoff ();
583
  UpdateBackoff ();
572
  m_lastRxStart = Simulator::Now ();
584
  m_lastRxStart = Simulator::Now ().GetNanoSeconds ();
573
  m_lastRxDuration = duration;
585
  m_lastRxDuration = duration.GetNanoSeconds ();
574
  m_rxing = true;
586
  m_rxing = true;
575
}
587
}
576
void 
588
void 
577
DcfManager::NotifyRxEndOkNow (void)
589
DcfManager::NotifyRxEndOkNow (void)
578
{
590
{
579
  MY_DEBUG ("rx end ok");
591
  MY_DEBUG ("rx end ok");
580
  m_lastRxEnd = Simulator::Now ();
592
  m_lastRxEnd = Simulator::Now ().GetNanoSeconds ();
581
  m_lastRxReceivedOk = true;
593
  m_lastRxReceivedOk = true;
582
  m_rxing = false;
594
  m_rxing = false;
583
}
595
}
 Lines 585-591    Link Here 
585
DcfManager::NotifyRxEndErrorNow (void)
597
DcfManager::NotifyRxEndErrorNow (void)
586
{
598
{
587
  MY_DEBUG ("rx end error");
599
  MY_DEBUG ("rx end error");
588
  m_lastRxEnd = Simulator::Now ();
600
  m_lastRxEnd = Simulator::Now ().GetNanoSeconds ();
589
  m_lastRxReceivedOk = false;
601
  m_lastRxReceivedOk = false;
590
  m_rxing = false;
602
  m_rxing = false;
591
}
603
}
 Lines 597-634    Link Here 
597
      //this may be caused only if PHY has started to receive a packet
609
      //this may be caused only if PHY has started to receive a packet
598
      //inside SIFS, so, we check that lastRxStart was maximum a SIFS
610
      //inside SIFS, so, we check that lastRxStart was maximum a SIFS
599
      //ago
611
      //ago
600
      NS_ASSERT (Simulator::Now () - m_lastRxStart <= m_sifs);
612
      NS_ASSERT (Simulator::Now () - NanoSeconds (m_lastRxStart) <= m_sifs);
601
      m_lastRxEnd = Simulator::Now ();
613
      m_lastRxEnd = Simulator::Now ().GetNanoSeconds ();
602
      m_lastRxDuration = m_lastRxEnd - m_lastRxStart;
614
      m_lastRxDuration = m_lastRxEnd - m_lastRxStart;
603
      m_lastRxReceivedOk = true;
615
      m_lastRxReceivedOk = true;
604
      m_rxing = false;
616
      m_rxing = false;
605
    }
617
    }
606
  MY_DEBUG ("tx start for "<<duration);
618
  MY_DEBUG ("tx start for "<<duration);
607
  UpdateBackoff ();
619
  UpdateBackoff ();
608
  m_lastTxStart = Simulator::Now ();
620
  m_lastTxStart = Simulator::Now ().GetNanoSeconds ();
609
  m_lastTxDuration = duration;
621
  m_lastTxDuration = duration.GetNanoSeconds ();
610
}
622
}
611
void 
623
void 
612
DcfManager::NotifyMaybeCcaBusyStartNow (Time duration)
624
DcfManager::NotifyMaybeCcaBusyStartNow (Time duration)
613
{
625
{
614
  MY_DEBUG ("busy start for "<<duration);
626
  MY_DEBUG ("busy start for "<<duration);
615
  UpdateBackoff ();
627
  UpdateBackoff ();
616
  m_lastBusyStart = Simulator::Now ();
628
  m_lastBusyStart = Simulator::Now ().GetNanoSeconds ();
617
  m_lastBusyDuration = duration;
629
  m_lastBusyDuration = duration.GetNanoSeconds ();
618
}
630
}
619
631
620
632
621
void 
633
void 
622
DcfManager::NotifySwitchingStartNow (Time duration)
634
DcfManager::NotifySwitchingStartNow (Time duration)
623
{
635
{
624
  Time now = Simulator::Now ();
636
  uint64_t now = Simulator::Now ().GetNanoSeconds ();
625
  NS_ASSERT (m_lastTxStart + m_lastTxDuration <= now);
637
  NS_ASSERT (m_lastTxStart + m_lastTxDuration <= now);
626
  NS_ASSERT (m_lastSwitchingStart + m_lastSwitchingDuration <= now);
638
  NS_ASSERT (m_lastSwitchingStart + m_lastSwitchingDuration <= now);
627
639
628
  if (m_rxing)
640
  if (m_rxing)
629
    {
641
    {
630
      // channel switching during packet reception
642
      // channel switching during packet reception
631
      m_lastRxEnd = Simulator::Now ();
643
      m_lastRxEnd = Simulator::Now ().GetNanoSeconds ();
632
      m_lastRxDuration = m_lastRxEnd - m_lastRxStart;
644
      m_lastRxDuration = m_lastRxEnd - m_lastRxStart;
633
      m_lastRxReceivedOk = true;
645
      m_lastRxReceivedOk = true;
634
      m_rxing = false;
646
      m_rxing = false;
 Lines 663-669    Link Here 
663
      uint32_t remainingSlots = state->GetBackoffSlots ();
675
      uint32_t remainingSlots = state->GetBackoffSlots ();
664
      if (remainingSlots > 0) 
676
      if (remainingSlots > 0) 
665
        {
677
        {
666
          state->UpdateBackoffSlotsNow (remainingSlots, now);
678
          state->UpdateBackoffSlotsNow (remainingSlots, NanoSeconds(now));
667
          NS_ASSERT(state->GetBackoffSlots()==0);
679
          NS_ASSERT(state->GetBackoffSlots()==0);
668
        }
680
        }
669
      state->ResetCw();
681
      state->ResetCw();
 Lines 672-679    Link Here 
672
    } 
684
    } 
673
 
685
 
674
  MY_DEBUG ("switching start for "<<duration);
686
  MY_DEBUG ("switching start for "<<duration);
675
  m_lastSwitchingStart = Simulator::Now ();
687
  m_lastSwitchingStart = Simulator::Now ().GetNanoSeconds ();
676
  m_lastSwitchingDuration = duration;
688
  m_lastSwitchingDuration = duration.GetNanoSeconds ();
677
689
678
}
690
}
679
691
 Lines 682-689    Link Here 
682
{
694
{
683
  MY_DEBUG ("nav reset for="<<duration);
695
  MY_DEBUG ("nav reset for="<<duration);
684
  UpdateBackoff ();
696
  UpdateBackoff ();
685
  m_lastNavStart = Simulator::Now ();
697
  m_lastNavStart = Simulator::Now ().GetNanoSeconds ();
686
  m_lastNavDuration = duration;
698
  m_lastNavDuration = duration.GetNanoSeconds ();
687
  UpdateBackoff ();
699
  UpdateBackoff ();
688
  /**
700
  /**
689
   * If the nav reset indicates an end-of-nav which is earlier
701
   * If the nav reset indicates an end-of-nav which is earlier
 Lines 696-733    Link Here 
696
void 
708
void 
697
DcfManager::NotifyNavStartNow (Time duration)
709
DcfManager::NotifyNavStartNow (Time duration)
698
{
710
{
699
  NS_ASSERT (m_lastNavStart < Simulator::Now ());
711
  NS_ASSERT (NanoSeconds (m_lastNavStart) < Simulator::Now ());
700
  MY_DEBUG ("nav start for="<<duration);
712
  MY_DEBUG ("nav start for="<<duration);
701
  UpdateBackoff ();
713
  UpdateBackoff ();
702
  Time newNavEnd = Simulator::Now () + duration;
714
  uint64_t newNavEnd = (Simulator::Now () + duration).GetNanoSeconds ();
703
  Time lastNavEnd = m_lastNavStart + m_lastNavDuration;
715
  uint64_t lastNavEnd = m_lastNavStart + m_lastNavDuration;
704
  if (newNavEnd > lastNavEnd)
716
  if (newNavEnd > lastNavEnd)
705
    {
717
    {
706
      m_lastNavStart = Simulator::Now ();
718
      m_lastNavStart = Simulator::Now ().GetNanoSeconds ();
707
      m_lastNavDuration = duration;
719
      m_lastNavDuration = duration.GetNanoSeconds ();
708
    }
720
    }
709
}
721
}
710
void
722
void
711
DcfManager::NotifyAckTimeoutStartNow (Time duration)
723
DcfManager::NotifyAckTimeoutStartNow (Time duration)
712
{
724
{
713
  NS_ASSERT(m_lastAckTimeoutEnd < Simulator::Now ());
725
  NS_ASSERT(NanoSeconds(m_lastAckTimeoutEnd) < Simulator::Now ());
714
  m_lastAckTimeoutEnd = Simulator::Now () + duration;
726
  m_lastAckTimeoutEnd = (Simulator::Now () + duration).GetNanoSeconds ();
715
}
727
}
716
void
728
void
717
DcfManager::NotifyAckTimeoutResetNow ()
729
DcfManager::NotifyAckTimeoutResetNow ()
718
{
730
{
719
  m_lastAckTimeoutEnd = Simulator::Now ();
731
  m_lastAckTimeoutEnd = Simulator::Now ().GetNanoSeconds ();
720
  DoRestartAccessTimeoutIfNeeded ();
732
  DoRestartAccessTimeoutIfNeeded ();
721
}
733
}
722
void
734
void
723
DcfManager::NotifyCtsTimeoutStartNow (Time duration)
735
DcfManager::NotifyCtsTimeoutStartNow (Time duration)
724
{
736
{
725
  m_lastCtsTimeoutEnd = Simulator::Now () + duration;
737
  m_lastCtsTimeoutEnd = (Simulator::Now () + duration).GetNanoSeconds ();
726
}
738
}
727
void
739
void
728
DcfManager::NotifyCtsTimeoutResetNow ()
740
DcfManager::NotifyCtsTimeoutResetNow ()
729
{
741
{
730
  m_lastCtsTimeoutEnd = Simulator::Now ();
742
  m_lastCtsTimeoutEnd = Simulator::Now ().GetNanoSeconds ();
731
  DoRestartAccessTimeoutIfNeeded ();
743
  DoRestartAccessTimeoutIfNeeded ();
732
}
744
}
733
} // namespace ns3
745
} // namespace ns3
(-)a/src/devices/wifi/dcf-manager.h (-13 / +14 lines)
 Lines 287-292    Link Here 
287
  Time MostRecent (Time a, Time b, Time c, Time d) const;
287
  Time MostRecent (Time a, Time b, Time c, Time d) const;
288
  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f) const;
288
  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f) const;
289
  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g) const; 
289
  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f, Time g) const; 
290
  uint64_t Maximum (uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e, uint64_t f, uint64_t g) const;
290
  /**
291
  /**
291
   * Access will never be granted to the medium _before_
292
   * Access will never be granted to the medium _before_
292
   * the time returned by this method.
293
   * the time returned by this method.
 Lines 305-324    Link Here 
305
  typedef std::vector<DcfState *> States;
306
  typedef std::vector<DcfState *> States;
306
307
307
  States m_states;
308
  States m_states;
308
  Time m_lastAckTimeoutEnd;
309
  uint64_t m_lastAckTimeoutEnd;
309
  Time m_lastCtsTimeoutEnd;
310
  uint64_t m_lastCtsTimeoutEnd;
310
  Time m_lastNavStart;
311
  uint64_t m_lastNavStart;
311
  Time m_lastNavDuration;
312
  uint64_t m_lastNavDuration;
312
  Time m_lastRxStart;
313
  uint64_t m_lastRxStart;
313
  Time m_lastRxDuration;
314
  uint64_t m_lastRxDuration;
314
  bool m_lastRxReceivedOk;
315
  bool m_lastRxReceivedOk;
315
  Time m_lastRxEnd;
316
  uint64_t m_lastRxEnd;
316
  Time m_lastTxStart;
317
  uint64_t m_lastTxStart;
317
  Time m_lastTxDuration;
318
  uint64_t m_lastTxDuration;
318
  Time m_lastBusyStart;
319
  uint64_t m_lastBusyStart;
319
  Time m_lastBusyDuration;
320
  uint64_t m_lastBusyDuration;
320
  Time m_lastSwitchingStart; 
321
  uint64_t m_lastSwitchingStart; 
321
  Time m_lastSwitchingDuration; 
322
  uint64_t m_lastSwitchingDuration; 
322
  bool m_rxing;
323
  bool m_rxing;
323
  bool m_sleeping;
324
  bool m_sleeping;
324
  Time m_eifsNoDifs;
325
  Time m_eifsNoDifs;

Return to bug 826