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

(-)a/src/devices/wifi/dcf-manager-test.cc (-65 / +105 lines)
 Lines 30-36   class DcfStateTest : public DcfState Link Here 
30
{
30
{
31
public:
31
public:
32
  DcfStateTest (DcfManagerTest *test, uint32_t i);
32
  DcfStateTest (DcfManagerTest *test, uint32_t i);
33
  void QueueTx (uint64_t txTime, uint64_t expectedGrantTime);
33
  void QueueTx (uint64_t txTime, uint64_t expectedGrantTime, uint32_t nBackoffSlots);
34
private:
34
private:
35
  friend class DcfManagerTest;
35
  friend class DcfManagerTest;
36
  virtual void DoNotifyAccessGranted (void);
36
  virtual void DoNotifyAccessGranted (void);
 Lines 38-45   private: Link Here 
38
  virtual void DoNotifyCollision (void);
38
  virtual void DoNotifyCollision (void);
39
  virtual void DoNotifyChannelSwitching (void); 
39
  virtual void DoNotifyChannelSwitching (void); 
40
40
41
  typedef std::pair<uint64_t,uint64_t> ExpectedGrant;
41
  struct ExpectedGrant {
42
  typedef std::list<ExpectedGrant> ExpectedGrants;
42
    uint64_t m_txTime;
43
    uint64_t m_expectedGrantTime;
44
    uint32_t m_nBackoffSlots;
45
  };
46
  typedef std::list<struct ExpectedGrant> ExpectedGrants;
47
43
  struct ExpectedCollision {
48
  struct ExpectedCollision {
44
    uint64_t at;
49
    uint64_t at;
45
    uint32_t nSlots;
50
    uint32_t nSlots;
 Lines 80-93   private: Link Here 
80
  void AddNavReset (uint64_t at, uint64_t duration);
85
  void AddNavReset (uint64_t at, uint64_t duration);
81
  void AddNavStart (uint64_t at, uint64_t duration);
86
  void AddNavStart (uint64_t at, uint64_t duration);
82
  void AddAckTimeoutReset (uint64_t at);
87
  void AddAckTimeoutReset (uint64_t at);
83
  void AddAccessRequest (uint64_t at, uint64_t txTime, 
88
  void AddAccessRequest (uint64_t at, uint64_t txTime, uint64_t expectedGrantTime,
84
                         uint64_t expectedGrantTime, uint32_t from);
89
                         uint32_t nBackoffSlots, uint32_t from);
85
  void AddAccessRequestWithAckTimeout (uint64_t at, uint64_t txTime, 
90
  void AddAccessRequestWithAckTimeout (uint64_t at, uint64_t txTime, uint64_t expectedGrantTime,
86
                                  uint64_t expectedGrantTime, uint32_t from);
91
                                       uint32_t nBackoffSlots, uint32_t from);
87
  ///\param ackDelay is delay of the ack after txEnd
92
  ///\param ackDelay is delay of the ack after txEnd
88
  void AddAccessRequestWithSuccessfullAck (uint64_t at, uint64_t txTime, 
93
  void AddAccessRequestWithSuccessfullAck (uint64_t at, uint64_t txTime, uint64_t expectedGrantTime,
89
                                  uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from);
94
                                           uint32_t nBackoffSlots, uint32_t ackDelay, uint32_t from);
90
  void DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, DcfStateTest *state);
95
  void DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, uint32_t nBackoffSlots, DcfStateTest *state);
91
  void AddCcaBusyEvt (uint64_t at, uint64_t duration); 
96
  void AddCcaBusyEvt (uint64_t at, uint64_t duration); 
92
  void AddSwitchingEvt (uint64_t at, uint64_t duration); 
97
  void AddSwitchingEvt (uint64_t at, uint64_t duration); 
93
  void AddRxStartEvt (uint64_t at, uint64_t duration); 
98
  void AddRxStartEvt (uint64_t at, uint64_t duration); 
 Lines 105-113   DcfStateTest::DcfStateTest (DcfManagerTe Link Here 
105
  : m_test (test), m_i(i)
110
  : m_test (test), m_i(i)
106
{}
111
{}
107
void 
112
void 
108
DcfStateTest::QueueTx (uint64_t txTime, uint64_t expectedGrantTime)
113
DcfStateTest::QueueTx (uint64_t txTime, uint64_t expectedGrantTime, uint32_t nBackoffSlots)
109
{
114
{
110
  m_expectedGrants.push_back (std::make_pair (txTime, expectedGrantTime));
115
  struct ExpectedGrant grant;
116
  grant.m_txTime = txTime;
117
  grant.m_expectedGrantTime = expectedGrantTime;
118
  grant.m_nBackoffSlots = nBackoffSlots;
119
  m_expectedGrants.push_back (grant);
111
}
120
}
112
void 
121
void 
113
DcfStateTest::DoNotifyAccessGranted (void)
122
DcfStateTest::DoNotifyAccessGranted (void)
 Lines 140-150   DcfManagerTest::NotifyAccessGranted (uin Link Here 
140
{
149
{
141
  DcfStateTest *state = m_dcfStates[i];
150
  DcfStateTest *state = m_dcfStates[i];
142
  NS_TEST_EXPECT_MSG_EQ (state->m_expectedGrants.empty (), false, "Have expected grants");
151
  NS_TEST_EXPECT_MSG_EQ (state->m_expectedGrants.empty (), false, "Have expected grants");
143
  std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
152
  struct DcfStateTest::ExpectedGrant expected = state->m_expectedGrants.front ();
144
  state->m_expectedGrants.pop_front ();
153
  state->m_expectedGrants.pop_front ();
145
  NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.second), "Expected access grant is now");
154
  NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.m_expectedGrantTime), "Expected access grant is now");
146
  m_dcfManager->NotifyTxStartNow (MicroSeconds (expected.first));
155
  m_dcfManager->NotifyTxStartNow (MicroSeconds (expected.m_txTime));
147
  m_dcfManager->NotifyAckTimeoutStartNow (MicroSeconds (m_ackTimeoutValue + expected.first));
156
  state->StartBackoffNow (expected.m_nBackoffSlots);
157
  m_dcfManager->NotifyAckTimeoutStartNow (MicroSeconds (m_ackTimeoutValue + expected.m_txTime));
148
}
158
}
149
void
159
void
150
DcfManagerTest::AddTxEvt (uint64_t at, uint64_t duration)
160
DcfManagerTest::AddTxEvt (uint64_t at, uint64_t duration)
 Lines 179-187   DcfManagerTest::NotifyChannelSwitching ( Link Here 
179
  DcfStateTest *state = m_dcfStates[i];
189
  DcfStateTest *state = m_dcfStates[i];
180
  if (!state->m_expectedGrants.empty ())
190
  if (!state->m_expectedGrants.empty ())
181
    {
191
    {
182
      std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
192
      struct DcfStateTest::ExpectedGrant expected = state->m_expectedGrants.front ();
183
      state->m_expectedGrants.pop_front ();
193
      state->m_expectedGrants.pop_front ();
184
      NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.second), "Expected grant is now");
194
      NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.m_expectedGrantTime), "Expected grant is now");
