This documentation is not the Latest Release.
A Discrete-Event Network Simulator
API
dcf-manager-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
4  *
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
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ns3/test.h"
22 #include "ns3/simulator.h"
23 #include "ns3/dcf-manager.h"
24 
25 using namespace ns3;
26 
27 class DcfManagerTest;
28 
29 class DcfStateTest : public DcfState
30 {
31 public:
32  DcfStateTest (DcfManagerTest *test, uint32_t i);
33  void QueueTx (uint64_t txTime, uint64_t expectedGrantTime);
34 
35 
36 private:
37  friend class DcfManagerTest;
38  virtual void DoNotifyAccessGranted (void);
39  virtual void DoNotifyInternalCollision (void);
40  virtual void DoNotifyCollision (void);
41  virtual void DoNotifyChannelSwitching (void);
42  virtual void DoNotifySleep (void);
43  virtual void DoNotifyWakeUp (void);
44 
45  typedef std::pair<uint64_t,uint64_t> ExpectedGrant;
46  typedef std::list<ExpectedGrant> ExpectedGrants;
48  {
49  uint64_t at;
50  uint32_t nSlots;
51  };
52  typedef std::list<struct ExpectedCollision> ExpectedCollisions;
53 
54  ExpectedCollisions m_expectedInternalCollision;
55  ExpectedCollisions m_expectedCollision;
56  ExpectedGrants m_expectedGrants;
58  uint32_t m_i;
59 };
60 
61 
62 class DcfManagerTest : public TestCase
63 {
64 public:
65  DcfManagerTest ();
66  virtual void DoRun (void);
67 
68  void NotifyAccessGranted (uint32_t i);
69  void NotifyInternalCollision (uint32_t i);
70  void NotifyCollision (uint32_t i);
71  void NotifyChannelSwitching (uint32_t i);
72 
73 
74 private:
75  void StartTest (uint64_t slotTime, uint64_t sifs, uint64_t eifsNoDifsNoSifs, uint32_t ackTimeoutValue = 20);
76  void AddDcfState (uint32_t aifsn);
77  void EndTest (void);
78  void ExpectInternalCollision (uint64_t time, uint32_t from, uint32_t nSlots);
79  void ExpectCollision (uint64_t time, uint32_t from, uint32_t nSlots);
80  void AddRxOkEvt (uint64_t at, uint64_t duration);
81  void AddRxErrorEvt (uint64_t at, uint64_t duration);
82  void AddRxInsideSifsEvt (uint64_t at, uint64_t duration);
83  void AddTxEvt (uint64_t at, uint64_t duration);
84  void AddNavReset (uint64_t at, uint64_t duration);
85  void AddNavStart (uint64_t at, uint64_t duration);
86  void AddAckTimeoutReset (uint64_t at);
87  void AddAccessRequest (uint64_t at, uint64_t txTime,
88  uint64_t expectedGrantTime, uint32_t from);
89  void AddAccessRequestWithAckTimeout (uint64_t at, uint64_t txTime,
90  uint64_t expectedGrantTime, uint32_t from);
96  void AddAccessRequestWithSuccessfullAck (uint64_t at, uint64_t txTime,
97  uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from);
98  void DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, DcfStateTest *state);
99  void AddCcaBusyEvt (uint64_t at, uint64_t duration);
100  void AddSwitchingEvt (uint64_t at, uint64_t duration);
101  void AddRxStartEvt (uint64_t at, uint64_t duration);
102 
103  typedef std::vector<DcfStateTest *> DcfStates;
104 
106  DcfStates m_dcfStates;
108 };
109 
111  : m_test (test),
112  m_i (i)
113 {
114 }
115 
116 void
117 DcfStateTest::QueueTx (uint64_t txTime, uint64_t expectedGrantTime)
118 {
119  m_expectedGrants.push_back (std::make_pair (txTime, expectedGrantTime));
120 }
121 
122 void
124 {
126 }
127 
128 void
130 {
132 }
133 
134 void
136 {
138 }
139 
140 void
142 {
144 }
145 
146 void
148 {
149 }
150 
151 void
153 {
154 }
155 
157  : TestCase ("DcfManager")
158 {
159 }
160 
161 void
163 {
164  DcfStateTest *state = m_dcfStates[i];
165  NS_TEST_EXPECT_MSG_EQ (state->m_expectedGrants.empty (), false, "Have expected grants");
166  std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
167  state->m_expectedGrants.pop_front ();
168  NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.second), "Expected access grant is now");
169  m_dcfManager->NotifyTxStartNow (MicroSeconds (expected.first));
171 }
172 
173 void
174 DcfManagerTest::AddTxEvt (uint64_t at, uint64_t duration)
175 {
176  Simulator::Schedule (MicroSeconds (at) - Now (),
177  &DcfManager::NotifyTxStartNow, m_dcfManager,
178  MicroSeconds (duration));
179 }
180 
181 void
183 {
184  DcfStateTest *state = m_dcfStates[i];
185  NS_TEST_EXPECT_MSG_EQ (state->m_expectedInternalCollision.empty (), false, "Have expected internal collisions");
186  struct DcfStateTest::ExpectedCollision expected = state->m_expectedInternalCollision.front ();
187  state->m_expectedInternalCollision.pop_front ();
188  NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.at), "Expected internal collision time is now");
189  state->StartBackoffNow (expected.nSlots);
190 }
191 
192 void
194 {
195  DcfStateTest *state = m_dcfStates[i];
196  NS_TEST_EXPECT_MSG_EQ (state->m_expectedCollision.empty (), false, "Have expected collisions");
197  struct DcfStateTest::ExpectedCollision expected = state->m_expectedCollision.front ();
198  state->m_expectedCollision.pop_front ();
199  NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.at), "Expected collision is now");
200  state->StartBackoffNow (expected.nSlots);
201 }
202 
203 void
205 {
206  DcfStateTest *state = m_dcfStates[i];
207  if (!state->m_expectedGrants.empty ())
208  {
209  std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
210  state->m_expectedGrants.pop_front ();
211  NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.second), "Expected grant is now");
212  }
213 }
214 
215 void
216 DcfManagerTest::ExpectInternalCollision (uint64_t time, uint32_t nSlots, uint32_t from)
217 {
218  DcfStateTest *state = m_dcfStates[from];
220  col.at = time;
221  col.nSlots = nSlots;
222  state->m_expectedInternalCollision.push_back (col);
223 }
224 
225 void
226 DcfManagerTest::ExpectCollision (uint64_t time, uint32_t nSlots, uint32_t from)
227 {
228  DcfStateTest *state = m_dcfStates[from];
230  col.at = time;
231  col.nSlots = nSlots;
232  state->m_expectedCollision.push_back (col);
233 }
234 
235 void
236 DcfManagerTest::StartTest (uint64_t slotTime, uint64_t sifs, uint64_t eifsNoDifsNoSifs, uint32_t ackTimeoutValue)
237 {
238  m_dcfManager = new DcfManager ();
239  m_dcfManager->SetSlot (MicroSeconds (slotTime));
241  m_dcfManager->SetEifsNoDifs (MicroSeconds (eifsNoDifsNoSifs + sifs));
242  m_ackTimeoutValue = ackTimeoutValue;
243 }
244 
245 void
247 {
248  DcfStateTest *state = new DcfStateTest (this, m_dcfStates.size ());
249  state->SetAifsn (aifsn);
250  m_dcfStates.push_back (state);
251  m_dcfManager->Add (state);
252 }
253 
254 void
256 {
257  Simulator::Run ();
258  Simulator::Destroy ();
259  for (DcfStates::const_iterator i = m_dcfStates.begin (); i != m_dcfStates.end (); i++)
260  {
261  DcfStateTest *state = *i;
262  NS_TEST_EXPECT_MSG_EQ (state->m_expectedGrants.empty (), true, "Have no expected grants");
263  NS_TEST_EXPECT_MSG_EQ (state->m_expectedInternalCollision.empty (), true, "Have no internal collisions");
264  NS_TEST_EXPECT_MSG_EQ (state->m_expectedCollision.empty (), true, "Have no expected collisions");
265  delete state;
266  }
267  m_dcfStates.clear ();
268  delete m_dcfManager;
269 }
270 
271 void
272 DcfManagerTest::AddRxOkEvt (uint64_t at, uint64_t duration)
273 {
274  Simulator::Schedule (MicroSeconds (at) - Now (),
275  &DcfManager::NotifyRxStartNow, m_dcfManager,
276  MicroSeconds (duration));
277  Simulator::Schedule (MicroSeconds (at + duration) - Now (),
278  &DcfManager::NotifyRxEndOkNow, m_dcfManager);
279 }
280 
281 void
282 DcfManagerTest::AddRxInsideSifsEvt (uint64_t at, uint64_t duration)
283 {
284  Simulator::Schedule (MicroSeconds (at) - Now (),
285  &DcfManager::NotifyRxStartNow, m_dcfManager,
286  MicroSeconds (duration));
287 }
288 
289 void
290 DcfManagerTest::AddRxErrorEvt (uint64_t at, uint64_t duration)
291 {
292  Simulator::Schedule (MicroSeconds (at) - Now (),
293  &DcfManager::NotifyRxStartNow, m_dcfManager,
294  MicroSeconds (duration));
295  Simulator::Schedule (MicroSeconds (at + duration) - Now (),
296  &DcfManager::NotifyRxEndErrorNow, m_dcfManager);
297 }
298 
299 void
300 DcfManagerTest::AddNavReset (uint64_t at, uint64_t duration)
301 {
302  Simulator::Schedule (MicroSeconds (at) - Now (),
303  &DcfManager::NotifyNavResetNow, m_dcfManager,
304  MicroSeconds (duration));
305 }
306 
307 void
308 DcfManagerTest::AddNavStart (uint64_t at, uint64_t duration)
309 {
310  Simulator::Schedule (MicroSeconds (at) - Now (),
311  &DcfManager::NotifyNavStartNow, m_dcfManager,
312  MicroSeconds (duration));
313 }
314 
315 void
317 {
318  Simulator::Schedule (MicroSeconds (at) - Now (),
319  &DcfManager::NotifyAckTimeoutResetNow, m_dcfManager);
320 }
321 
322 void
323 DcfManagerTest::AddAccessRequest (uint64_t at, uint64_t txTime,
324  uint64_t expectedGrantTime, uint32_t from)
325 {
326  AddAccessRequestWithSuccessfullAck (at, txTime, expectedGrantTime, 0, from);
327 }
328 
329 void
331  uint64_t expectedGrantTime, uint32_t from)
332 {
333  Simulator::Schedule (MicroSeconds (at) - Now (),
335  txTime, expectedGrantTime, m_dcfStates[from]);
336 }
337 
338 void
340  uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from)
341 {
342  NS_ASSERT (ackDelay < m_ackTimeoutValue);
343  Simulator::Schedule (MicroSeconds (at) - Now (),
345  txTime, expectedGrantTime, m_dcfStates[from]);
346  AddAckTimeoutReset (expectedGrantTime + txTime + ackDelay);
347 }
348 
349 void
350 DcfManagerTest::DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, DcfStateTest *state)
351 {
352  state->QueueTx (txTime, expectedGrantTime);
353  m_dcfManager->RequestAccess (state);
354 }
355 
356 void
357 DcfManagerTest::AddCcaBusyEvt (uint64_t at, uint64_t duration)
358 {
359  Simulator::Schedule (MicroSeconds (at) - Now (),
360  &DcfManager::NotifyMaybeCcaBusyStartNow, m_dcfManager,
361  MicroSeconds (duration));
362 }
363 
364 void
365 DcfManagerTest::AddSwitchingEvt (uint64_t at, uint64_t duration)
366 {
367  Simulator::Schedule (MicroSeconds (at) - Now (),
368  &DcfManager::NotifySwitchingStartNow, m_dcfManager,
369  MicroSeconds (duration));
370 }
371 
372 void
373 DcfManagerTest::AddRxStartEvt (uint64_t at, uint64_t duration)
374 {
375  Simulator::Schedule (MicroSeconds (at) - Now (),
376  &DcfManager::NotifyRxStartNow, m_dcfManager,
377  MicroSeconds (duration));
378 }
379 
380 void
382 {
383  // 0 3 4 5 8 9 10 12
384  // | sifs | aifsn | tx | sifs | aifsn | | tx |
385  //
386  StartTest (1, 3, 10);
387  AddDcfState (1);
388  AddAccessRequest (1, 1, 4, 0);
389  AddAccessRequest (10, 2, 10, 0);
390  EndTest ();
391  // Check that receiving inside SIFS shall be cancelled properly:
392  // 0 3 4 5 8 9 12 13 14
393  // | sifs | aifsn | tx | sifs | ack | sifs | aifsn | |tx |
394  //
395 
396  StartTest (1, 3, 10);
397  AddDcfState (1);
398  AddAccessRequest (1, 1, 4, 0);
399  AddRxInsideSifsEvt (6, 10);
400  AddTxEvt (8, 1);
401  AddAccessRequest (14, 2, 14, 0);
402  EndTest ();
403  // The test below mainly intends to test the case where the medium
404  // becomes busy in the middle of a backoff slot: the backoff counter
405  // must not be decremented for this backoff slot. This is the case
406  // below for the backoff slot starting at time 78us.
407  //
408  // 20 60 66 70 74 78 80 100 106 110 114 118 120
409  // | rx | sifs | aifsn | bslot0 | bslot1 | | rx | sifs | aifsn | bslot2 | bslot3 | tx |
410  // |
411  // 30 request access. backoff slots: 4
412 
413  StartTest (4, 6, 10);
414  AddDcfState (1);
415  AddRxOkEvt (20, 40);
416  AddRxOkEvt (80, 20);
417  AddAccessRequest (30, 2, 118, 0);
418  ExpectCollision (30, 4, 0); //backoff: 4 slots
419  EndTest ();
420  // Test the case where the backoff slots is zero.
421  //
422  // 20 60 66 70 72
423  // | rx | sifs | aifsn | tx |
424  // |
425  // 30 request access. backoff slots: 0
426 
427  StartTest (4, 6, 10);
428  AddDcfState (1);
429  AddRxOkEvt (20, 40);
430  AddAccessRequest (30, 2, 70, 0);
431  ExpectCollision (30, 0, 0); // backoff: 0 slots
432  EndTest ();
433  // Test shows when two frames are received without interval between
434  // them:
435  // 20 60 100 106 110 112
436  // | rx | rx |sifs | aifsn | tx |
437  // |
438  // 30 request access. backoff slots: 0
439 
440  StartTest (4, 6, 10);
441  AddDcfState (1);
442  AddRxOkEvt (20, 40);
443  AddRxOkEvt (60, 40);
444  AddAccessRequest (30, 2, 110, 0);
445  ExpectCollision (30, 0, 0); //backoff: 0 slots
446  EndTest ();
447 
448  // The test below is subject to some discussion because I am
449  // not sure I understand the intent of the spec here.
450  // i.e., what happens if you make a request to get access
451  // to the medium during the difs idle time after a busy period ?
452  // do you need to start a backoff ? Or do you need to wait until
453  // the end of difs and access the medium ?
454  // Here, we wait until the end of difs and access the medium.
455  //
456  // 20 60 66 70 72
457  // | rx | sifs | aifsn | tx |
458  // |
459  // 62 request access.
460  //
461  StartTest (4, 6, 10);
462  AddDcfState (1);
463  AddRxOkEvt (20, 40);
464  AddAccessRequest (62, 2, 70, 0);
465  EndTest ();
466 
467  // Test an EIFS
468  //
469  // 20 60 66 76 86 90 94 98 102 106
470  // | rx | sifs | acktxttime | sifs + aifsn | bslot0 | bslot1 | bslot2 | bslot3 | tx |
471  // | | <------eifs------>|
472  // 30 request access. backoff slots: 4
473  StartTest (4, 6, 10);
474  AddDcfState (1);
475  AddRxErrorEvt (20, 40);
476  AddAccessRequest (30, 2, 102, 0);
477  ExpectCollision (30, 4, 0); //backoff: 4 slots
478  EndTest ();
479 
480  // Test an EIFS which is interupted by a successfull transmission.
481  //
482  // 20 60 66 69 75 81 85 89 93 97 101 103
483  // | rx | sifs | | rx | sifs | aifsn | bslot0 | bslot1 | bslot2 | bslot3 | tx |
484  // | | <--eifs-->|
485  // 30 request access. backoff slots: 4
486  StartTest (4, 6, 10);
487  AddDcfState (1);
488  AddRxErrorEvt (20, 40);
489  AddAccessRequest (30, 2, 101, 0);
490  ExpectCollision (30, 4, 0); //backoff: 4 slots
491  AddRxOkEvt (69, 6);
492  EndTest ();
493 
494  // Test two DCFs which suffer an internal collision. the first DCF has a higher
495  // priority than the second DCF.
496  //
497  // 20 60 66 70 74 78 88
498  // DCF0 | rx | sifs | aifsn | bslot0 | bslot1 | tx |
499  // DCF1 | rx | sifs | aifsn | aifsn | aifsn | | sifs | aifsn | aifsn | aifsn | bslot | tx |
500  // 94 98 102 106 110 112
501  StartTest (4, 6, 10);
502  AddDcfState (1); //high priority DCF
503  AddDcfState (3); //low priority DCF
504  AddRxOkEvt (20, 40);
505  AddAccessRequest (30, 10, 78, 0);
506  ExpectCollision (30, 2, 0); //backoff: 2 slot
507  AddAccessRequest (40, 2, 110, 1);
508  ExpectCollision (40, 0, 1); //backoff: 0 slot
509  ExpectInternalCollision (78, 1, 1); //backoff: 1 slot
510  EndTest ();
511 
512  // Test of AckTimeout handling: First queue requests access and ack procedure fails,
513  // inside the ack timeout second queue with higher priority requests access.
514  //
515  // 20 40 50 60 66 76
516  // DCF0 - low | tx | ack timeout |sifs| |
517  // DCF1 - high | | |sifs| tx |
518  // ^ request access
519  StartTest (4, 6, 10);
520  AddDcfState (2); //high priority DCF
521  AddDcfState (0); //low priority DCF
522  AddAccessRequestWithAckTimeout (20, 20, 20, 0);
523  AddAccessRequest (50, 10, 66, 1);
524  EndTest ();
525 
526  // Test of AckTimeout handling:
527  //
528  // First queue requests access and ack is 2 us delayed (got ack interval at the picture),
529  // inside this interval second queue with higher priority requests access.
530  //
531  // 20 40 41 42 48 58
532  // DCF0 - low | tx |got ack |sifs| |
533  // DCF1 - high | | |sifs| tx |
534  // ^ request access
535  StartTest (4, 6, 10);
536  AddDcfState (2); //high priority DCF
537  AddDcfState (0); //low priority DCF
538  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 0);
539  AddAccessRequest (41, 10, 48, 1);
540  EndTest ();
541 
542  //Repeat the same but with one queue:
543  // 20 40 41 42 48 58
544  // DCF0 - low | tx |got ack |sifs| |
545  // ^ request access
546  StartTest (4, 6, 10);
547  AddDcfState (2);
548  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 0);
549  AddAccessRequest (41, 10, 56, 0);
550  EndTest ();
551 
552  //Repeat the same when ack was delayed:
553  //and request the next access before previous tx end:
554  // 20 39 40 42 64 74
555  // DCF0 - low | tx |got ack |sifs + 4 * slot| |
556  // ^ request access
557  StartTest (4, 6, 10);
558  AddDcfState (2);
559  AddAccessRequestWithSuccessfullAck (20, 20, 20, 2, 0);
560  AddAccessRequest (39, 10, 64, 0);
561  ExpectCollision (39, 2, 0); //backoff: 2 slot
562  EndTest ();
563 
564  // test simple NAV count. This scenario modelizes a simple DATA+ACK handshake
565  // where the data rate used for the ACK is higher than expected by the DATA source
566  // so, the data exchange completes before the end of nav.
567  StartTest (4, 6, 10);
568  AddDcfState (1);
569  AddRxOkEvt (20, 40);
570  AddNavStart (60, 15);
571  AddRxOkEvt (66, 5);
572  AddNavStart (71, 0);
573  AddAccessRequest (30, 10, 93, 0);
574  ExpectCollision (30, 2, 0); //backoff: 2 slot
575  EndTest ();
576 
577  // test more complex NAV handling by a CF-poll. This scenario modelizes a
578  // simple DATA+ACK handshake interrupted by a CF-poll which resets the
579  // NAV counter.
580  StartTest (4, 6, 10);
581  AddDcfState (1);
582  AddRxOkEvt (20, 40);
583  AddNavStart (60, 15);
584  AddRxOkEvt (66, 5);
585  AddNavReset (71, 2);
586  AddAccessRequest (30, 10, 91, 0);
587  ExpectCollision (30, 2, 0); //backoff: 2 slot
588  EndTest ();
589 
590 
591  StartTest (4, 6, 10);
592  AddDcfState (2);
593  AddRxOkEvt (20, 40);
594  AddAccessRequest (80, 10, 80, 0);
595  EndTest ();
596 
597 
598  StartTest (4, 6, 10);
599  AddDcfState (2);
600  AddRxOkEvt (20, 40);
601  AddRxOkEvt (78, 8);
602  AddAccessRequest (30, 50, 108, 0);
603  ExpectCollision (30, 3, 0); //backoff: 3 slots
604  EndTest ();
605 
606 
607  // Channel switching tests
608 
609  // 0 20 23 24 25
610  // | switching | sifs | aifsn | tx |
611  // |
612  // 21 access request.
613  StartTest (1, 3, 10);
614  AddDcfState (1);
615  AddSwitchingEvt (0,20);
616  AddAccessRequest (21, 1, 24, 0);
617  EndTest ();
618 
619  // 20 40 50 53 54 55
620  // | switching | busy | sifs | aifsn | tx |
621  // | |
622  // 30 busy. 45 access request.
623  //
624  StartTest (1, 3, 10);
625  AddDcfState (1);
626  AddSwitchingEvt (20,20);
627  AddCcaBusyEvt (30,20);
628  AddAccessRequest (45, 1, 54, 0);
629  EndTest ();
630 
631  // 20 30 50 53 54 55
632  // | rx | switching | sifs | aifsn | tx |
633  // |
634  // 51 access request.
635  //
636  StartTest (1, 3, 10);
637  AddDcfState (1);
638  AddRxStartEvt (20,40);
639  AddSwitchingEvt (30,20);
640  AddAccessRequest (51, 1, 54, 0);
641  EndTest ();
642 
643  // 20 30 50 53 54 55
644  // | busy | switching | sifs | aifsn | tx |
645  // |
646  // 51 access request.
647  //
648  StartTest (1, 3, 10);
649  AddDcfState (1);
650  AddCcaBusyEvt (20,40);
651  AddSwitchingEvt (30,20);
652  AddAccessRequest (51, 1, 54, 0);
653  EndTest ();
654 
655  // 20 30 50 53 54 55
656  // | nav | switching | sifs | aifsn | tx |
657  // |
658  // 51 access request.
659  //
660  StartTest (1, 3, 10);
661  AddDcfState (1);
662  AddNavStart (20,40);
663  AddSwitchingEvt (30,20);
664  AddAccessRequest (51, 1, 54, 0);
665  EndTest ();
666 
667  // 20 40 50 55 58 59 60
668  // | tx | ack timeout | switching | sifs | aifsn | tx |
669  // | |
670  // 45 access request. 56 access request.
671  //
672  StartTest (1, 3, 10);
673  AddDcfState (1);
674  AddAccessRequestWithAckTimeout (20, 20, 20, 0);
675  AddAccessRequest (45, 1, 50, 0);
676  AddSwitchingEvt (50,5);
677  AddAccessRequest (56, 1, 59, 0);
678  EndTest ();
679 
680  // 20 60 66 70 74 78 80 100 106 110 112
681  // | rx | sifs | aifsn | bslot0 | bslot1 | | switching | sifs | aifsn | tx |
682  // | |
683  // 30 access request. 101 access request.
684  //
685  StartTest (4, 6, 10);
686  AddDcfState (1);
687  AddRxOkEvt (20,40);
688  AddAccessRequest (30, 2, 80, 0);
689  ExpectCollision (30, 4, 0); //backoff: 4 slots
690  AddSwitchingEvt (80,20);
691  AddAccessRequest (101, 2, 110, 0);
692  EndTest ();
693 }
694 
695 
696 class DcfTestSuite : public TestSuite
697 {
698 public:
699  DcfTestSuite ();
700 };
701 
703  : TestSuite ("devices-wifi-dcf", UNIT)
704 {
705  AddTestCase (new DcfManagerTest, TestCase::QUICK);
706 }
707 
std::pair< uint64_t, uint64_t > ExpectedGrant
DcfManager * m_dcfManager
virtual void DoNotifyAccessGranted(void)
Called by DcfManager to notify a DcfState subclass that access to the medium is granted and can start...
static DcfTestSuite g_dcfTestSuite
A suite of tests to run.
Definition: test.h:1333
void RequestAccess(DcfState *state)
Definition: dcf-manager.cc:479
ExpectedCollisions m_expectedInternalCollision
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
void AddRxOkEvt(uint64_t at, uint64_t duration)
void AddAccessRequestWithAckTimeout(uint64_t at, uint64_t txTime, uint64_t expectedGrantTime, uint32_t from)
DcfStateTest(DcfManagerTest *test, uint32_t i)
void AddSwitchingEvt(uint64_t at, uint64_t duration)
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:278
void SetAifsn(uint32_t aifsn)
Definition: dcf-manager.cc:56
std::list< ExpectedGrant > ExpectedGrants
void AddTxEvt(uint64_t at, uint64_t duration)
encapsulates test code
Definition: test.h:1147
void ExpectInternalCollision(uint64_t time, uint32_t from, uint32_t nSlots)
virtual void DoNotifyCollision(void)
Called by DcfManager to notify a DcfState subclass that a normal collision occured, that is, that the medium was busy when access was requested.
void DoAccessRequest(uint64_t txTime, uint64_t expectedGrantTime, DcfStateTest *state)
void AddRxInsideSifsEvt(uint64_t at, uint64_t duration)
void Add(DcfState *dcf)
Definition: dcf-manager.cc:397
void NotifyChannelSwitching(uint32_t i)
void StartTest(uint64_t slotTime, uint64_t sifs, uint64_t eifsNoDifsNoSifs, uint32_t ackTimeoutValue=20)
ExpectedCollisions m_expectedCollision
void AddAckTimeoutReset(uint64_t at)
virtual void DoNotifySleep(void)
Called by DcfManager to notify a DcfState subclass that the device has begun to sleep.
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:297
void NotifyTxStartNow(Time duration)
Definition: dcf-manager.cc:720
void NotifyAckTimeoutStartNow(Time duration)
Notify that ACK timer has started for the given duration.
Definition: dcf-manager.cc:883
Manage a set of ns3::DcfStateHandle a set of independent ns3::DcfState, each of which represents a si...
Definition: dcf-manager.h:252
void NotifyCollision(uint32_t i)
keep track of the state needed for a single DCF function.
Definition: dcf-manager.h:46
void AddNavReset(uint64_t at, uint64_t duration)
void AddCcaBusyEvt(uint64_t at, uint64_t duration)
friend class DcfManager
Definition: dcf-manager.h:122
virtual void DoNotifyWakeUp(void)
Called by DcfManager to notify a DcfState subclass that the device has begun to wake up...
void StartBackoffNow(uint32_t nSlots)
Definition: dcf-manager.cc:115
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ExpectedGrants m_expectedGrants
void SetEifsNoDifs(Time eifsNoDifs)
Definition: dcf-manager.cc:383
uint32_t m_ackTimeoutValue
void AddRxStartEvt(uint64_t at, uint64_t duration)
std::list< struct ExpectedCollision > ExpectedCollisions
void SetSlot(Time slotTime)
Definition: dcf-manager.cc:369
void ExpectCollision(uint64_t time, uint32_t from, uint32_t nSlots)
DcfManagerTest * m_test
void NotifyAccessGranted(uint32_t i)
virtual void DoNotifyChannelSwitching(void)
Called by DcfManager to notify a DcfState subclass that a channel switching occured.
void NotifyInternalCollision(uint32_t i)
void AddNavStart(uint64_t at, uint64_t duration)
void AddAccessRequest(uint64_t at, uint64_t txTime, uint64_t expectedGrantTime, uint32_t from)
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:911
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:330
virtual void DoNotifyInternalCollision(void)
Called by DcfManager to notify a DcfState subclass that an 'internal' collision occured, that is, that the backoff timer of a higher priority DcfState expired at the same time and that access was granted to this higher priority DcfState.
void AddDcfState(uint32_t aifsn)
void AddAccessRequestWithSuccessfullAck(uint64_t at, uint64_t txTime, uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from)
std::vector< DcfStateTest * > DcfStates
void AddRxErrorEvt(uint64_t at, uint64_t duration)
void test(void)
Example use of ns3::SystemThread.
void SetSifs(Time sifs)
Definition: dcf-manager.cc:376
void QueueTx(uint64_t txTime, uint64_t expectedGrantTime)
virtual void DoRun(void)
Implementation to actually run this TestCase.