Skip to content

Commit de2c14a

Browse files
author
Stefano Avallone
committed
wifi: Add test cases to check backoff after sleep/off period
1 parent 1ae62e6 commit de2c14a

File tree

1 file changed

+117
-29
lines changed

1 file changed

+117
-29
lines changed

src/wifi/test/channel-access-manager-test.cc

Lines changed: 117 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ class TxopTest : public TxopType
7676
void NotifyChannelAccessed(uint8_t linkId, Time txopDuration = Seconds(0)) override;
7777
/// @copydoc ns3::Txop::HasFramesToTransmit
7878
bool HasFramesToTransmit(uint8_t linkId) override;
79-
/// @copydoc ns3::Txop::NotifySleep
80-
void NotifySleep(uint8_t linkId) override;
81-
/// @copydoc ns3::Txop::NotifyWakeUp
82-
void NotifyWakeUp(uint8_t linkId) override;
8379
/// @copydoc ns3::Txop::GenerateBackoff
8480
void GenerateBackoff(uint8_t linkId) override;
8581

@@ -117,8 +113,18 @@ class TxopTest : public TxopType
117113
class ChannelAccessManagerStub : public ChannelAccessManager
118114
{
119115
public:
120-
ChannelAccessManagerStub()
116+
/**
117+
* @brief Get the type ID.
118+
* @return the object TypeId
119+
*/
120+
static TypeId GetTypeId()
121121
{
122+
static TypeId tid = TypeId("ns3::ChannelAccessManagerStub")
123+
.SetParent<ns3::ChannelAccessManager>()
124+
.SetGroupName("Wifi")
125+
.AddConstructor<ChannelAccessManagerStub>()
126+
.HideFromDocumentation();
127+
return tid;
122128
}
123129

124130
/**
@@ -240,6 +246,7 @@ class ChannelAccessManagerTest : public TestCase
240246
uint64_t eifsNoDifsNoSifs{10}; ///< the EIFS no DIFS no SIFS in microseconds
241247
uint32_t ackTimeoutValue{20}; ///< the Ack timeout value in microseconds
242248
MHz_u chWidth{20}; ///< the channel width
249+
uint64_t resetBackoffThr{}; ///< reset backoff threshold
243250
};
244251

245252
ChannelAccessManagerTest();
@@ -420,10 +427,9 @@ class ChannelAccessManagerTest : public TestCase
420427
*
421428
* @param at the event time
422429
* @param duration the duration of the interval during which no PHY is connected
423-
* @param threshold the value for the ResetBackoffThreshold attribute
424430
* @param from the index of the Txop that has to request channel access when PHY is reconnected
425431
*/
426-
void AddPhyDisconnectEvt(uint64_t at, uint64_t duration, uint64_t threshold, uint32_t from);
432+
void AddPhyDisconnectEvt(uint64_t at, uint64_t duration, uint32_t from);
427433

428434
/**
429435
* Add a PHY reconnect event consisting in another PHY operating on the link for the given time.
@@ -433,6 +439,22 @@ class ChannelAccessManagerTest : public TestCase
433439
*/
434440
void AddPhyReconnectEvt(uint64_t at, uint64_t duration);
435441

442+
/**
443+
* Add PHY sleep/resume events.
444+
*
445+
* @param at the event time
446+
* @param duration the duration of the interval during which the PHY is in sleep state
447+
*/
448+
void AddPhySleepEvt(uint64_t at, uint64_t duration);
449+
450+
/**
451+
* Add PHY off/on events.
452+
*
453+
* @param at the event time
454+
* @param duration the duration of the interval during which the PHY is in off state
455+
*/
456+
void AddPhyOffEvt(uint64_t at, uint64_t duration);
457+
436458
typedef std::vector<Ptr<TxopTest<TxopType>>> TxopTests; //!< the TXOP tests typedef
437459

438460
Ptr<FrameExchangeManagerStub<TxopType>> m_feManager; //!< the Frame Exchange Manager stubbed
@@ -486,18 +508,6 @@ TxopTest<TxopType>::HasFramesToTransmit(uint8_t linkId)
486508
return !m_expectedGrants.empty();
487509
}
488510

