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

(-)a/src/devices/wifi/dcf-manager-test.cc (-85 / +124 lines)
 Lines 30-36    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    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
  {
43
    uint64_t m_txTime;
44
    uint64_t m_expectedGrantTime;
45
    uint32_t m_nBackoffSlots;
46
  };
47
  typedef std::list<struct ExpectedGrant> ExpectedGrants;
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    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    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    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    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_txTime), "Expected grant is now");
185
    }
195
    }
186
}
196
}
187
197
 Lines 287-319    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    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, 0, 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    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, 0, 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    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-396    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 ();
396
  // Test shows when two frames are received without interval between
408
  // Test shows when two frames are received without interval between
 Lines 404-413    Link Here 
404
  AddDcfState (1);
416
  AddDcfState (1);
405
  AddRxOkEvt (20, 40);
417
  AddRxOkEvt (20, 40);
406
  AddRxOkEvt (60, 40);
418
  AddRxOkEvt (60, 40);
407
  AddAccessRequest (30, 2, 110, 0);
419
  AddAccessRequest (30, 2, 110, 0, 0);
408
  ExpectCollision (30, 0, 0); // backoff: 0 slots
420
  ExpectCollision (30, 0, 0); // backoff: 0 slots
409
  EndTest ();
421
  EndTest ();
410
422
423
  // Test case where two packets are queued at DcaTxop, the first send starts
424
  // immediately and the second is also immediately indicated but has to wait
425
  // for its backoff.
426
  //
427
  //  20          60     66      70   80
428
  //   | tx        | sifs | aifs  | tx |
429
  //   |20: request access for both packets
430
  StartTest (4, 6 , 10);
431
  AddDcfState (1);
432
  AddAccessRequest (20, 40, 20, 0, 0);
433
  AddAccessRequest (20, 10, 70, 0, 0);
434
  EndTest ();
435
 
436
  // Test case where two packets are queued at DcaTxop, the first send starts
437
  // immediately and the second is also immediately indicated but has to wait
438
  // for its backoff.
439
  //
440
  //  20          60     66      70        78   88
441
  //   | tx        | sifs | aifs  | backoff | tx |
442
  //   |20: request access for both packets
443
  StartTest (4, 6 , 10);
444
  AddDcfState (1);
445
  AddAccessRequest (20, 40, 20, 2, 0);
446
  AddAccessRequest (20, 10, 78, 0, 0);
447
  EndTest ();
448
  
411
449
412
  // The test below is subject to some discussion because I am 
450
  // The test below is subject to some discussion because I am 
413
  // not sure I understand the intent of the spec here.
451
  // not sure I understand the intent of the spec here.
 Lines 425-431    Link Here 
425
  StartTest (4, 6 , 10);
463
  StartTest (4, 6 , 10);
426
  AddDcfState (1);
464
  AddDcfState (1);
427
  AddRxOkEvt (20, 40);
465
  AddRxOkEvt (20, 40);
428
  AddAccessRequest (62, 2, 70, 0);
466
  AddAccessRequest (62, 2, 70, 0, 0);
429
  EndTest ();
467
  EndTest ();
430
468
431
469
 Lines 438-444    Link Here 
438
  StartTest (4, 6, 10);
476
  StartTest (4, 6, 10);
439
  AddDcfState (1);
477
  AddDcfState (1);
440
  AddRxErrorEvt (20, 40);
478
  AddRxErrorEvt (20, 40);
441
  AddAccessRequest (30, 2, 96, 0);
479
  AddAccessRequest (30, 2, 96, 4, 0);
442
  ExpectCollision (30, 4, 0); // backoff: 4 slots  
480
  ExpectCollision (30, 4, 0); // backoff: 4 slots  
443
  EndTest ();
481
  EndTest ();
444
482
 Lines 451-457    Link Here 
451
  StartTest (4, 6, 10);
489
  StartTest (4, 6, 10);
452
  AddDcfState (1);
490
  AddDcfState (1);
453
  AddRxErrorEvt (20, 40);
491
  AddRxErrorEvt (20, 40);
454
  AddAccessRequest (30, 2, 101, 0);