185
    }
195
    }
186
}
196
}
187
197
 Lines 287-319   DcfManagerTest::AddAckTimeoutReset (uint Link Here 
287
                       &DcfManager::NotifyAckTimeoutResetNow, m_dcfManager);
297
                       &DcfManager::NotifyAckTimeoutResetNow, m_dcfManager);
288
}
298
}
289
void 
299
void 
290
DcfManagerTest::AddAccessRequest (uint64_t at, uint64_t txTime, 
300
DcfManagerTest::AddAccessRequest (uint64_t at, uint64_t txTime,
291
                                  uint64_t expectedGrantTime, uint32_t from)
301
                                  uint64_t expectedGrantTime, uint32_t nBackoffSlots,
302
                                  uint32_t from)
292
{
303
{
293
  AddAccessRequestWithSuccessfullAck (at, txTime, expectedGrantTime, 0, from);
304
  AddAccessRequestWithSuccessfullAck (at, txTime, expectedGrantTime, 0, nBackoffSlots, from);
294
}
305
}
295
void 
306
void 
296
DcfManagerTest::AddAccessRequestWithAckTimeout (uint64_t at, uint64_t txTime, 
307
DcfManagerTest::AddAccessRequestWithAckTimeout (uint64_t at, uint64_t txTime, uint64_t expectedGrantTime,
297
                                  uint64_t expectedGrantTime, uint32_t from)
308
                                                uint32_t nBackoffSlots, uint32_t from)
