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

(-)./src/devices/wifi/dcf-manager.cc (-10 / +59 lines)
 Lines 160-175    Link Here 
160
 *         Listener for Nav events. Forwards to DcfManager
160
 *         Listener for Nav events. Forwards to DcfManager
161
 ***************************************************************/
161
 ***************************************************************/
162
162
163
class LowNavListener : public ns3::MacLowNavListener {
163
class LowDcfListener : public ns3::MacLowDcfListener {
164
public:
164
public:
165
  LowNavListener (ns3::DcfManager *dcf)
165
  LowDcfListener (ns3::DcfManager *dcf)
166
    : m_dcf (dcf) {}
166
    : m_dcf (dcf) {}
167
  virtual ~LowNavListener () {}
167
  virtual ~LowDcfListener () {}
168
  virtual void NavStart (Time duration) {
168
  virtual void NavStart (Time duration) {
169
    m_dcf->NotifyNavStartNow (duration);
169
    m_dcf->NotifyNavStartNow (duration);
170
  }
170
  }
171
  virtual void NavReset (Time duration) {
171
  virtual void NavReset (Time duration) {
172
    m_dcf->NotifyNavResetNow (duration);
172
    m_dcf->NotifyNavResetNow (duration);
173
  }
174
  virtual void AckTimeoutStart (Time duration) {
175
    m_dcf->NotifyAckTimeoutStartNow (duration);
176
  }
177
  virtual void AckTimeoutReset () {
178
    m_dcf->NotifyAckTimeoutResetNow ();
179
  }
180
  virtual void CtsTimeoutStart (Time duration) {
181
    m_dcf->NotifyCtsTimeoutStartNow (duration);
182
  }
183
  virtual void CtsTimeoutReset () {
184
    m_dcf->NotifyCtsTimeoutResetNow ();
173
  }
185
  }
174
private:
186
private:
175
  ns3::DcfManager *m_dcf;
187
  ns3::DcfManager *m_dcf;
 Lines 208-214    Link Here 
208
 ****************************************************************/
220
 ****************************************************************/
209
221
210
DcfManager::DcfManager ()
222
DcfManager::DcfManager ()
211
  : m_lastNavStart (MicroSeconds (0)),
223
  : m_lastAckTimeoutEnd (MicroSeconds (0)),
224
    m_lastCtsTimeoutEnd (MicroSeconds (0)),
225
    m_lastNavStart (MicroSeconds (0)),
212
    m_lastNavDuration (MicroSeconds (0)),
226
    m_lastNavDuration (MicroSeconds (0)),
213
    m_lastRxStart (MicroSeconds (0)),
227
    m_lastRxStart (MicroSeconds (0)),
214
    m_lastRxDuration (MicroSeconds (0)),
228
    m_lastRxDuration (MicroSeconds (0)),
 Lines 242-249    Link Here 
242
void 
256
void 
243
DcfManager::SetupLowListener (Ptr<MacLow> low)
257
DcfManager::SetupLowListener (Ptr<MacLow> low)
244
{
258
{
245
  m_lowListener = new LowNavListener (this);
259
  m_lowListener = new LowDcfListener (this);
246
  low->RegisterNavListener (m_lowListener);
260
  low->RegisterDcfListener (m_lowListener);
247
}
261
}
248
262
249
void 
263
void 
 Lines 289-294    Link Here 
289
  Time retval = Max (e, f);
303
  Time retval = Max (e, f);
290
  return retval;
304
  return retval;
291
}
305
}
306
Time
307
DcfManager::MostRecent (Time a, Time b, Time c, Time d, Time e, Time f) const
308
{
309
  Time g = Max (a, b);
310
  Time h = Max (c, d);
311
  Time i = Max (e, f);
312
  Time k = Max (g, h);
313
  Time retval = Max (k, i);
314
  return retval;
315
}
292
316
293
bool 
317
bool 
294
DcfManager::IsBusy (void) const
318
DcfManager::IsBusy (void) const
 Lines 346-352    Link Here 