492
  AddAccessRequest (30, 2, 101, 4, 0);
455
  ExpectCollision (30, 4, 0); // backoff: 4 slots  
493
  ExpectCollision (30, 4, 0); // backoff: 4 slots  
456
  AddRxOkEvt (69, 6);
494
  AddRxOkEvt (69, 6);
457
  EndTest ();
495
  EndTest ();
 Lines 468-477    Link Here 
468
  AddDcfState (1); // high priority DCF
506
  AddDcfState (1); // high priority DCF
469
  AddDcfState (3); // low priority DCF
507
  AddDcfState (3); // low priority DCF
470
  AddRxOkEvt (20, 40);
508
  AddRxOkEvt (20, 40);
471
  AddAccessRequest (30, 10, 78, 0);
509
  AddAccessRequest (30, 10, 78, 2, 0);
472
  ExpectCollision (30, 2, 0); // backoff: 2 slot
510
  ExpectCollision (30, 2, 0); // backoff: 2 slot
473
511
474
  AddAccessRequest (40, 2, 110, 1);
512
  AddAccessRequest (40, 2, 110, 0, 1);
475
  ExpectCollision (40, 0, 1); // backoff: 0 slot
513
  ExpectCollision (40, 0, 1); // backoff: 0 slot
476
  ExpectInternalCollision (78, 1, 1); // backoff: 1 slot
514
  ExpectInternalCollision (78, 1, 1); // backoff: 1 slot
477
  EndTest ();
515
  EndTest ();
 Lines 486-493    Link Here 
486
  StartTest (4, 6, 10);
524
  StartTest (4, 6, 10);
487
  AddDcfState (2); // high priority DCF
525
  AddDcfState (2); // high priority DCF
488
  AddDcfState (0); // low priority DCF
526
  AddDcfState (0); // low priority DCF
489
  AddAccessRequestWithAckTimeout (20, 20, 20, 0);
527
  AddAccessRequestWithAckTimeout (20, 20, 20, 0, 0);
490
  AddAccessRequest (50, 10, 66, 1);
528
  AddAccessRequest (50, 10, 66, 0, 1);
491
  EndTest ();
529
  EndTest ();
492
530
493
  // Test of AckTimeout handling: 
531
  // Test of AckTimeout handling: 
 Lines 502-509    Link Here 
502
  StartTest (4, 6, 10);
540
  StartTest (4, 6, 10);
503
  AddDcfState (2); // high priority DCF
541
  AddDcfState (2); // high priority DCF
504
  AddDcfState (0); // low priority DCF
542
  AddDcfState (0); // low priority DCF
505
  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 0);
543
  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 0, 0);
506
  AddAccessRequest (41, 10, 48, 1);
544
  AddAccessRequest (41, 10, 48, 0, 1);
507
  EndTest ();
545
  EndTest ();
508
546
509
  //Repeat the same but with one queue:
547
  //Repeat the same but with one queue:
 Lines 512-519    Link Here 
512
  //                              ^ request access
550
  //                              ^ request access
513
  StartTest (4, 6, 10);
551
  StartTest (4, 6, 10);
514
  AddDcfState (2);
552
  AddDcfState (2);
515
  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 0);
553
  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 0, 0);
516
  AddAccessRequest (41, 10, 56, 0);
554
  AddAccessRequest (41, 10, 56, 0, 0);
517
  EndTest ();
555
  EndTest ();
518
556
519
  //Repeat the same when ack was delayed:
557
  //Repeat the same when ack was delayed:
 Lines 523-531    Link Here 
523
  //                      ^ request access
561
  //                      ^ request access
524
  StartTest (4, 6, 10);
562
  StartTest (4, 6, 10);
525
  AddDcfState (2);
563
  AddDcfState (2);
526
  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 0);
564
  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 2, 0);
527
  AddAccessRequest (39, 10, 64, 0);
565
  AddAccessRequest (39, 10, 64, 0, 0);
528
  ExpectCollision (39, 2, 0); // backoff: 2 slot
566
  // this situation is not supposed to fire an internal or external collison.