298
{
309
{
299
  Simulator::Schedule (MicroSeconds (at) - Now (), 
310
  Simulator::Schedule (MicroSeconds (at) - Now (), 
300
                       &DcfManagerTest::DoAccessRequest, this,
311
                       &DcfManagerTest::DoAccessRequest, this,
301
                       txTime, expectedGrantTime, m_dcfStates[from]);
312
                       txTime, expectedGrantTime, nBackoffSlots, m_dcfStates[from]);
302
}
313
}
303
void 
314
void 
304
DcfManagerTest::AddAccessRequestWithSuccessfullAck (uint64_t at, uint64_t txTime, 
315
DcfManagerTest::AddAccessRequestWithSuccessfullAck (uint64_t at, uint64_t txTime, uint64_t expectedGrantTime,
305
                                  uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from)
316
                                                    uint32_t ackDelay, uint32_t nBackoffSlots, uint32_t from)
306
{
317
{
307
  NS_ASSERT(ackDelay < m_ackTimeoutValue);
318
  NS_ASSERT(ackDelay < m_ackTimeoutValue);
308
  Simulator::Schedule (MicroSeconds (at) - Now (), 
319
  Simulator::Schedule (MicroSeconds (at) - Now (), 
309
                       &DcfManagerTest::DoAccessRequest, this,
320
                       &DcfManagerTest::DoAccessRequest, this,
310
                       txTime, expectedGrantTime, m_dcfStates[from]);
321
                       txTime, expectedGrantTime, nBackoffSlots, m_dcfStates[from]);
311
  AddAckTimeoutReset (expectedGrantTime + txTime + ackDelay);
322
  AddAckTimeoutReset (expectedGrantTime + txTime + ackDelay);
312
}
323
}
313
void
324
void
314
DcfManagerTest::DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, DcfStateTest *state)
325
DcfManagerTest::DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, uint32_t nBackoffSlots,
326
                                 DcfStateTest *state)
315
{
327
{
316
  state->QueueTx (txTime, expectedGrantTime);
328
  state->QueueTx (txTime, expectedGrantTime, nBackoffSlots);
317
  m_dcfManager->RequestAccess (state);
329
  m_dcfManager->RequestAccess (state);
318
}
330
}
319
void 
331
void 
 Lines 348-355   DcfManagerTest::DoRun (void) Link Here 
348
  //
360
  //
349
  StartTest (1, 3, 10);
361
  StartTest (1, 3, 10);
350
  AddDcfState (1);
362
  AddDcfState (1);
351
  AddAccessRequest (1, 1, 4, 0);
363
  AddAccessRequest (1, 1, 4, 1, 0);
352
  AddAccessRequest (10, 2, 10, 0);
364
  AddAccessRequest (10, 2, 10, 0, 0);
353
  EndTest ();
365
  EndTest ();
354
  // Check that receiving inside SIFS shall be cancelled properly:
366
  // Check that receiving inside SIFS shall be cancelled properly:
355
  //  0      3       4    5      8     9     12       13 14
367
  //  0      3       4    5      8     9     12       13 14
 Lines 357-366   DcfManagerTest::DoRun (void) Link Here 
357
  //
369
  //
358
  StartTest (1, 3, 10);
370
  StartTest (1, 3, 10);
359
  AddDcfState (1);
371
  AddDcfState (1);
360
  AddAccessRequest (1, 1, 4, 0);
372
  AddAccessRequest (1, 1, 4, 1, 0);
361
  AddRxInsideSifsEvt (6, 10);
373
  AddRxInsideSifsEvt (6, 10);
362
  AddTxEvt(8, 1);
374
  AddTxEvt(8, 1);
363
  AddAccessRequest (14, 2, 14, 0);
375
  AddAccessRequest (14, 2, 14, 0, 0);
364
  EndTest ();
376
  EndTest ();
365
377
366
378
 Lines 377-383   DcfManagerTest::DoRun (void) Link Here 
377
  AddDcfState (1);
389
  AddDcfState (1);
378
  AddRxOkEvt (20, 40);