489-
template <typename TxopType>
490-
void
491-
TxopTest<TxopType>::NotifySleep(uint8_t linkId)
492-
{
493-
}
494-
495-
template <typename TxopType>
496-
void
497-
TxopTest<TxopType>::NotifyWakeUp(uint8_t linkId)
498-
{
499-
}
500-
501511
template <typename TxopType>
502512
ChannelAccessManagerTest<TxopType>::ChannelAccessManagerTest()
503513
: TestCase("ChannelAccessManager")
@@ -632,7 +642,9 @@ template <typename TxopType>
632642
void
633643
ChannelAccessManagerTest<TxopType>::StartTest(const Params& params)
634644
{
635-
m_ChannelAccessManager = CreateObject<ChannelAccessManagerStub>();
645+
m_ChannelAccessManager = CreateObjectWithAttributes<ChannelAccessManagerStub>(
646+
"ResetBackoffThreshold",
647+
TimeValue(MicroSeconds(params.resetBackoffThr)));
636648
m_feManager = CreateObject<FrameExchangeManagerStub<TxopType>>(this);
637649
m_ChannelAccessManager->SetupFrameExchangeManager(m_feManager);
638650
m_ChannelAccessManager->SetSlot(MicroSeconds(params.slotTime));
@@ -662,7 +674,8 @@ ChannelAccessManagerTest<TxopType>::AddTxop(uint32_t aifsn)
662674
auto mac = CreateObjectWithAttributes<AdhocWifiMac>(
663675
"Txop",
664676
PointerValue(CreateObjectWithAttributes<Txop>("AcIndex", StringValue("AC_BE_NQOS"))));
665-
mac->SetWifiPhys({nullptr});
677+
mac->SetWifiPhys({m_phy});
678+
mac->SetChannelAccessManagers({m_ChannelAccessManager});
666679
txop->SetWifiMac(mac);
667680
txop->SetAifsn(aifsn);
668681
}
@@ -908,11 +921,10 @@ template <typename TxopType>
908921
void
909922
ChannelAccessManagerTest<TxopType>::AddPhyDisconnectEvt(uint64_t at,
910923
uint64_t duration,
911-
uint64_t threshold,
912924
uint32_t from)
913925
{
914-
m_ChannelAccessManager->SetAttribute("ResetBackoffThreshold",
915-
TimeValue(MicroSeconds(threshold)));
926+
TimeValue threshold;
927+
m_ChannelAccessManager->GetAttribute("ResetBackoffThreshold", threshold);
916928

917929
Simulator::Schedule(MicroSeconds(at) - Now(),
918930
&ChannelAccessManager::RemovePhyListener,
@@ -923,7 +935,7 @@ ChannelAccessManagerTest<TxopType>::AddPhyDisconnectEvt(uint64_t at,
923935
auto txop = m_txop[from];
924936
auto hadFramesToTransmit = txop->HasFramesToTransmit(SINGLE_LINK_OP_ID);
925937
m_ChannelAccessManager->SetupPhyListener(m_phy);
926-
if (duration > threshold)
938+
if (MicroSeconds(duration) > threshold.Get())
927939
{
928940
// request channel access again because all backoffs have been reset
929941
if (m_ChannelAccessManager->NeedBackoffUponAccess(txop, hadFramesToTransmit, true))
@@ -958,6 +970,22 @@ ChannelAccessManagerTest<TxopType>::AddPhyReconnectEvt(uint64_t at, uint64_t dur
958970
});
959971
}
960972

973+
template <typename TxopType>
974+
void
975+
ChannelAccessManagerTest<TxopType>::AddPhySleepEvt(uint64_t at, uint64_t duration)
976+
{
977+
Simulator::Schedule(MicroSeconds(at) - Now(), &WifiPhy::SetSleepMode, m_phy, false);
978+
Simulator::Schedule(MicroSeconds(at + duration) - Now(), &WifiPhy::ResumeFromSleep, m_phy);
979+
}
980+
981+
template <typename TxopType>
982+
void
983+
ChannelAccessManagerTest<TxopType>::AddPhyOffEvt(uint64_t at, uint64_t duration)
984+
{
985+
Simulator::Schedule(MicroSeconds(at) - Now(), &WifiPhy::SetOffMode, m_phy);
986+
Simulator::Schedule(MicroSeconds(at + duration) - Now(), &WifiPhy::ResumeFromOff, m_phy);
987+
}
988+
961989
/*
962990
* Specialization of DoRun () method for DCF
963991
*/
@@ -1489,12 +1517,12 @@ ChannelAccessManagerTest<QosTxop>::DoRun()
14891517
// | | |
14901518
// 30 request access. decrement reset
14911519
// backoff slots: 3 slots: 2 backoff
1492-
StartTest({.slotTime = 4, .sifs = 6});
1520+
StartTest({.slotTime = 4, .sifs = 6, .resetBackoffThr = 5});
14931521
AddTxop(1);
14941522
AddRxOkEvt(20, 30);
14951523
AddAccessRequest(30, 20, 81, 0);
14961524
ExpectBackoff(30, 3, 0);
1497-
AddPhyDisconnectEvt(61, 10, 0, 0);
1525+
AddPhyDisconnectEvt(61, 10, 0);
14981526
EndTest();
14991527

15001528
// Check backoff freeze while no PHY operates on a link for less than the threshold.
@@ -1503,12 +1531,12 @@ ChannelAccessManagerTest<QosTxop>::DoRun()
15031531
// | | | | |
15041532
// 30 request access. decrement resume decrement decrement
15051533
// backoff slots: 3 slots: 2 backoff slots: 1 slots: 0
1506-
StartTest({.slotTime = 4, .sifs = 6});
1534+
StartTest({.slotTime = 4, .sifs = 6, .resetBackoffThr = 20});
15071535
AddTxop(1);
15081536
AddRxOkEvt(20, 30);
15091537
AddAccessRequest(30, 20, 89, 0);
15101538
ExpectBackoff(30, 3, 0);
1511-
AddPhyDisconnectEvt(61, 10, 20, 0);
1539+
AddPhyDisconnectEvt(61, 10, 0);
15121540
EndTest();
15131541

15141542
// Check backoff left unmodified when previous PHY is reconnected to the link
@@ -1525,6 +1553,66 @@ ChannelAccessManagerTest<QosTxop>::DoRun()
15251553
ExpectBackoff(30, 4, 0);
15261554
AddPhyReconnectEvt(61, 10);
15271555
EndTest();
1556+
1557+
// Check reset of backoff and generation of new backoff value after that PHY is put to sleep for
1558+
// more than the threshold.
1559+
// 20 50 56 60 63 73 79 83 87 91 95 115
1560+
// | rx | sifs | aifsn | idle | phy sleep | sifs | aifsn | idle | idle | idle | tx |
1561+
// | | | | | |
1562+
// 30 request access. decrement reset backoff decrement decrement decrement
1563+
// backoff slots: 3 slots: 2 backoff slots: 3 slots: 2 slots: 1 slots: 0
1564+
StartTest({.slotTime = 4, .sifs = 6, .resetBackoffThr = 5});
1565+
AddTxop(1);
1566+
AddRxOkEvt(20, 30);
1567+
AddAccessRequest(30, 20, 95, 0);
1568+
ExpectBackoff(30, 3, 0);
1569+
AddPhySleepEvt(63, 10);
1570+
ExpectBackoff(73, 3, 0);
1571+
EndTest();
1572+
1573+
// Check backoff freeze while PHY is put to sleep for less than the threshold.
1574+
// 20 50 56 60 61 71 77 81 85 89 109
1575+
// | rx | sifs | aifsn | idle | phy sleep | sifs | aifsn | idle | idle | tx |
1576+
// | | | | |
1577+
// 30 request access. decrement resume decrement decrement
1578+
// backoff slots: 3 slots: 2 backoff slots: 1 slots: 0
1579+
StartTest({.slotTime = 4, .sifs = 6, .resetBackoffThr = 20});
1580+
AddTxop(1);
1581+
AddRxOkEvt(20, 30);
1582+
AddAccessRequest(30, 20, 89, 0);
1583+
ExpectBackoff(30, 3, 0);
1584+
AddPhySleepEvt(61, 10);
1585+
EndTest();
1586+
1587+
// Check reset of backoff and generation of new backoff value after that PHY is put to off for
1588+
// more than the threshold.
1589+
// 20 50 56 60 61 71 77 81 85 89 93 113
1590+
// | rx | sifs | aifsn | idle | phy off | sifs | aifsn | idle | idle | idle | tx |
1591+
// | | | | | |
1592+
// 30 request access. decrement reset backoff decrement decrement decrement
1593+
// backoff slots: 3 slots: 2 backoff slots: 3 slots: 2 slots: 1 slots: 0
1594+
StartTest({.slotTime = 4, .sifs = 6, .resetBackoffThr = 5});
1595+
AddTxop(1);
1596+
AddRxOkEvt(20, 30);
1597+
AddAccessRequest(30, 20, 93, 0);
1598+
ExpectBackoff(30, 3, 0);
1599+
AddPhyOffEvt(61, 10);
1600+
ExpectBackoff(71, 3, 0);
1601+
EndTest();
1602+
1603+
// Check backoff freeze while PHY is put to off for less than the threshold.
1604+
// 20 50 56 60 63 73 79 83 87 91 111
1605+
// | rx | sifs | aifsn | idle | phy off | sifs | aifsn | idle | idle | tx |
1606+
// | | | | |
1607+
// 30 request access. decrement resume decrement decrement
1608+
// backoff slots: 3 slots: 2 backoff slots: 1 slots: 0
1609+
StartTest({.slotTime = 4, .sifs = 6, .resetBackoffThr = 20});
1610+
AddTxop(1);
1611+
AddRxOkEvt(20, 30);
1612+
AddAccessRequest(30, 20, 91, 0);
1613+
ExpectBackoff(30, 3, 0);
1614+
AddPhyOffEvt(63, 10);
1615+
EndTest();
15281616
}
15291617

15301618
/**

0 commit comments

Comments
 (0)