22 #include "ns3/simulator.h" 23 #include "ns3/channel-access-manager.h" 24 #include "ns3/qos-txop.h" 25 #include "ns3/mac-low.h" 29 template <
typename TxopType>
38 template <
typename TxopType>
55 void QueueTx (uint64_t txTime, uint64_t expectedGrantTime);
62 void DoDispose (
void);
82 bool IsAccessRequested (
void)
const;
86 void NotifyAccessRequested (
void);
90 void NotifyAccessGranted (
void);
94 void NotifyInternalCollision (
void);
98 void GenerateBackoff (
void);
103 bool HasFramesToTransmit (
void);
107 void NotifyChannelSwitching (
void);
112 void NotifySleep (
void);
116 void NotifyWakeUp (
void);
184 m_eifsNoDifs = eifsNoDifs;
215 template <
typename TxopType>
220 virtual void DoRun (
void);
226 void NotifyAccessGranted (uint32_t i);
231 void NotifyInternalCollision (uint32_t i);
236 void GenerateBackoff (uint32_t i);
241 void NotifyChannelSwitching (uint32_t i);
252 void StartTest (uint64_t slotTime, uint64_t sifs, uint64_t eifsNoDifsNoSifs, uint32_t ackTimeoutValue = 20);
257 void AddTxop (uint32_t aifsn);
266 void ExpectInternalCollision (uint64_t time, uint32_t nSlots, uint32_t from);
273 void ExpectBackoff (uint64_t time, uint32_t nSlots, uint32_t from);
279 void ExpectBusy (uint64_t time,
bool busy);
284 void DoCheckBusy (
bool busy);
290 void AddRxOkEvt (uint64_t at, uint64_t duration);
296 void AddRxErrorEvt (uint64_t at, uint64_t duration);
303 void AddRxErrorEvt (uint64_t at, uint64_t duration, uint64_t timeUntilError);
309 void AddRxInsideSifsEvt (uint64_t at, uint64_t duration);
315 void AddTxEvt (uint64_t at, uint64_t duration);
321 void AddNavReset (uint64_t at, uint64_t duration);
327 void AddNavStart (uint64_t at, uint64_t duration);
332 void AddAckTimeoutReset (uint64_t at);
340 void AddAccessRequest (uint64_t at, uint64_t txTime,
341 uint64_t expectedGrantTime, uint32_t from);
349 void AddAccessRequestWithAckTimeout (uint64_t at, uint64_t txTime,
350 uint64_t expectedGrantTime, uint32_t from);
359 void AddAccessRequestWithSuccessfullAck (uint64_t at, uint64_t txTime,
360 uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from);
373 void AddCcaBusyEvt (uint64_t at, uint64_t duration);
379 void AddSwitchingEvt (uint64_t at, uint64_t duration);
385 void AddRxStartEvt (uint64_t at, uint64_t duration);
395 template <
typename TxopType>
399 m_expectedGrants.push_back (std::make_pair (txTime, expectedGrantTime));
402 template <
typename TxopType>
406 m_accessRequested (false)
410 template <
typename TxopType>
418 template <
typename TxopType>
422 return m_accessRequested;
425 template <
typename TxopType>
429 m_accessRequested =
true;
432 template <
typename TxopType>
436 m_accessRequested =
false;
437 m_test->NotifyAccessGranted (m_i);
440 template <
typename TxopType>
444 m_test->NotifyInternalCollision (m_i);
447 template <
typename TxopType>
451 m_test->GenerateBackoff (m_i);
454 template <
typename TxopType>
458 return !m_expectedGrants.empty ();
461 template <
typename TxopType>
465 m_test->NotifyChannelSwitching (m_i);
468 template <
typename TxopType>
474 template <
typename TxopType>
480 template <
typename TxopType>
486 template <
typename TxopType>
492 if (!state->m_expectedGrants.empty ())
494 std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
495 state->m_expectedGrants.pop_front ();
497 m_ChannelAccessManager->NotifyTxStartNow (
MicroSeconds (expected.first));
498 m_ChannelAccessManager->NotifyAckTimeoutStartNow (
MicroSeconds (m_ackTimeoutValue + expected.first));
502 template <
typename TxopType>
507 &ChannelAccessManager::NotifyTxStartNow, m_ChannelAccessManager,
511 template <
typename TxopType>
516 NS_TEST_EXPECT_MSG_EQ (state->m_expectedInternalCollision.empty (),
false,
"Have expected internal collisions");
517 if (!state->m_expectedInternalCollision.empty ())
521 NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.at), "Expected internal collision time is now");
522 state->StartBackoffNow (expected.nSlots);
526 template <typename TxopType>
532 if (!state->m_expectedBackoff.empty ())
537 state->StartBackoffNow (expected.nSlots);
541 template <typename TxopType>
546 if (!state->m_expectedGrants.empty ())
548 std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
549 state->m_expectedGrants.pop_front ();
552 state->m_accessRequested =
false;
555 template <
typename TxopType>
560 struct TxopTest<TxopType>::ExpectedBackoff col;
566 template <typename TxopType>
571 struct TxopTest<TxopType>::ExpectedBackoff backoff;
573 backoff.nSlots = nSlots;
577 template <typename TxopType>
585 template <
typename TxopType>
592 template <
typename TxopType>
596 m_ChannelAccessManager = CreateObject<ChannelAccessManagerStub> ();
597 m_low = CreateObject<MacLowStub> ();
598 m_ChannelAccessManager->SetupLow (m_low);
599 m_ChannelAccessManager->SetSlot (
MicroSeconds (slotTime));
601 m_ChannelAccessManager->SetEifsNoDifs (
MicroSeconds (eifsNoDifsNoSifs + sifs));
602 m_ackTimeoutValue = ackTimeoutValue;
605 template <
typename TxopType>
610 txop->SetAifsn (aifsn);
611 m_txop.push_back (txop);
612 txop->SetChannelAccessManager (m_ChannelAccessManager);
613 txop->SetMacLow (m_low);
616 template <
typename TxopType>
621 Simulator::Destroy ();
623 for (
typename TxopTests::const_iterator i = m_txop.begin (); i != m_txop.end (); i++)
627 NS_TEST_EXPECT_MSG_EQ (state->m_expectedInternalCollision.empty (),
true,
"Have no internal collisions");
634 m_ChannelAccessManager = 0;
638 template <
typename TxopType>
643 &ChannelAccessManager::NotifyRxStartNow, m_ChannelAccessManager,
646 &ChannelAccessManager::NotifyRxEndOkNow, m_ChannelAccessManager);
649 template <
typename TxopType>
654 &ChannelAccessManager::NotifyRxStartNow, m_ChannelAccessManager,
658 template <
typename TxopType>
663 &ChannelAccessManager::NotifyRxStartNow, m_ChannelAccessManager,
666 &ChannelAccessManager::NotifyRxEndErrorNow, m_ChannelAccessManager);
669 template <
typename TxopType>
674 &ChannelAccessManager::NotifyRxStartNow, m_ChannelAccessManager,
677 &ChannelAccessManager::NotifyRxEndErrorNow, m_ChannelAccessManager);
681 template <
typename TxopType>
686 &ChannelAccessManager::NotifyNavResetNow, m_ChannelAccessManager,
690 template <
typename TxopType>
695 &ChannelAccessManager::NotifyNavStartNow, m_ChannelAccessManager,
699 template <
typename TxopType>
704 &ChannelAccessManager::NotifyAckTimeoutResetNow, m_ChannelAccessManager);
707 template <
typename TxopType>
710 uint64_t expectedGrantTime, uint32_t from)
712 AddAccessRequestWithSuccessfullAck (at, txTime, expectedGrantTime, 0, from);
715 template <
typename TxopType>
718 uint64_t expectedGrantTime, uint32_t from)
722 txTime, expectedGrantTime, m_txop[from]);
725 template <
typename TxopType>
728 uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from)
730 NS_ASSERT (ackDelay < m_ackTimeoutValue);
733 txTime, expectedGrantTime, m_txop[from]);
734 AddAckTimeoutReset (expectedGrantTime + txTime + ackDelay);
737 template <
typename TxopType>
742 if (m_ChannelAccessManager->NeedBackoffUponAccess (state))
744 state->GenerateBackoff ();
746 state->QueueTx (txTime, expectedGrantTime);
747 m_ChannelAccessManager->RequestAccess (state);
750 template <
typename TxopType>
755 &ChannelAccessManager::NotifyMaybeCcaBusyStartNow, m_ChannelAccessManager,
759 template <
typename TxopType>
764 &ChannelAccessManager::NotifySwitchingStartNow, m_ChannelAccessManager,
768 template <
typename TxopType>
773 &ChannelAccessManager::NotifyRxStartNow, m_ChannelAccessManager,
788 StartTest (1, 3, 10);
790 AddAccessRequest (1, 1, 5, 0);
791 AddAccessRequest (8, 2, 12, 0);
800 StartTest (1, 3, 10);
802 AddAccessRequest (1, 1, 5, 0);
803 AddRxInsideSifsEvt (7, 10);
805 AddAccessRequest (14, 2, 18, 0);
817 StartTest (4, 6, 10);
821 AddAccessRequest (30, 2, 118, 0);
822 ExpectBackoff (30, 4, 0);
831 StartTest (4, 6, 10);
834 AddAccessRequest (30, 2, 70, 0);
835 ExpectBackoff (30, 0, 0);
844 StartTest (4, 6, 10);
848 AddAccessRequest (30, 2, 110, 0);
849 ExpectBackoff (30, 0, 0);
857 StartTest (4, 6, 10);
860 AddAccessRequest (62, 2, 72, 0);
868 StartTest (4, 6, 10);
871 AddAccessRequest (70, 2, 80, 0);
880 StartTest (4, 6, 10);
882 AddRxErrorEvt (20, 40);
883 AddAccessRequest (30, 2, 102, 0);
884 ExpectBackoff (30, 4, 0);
894 StartTest (4, 6, 10);
896 AddRxErrorEvt (20, 40);
897 AddAccessRequest (70, 2, 86, 0);
906 StartTest (4, 6, 10);
908 AddRxErrorEvt (20, 40, 20);
909 ExpectBusy (41,
true);
910 ExpectBusy (59,
true);
911 ExpectBusy (61,
false);
920 StartTest (4, 6, 10);
922 AddRxErrorEvt (20, 40);
923 AddAccessRequest (30, 2, 101, 0);
924 ExpectBackoff (30, 4, 0);
935 StartTest (4, 6, 10);
939 AddAccessRequest (30, 10, 78, 0);
940 ExpectBackoff (30, 2, 0);
941 AddAccessRequest (40, 2, 110, 1);
942 ExpectBackoff (40, 0, 1);
943 ExpectInternalCollision (78, 1, 1);
953 StartTest (4, 6, 10);
956 AddAccessRequestWithAckTimeout (20, 20, 34, 1);
957 AddAccessRequest (64, 10, 80, 0);
969 StartTest (4, 6, 10);
972 AddAccessRequestWithSuccessfullAck (20, 20, 34, 2, 1);
973 AddAccessRequest (55, 10, 62, 0);
980 StartTest (4, 6, 10);
982 AddAccessRequest (20, 20, 34, 0);
984 AddAccessRequest (61, 10, 80, 0);
985 ExpectBackoff (61, 1, 0);
991 StartTest (4, 6, 10);
994 AddNavStart (60, 15);
997 AddAccessRequest (30, 10, 93, 0);
998 ExpectBackoff (30, 2, 0);
1004 StartTest (4, 6, 10);
1006 AddRxOkEvt (20, 40);
1007 AddNavStart (60, 15);
1009 AddNavReset (71, 2);
1010 AddAccessRequest (30, 10, 91, 0);
1011 ExpectBackoff (30, 2, 0);
1018 StartTest (4, 6, 10);
1020 AddRxOkEvt (20, 40);
1021 AddAccessRequest (80, 10, 94, 0);
1025 StartTest (4, 6, 10);
1027 AddRxOkEvt (20, 40);
1029 AddAccessRequest (30, 50, 108, 0);
1030 ExpectBackoff (30, 3, 0);
1039 StartTest (1, 3, 10);
1041 AddSwitchingEvt (0, 20);
1042 AddAccessRequest (21, 1, 25, 0);
1050 StartTest (1, 3, 10);
1052 AddSwitchingEvt (20,20);
1053 AddCcaBusyEvt (30,20);
1054 ExpectBackoff (45, 2, 0);
1055 AddAccessRequest (45, 1, 56, 0);
1062 StartTest (1, 3, 10);
1064 AddRxStartEvt (20, 40);
1065 AddSwitchingEvt (30, 20);
1066 AddAccessRequest (51, 1, 55, 0);
1073 StartTest (1, 3, 10);
1075 AddCcaBusyEvt (20, 40);
1076 AddSwitchingEvt (30, 20);
1077 AddAccessRequest (51, 1, 55, 0);
1084 StartTest (1, 3, 10);
1086 AddNavStart (20,40);
1087 AddSwitchingEvt (30,20);
1088 AddAccessRequest (51, 1, 55, 0);
1096 StartTest (1, 3, 10);
1098 AddAccessRequestWithAckTimeout (20, 20, 24, 0);
1099 AddAccessRequest (49, 1, 54, 0);
1100 AddSwitchingEvt (54, 5);
1101 AddAccessRequest (60, 1, 64, 0);
1109 StartTest (4, 6, 10);
1112 AddAccessRequest (30, 2, 80, 0);
1113 ExpectBackoff (30, 4, 0);
1114 AddSwitchingEvt (80,20);
1115 AddAccessRequest (101, 2, 111, 0);
1131 StartTest (4, 6, 10);
1133 AddRxOkEvt (20, 30);
1134 AddAccessRequest (52, 20, 60, 0);
1142 StartTest (4, 6, 10);
1144 AddRxOkEvt (20, 30);
1145 AddAccessRequest (52, 20, 60, 0);
1153 StartTest (4, 6, 10);
1155 AddRxOkEvt (20, 30);
1156 AddAccessRequest (62, 20, 64, 0);
1165 StartTest (4, 6, 10);
1167 AddRxErrorEvt (20, 30);
1168 AddAccessRequest (55, 20, 76, 0);
1177 StartTest (4, 6, 10);
1179 AddRxErrorEvt (20, 30);
1180 AddAccessRequest (70, 20, 76, 0);
1189 StartTest (4, 6, 10);
1191 AddRxErrorEvt (20, 30);
1192 AddAccessRequest (82, 20, 84, 0);
1201 StartTest (4, 6, 10);
1203 AddRxOkEvt (20, 30);
1204 AddAccessRequest (30, 20, 76, 0);
1205 ExpectBackoff (30, 4, 0);
1214 StartTest (4, 6, 10);
1216 AddRxOkEvt (20, 30);
1217 AddRxOkEvt (61, 10);
1218 AddRxOkEvt (87, 10);
1219 AddAccessRequest (30, 20, 107, 0);
1220 ExpectBackoff (30, 3, 0);
Simulation virtual time values and global simulation resolution.
Smart pointer class similar to boost::intrusive_ptr.
ExpectedBackoffs m_expectedBackoff
expected backoff (not due to an internal collision)
TxopTest(ChannelAccessManagerTest< TxopType > *test, uint32_t i)
Constructor.
void AddSwitchingEvt(uint64_t at, uint64_t duration)
Add switching event function.
void AddRxOkEvt(uint64_t at, uint64_t duration)
Add receive OK event function.
Time GetSifs(void) const
Return the Short Interframe Space (SIFS) for this PHY.
std::list< struct ExpectedBackoff > ExpectedBackoffs
expected backoffs typedef
void AddNavStart(uint64_t at, uint64_t duration)
Add NAV start function.
std::list< ExpectedGrant > ExpectedGrants
the collection of expected grants typedef
bool IsCfPeriod(void) const
This function indicates whether Simulator::Now is in the CF period.
void AddAccessRequestWithSuccessfullAck(uint64_t at, uint64_t txTime, uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from)
Add access request with successful ack.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
void QueueTx(uint64_t txTime, uint64_t expectedGrantTime)
Queue transmit function.
void DoAccessRequest(uint64_t txTime, uint64_t expectedGrantTime, Ptr< TxopTest< TxopType >> state)
Add access request with successful Ack.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Manage a set of ns3::TxopHandle a set of independent ns3::Txop, each of which represents a single DCF...
void DoDispose(void)
Inherited.
static TxopTestSuite g_dcfTestSuite
TxopTests m_txop
the vector of Txop test instances
void SetSifs(Time sifs)
Set the Short Interframe Space (SIFS).
ChannelAccessManagerStub()
ExpectedGrants m_expectedGrants
expected grants
void AddTxop(uint32_t aifsn)
Add Txop function.
ExpectedBackoff structure.
bool IsAccessRequested(void) const
void NotifyAccessRequested(void)
Notify that access request has been received.
void NotifyChannelSwitching(void)
When a channel switching occurs, enqueued packets are removed.
bool m_accessRequested
true if access requested
void AddCcaBusyEvt(uint64_t at, uint64_t duration)
Add CCA busy event function.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
static QosTxopTestSuite g_edcaTestSuite
std::vector< Ptr< TxopTest< TxopType > > > TxopTests
the TXOP tests typedef
uint32_t nSlots
number of slots
Channel Access Manager Test.
void AddRxStartEvt(uint64_t at, uint64_t duration)
Add receive start event function.
uint32_t m_ackTimeoutValue
the Ack timeout value
Time GetSlot(void) const
Return the slot duration for this PHY.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void AddAckTimeoutReset(uint64_t at)
Add Ack timeout reset function.
void NotifyAccessGranted(uint32_t i)
Notify access granted function.
void SetEifsNoDifs(Time eifsNoDifs)
Set the duration of EIFS - DIFS.
void AddTxEvt(uint64_t at, uint64_t duration)
Add transmit event function.
void EndTest(void)
End test function.
std::pair< uint64_t, uint64_t > ExpectedGrant
the expected grant typedef
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ChannelAccessManager Stub.
void NotifyInternalCollision(void)
Notify the Txop that internal collision has occurred.
Time GetEifsNoDifs(void) const
Return the EIFS duration minus a DIFS.
Ptr< ChannelAccessManagerStub > m_ChannelAccessManager
the channel access manager
void NotifyAccessGranted(void)
Notify the Txop that access has been granted.
handle RTS/CTS/Data/Ack transactions.
void AddRxInsideSifsEvt(uint64_t at, uint64_t duration)
Add receive inside SIFS event function.
void NotifyWakeUp(void)
When wake up operation occurs, channel access will be restarted.
void AddRxErrorEvt(uint64_t at, uint64_t duration)
Add receive error event function for error at end of frame.
uint32_t m_i
the index of the Txop
void ExpectInternalCollision(uint64_t time, uint32_t nSlots, uint32_t from)
Expect internal collision function.
Ptr< MacLowStub > m_low
the MAC low stubbed
void NotifySleep(void)
When sleep operation occurs, if there is a pending packet transmission, it will be reinserted to the ...
void DoCheckBusy(bool busy)
Perform check that channel access manager is busy or idle.
ChannelAccessManagerTest()
void NotifyInternalCollision(uint32_t i)
Notify internal collision function.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
void GenerateBackoff(void)
Generate a new backoff now.
void AddAccessRequestWithAckTimeout(uint64_t at, uint64_t txTime, uint64_t expectedGrantTime, uint32_t from)
Add access request with Ack timeout.
ExpectedBackoffs m_expectedInternalCollision
expected backoff due to an internal collision
void AddAccessRequest(uint64_t at, uint64_t txTime, uint64_t expectedGrantTime, uint32_t from)
Add access function.
void StartTest(uint64_t slotTime, uint64_t sifs, uint64_t eifsNoDifsNoSifs, uint32_t ackTimeoutValue=20)
Start test function.
ChannelAccessManagerTest< TxopType > * m_test
the test DCF/EDCA manager
void SetSlot(Time slot)
Set the slot duration.
void AddNavReset(uint64_t at, uint64_t duration)
Add NAV reset function.
bool HasFramesToTransmit(void)
Check if the Txop has frames to transmit.