390
  AddRxOkEvt (20, 40);
379
  AddRxOkEvt (80, 20);
391
  AddRxOkEvt (80, 20);
380
  AddAccessRequest (30, 2, 118, 0);
392
  AddAccessRequest (30, 2, 118, 4, 0);
381
  ExpectCollision (30, 4, 0); // backoff: 4 slots
393
  ExpectCollision (30, 4, 0); // backoff: 4 slots
382
  EndTest ();
394
  EndTest ();
383
395
 Lines 390-398   DcfManagerTest::DoRun (void) Link Here 
390
  StartTest (4, 6 , 10);
402
  StartTest (4, 6 , 10);
391
  AddDcfState (1);
403
  AddDcfState (1);
392
  AddRxOkEvt (20, 40);
404
  AddRxOkEvt (20, 40);
393
  AddAccessRequest (30, 2, 70, 0);
405
  AddAccessRequest (30, 2, 70, 0, 0);
394
  ExpectCollision (30, 0, 0); // backoff: 0 slots
406
  ExpectCollision (30, 0, 0); // backoff: 0 slots
395
  EndTest ();
407
  EndTest ();
408
396
  // Test shows when two frames are received without interval between
409
  // Test shows when two frames are received without interval between
397
  // them:
410
  // them:
398
  //  20          60         100   106     110  112
411
  //  20          60         100   106     110  112
 Lines 404-414   DcfManagerTest::DoRun (void) Link Here 
404
  AddDcfState (1);
417
  AddDcfState (1);
405
  AddRxOkEvt (20, 40);
418
  AddRxOkEvt (20, 40);
406
  AddRxOkEvt (60, 40);
419
  AddRxOkEvt (60, 40);
407
  AddAccessRequest (30, 2, 110, 0);
420
  AddAccessRequest (30, 2, 110, 0, 0);
408
  ExpectCollision (30, 0, 0); // backoff: 0 slots
421
  ExpectCollision (30, 0, 0); // backoff: 0 slots
409
  EndTest ();
422
  EndTest ();
410
423
411
424
425
  // Test case where two packets are queued at DcaTxop, the first send starts
426
  // immediately and the second is also immediately indicated but has to wait
427
  // for its backoff.
428
  //
429
  //  20          60     66      70   80
430
  //   | tx        | sifs | aifs  | tx |
431
  //   |20: request access for both packets
432
  StartTest (4, 6 , 10);
433
  AddDcfState (1);
434
  AddAccessRequest (20, 40, 20, 0, 0);
435
  AddAccessRequest (20, 10, 70, 0, 0);
436
  EndTest ();
437
438
  // Test case where two packets are queued at DcaTxop, the first send starts
439
  // immediately and the second is also immediately indicated but has to wait
440
  // for its backoff.
441
  //
442
  //  20          60     66      70        78   88
443
  //   | tx        | sifs | aifs  | backoff | tx |
444
  //   |20: request access for both packets
445
  StartTest (4, 6 , 10);
446
  AddDcfState (1);
447
  AddAccessRequest (20, 40, 20, 2, 0);
448
  AddAccessRequest (20, 10, 78, 0, 0);
449
  EndTest ();
450
412
  // The test below is subject to some discussion because I am 
451
  // The test below is subject to some discussion because I am 
413
  // not sure I understand the intent of the spec here.
452
  // not sure I understand the intent of the spec here.
414
  // i.e., what happens if you make a request to get access
453
  // i.e., what happens if you make a request to get access
 Lines 425-431   DcfManagerTest::DoRun (void) Link Here 
425
  StartTest (4, 6 , 10);
464
  StartTest (4, 6 , 10);
426
  AddDcfState (1);
465
  AddDcfState (1);
427
  AddRxOkEvt (20, 40);
466
  AddRxOkEvt (20, 40);
428
  AddAccessRequest (62, 2, 70, 0);
467
  AddAccessRequest (62, 2, 70, 0, 0);
429
  EndTest ();
468
  EndTest ();
430
469
431
470
 Lines 438-444   DcfManagerTest::DoRun (void) Link Here 
438
  StartTest (4, 6, 10);
477
  StartTest (4, 6, 10);
439
  AddDcfState (1);
478
  AddDcfState (1);
440
  AddRxErrorEvt (20, 40);
