22 #include "ns3/simulator.h"
23 #include "ns3/channel-access-manager.h"
24 #include "ns3/frame-exchange-manager.h"
25 #include "ns3/qos-txop.h"
29 template <
typename TxopType>
38 template <
typename TxopType>
55 void QueueTx (uint64_t txTime, uint64_t expectedGrantTime);
62 void DoDispose (
void)
override;
64 void NotifyChannelAccessed (
Time txopDuration =
Seconds (0))
override;
66 bool HasFramesToTransmit (
void)
override;
70 void NotifySleep (
void)
override;
72 void NotifyWakeUp (
void)
override;
136 m_eifsNoDifs = eifsNoDifs;
166 template <
typename TxopType>
207 template <
typename TxopType>
218 void NotifyAccessGranted (uint32_t i);
228 void GenerateBackoff (uint32_t i);
233 void NotifyChannelSwitching (uint32_t i);
244 void StartTest (uint64_t slotTime, uint64_t sifs, uint64_t eifsNoDifsNoSifs, uint32_t ackTimeoutValue = 20);
249 void AddTxop (uint32_t aifsn);
258 void ExpectInternalCollision (uint64_t time, uint32_t nSlots, uint32_t from);
265 void ExpectBackoff (uint64_t time, uint32_t nSlots, uint32_t from);
271 void ExpectBusy (uint64_t time,
bool busy);
276 void DoCheckBusy (
bool busy);
282 void AddRxOkEvt (uint64_t at, uint64_t duration);
288 void AddRxErrorEvt (uint64_t at, uint64_t duration);
295 void AddRxErrorEvt (uint64_t at, uint64_t duration, uint64_t timeUntilError);
301 void AddRxInsideSifsEvt (uint64_t at, uint64_t duration);
307 void AddTxEvt (uint64_t at, uint64_t duration);
313 void AddNavReset (uint64_t at, uint64_t duration);
319 void AddNavStart (uint64_t at, uint64_t duration);
324 void AddAckTimeoutReset (uint64_t at);
332 void AddAccessRequest (uint64_t at, uint64_t txTime,
333 uint64_t expectedGrantTime, uint32_t from);
341 void AddAccessRequestWithAckTimeout (uint64_t at, uint64_t txTime,
342 uint64_t expectedGrantTime, uint32_t from);
351 void AddAccessRequestWithSuccessfullAck (uint64_t at, uint64_t txTime,
352 uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from);
365 void AddCcaBusyEvt (uint64_t at, uint64_t duration);
371 void AddSwitchingEvt (uint64_t at, uint64_t duration);
377 void AddRxStartEvt (uint64_t at, uint64_t duration);
387 template <
typename TxopType>
391 m_expectedGrants.push_back (std::make_pair (txTime, expectedGrantTime));
394 template <
typename TxopType>
401 template <
typename TxopType>
406 TxopType::DoDispose ();
409 template <
typename TxopType>
413 Txop::m_access = Txop::NOT_REQUESTED;
414 m_test->NotifyAccessGranted (m_i);
417 template <
typename TxopType>
421 m_test->GenerateBackoff (m_i);
424 template <
typename TxopType>
428 return !m_expectedGrants.empty ();
431 template <
typename TxopType>
435 m_test->NotifyChannelSwitching (m_i);
438 template <
typename TxopType>
444 template <
typename TxopType>
450 template <
typename TxopType>
456 template <
typename TxopType>
462 if (!state->m_expectedGrants.empty ())
464 std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
465 state->m_expectedGrants.pop_front ();
467 m_ChannelAccessManager->NotifyTxStartNow (
MicroSeconds (expected.first));
468 m_ChannelAccessManager->NotifyAckTimeoutStartNow (
MicroSeconds (m_ackTimeoutValue + expected.first));
472 template <
typename TxopType>
477 &ChannelAccessManager::NotifyTxStartNow, m_ChannelAccessManager,
481 template <
typename TxopType>
485 NS_TEST_EXPECT_MSG_EQ (state->m_expectedInternalCollision.empty (),
false,
"Have expected internal collisions");
486 if (!state->m_expectedInternalCollision.empty ())
490 NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.at), "Expected internal collision time is now");
491 state->StartBackoffNow (expected.nSlots);
495 template <typename TxopType>
501 if (!state->m_expectedBackoff.empty ())
506 state->StartBackoffNow (expected.nSlots);
510 template <typename TxopType>
515 if (!state->m_expectedGrants.empty ())
517 std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
518 state->m_expectedGrants.pop_front ();
521 state->Txop::m_access = Txop::NOT_REQUESTED;
524 template <
typename TxopType>
529 struct TxopTest<TxopType>::ExpectedBackoff col;
535 template <typename TxopType>
540 struct TxopTest<TxopType>::ExpectedBackoff backoff;
542 backoff.nSlots = nSlots;
546 template <typename TxopType>
554 template <
typename TxopType>
561 template <
typename TxopType>
565 m_ChannelAccessManager = CreateObject<ChannelAccessManagerStub> ();
566 m_feManager = CreateObject<FrameExchangeManagerStub<TxopType>> (
this);
567 m_ChannelAccessManager->SetupFrameExchangeManager (m_feManager);
568 m_ChannelAccessManager->SetSlot (
MicroSeconds (slotTime));
570 m_ChannelAccessManager->SetEifsNoDifs (
MicroSeconds (eifsNoDifsNoSifs + sifs));
571 m_ackTimeoutValue = ackTimeoutValue;
574 template <
typename TxopType>
579 txop->SetAifsn (aifsn);
580 m_txop.push_back (txop);
581 txop->SetChannelAccessManager (m_ChannelAccessManager);
584 template <
typename TxopType>
590 for (
typename TxopTests::const_iterator i = m_txop.begin (); i != m_txop.end (); i++)
594 NS_TEST_EXPECT_MSG_EQ (state->m_expectedInternalCollision.empty (),
true,
"Have no internal collisions");
601 m_ChannelAccessManager->Dispose ();
602 m_ChannelAccessManager = 0;
604 Simulator::Destroy ();
607 template <
typename TxopType>
612 &ChannelAccessManager::NotifyRxStartNow, m_ChannelAccessManager,
615 &ChannelAccessManager::NotifyRxEndOkNow, m_ChannelAccessManager);
618 template <
typename TxopType>
623 &ChannelAccessManager::NotifyRxStartNow, m_ChannelAccessManager,
627 template <
typename TxopType>
632 &ChannelAccessManager::NotifyRxStartNow, m_ChannelAccessManager,
635 &ChannelAccessManager::NotifyRxEndErrorNow, m_ChannelAccessManager);
638 template <
typename TxopType>
643 &ChannelAccessManager::NotifyRxStartNow, m_ChannelAccessManager,
646 &ChannelAccessManager::NotifyRxEndErrorNow, m_ChannelAccessManager);
650 template <
typename TxopType>
655 &ChannelAccessManager::NotifyNavResetNow, m_ChannelAccessManager,
659 template <
typename TxopType>
664 &ChannelAccessManager::NotifyNavStartNow, m_ChannelAccessManager,
668 template <
typename TxopType>
673 &ChannelAccessManager::NotifyAckTimeoutResetNow, m_ChannelAccessManager);
676 template <
typename TxopType>
679 uint64_t expectedGrantTime, uint32_t from)
681 AddAccessRequestWithSuccessfullAck (at, txTime, expectedGrantTime, 0, from);
684 template <
typename TxopType>
687 uint64_t expectedGrantTime, uint32_t from)
691 txTime, expectedGrantTime, m_txop[from]);
694 template <
typename TxopType>
697 uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from)
699 NS_ASSERT (ackDelay < m_ackTimeoutValue);
702 txTime, expectedGrantTime, m_txop[from]);
703 AddAckTimeoutReset (expectedGrantTime + txTime + ackDelay);
706 template <
typename TxopType>
711 if (m_ChannelAccessManager->NeedBackoffUponAccess (state))
713 state->GenerateBackoff ();
715 state->QueueTx (txTime, expectedGrantTime);
716 m_ChannelAccessManager->RequestAccess (state);
719 template <
typename TxopType>
724 &ChannelAccessManager::NotifyMaybeCcaBusyStartNow, m_ChannelAccessManager,
728 template <
typename TxopType>
733 &ChannelAccessManager::NotifySwitchingStartNow, m_ChannelAccessManager,
737 template <
typename TxopType>
742 &ChannelAccessManager::NotifyRxStartNow, m_ChannelAccessManager,
757 StartTest (1, 3, 10);
759 AddAccessRequest (1, 1, 5, 0);
760 AddAccessRequest (8, 2, 12, 0);
769 StartTest (1, 3, 10);
771 AddAccessRequest (1, 1, 5, 0);
772 AddRxInsideSifsEvt (7, 10);
774 AddAccessRequest (14, 2, 18, 0);
786 StartTest (4, 6, 10);
790 AddAccessRequest (30, 2, 118, 0);
791 ExpectBackoff (30, 4, 0);
800 StartTest (4, 6, 10);
803 AddAccessRequest (30, 2, 70, 0);
804 ExpectBackoff (30, 0, 0);
813 StartTest (4, 6, 10);
817 AddAccessRequest (30, 2, 110, 0);
818 ExpectBackoff (30, 0, 0);
826 StartTest (4, 6, 10);
829 AddAccessRequest (62, 2, 72, 0);
837 StartTest (4, 6, 10);
840 AddAccessRequest (70, 2, 80, 0);
849 StartTest (4, 6, 10);
851 AddRxErrorEvt (20, 40);
852 AddAccessRequest (30, 2, 102, 0);
853 ExpectBackoff (30, 4, 0);
863 StartTest (4, 6, 10);
865 AddRxErrorEvt (20, 40);
866 AddAccessRequest (70, 2, 86, 0);
875 StartTest (4, 6, 10);
877 AddRxErrorEvt (20, 40, 20);
878 ExpectBusy (41,
true);
879 ExpectBusy (59,
true);
880 ExpectBusy (61,
false);
889 StartTest (4, 6, 10);
891 AddRxErrorEvt (20, 40);
892 AddAccessRequest (30, 2, 101, 0);
893 ExpectBackoff (30, 4, 0);
904 StartTest (4, 6, 10);
908 AddAccessRequest (30, 10, 78, 0);
909 ExpectBackoff (30, 2, 0);
910 AddAccessRequest (40, 2, 110, 1);
911 ExpectBackoff (40, 0, 1);
912 ExpectInternalCollision (78, 1, 1);
922 StartTest (4, 6, 10);
925 AddAccessRequestWithAckTimeout (20, 20, 34, 1);
926 AddAccessRequest (64, 10, 80, 0);
938 StartTest (4, 6, 10);
941 AddAccessRequestWithSuccessfullAck (20, 20, 34, 2, 1);
942 AddAccessRequest (55, 10, 62, 0);
949 StartTest (4, 6, 10);
951 AddAccessRequest (20, 20, 34, 0);
953 AddAccessRequest (61, 10, 80, 0);
954 ExpectBackoff (61, 1, 0);
960 StartTest (4, 6, 10);
963 AddNavStart (60, 15);
966 AddAccessRequest (30, 10, 93, 0);
967 ExpectBackoff (30, 2, 0);
973 StartTest (4, 6, 10);
976 AddNavStart (60, 15);
979 AddAccessRequest (30, 10, 91, 0);
980 ExpectBackoff (30, 2, 0);
987 StartTest (4, 6, 10);
990 AddAccessRequest (80, 10, 94, 0);
994 StartTest (4, 6, 10);
998 AddAccessRequest (30, 50, 108, 0);
999 ExpectBackoff (30, 3, 0);
1008 StartTest (1, 3, 10);
1010 AddSwitchingEvt (0, 20);
1011 AddAccessRequest (21, 1, 25, 0);
1019 StartTest (1, 3, 10);
1021 AddSwitchingEvt (20,20);
1022 AddCcaBusyEvt (30,20);
1023 ExpectBackoff (45, 2, 0);
1024 AddAccessRequest (45, 1, 56, 0);
1031 StartTest (1, 3, 10);
1033 AddRxStartEvt (20, 40);
1034 AddSwitchingEvt (30, 20);
1035 AddAccessRequest (51, 1, 55, 0);
1042 StartTest (1, 3, 10);
1044 AddCcaBusyEvt (20, 40);
1045 AddSwitchingEvt (30, 20);
1046 AddAccessRequest (51, 1, 55, 0);
1053 StartTest (1, 3, 10);
1055 AddNavStart (20,40);
1056 AddSwitchingEvt (30,20);
1057 AddAccessRequest (51, 1, 55, 0);
1065 StartTest (1, 3, 10);
1067 AddAccessRequestWithAckTimeout (20, 20, 24, 0);
1068 AddAccessRequest (49, 1, 54, 0);
1069 AddSwitchingEvt (54, 5);
1070 AddAccessRequest (60, 1, 64, 0);
1078 StartTest (4, 6, 10);
1081 AddAccessRequest (30, 2, 80, 0);
1082 ExpectBackoff (30, 4, 0);
1083 AddSwitchingEvt (80,20);
1084 AddAccessRequest (101, 2, 111, 0);
1100 StartTest (4, 6, 10);
1102 AddRxOkEvt (20, 30);
1103 AddAccessRequest (52, 20, 60, 0);
1111 StartTest (4, 6, 10);
1113 AddRxOkEvt (20, 30);
1114 AddAccessRequest (58, 20, 60, 0);
1122 StartTest (4, 6, 10);
1124 AddRxOkEvt (20, 30);
1125 AddAccessRequest (62, 20, 64, 0);
1134 StartTest (4, 6, 10);
1136 AddRxErrorEvt (20, 30);
1137 AddAccessRequest (55, 20, 76, 0);
1146 StartTest (4, 6, 10);
1148 AddRxErrorEvt (20, 30);
1149 AddAccessRequest (70, 20, 76, 0);
1158 StartTest (4, 6, 10);
1160 AddRxErrorEvt (20, 30);
1161 AddAccessRequest (82, 20, 84, 0);
1170 StartTest (4, 6, 10);
1172 AddRxOkEvt (20, 30);
1173 AddAccessRequest (30, 20, 76, 0);
1174 ExpectBackoff (30, 4, 0);
1183 StartTest (4, 6, 10);
1185 AddRxOkEvt (20, 30);
1186 AddRxOkEvt (61, 10);
1187 AddRxOkEvt (87, 10);
1188 AddAccessRequest (30, 20, 107, 0);
1189 ExpectBackoff (30, 3, 0);