346
    {
370
    {
347
      DcfState *state = *i;
371
      DcfState *state = *i;
348
      if (state->IsAccessRequested () && 
372
      if (state->IsAccessRequested () && 
349
          GetBackoffEndFor (state) <= Simulator::Now ())
373
          GetBackoffEndFor (state).GetTimeStep() <= Simulator::Now ().GetTimeStep ())
350
        {
374
        {
351
          /**
375
          /**
352
           * This is the first dcf we find with an expired backoff and which
376
           * This is the first dcf we find with an expired backoff and which
 Lines 426-432    Link Here 
426
  Time accessGrantedStart = MostRecent (rxAccessStart, 
450
  Time accessGrantedStart = MostRecent (rxAccessStart, 
427
                                        busyAccessStart,
451
                                        busyAccessStart,
428
                                        txAccessStart, 
452
                                        txAccessStart, 
429
                                        navAccessStart);
453
                                        navAccessStart,
454
                                        m_lastAckTimeoutEnd,
455
                                        m_lastCtsTimeoutEnd
456
                                        );
430
  NS_LOG_INFO ("access grant start=" << accessGrantedStart <<
457
  NS_LOG_INFO ("access grant start=" << accessGrantedStart <<
431
               ", rx access start=" << rxAccessStart <<
458
               ", rx access start=" << rxAccessStart <<
432
               ", busy access start=" << busyAccessStart <<
459
               ", busy access start=" << busyAccessStart <<
 Lines 486-493    Link Here 
486
      if (state->IsAccessRequested ())
513
      if (state->IsAccessRequested ())
487
        {
514
        {
488
          Time tmp = GetBackoffEndFor (state);
515
          Time tmp = GetBackoffEndFor (state);
489
          if (tmp > Simulator::Now ())
516
          if (tmp.GetTimeStep () > Simulator::Now ().GetTimeStep ())
490
            {
517
            {
518
              //NS_LOG_UNCOND("Now:"<<Simulator::Now ().GetTimeStep ());
491
              accessTimeoutNeeded = true;
519
              accessTimeoutNeeded = true;
492
              expectedBackoffEnd = std::min (expectedBackoffEnd, tmp);
520
              expectedBackoffEnd = std::min (expectedBackoffEnd, tmp);
493
            }
521
            }
 Lines 581-585    Link Here 
581
      m_lastNavDuration = duration;
609
      m_lastNavDuration = duration;
582
    }
610
    }
583
}
611
}
584
612
void
613
DcfManager::NotifyAckTimeoutStartNow (Time duration)
614
{
615
  m_lastAckTimeoutEnd = Simulator::Now () + duration;
616
}
617
void
618
DcfManager::NotifyAckTimeoutResetNow ()
619
{
620
  m_lastAckTimeoutEnd = Simulator::Now ();
621
  DoRestartAccessTimeoutIfNeeded ();
622
}
623
void
624
DcfManager::NotifyCtsTimeoutStartNow (Time duration)
625
{
626
  m_lastCtsTimeoutEnd = Simulator::Now () + duration;
627
}
628
void
629
DcfManager::NotifyCtsTimeoutResetNow ()
630
{
631
  m_lastCtsTimeoutEnd = Simulator::Now ();
632
  DoRestartAccessTimeoutIfNeeded ();
633
}
585
} // namespace ns3
634
} // namespace ns3
(-)./src/devices/wifi/dcf-manager.h (-2 / +9 lines)
 Lines 233-244    Link Here 
233
   * Called at end of rx
233
   * Called at end of rx
234
   */
234
   */
235
  void NotifyNavStartNow (Time duration);
235
  void NotifyNavStartNow (Time duration);
236
236
  void NotifyAckTimeoutStartNow (Time duration);
237
  void NotifyAckTimeoutResetNow ();
238
  void NotifyCtsTimeoutStartNow (Time duration);
239
  void NotifyCtsTimeoutResetNow ();
240
  void NotifyAckTimeoutEnd (Time duration);
237
private:
241
private:
238
  void UpdateBackoff (void);
242
  void UpdateBackoff (void);
239
  Time MostRecent (Time a, Time b) const;
243
  Time MostRecent (Time a, Time b) const;
240
  Time MostRecent (Time a, Time b, Time c) const;
244
  Time MostRecent (Time a, Time b, Time c) const;
241
  Time MostRecent (Time a, Time b, Time c, Time d) const;
245
  Time MostRecent (Time a, Time b, Time c, Time d) const;
246
  Time MostRecent (Time a, Time b, Time c, Time d, Time e, Time f) const;
242
  /**
247
  /**
243
   * Access will never be granted to the medium _before_
248
   * Access will never be granted to the medium _before_
244
   * the time returned by this method.
249
   * the time returned by this method.
 Lines 257-262    Link Here 
257
  typedef std::vector<DcfState *> States;
262
  typedef std::vector<DcfState *> States;
258
263
259
  States m_states;
264
  States m_states;
265
  Time m_lastAckTimeoutEnd;
266
  Time m_lastCtsTimeoutEnd;
260
  Time m_lastNavStart;
267
  Time m_lastNavStart;
261
  Time m_lastNavDuration;
268
  Time m_lastNavDuration;
262
  Time m_lastRxStart;
269
  Time m_lastRxStart;
 Lines 274-280    Link Here 
274
  Time m_slotTime;
281
  Time m_slotTime;
275
  Time m_sifs;
282
  Time m_sifs;
276
  class PhyListener *m_phyListener;
283
  class PhyListener *m_phyListener;
277
  class LowNavListener *m_lowListener;
284
  class LowDcfListener *m_lowListener;
278
};
285
};
279
286
280
} // namespace ns3
287
} // namespace ns3
(-)./src/devices/wifi/mac-low.cc (-6 / +45 lines)
 Lines 110-118    Link Here 
110
{}
110
{}
111
MacLowTransmissionListener::~MacLowTransmissionListener ()
111
MacLowTransmissionListener::~MacLowTransmissionListener ()
112
{}
112
{}
113
MacLowNavListener::MacLowNavListener ()
113
MacLowDcfListener::MacLowDcfListener ()
114
{}
114
{}
115
MacLowNavListener::~MacLowNavListener ()
115
MacLowDcfListener::~MacLowDcfListener ()
116
{}
116
{}
117
117
118
MacLowTransmissionParameters::MacLowTransmissionParameters ()
118
MacLowTransmissionParameters::MacLowTransmissionParameters ()
 Lines 424-432    Link Here 
424
  m_rxCallback = callback;
423
  m_rxCallback = callback;
425
}
424
}
426
void 
425
void 
427
MacLow::RegisterNavListener (MacLowNavListener *listener)
426
MacLow::RegisterDcfListener (MacLowDcfListener *listener)
428
{
427
{
429
  m_navListeners.push_back (listener);
428
  m_dcfListeners.push_back (listener);
430
}
429
}
431
430
432
431
 Lines 544-549    Link Here 
544
      station->ReportRtsOk (rxSnr, txMode, tag.Get ());
543
      station->ReportRtsOk (rxSnr, txMode, tag.Get ());
545
      
544
      
546
      m_ctsTimeoutEvent.Cancel ();
545
      m_ctsTimeoutEvent.Cancel ();
546
      NotifyCtsTimeoutResetNow ();
547
      m_listener->GotCts (rxSnr, txMode);
547
      m_listener->GotCts (rxSnr, txMode);
548
      NS_ASSERT (m_sendDataEvent.IsExpired ());
548
      NS_ASSERT (m_sendDataEvent.IsExpired ());
549
      m_sendDataEvent = Simulator::Schedule (GetSifs (), 
549
      m_sendDataEvent = Simulator::Schedule (GetSifs (), 
 Lines 570-581    Link Here 
570
          m_normalAckTimeoutEvent.IsRunning ()) 
570
          m_normalAckTimeoutEvent.IsRunning ()) 
571
        {
571
        {
572
          m_normalAckTimeoutEvent.Cancel ();
572
          m_normalAckTimeoutEvent.Cancel ();
573
          NotifyAckTimeoutResetNow ();
573
          gotAck = true;
574
          gotAck = true;
574
        }
575
        }
575
      if (m_txParams.MustWaitFastAck () &&
576
      if (m_txParams.MustWaitFastAck () &&
576
          m_fastAckTimeoutEvent.IsRunning ()) 
577
          m_fastAckTimeoutEvent.IsRunning ()) 
577
        {
578
        {
578
          m_fastAckTimeoutEvent.Cancel ();
579
          m_fastAckTimeoutEvent.Cancel ();
580
          NotifyAckTimeoutResetNow ();
579
          gotAck = true;
581
          gotAck = true;
580
        }
582
        }
581
      if (gotAck) 
583
      if (gotAck) 
 Lines 797-803    Link Here 
797
void
799
void
798
MacLow::DoNavResetNow (Time duration)
800
MacLow::DoNavResetNow (Time duration)
799
{
801
{
800
  for (NavListenersCI i = m_navListeners.begin (); i != m_navListeners.end (); i++) 
802
  for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) 
801
    {
803
    {
802
      (*i)->NavReset (duration);
804
      (*i)->NavReset (duration);
803
    }
805
    }
 Lines 807-813    Link Here 
807
bool
809
bool
808
MacLow::DoNavStartNow (Time duration)
810
MacLow::DoNavStartNow (Time duration)
809
{
811
{
810
  for (NavListenersCI i = m_navListeners.begin (); i != m_navListeners.end (); i++) 
812
  for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) 
811
    {
813
    {
812
      (*i)->NavStart (duration);
814
      (*i)->NavStart (duration);
813
    }
815
    }
 Lines 820-825    Link Here 
820
      return true;
822
      return true;
821
    }
823
    }
822
  return false;
824
  return false;
825
}
826
void
827
MacLow::NotifyAckTimeoutStartNow (Time duration)
828
{
829
  for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) 
830
    {
831
      (*i)->AckTimeoutStart (duration);
832
    }
833
}
834
void
835
MacLow::NotifyAckTimeoutResetNow ()
836
{
837
  for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) 
838
    {
839
      (*i)->AckTimeoutReset ();
840
    }
841
}
842
void
843
MacLow::NotifyCtsTimeoutStartNow (Time duration)
844
{
845
  for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) 
846
    {
847
      (*i)->CtsTimeoutStart (duration);
848
    }
849
}
850
void
851
MacLow::NotifyCtsTimeoutResetNow ()
852
{
853
  for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) 
854
    {
855
      (*i)->CtsTimeoutReset ();
856
    }
823
}
857
}
824
858
825
void
859
void
 Lines 946-951    Link Here 
946
  Time timerDelay = txDuration + GetCtsTimeout ();
980
  Time timerDelay = txDuration + GetCtsTimeout ();
947
981
948
  NS_ASSERT (m_ctsTimeoutEvent.IsExpired ());
982
  NS_ASSERT (m_ctsTimeoutEvent.IsExpired ());
983
  NotifyCtsTimeoutStartNow (timerDelay);
949
  m_ctsTimeoutEvent = Simulator::Schedule (timerDelay, &MacLow::CtsTimeout, this);
984
  m_ctsTimeoutEvent = Simulator::Schedule (timerDelay, &MacLow::CtsTimeout, this);
950
985
951
  Ptr<Packet> packet = Create<Packet> ();
986
  Ptr<Packet> packet = Create<Packet> ();
 Lines 965-982    Link Here 
965
    {
1000
    {
966
      Time timerDelay = txDuration + GetAckTimeout ();
1001
      Time timerDelay = txDuration + GetAckTimeout ();
967
      NS_ASSERT (m_normalAckTimeoutEvent.IsExpired ());
1002
      NS_ASSERT (m_normalAckTimeoutEvent.IsExpired ());
1003
      NotifyAckTimeoutStartNow (timerDelay);
968
      m_normalAckTimeoutEvent = Simulator::Schedule (timerDelay, &MacLow::NormalAckTimeout, this);
1004
      m_normalAckTimeoutEvent = Simulator::Schedule (timerDelay, &MacLow::NormalAckTimeout, this);
969
    } 
1005
    } 
970
  else if (m_txParams.MustWaitFastAck ()) 
1006
  else if (m_txParams.MustWaitFastAck ()) 
971
    {
1007
    {
972
      Time timerDelay = txDuration + GetPifs ();
1008
      Time timerDelay = txDuration + GetPifs ();
973
      NS_ASSERT (m_fastAckTimeoutEvent.IsExpired ());
1009
      NS_ASSERT (m_fastAckTimeoutEvent.IsExpired ());
1010
      NotifyAckTimeoutStartNow (timerDelay);
974
      m_fastAckTimeoutEvent = Simulator::Schedule (timerDelay, &MacLow::FastAckTimeout, this);
1011
      m_fastAckTimeoutEvent = Simulator::Schedule (timerDelay, &MacLow::FastAckTimeout, this);
975
    } 
1012
    } 
976
  else if (m_txParams.MustWaitSuperFastAck ()) 
1013
  else if (m_txParams.MustWaitSuperFastAck ()) 
977
    {
1014
    {
978
      Time timerDelay = txDuration + GetPifs ();
1015
      Time timerDelay = txDuration + GetPifs ();
979
      NS_ASSERT (m_superFastAckTimeoutEvent.IsExpired ());
1016
      NS_ASSERT (m_superFastAckTimeoutEvent.IsExpired ());
1017
      NotifyAckTimeoutStartNow (timerDelay);
980
      m_superFastAckTimeoutEvent = Simulator::Schedule (timerDelay, 
1018
      m_superFastAckTimeoutEvent = Simulator::Schedule (timerDelay, 
981
                                                        &MacLow::SuperFastAckTimeout, this);
1019
                                                        &MacLow::SuperFastAckTimeout, this);
982
    } 
1020
    } 
(-)./src/devices/wifi/mac-low.h (-7 / +15 lines)
 Lines 100-109    Link Here 
100
 * and calls to its methods are forwards to the corresponding
100
 * and calls to its methods are forwards to the corresponding
101
 * ns3::Dcf methods.
101
 * ns3::Dcf methods.
102
 */
102
 */
103
class MacLowNavListener {
103
class MacLowDcfListener {
104
public:
104
public:
105
  MacLowNavListener ();
105
  MacLowDcfListener ();
106
  virtual ~MacLowNavListener ();
106
  virtual ~MacLowDcfListener ();
107
  /**
107
  /**
108
   * \param duration duration of NAV timer
108
   * \param duration duration of NAV timer
109
   */
109
   */
 Lines 112-117    Link Here 
112
   * \param duration duration of NAV timer
112
   * \param duration duration of NAV timer
113
   */
113
   */
114
  virtual void NavReset (Time duration) = 0;
114
  virtual void NavReset (Time duration) = 0;
115
  virtual void AckTimeoutStart (Time duration) = 0;
116
  virtual void AckTimeoutReset () = 0;
117
  virtual void CtsTimeoutStart (Time duration) = 0;
118
  virtual void CtsTimeoutReset () = 0;
115
};
119
};
116
120
117
/**
121
/**
 Lines 306-312    Link Here 
306
   * \param listener listen to NAV events for every incoming
310
   * \param listener listen to NAV events for every incoming
307
   *        and outgoing packet.
311
   *        and outgoing packet.
308
   */
312
   */
309
  void RegisterNavListener (MacLowNavListener *listener);
313
  void RegisterDcfListener (MacLowDcfListener *listener);
310
314
311
  /**
315
  /**
312
   * \param packet to send (does not include the 802.11 MAC header and checksum)
316
   * \param packet to send (does not include the 802.11 MAC header and checksum)
 Lines 375-380    Link Here 
375
  void DoNavResetNow (Time duration);
379
  void DoNavResetNow (Time duration);
376
  bool DoNavStartNow (Time duration);
380
  bool DoNavStartNow (Time duration);
377
  bool IsNavZero (void) const;
381
  bool IsNavZero (void) const;
382
  void NotifyAckTimeoutStartNow (Time duration);
383
  void NotifyAckTimeoutResetNow ();
384
  void NotifyCtsTimeoutStartNow (Time duration);
385
  void NotifyCtsTimeoutResetNow ();
378
  void MaybeCancelPrevious (void);
386
  void MaybeCancelPrevious (void);
379
  
387
  
380
  void NavCounterResetCtsMissed (Time rtsEndRxTime);
388
  void NavCounterResetCtsMissed (Time rtsEndRxTime);
 Lines 397-405    Link Here 
397
  Ptr<WifiPhy> m_phy;
405
  Ptr<WifiPhy> m_phy;
398
  Ptr<WifiRemoteStationManager> m_stationManager;
406
  Ptr<WifiRemoteStationManager> m_stationManager;
399
  MacLowRxCallback m_rxCallback;
407
  MacLowRxCallback m_rxCallback;
400
  typedef std::vector<MacLowNavListener *>::const_iterator NavListenersCI;
408
  typedef std::vector<MacLowDcfListener *>::const_iterator DcfListenersCI;
401
  typedef std::vector<MacLowNavListener *> NavListeners;
409
  typedef std::vector<MacLowDcfListener *> DcfListeners;
402
  NavListeners m_navListeners;
410
  DcfListeners m_dcfListeners;
403
411
404
  EventId m_normalAckTimeoutEvent;
412
  EventId m_normalAckTimeoutEvent;
405
  EventId m_fastAckTimeoutEvent;
413
  EventId m_fastAckTimeoutEvent;

Return to bug 556