479
  AddRxErrorEvt (20, 40);
441
  AddAccessRequest (30, 2, 96, 0);
480
  AddAccessRequest (30, 2, 96, 4, 0);
442
  ExpectCollision (30, 4, 0); // backoff: 4 slots  
481
  ExpectCollision (30, 4, 0); // backoff: 4 slots  
443
  EndTest ();
482
  EndTest ();
444
483
 Lines 451-457   DcfManagerTest::DoRun (void) Link Here 
451
  StartTest (4, 6, 10);
490
  StartTest (4, 6, 10);
452
  AddDcfState (1);
491
  AddDcfState (1);
453
  AddRxErrorEvt (20, 40);
492
  AddRxErrorEvt (20, 40);
454
  AddAccessRequest (30, 2, 101, 0);
493
  AddAccessRequest (30, 2, 101, 4, 0);
455
  ExpectCollision (30, 4, 0); // backoff: 4 slots  
494
  ExpectCollision (30, 4, 0); // backoff: 4 slots  
456
  AddRxOkEvt (69, 6);
495
  AddRxOkEvt (69, 6);
457
  EndTest ();
496
  EndTest ();
 Lines 468-477   DcfManagerTest::DoRun (void) Link Here 
468
  AddDcfState (1); // high priority DCF
507
  AddDcfState (1); // high priority DCF
469
  AddDcfState (3); // low priority DCF
508
  AddDcfState (3); // low priority DCF
470
  AddRxOkEvt (20, 40);
509
  AddRxOkEvt (20, 40);
471
  AddAccessRequest (30, 10, 78, 0);
510
  AddAccessRequest (30, 10, 78, 2, 0);
472
  ExpectCollision (30, 2, 0); // backoff: 2 slot
511
  ExpectCollision (30, 2, 0); // backoff: 2 slot
473
512
474
  AddAccessRequest (40, 2, 110, 1);
513
  AddAccessRequest (40, 2, 110, 0, 1);
475
  ExpectCollision (40, 0, 1); // backoff: 0 slot
514
  ExpectCollision (40, 0, 1); // backoff: 0 slot
476
  ExpectInternalCollision (78, 1, 1); // backoff: 1 slot
515
  ExpectInternalCollision (78, 1, 1); // backoff: 1 slot
477
  EndTest ();
516
  EndTest ();
 Lines 486-493   DcfManagerTest::DoRun (void) Link Here 
486
  StartTest (4, 6, 10);
525
  StartTest (4, 6, 10);
487
  AddDcfState (2); // high priority DCF
526
  AddDcfState (2); // high priority DCF
488
  AddDcfState (0); // low priority DCF
527
  AddDcfState (0); // low priority DCF
489
  AddAccessRequestWithAckTimeout (20, 20, 20, 0);
528
  AddAccessRequestWithAckTimeout (20, 20, 20, 0, 0);
490
  AddAccessRequest (50, 10, 66, 1);
529
  AddAccessRequest (50, 10, 66, 0, 1);
491
  EndTest ();
530
  EndTest ();
492
531
493
  // Test of AckTimeout handling: 
532
  // Test of AckTimeout handling: 
 Lines 502-509   DcfManagerTest::DoRun (void) Link Here 
502
  StartTest (4, 6, 10);
541
  StartTest (4, 6, 10);
503
  AddDcfState (2); // high priority DCF
542
  AddDcfState (2); // high priority DCF
504
  AddDcfState (0); // low priority DCF
543
  AddDcfState (0); // low priority DCF
505
  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 0);
544
  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 0, 0);
506
  AddAccessRequest (41, 10, 48, 1);
545
  AddAccessRequest (41, 10, 48, 0, 1);
507
  EndTest ();
546
  EndTest ();
508
547
509
  //Repeat the same but with one queue:
548
  //Repeat the same but with one queue:
 Lines 512-519   DcfManagerTest::DoRun (void) Link Here 
512
  //                              ^ request access
551
  //                              ^ request access
513
  StartTest (4, 6, 10);
552
  StartTest (4, 6, 10);
514
  AddDcfState (2);
553
  AddDcfState (2);
515
  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 0);
554
  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 0, 0);
516
  AddAccessRequest (41, 10, 56, 0);