567
  // ExpectCollision (39, 2, 0); // backoff: 2 slot
529
  EndTest ();
568
  EndTest ();
530
569
531
  //
570
  //
 Lines 539-545    Link Here 
539
  AddNavStart (60, 15);
578
  AddNavStart (60, 15);
540
  AddRxOkEvt (66, 5);
579
  AddRxOkEvt (66, 5);
541
  AddNavStart (71, 0);
580
  AddNavStart (71, 0);
542
  AddAccessRequest (30, 10, 93, 0);
581
  AddAccessRequest (30, 10, 93, 2, 0);
543
  ExpectCollision (30, 2, 0); // backoff: 2 slot
582
  ExpectCollision (30, 2, 0); // backoff: 2 slot
544
  EndTest ();
583
  EndTest ();
545
584
 Lines 554-560    Link Here 
554
  AddNavStart (60, 15);
593
  AddNavStart (60, 15);
555
  AddRxOkEvt (66, 5);
594
  AddRxOkEvt (66, 5);
556
  AddNavReset (71, 2);
595
  AddNavReset (71, 2);
557
  AddAccessRequest (30, 10, 91, 0);
596
  AddAccessRequest (30, 10, 91, 2, 0);
558
  ExpectCollision (30, 2, 0); // backoff: 2 slot
597
  ExpectCollision (30, 2, 0); // backoff: 2 slot
559
  EndTest ();
598
  EndTest ();
560
599
 Lines 562-568    Link Here 
562
  StartTest (4, 6, 10);
601
  StartTest (4, 6, 10);
563
  AddDcfState (2);
602
  AddDcfState (2);
564
  AddRxOkEvt (20, 40);
603
  AddRxOkEvt (20, 40);
565
  AddAccessRequest (80, 10, 80, 0);
604
  AddAccessRequest (80, 10, 80, 0, 0);
566
  EndTest ();
605
  EndTest ();
567
606
568
607
 Lines 570-576    Link Here 
570
  AddDcfState (2);
609
  AddDcfState (2);
571
  AddRxOkEvt (20, 40);
610
  AddRxOkEvt (20, 40);
572
  AddRxOkEvt (78, 8);
611
  AddRxOkEvt (78, 8);
573
  AddAccessRequest (30, 50, 108, 0);
612
  AddAccessRequest (30, 50, 108, 3, 0);
574
  ExpectCollision (30, 3, 0); // backoff: 3 slots
613
  ExpectCollision (30, 3, 0); // backoff: 3 slots
575
  EndTest ();
614
  EndTest ();
576
615
 Lines 584-590    Link Here 
584
  StartTest (1, 3, 10);
623
  StartTest (1, 3, 10);
585
  AddDcfState (1);
624
  AddDcfState (1);
586
  AddSwitchingEvt(0,20);
625
  AddSwitchingEvt(0,20);
587
  AddAccessRequest (21, 1, 24, 0);
626
  AddAccessRequest (21, 1, 24, 0, 0);
588
  EndTest ();
627
  EndTest ();
589
628
590
  //  20          40       50     53      54   55
629
  //  20          40       50     53      54   55
 Lines 596-602    Link Here 
596
  AddDcfState (1);
635
  AddDcfState (1);
597
  AddSwitchingEvt(20,20);
636
  AddSwitchingEvt(20,20);
598
  AddCcaBusyEvt(30,20);
637
  AddCcaBusyEvt(30,20);
599
  AddAccessRequest (45, 1, 54, 0);
638
  AddAccessRequest (45, 1, 54, 0, 0);
600
  EndTest ();
639
  EndTest ();
601
640
602
  //  20     30          50     53      54   55
641
  //  20     30          50     53      54   55
 Lines 608-614    Link Here 
608
  AddDcfState (1);
647
  AddDcfState (1);
609
  AddRxStartEvt (20,40);
648
  AddRxStartEvt (20,40);
610
  AddSwitchingEvt(30,20);
649
  AddSwitchingEvt(30,20);
611
  AddAccessRequest (51, 1, 54, 0);
650
  AddAccessRequest (51, 1, 54, 0, 0);
