src/devices/wifi/dcf-manager-test.cc
changeset 5189 8fcdf87a790a
parent 4686 f17f12944235
child 5320 0fb5a9f1a9c0
equal deleted inserted replaced
5188:799fdd8fc54a 5189:8fcdf87a790a
    36 private:
    36 private:
    37   friend class DcfManagerTest;
    37   friend class DcfManagerTest;
    38   virtual void DoNotifyAccessGranted (void);
    38   virtual void DoNotifyAccessGranted (void);
    39   virtual void DoNotifyInternalCollision (void);
    39   virtual void DoNotifyInternalCollision (void);
    40   virtual void DoNotifyCollision (void);
    40   virtual void DoNotifyCollision (void);
       
    41   virtual void DoNotifyChannelSwitching (void); 
    41 
    42 
    42   typedef std::pair<uint64_t,uint64_t> ExpectedGrant;
    43   typedef std::pair<uint64_t,uint64_t> ExpectedGrant;
    43   typedef std::list<ExpectedGrant> ExpectedGrants;
    44   typedef std::list<ExpectedGrant> ExpectedGrants;
    44   struct ExpectedCollision {
    45   struct ExpectedCollision {
    45     uint64_t at;
    46     uint64_t at;
    63 
    64 
    64 
    65 
    65   void NotifyAccessGranted (uint32_t i);
    66   void NotifyAccessGranted (uint32_t i);
    66   void NotifyInternalCollision (uint32_t i);
    67   void NotifyInternalCollision (uint32_t i);
    67   void NotifyCollision (uint32_t i);
    68   void NotifyCollision (uint32_t i);
       
    69   void NotifyChannelSwitching (uint32_t i); 
    68 
    70 
    69 
    71 
    70 private:
    72 private:
    71   void StartTest (uint64_t slotTime, uint64_t sifs, uint64_t eifsNoDifsNoSifs, uint32_t ackTimeoutValue = 20);
    73   void StartTest (uint64_t slotTime, uint64_t sifs, uint64_t eifsNoDifsNoSifs, uint32_t ackTimeoutValue = 20);
    72   void AddDcfState (uint32_t aifsn);
    74   void AddDcfState (uint32_t aifsn);
    86                                   uint64_t expectedGrantTime, uint32_t from);
    88                                   uint64_t expectedGrantTime, uint32_t from);
    87   ///\param ackDelay is delay of the ack after txEnd
    89   ///\param ackDelay is delay of the ack after txEnd
    88   void AddAccessRequestWithSuccessfullAck (uint64_t at, uint64_t txTime, 
    90   void AddAccessRequestWithSuccessfullAck (uint64_t at, uint64_t txTime, 
    89                                   uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from);
    91                                   uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from);
    90   void DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, DcfStateTest *state);
    92   void DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, DcfStateTest *state);
       
    93   void AddCcaBusyEvt (uint64_t at, uint64_t duration); 
       
    94   void AddSwitchingEvt (uint64_t at, uint64_t duration); 
       
    95   void AddRxStartEvt (uint64_t at, uint64_t duration); 
    91   
    96   
    92   typedef std::vector<DcfStateTest *> DcfStates;
    97   typedef std::vector<DcfStateTest *> DcfStates;
    93 
    98 
    94   DcfManager *m_dcfManager;
    99   DcfManager *m_dcfManager;
    95   DcfStates m_dcfStates;
   100   DcfStates m_dcfStates;
   120 void 
   125 void 
   121 DcfStateTest::DoNotifyCollision (void)
   126 DcfStateTest::DoNotifyCollision (void)
   122 {
   127 {
   123   m_test->NotifyCollision (m_i);
   128   m_test->NotifyCollision (m_i);
   124 }
   129 }
   125 
   130 void 
       
   131 DcfStateTest::DoNotifyChannelSwitching (void)
       
   132 {
       
   133   m_test->NotifyChannelSwitching (m_i);
       
   134 }
   126 
   135 
   127 
   136 
   128 DcfManagerTest::DcfManagerTest ()
   137 DcfManagerTest::DcfManagerTest ()
   129   : Test ("DcfManager")
   138   : Test ("DcfManager")
   130 {}
   139 {}
   180   if (!result)
   189   if (!result)
   181     {
   190     {
   182       m_result = result;
   191       m_result = result;
   183     }
   192     }
   184 }
   193 }
   185 
   194 void 
       
   195 DcfManagerTest::NotifyChannelSwitching (uint32_t i)
       
   196 {
       
   197   DcfStateTest *state = m_dcfStates[i];
       
   198   bool result = true;
       
   199   if (!state->m_expectedGrants.empty ())
       
   200     {
       
   201       std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
       
   202       state->m_expectedGrants.pop_front ();
       
   203       NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.second));
       
   204     }
       
   205   if (!result)
       
   206     {
       
   207       m_result = result;
       
   208     }
       
   209 }
   186 
   210 
   187 void 
   211 void 
   188 DcfManagerTest::ExpectInternalCollision (uint64_t time, uint32_t nSlots, uint32_t from)
   212 DcfManagerTest::ExpectInternalCollision (uint64_t time, uint32_t nSlots, uint32_t from)
   189 {
   213 {
   190   DcfStateTest *state = m_dcfStates[from];
   214   DcfStateTest *state = m_dcfStates[from];
   318 DcfManagerTest::DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, DcfStateTest *state)
   342 DcfManagerTest::DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, DcfStateTest *state)
   319 {
   343 {
   320   state->QueueTx (txTime, expectedGrantTime);
   344   state->QueueTx (txTime, expectedGrantTime);
   321   m_dcfManager->RequestAccess (state);
   345   m_dcfManager->RequestAccess (state);
   322 }
   346 }
   323 
   347 void 
       
   348 DcfManagerTest::AddCcaBusyEvt (uint64_t at, uint64_t duration)
       
   349 {
       
   350   Simulator::Schedule (MicroSeconds (at) - Now (), 
       
   351                        &DcfManager::NotifyMaybeCcaBusyStartNow, m_dcfManager, 
       
   352                        MicroSeconds (duration));
       
   353 }
       
   354 void
       
   355 DcfManagerTest::AddSwitchingEvt (uint64_t at, uint64_t duration)
       
   356 {
       
   357   Simulator::Schedule (MicroSeconds (at) - Now (), 
       
   358                        &DcfManager::NotifySwitchingStartNow, m_dcfManager, 
       
   359                        MicroSeconds (duration));
       
   360 }
       
   361 void
       
   362 DcfManagerTest::AddRxStartEvt (uint64_t at, uint64_t duration)
       
   363 {
       
   364   Simulator::Schedule (MicroSeconds (at) - Now (), 
       
   365                        &DcfManager::NotifyRxStartNow, m_dcfManager, 
       
   366                        MicroSeconds (duration));
       
   367 }
   324 
   368 
   325 
   369 
   326 
   370 
   327 bool 
   371 bool 
   328 DcfManagerTest::RunTests (void)
   372 DcfManagerTest::RunTests (void)
   557   AddRxOkEvt (20, 40);
   601   AddRxOkEvt (20, 40);
   558   AddRxOkEvt (78, 8);
   602   AddRxOkEvt (78, 8);
   559   AddAccessRequest (30, 50, 108, 0);
   603   AddAccessRequest (30, 50, 108, 0);
   560   ExpectCollision (30, 3, 0); // backoff: 3 slots
   604   ExpectCollision (30, 3, 0); // backoff: 3 slots
   561   EndTest ();
   605   EndTest ();
   562  
   606 
       
   607 
       
   608   // Channel switching tests
       
   609 
       
   610   //  0          20     23      24   25  
       
   611   //  | switching | sifs | aifsn | tx |   
       
   612   //                | 
       
   613   //               21 access request. 
       
   614   StartTest (1, 3, 10);
       
   615   AddDcfState (1);
       
   616   AddSwitchingEvt(0,20);
       
   617   AddAccessRequest (21, 1, 24, 0);
       
   618   EndTest ();
       
   619 
       
   620   //  20          40       50     53      54   55
       
   621   //   | switching |  busy  | sifs | aifsn | tx |   
       
   622   //         |          |
       
   623   //        30 busy.   45 access request.   
       
   624   //
       
   625   StartTest (1, 3, 10);
       
   626   AddDcfState (1);
       
   627   AddSwitchingEvt(20,20);
       
   628   AddCcaBusyEvt(30,20);
       
   629   AddAccessRequest (45, 1, 54, 0);
       
   630   EndTest ();
       
   631 
       
   632   //  20     30          50     53      54   55
       
   633   //   |  rx  | switching | sifs | aifsn | tx |   
       
   634   //                        |
       
   635   //                       51 access request.   
       
   636   //
       
   637   StartTest (1, 3, 10);
       
   638   AddDcfState (1);
       
   639   AddRxStartEvt (20,40);
       
   640   AddSwitchingEvt(30,20);
       
   641   AddAccessRequest (51, 1, 54, 0);
       
   642   EndTest ();
       
   643 
       
   644   //  20     30          50     53      54   55
       
   645   //   | busy | switching | sifs | aifsn | tx |   
       
   646   //                        |
       
   647   //                       51 access request.   
       
   648   //
       
   649   StartTest (1, 3, 10);
       
   650   AddDcfState (1);
       
   651   AddCcaBusyEvt (20,40);
       
   652   AddSwitchingEvt(30,20);
       
   653   AddAccessRequest (51, 1, 54, 0);
       
   654   EndTest ();
       
   655 
       
   656   //  20      30          50     53      54   55
       
   657   //   |  nav  | switching | sifs | aifsn | tx |   
       
   658   //                        |
       
   659   //                       51 access request.   
       
   660   //
       
   661   StartTest (1, 3, 10);
       
   662   AddDcfState (1);
       
   663   AddNavStart (20,40);
       
   664   AddSwitchingEvt(30,20);
       
   665   AddAccessRequest (51, 1, 54, 0);
       
   666   EndTest ();
       
   667 
       
   668   //  20      40             50          55     58      59   60
       
   669   //   |  tx   | ack timeout  | switching | sifs | aifsn | tx |   
       
   670   //                  |                     |
       
   671   //                 45 access request.    56 access request.   
       
   672   //
       
   673   StartTest (1, 3, 10);
       
   674   AddDcfState (1);
       
   675   AddAccessRequestWithAckTimeout (20, 20, 20, 0);
       
   676   AddAccessRequest (45, 1, 50, 0);
       
   677   AddSwitchingEvt(50,5);
       
   678   AddAccessRequest (56, 1, 59, 0);
       
   679   EndTest ();
       
   680 
       
   681   //  20         60     66      70       74       78  80         100    106     110  112
       
   682   //   |    rx    | sifs | aifsn | bslot0 | bslot1 |   | switching | sifs | aifsn | tx |   
       
   683   //        |                                                        |
       
   684   //       30 access request.                                      101 access request.   
       
   685   //
       
   686   StartTest (4, 6, 10);
       
   687   AddDcfState (1);
       
   688   AddRxOkEvt(20,40);
       
   689   AddAccessRequest (30, 2, 80, 0); 
       
   690   ExpectCollision(30, 4, 0); // backoff: 4 slots
       
   691   AddSwitchingEvt(80,20);
       
   692   AddAccessRequest (101, 2, 110, 0);
       
   693   EndTest ();
       
   694 
   563 
   695 
   564   return m_result;
   696   return m_result;
   565 }
   697 }
   566 
   698 
   567 
   699