555
  AddAccessRequest (41, 10, 56, 0, 0);
517
  EndTest ();
556
  EndTest ();
518
557
519
  //Repeat the same when ack was delayed:
558
  //Repeat the same when ack was delayed:
 Lines 523-531   DcfManagerTest::DoRun (void) Link Here 
523
  //                      ^ request access
562
  //                      ^ request access
524
  StartTest (4, 6, 10);
563
  StartTest (4, 6, 10);
525
  AddDcfState (2);
564
  AddDcfState (2);
526
  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 0);
565
  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 2, 0);
527
  AddAccessRequest (39, 10, 64, 0);
566
  AddAccessRequest (39, 10, 64, 0, 0);
528
  ExpectCollision (39, 2, 0); // backoff: 2 slot
567
  // this situation is not supposed to fire an internal or external collison.
568
  // ExpectCollision (39, 2, 0); // backoff: 2 slot
529
  EndTest ();
569
  EndTest ();
530
570
531
  //
571
  //
 Lines 539-545   DcfManagerTest::DoRun (void) Link Here 
539
  AddNavStart (60, 15);
579
  AddNavStart (60, 15);
540
  AddRxOkEvt (66, 5);
580
  AddRxOkEvt (66, 5);
541
  AddNavStart (71, 0);
581
  AddNavStart (71, 0);
542
  AddAccessRequest (30, 10, 93, 0);
582
  AddAccessRequest (30, 10, 93, 0, 0);
543
  ExpectCollision (30, 2, 0); // backoff: 2 slot
583
  ExpectCollision (30, 2, 0); // backoff: 2 slot
544
  EndTest ();
584
  EndTest ();
545
585
 Lines 554-560   DcfManagerTest::DoRun (void) Link Here 
554
  AddNavStart (60, 15);
594
  AddNavStart (60, 15);
555
  AddRxOkEvt (66, 5);
595
  AddRxOkEvt (66, 5);
556
  AddNavReset (71, 2);
596
  AddNavReset (71, 2);
557
  AddAccessRequest (30, 10, 91, 0);
597
  AddAccessRequest (30, 10, 91, 0, 0);
558
  ExpectCollision (30, 2, 0); // backoff: 2 slot
598
  ExpectCollision (30, 2, 0); // backoff: 2 slot
559
  EndTest ();
599
  EndTest ();
560
600
 Lines 562-568   DcfManagerTest::DoRun (void) Link Here 
562
  StartTest (4, 6, 10);
602
  StartTest (4, 6, 10);
563
  AddDcfState (2);
603
  AddDcfState (2);
564
  AddRxOkEvt (20, 40);
604
  AddRxOkEvt (20, 40);
565
  AddAccessRequest (80, 10, 80, 0);
605
  AddAccessRequest (80, 10, 80, 0, 0);
566
  EndTest ();
606
  EndTest ();
567
607
568
608
 Lines 570-576   DcfManagerTest::DoRun (void) Link Here 
570
  AddDcfState (2);
610
  AddDcfState (2);
571
  AddRxOkEvt (20, 40);
611
  AddRxOkEvt (20, 40);
572
  AddRxOkEvt (78, 8);
612
  AddRxOkEvt (78, 8);
573
  AddAccessRequest (30, 50, 108, 0);
613
  AddAccessRequest (30, 50, 108, 0, 0);
574
  ExpectCollision (30, 3, 0); // backoff: 3 slots
614
  ExpectCollision (30, 3, 0); // backoff: 3 slots
575
  EndTest ();
615
  EndTest ();
576
616
 Lines 584-590   DcfManagerTest::DoRun (void) Link Here 
584
  StartTest (1, 3, 10);
624
  StartTest (1, 3, 10);
585
  AddDcfState (1);
625
  AddDcfState (1);
586
  AddSwitchingEvt(0,20);
626
  AddSwitchingEvt(0,20);
587
  AddAccessRequest (21, 1, 24, 0);
627
  AddAccessRequest (21, 1, 24, 0, 0);
588
  EndTest ();
628
  EndTest ();
589
629
590
  //  20          40       50     53      54   55
630
  //  20          40       50     53      54   55
 Lines 596-602   DcfManagerTest::DoRun (void) Link Here 
596
  AddDcfState (1);
636
  AddDcfState (1);