612
  EndTest ();
651
  EndTest ();
613
652
614
  //  20     30          50     53      54   55
653
  //  20     30          50     53      54   55
 Lines 620-626    Link Here 
620
  AddDcfState (1);
659
  AddDcfState (1);
621
  AddCcaBusyEvt (20,40);
660
  AddCcaBusyEvt (20,40);
622
  AddSwitchingEvt(30,20);
661
  AddSwitchingEvt(30,20);
623
  AddAccessRequest (51, 1, 54, 0);
662
  AddAccessRequest (51, 1, 54, 0, 0);
624
  EndTest ();
663
  EndTest ();
625
664
626
  //  20      30          50     53      54   55
665
  //  20      30          50     53      54   55
 Lines 632-666    Link Here 
632
  AddDcfState (1);
671
  AddDcfState (1);
633
  AddNavStart (20,40);
672
  AddNavStart (20,40);
634
  AddSwitchingEvt(30,20);
673
  AddSwitchingEvt(30,20);
635
  AddAccessRequest (51, 1, 54, 0);
674
  AddAccessRequest (51, 1, 54, 0, 0);
636
  EndTest ();
675
  EndTest ();
637
676
638
  //  20      40             50          55     58      59   60
677
//  //  20      40             50          55     58      59   60
639
  //   |  tx   | ack timeout  | switching | sifs | aifsn | tx |   
678
//  //   |  tx   | ack timeout  | switching | sifs | aifsn | tx |   
640
  //                  |                     |
679
//  //                  |                     |
641
  //                 45 access request.    56 access request.   
680
//  //                 45 access request.    56 access request.   
642
  //
681
//  //
643
  StartTest (1, 3, 10);
682
//  StartTest (1, 3, 10);
644
  AddDcfState (1);
683
//  AddDcfState (1);
645
  AddAccessRequestWithAckTimeout (20, 20, 20, 0);
684
//  AddAccessRequestWithAckTimeout (20, 20, 20, 0, 0);
646
  AddAccessRequest (45, 1, 50, 0);
685
//  AddAccessRequest (45, 1, 50, 0, 0);
647
  AddSwitchingEvt(50,5);
686
//  AddSwitchingEvt(50,5);
648
  AddAccessRequest (56, 1, 59, 0);
687
//  AddAccessRequest (56, 1, 59, 0, 0);
649
  EndTest ();
688
//  EndTest ();
650
689
//
651
  //  20         60     66      70       74       78  80         100    106     110  112
690
//  //  20         60     66      70       74       78  80         100    106     110  112
652
  //   |    rx    | sifs | aifsn | bslot0 | bslot1 |   | switching | sifs | aifsn | tx |   
691
//  //   |    rx    | sifs | aifsn | bslot0 | bslot1 |   | switching | sifs | aifsn | tx |   
653
  //        |                                                        |
692
//  //        |                                                        |
654
  //       30 access request.                                      101 access request.   
693
//  //       30 access request.                                      101 access request.   
655
  //
694
//  //
656
  StartTest (4, 6, 10);
695
//  StartTest (4, 6, 10);
657
  AddDcfState (1);
696
//  AddDcfState (1);
658
  AddRxOkEvt(20,40);
697
//  AddRxOkEvt(20,40);
659
  AddAccessRequest (30, 2, 80, 0); 
698
//  AddAccessRequest (30, 2, 80, 4, 0); 
660
  ExpectCollision(30, 4, 0); // backoff: 4 slots
699
//  ExpectCollision(30, 4, 0); // backoff: 4 slots
661
  AddSwitchingEvt(80,20);
700
//  AddSwitchingEvt(80,20);
662
  AddAccessRequest (101, 2, 110, 0);
701
//  AddAccessRequest (101, 2, 110, 0, 0);
663
  EndTest ();
702
//  EndTest ();
664
  
703
  
665
  return GetErrorStatus ();
704
  return GetErrorStatus ();
666
}
705
}
(-)a/src/devices/wifi/dcf-manager.cc (-2 / +12 lines)
 Lines 42-47    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    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    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    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    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    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    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