597
  AddSwitchingEvt(20,20);
637
  AddSwitchingEvt(20,20);
598
  AddCcaBusyEvt(30,20);
638
  AddCcaBusyEvt(30,20);
599
  AddAccessRequest (45, 1, 54, 0);
639
  AddAccessRequest (45, 1, 54, 0, 0);
600
  EndTest ();
640
  EndTest ();
601
641
602
  //  20     30          50     53      54   55
642
  //  20     30          50     53      54   55
 Lines 608-614   DcfManagerTest::DoRun (void) Link Here 
608
  AddDcfState (1);
648
  AddDcfState (1);
609
  AddRxStartEvt (20,40);
649
  AddRxStartEvt (20,40);
610
  AddSwitchingEvt(30,20);
650
  AddSwitchingEvt(30,20);
611
  AddAccessRequest (51, 1, 54, 0);
651
  AddAccessRequest (51, 1, 54, 0, 0);
612
  EndTest ();
652
  EndTest ();
613
653
614
  //  20     30          50     53      54   55
654
  //  20     30          50     53      54   55
 Lines 620-626   DcfManagerTest::DoRun (void) Link Here 
620
  AddDcfState (1);
660
  AddDcfState (1);
621
  AddCcaBusyEvt (20,40);
661
  AddCcaBusyEvt (20,40);
622
  AddSwitchingEvt(30,20);
662
  AddSwitchingEvt(30,20);
623
  AddAccessRequest (51, 1, 54, 0);
663
  AddAccessRequest (51, 1, 54, 0, 0);
624
  EndTest ();
664
  EndTest ();
625
665
626
  //  20      30          50     53      54   55
666
  //  20      30          50     53      54   55
 Lines 632-638   DcfManagerTest::DoRun (void) Link Here 
632
  AddDcfState (1);
672
  AddDcfState (1);
633
  AddNavStart (20,40);
673
  AddNavStart (20,40);
634
  AddSwitchingEvt(30,20);
674
  AddSwitchingEvt(30,20);
635
  AddAccessRequest (51, 1, 54, 0);
675
  AddAccessRequest (51, 1, 54, 0, 0);
636
  EndTest ();
676
  EndTest ();
637
677
638
  //  20      40             50          55     58      59   60
678
  //  20      40             50          55     58      59   60
 Lines 642-651   DcfManagerTest::DoRun (void) Link Here 
642
  //
682
  //
643
  StartTest (1, 3, 10);
683
  StartTest (1, 3, 10);
644
  AddDcfState (1);
684
  AddDcfState (1);
645
  AddAccessRequestWithAckTimeout (20, 20, 20, 0);
685
  AddAccessRequestWithAckTimeout (20, 20, 20, 0, 0);
646
  AddAccessRequest (45, 1, 50, 0);
686
  AddAccessRequest (45, 1, 50, 0, 0);
647
  AddSwitchingEvt(50,5);
687
  AddSwitchingEvt(50,5);
648
  AddAccessRequest (56, 1, 59, 0);
688
  AddAccessRequest (56, 1, 59, 0, 0);
649
  EndTest ();
689
  EndTest ();
650
690
651
  //  20         60     66      70       74       78  80         100    106     110  112
691
  //  20         60     66      70       74       78  80         100    106     110  112
 Lines 656-667   DcfManagerTest::DoRun (void) Link Here 
656
  StartTest (4, 6, 10);
696
  StartTest (4, 6, 10);
657
  AddDcfState (1);
697
  AddDcfState (1);
658
  AddRxOkEvt(20,40);
698
  AddRxOkEvt(20,40);
659
  AddAccessRequest (30, 2, 80, 0); 
699
  AddAccessRequest (30, 2, 80, 4, 0); 
660
  ExpectCollision(30, 4, 0); // backoff: 4 slots
700
  ExpectCollision(30, 4, 0); // backoff: 4 slots
661
  AddSwitchingEvt(80,20);
701
  AddSwitchingEvt(80,20);
662
  AddAccessRequest (101, 2, 110, 0);
702
  AddAccessRequest (101, 2, 110, 0, 0);
663
  EndTest ();
703
  EndTest ();
664
  
704
665
  return GetErrorStatus ();
705
  return GetErrorStatus ();
666
}
706
}
667
707
(-)a/src/devices/wifi/dcf-manager.cc (-2 / +12 lines)
 Lines 42-47   namespace ns3 { Link Here 
42
DcfState::DcfState ()
42
DcfState::DcfState ()
43
  : m_backoffSlots (0),
43
  : m_backoffSlots (0),
44
    m_backoffStart (Seconds (0.0)),
44
    m_backoffStart (Seconds (0.0)),
45
    m_backoffElapsed (true),
45
    m_cwMin (0),
46
    m_cwMin (0),
46
    m_cwMax (0),
47
    m_cwMax (0),
47
    m_cw (0),
48
    m_cw (0),
 Lines 101-106   DcfState::UpdateBackoffSlotsNow (uint32_ Link Here 
101
  m_backoffSlots -= nSlots;
102
  m_backoffSlots -= nSlots;
102
  m_backoffStart = backoffUpdateBound;
103
  m_backoffStart = backoffUpdateBound;
103
  MY_DEBUG ("update slots="<<nSlots<<" slots, backoff="<<m_backoffSlots);
104
  MY_DEBUG ("update slots="<<nSlots<<" slots, backoff="<<m_backoffSlots);
105
  if (m_backoffSlots == 0)
106
    {
107
      m_backoffElapsed = true;
108
    }
104
}
109
}
105
110
106
void 
111
void 
 Lines 110-115   DcfState::StartBackoffNow (uint32_t nSlo Link Here 
110
  MY_DEBUG ("start backoff="<<nSlots<<" slots");
115
  MY_DEBUG ("start backoff="<<nSlots<<" slots");
111
  m_backoffSlots = nSlots;
116
  m_backoffSlots = nSlots;
112
  m_backoffStart = Simulator::Now ();
117
  m_backoffStart = Simulator::Now ();
118
  m_backoffElapsed = false;
113
}
119
}
114
120
115
uint32_t
121
uint32_t
 Lines 127-132   DcfState::GetBackoffStart (void) const Link Here 
127
{
133
{
128
  return m_backoffStart;
134
  return m_backoffStart;
129
}
135
}
136
bool
137
DcfState::IsBackoffElapsed (void) const
138
{
139
  return m_backoffElapsed;
140
}
130
bool 
141
bool 
131
DcfState::IsAccessRequested (void) const
142
DcfState::IsAccessRequested (void) const
132
{
143
{
 Lines 374-381   DcfManager::RequestAccess (DcfState *sta Link Here 
374
   * If there is a collision, generate a backoff
385
   * If there is a collision, generate a backoff
375
   * by notifying the collision to the user.
386
   * by notifying the collision to the user.
376
   */
387
   */
377
  if (state->GetBackoffSlots () == 0 && 
388
  if (state->IsBackoffElapsed() && IsBusy ())
378
      IsBusy ())
379
    {
389
    {
380
      MY_DEBUG ("medium is busy: collision");
390
      MY_DEBUG ("medium is busy: collision");
381
      /* someone else has accessed the medium.
391
      /* someone else has accessed the medium.
(-)a/src/devices/wifi/dcf-manager.h (+5 lines)
 Lines 80-85   public: Link Here 
80
   */
80
   */
81
  void StartBackoffNow (uint32_t nSlots);
81
  void StartBackoffNow (uint32_t nSlots);
82
  /**
82
  /**
83
   * Returns true if the backoff procedure elapsed.
84
   */
85
  bool IsBackoffElapsed (void) const; 
86
  /**
83
   * \returns the current value of the CW variable. The initial value is
87
   * \returns the current value of the CW variable. The initial value is
84
   * minCW.
88
   * minCW.
85
   */
89
   */
 Lines 146-151   private: Link Here 
146
  // time at which a backoff was started or the time at which
150
  // time at which a backoff was started or the time at which
147
  // the backoff counter was last updated.
151
  // the backoff counter was last updated.
148
  Time m_backoffStart;
152
  Time m_backoffStart;
153
  bool m_backoffElapsed;
149
  uint32_t m_cwMin;
154
  uint32_t m_cwMin;
150
  uint32_t m_cwMax;
155
  uint32_t m_cwMax;
151
  uint32_t m_cw;
156
  uint32_t m_cw;

Return to bug 555