22 #include "ns3/string.h" 23 #include "ns3/qos-utils.h" 24 #include "ns3/packet.h" 25 #include "ns3/wifi-net-device.h" 26 #include "ns3/wifi-mac-header.h" 27 #include "ns3/mobility-helper.h" 28 #include "ns3/spectrum-wifi-helper.h" 29 #include "ns3/single-model-spectrum-channel.h" 30 #include "ns3/packet-socket-server.h" 31 #include "ns3/packet-socket-client.h" 32 #include "ns3/packet-socket-helper.h" 33 #include "ns3/config.h" 34 #include "ns3/pointer.h" 35 #include "ns3/rng-seed-manager.h" 36 #include "ns3/wifi-psdu.h" 37 #include "ns3/wifi-ppdu.h" 38 #include "ns3/ap-wifi-mac.h" 79 void CheckResults (
void);
82 void DoRun (
void)
override;
105 :
TestCase (
"Check correct operation within TXOPs"),
109 m_pifsRecovery (pifsRecovery)
131 if (!psduMap.begin ()->second->GetHeader (0).IsBeacon ()
136 psduMap[
SU_STA_ID]->GetHeader (0), txVector});
140 std::cout <<
Simulator::Now () <<
" " << psduMap.begin ()->second->GetHeader (0).GetTypeString ()
141 <<
" seq " << psduMap.begin ()->second->GetHeader (0).GetSequenceNumber ()
142 <<
" to " << psduMap.begin ()->second->GetAddr1 ()
143 <<
" TX duration " << WifiPhy::CalculateTxDuration (psduMap, txVector,
WIFI_PHY_BAND_5GHZ)
144 <<
" duration/ID " << psduMap.begin ()->second->GetHeader (0).GetDuration () << std::endl;
150 RngSeedManager::SetSeed (1);
151 RngSeedManager::SetRun (40);
152 int64_t streamNumber = 100;
167 phy.SetChannel (spectrumChannel);
174 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
179 mac.SetType (
"ns3::StaWifiMac",
185 mac.SetType (
"ns3::ApWifiMac",
200 Simulator::Schedule (init + i *
MicroSeconds (102400), &WifiMac::SetSsid,
210 positionAlloc->
Add (Vector (0.0, 0.0, 0.0));
211 positionAlloc->
Add (Vector (1.0, 0.0, 0.0));
212 positionAlloc->
Add (Vector (0.0, 1.0, 0.0));
213 positionAlloc->
Add (Vector (-1.0, 0.0, 0.0));
214 mobility.SetPositionAllocator (positionAlloc);
216 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
223 dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
272 dev->
GetMac ()->GetWifiPhy ()->SetPostReceptionErrorModel (apPem);
279 dev->
GetMac ()->GetWifiPhy ()->SetPostReceptionErrorModel (sta2Pem);
304 Config::Connect (
"/NodeList/*/ApplicationList/*/$ns3::PacketSocketServer/Rx",
307 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxPsduBegin",
315 Simulator::Destroy ();
325 sifs = DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetPhy ()->GetSifs (),
326 slot = DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetPhy ()->GetSlot (),
330 auto RoundDurationId = [] (
Time t)
332 return MicroSeconds (ceil (static_cast<double> (t.GetNanoSeconds ()) / 1000));
362 "Expected a QoS data frame");
364 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
365 "Expected a frame sent by the AP to the first station");
368 "Duration/ID of the first frame must cover the whole TXOP");
375 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the first frame sent too late");
378 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
379 "Expected a Normal Ack sent to the AP");
381 RoundDurationId (
m_txPsdus[0].header.GetDuration () - sifs -
m_txPsdus[1].txDuration),
382 "Duration/ID of the Ack must be derived from that of the first frame");
393 "Less than AIFS elapsed between AckTimeout and the next TXOP start");
395 "More than AIFS+BO elapsed between AckTimeout and the next TXOP start");
397 "Expected to retransmit a QoS data frame");
399 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
400 "Expected to retransmit a frame to the first station");
403 "Duration/ID of the retransmitted frame must cover the whole TXOP");
410 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the first frame sent too late");
413 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
414 "Expected a Normal Ack sent to the AP");
416 RoundDurationId (
m_txPsdus[2].header.GetDuration () - sifs -
m_txPsdus[3].txDuration),
417 "Duration/ID of the Ack must be derived from that of the previous frame");
426 "Expected a QoS data frame");
428 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (1))->GetMac ()->GetAddress (),
429 "Expected a frame sent by the AP to the second station");
432 "Duration/ID of the second frame does not cover the remaining TXOP");
438 + sifs + slot + WifiPhy::CalculatePhyPreambleAndHeaderDuration (
m_txPsdus[4].txVector);
448 "Less than AIFS elapsed between AckTimeout and the next transmission");
450 "More than AIFS+BO elapsed between AckTimeout and the next TXOP start");
453 "Expected a QoS data frame");
455 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (1))->GetMac ()->GetAddress (),
456 "Expected a frame sent by the AP to the second station");
459 "Duration/ID of the second frame does not cover the remaining TXOP");
466 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the second frame sent too late");
469 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
470 "Expected a Normal Ack sent to the AP");
472 RoundDurationId (
m_txPsdus[5].header.GetDuration () - sifs -
m_txPsdus[6].txDuration),
473 "Duration/ID of the Ack must be derived from that of the previous frame");
482 "Expected a QoS data frame");
484 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (2))->GetMac ()->GetAddress (),
485 "Expected a frame sent by the AP to the third station");
488 "Duration/ID of the third frame does not cover the remaining TXOP");
495 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the third frame sent too late");
498 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
499 "Expected a Normal Ack sent to the AP");
501 RoundDurationId (
m_txPsdus[7].header.GetDuration () - sifs -
m_txPsdus[8].txDuration),
502 "Duration/ID of the Ack must be derived from that of the previous frame");
512 "Duration/ID must be set to 0 for CF-End frames");
519 "Less than AIFS elapsed between two TXOPs");
521 "More than AIFS+BO elapsed between two TXOPs");
523 "Expected a QoS data frame");
525 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
526 "Expected a frame sent by the first station to the AP");
529 "Duration/ID of the frame sent by the first station does not cover the remaining TXOP");
539 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
540 "Expected a Normal Ack sent to the first station");
542 RoundDurationId (
m_txPsdus[10].header.GetDuration () - sifs -
m_txPsdus[11].txDuration),
543 "Duration/ID of the Ack must be derived from that of the previous frame");
553 "Duration/ID must be set to 0 for CF-End frames");
584 "Expected an RTS frame");
586 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
587 "Expected an RTS frame sent by the AP to the first station");
590 "Duration/ID of the first RTS frame must cover the whole TXOP");
596 NS_TEST_EXPECT_MSG_LT (tEnd + sifs, tStart,
"CTS in response to the first RTS frame sent too early");
597 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"CTS in response to the first RTS frame sent too late");
600 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
601 "Expected a CTS frame sent to the AP");
603 RoundDurationId (
m_txPsdus[13].header.GetDuration () - sifs -
m_txPsdus[14].txDuration),
604 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
613 "Expected a QoS data frame");
615 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
616 "Expected a frame sent by the AP to the first station");
619 "Duration/ID of the first QoS data frame does not cover the remaining TXOP");
625 NS_TEST_EXPECT_MSG_LT (tEnd + sifs, tStart,
"Ack in response to the first QoS data frame sent too early");
626 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the first QoS data frame sent too late");
629 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
630 "Expected a Normal Ack sent to the AP");
632 RoundDurationId (
m_txPsdus[15].header.GetDuration () - sifs -
m_txPsdus[16].txDuration),
633 "Duration/ID of the Ack must be derived from that of the previous frame");
642 "Expected an RTS frame");
644 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (1))->GetMac ()->GetAddress (),
645 "Expected an RTS frame sent by the AP to the second station");
648 "Duration/ID of the second RTS frame must cover the whole TXOP");
654 NS_TEST_EXPECT_MSG_LT (tEnd + sifs, tStart,
"CTS in response to the second RTS frame sent too early");
655 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"CTS in response to the second RTS frame sent too late");
658 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
659 "Expected a CTS frame sent to the AP");
661 RoundDurationId (
m_txPsdus[17].header.GetDuration () - sifs -
m_txPsdus[18].txDuration),
662 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
671 "Expected a QoS data frame");
673 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (1))->GetMac ()->GetAddress (),
674 "Expected a frame sent by the AP to the second station");
677 "Duration/ID of the second QoS data frame does not cover the remaining TXOP");
683 NS_TEST_EXPECT_MSG_LT (tEnd + sifs, tStart,
"Ack in response to the second QoS data frame sent too early");
684 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the second QoS data frame sent too late");
687 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
688 "Expected a Normal Ack sent to the AP");
690 RoundDurationId (
m_txPsdus[19].header.GetDuration () - sifs -
m_txPsdus[20].txDuration),
691 "Duration/ID of the Ack must be derived from that of the previous frame");
700 "Expected an RTS frame");
702 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (2))->GetMac ()->GetAddress (),
703 "Expected an RTS frame sent by the AP to the third station");
706 "Duration/ID of the third RTS frame must cover the whole TXOP");
712 NS_TEST_EXPECT_MSG_LT (tEnd + sifs, tStart,
"CTS in response to the third RTS frame sent too early");
713 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"CTS in response to the third RTS frame sent too late");
716 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
717 "Expected a CTS frame sent to the AP");
719 RoundDurationId (
m_txPsdus[21].header.GetDuration () - sifs -
m_txPsdus[22].txDuration),
720 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
729 "Expected a QoS data frame");
731 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (2))->GetMac ()->GetAddress (),
732 "Expected a frame sent by the AP to the third station");
735 "Duration/ID of the third QoS data frame does not cover the remaining TXOP");
741 NS_TEST_EXPECT_MSG_LT (tEnd + sifs, tStart,
"Ack in response to the third QoS data frame sent too early");
742 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the third QoS data frame sent too late");
745 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
746 "Expected a Normal Ack sent to the AP");
748 RoundDurationId (
m_txPsdus[23].header.GetDuration () - sifs -
m_txPsdus[24].txDuration),
749 "Duration/ID of the Ack must be derived from that of the previous frame");
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
void SetStopTime(Time stop)
Specify application stop time.
Simulation virtual time values and global simulation resolution.
std::vector< FrameInfo > m_txPsdus
transmitted PSDUs
NetDeviceContainer m_apDevices
container for AP's NetDevice
AttributeValue implementation for Boolean.
WifiTxVector txVector
TX vector used to transmit the frame.
void SetLocal(PacketSocketAddress addr)
set the local address and protocol to be used
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Hold variables of type string.
Time txDuration
Frame TX duration.
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
an address for a packet socket
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
void CheckResults(void)
Check correctness of transmitted frames.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
bool m_pifsRecovery
whether to use PIFS recovery
void AddPropagationLossModel(Ptr< PropagationLossModel > loss)
Add the single-frequency propagation loss model to be used.
helps to create WifiNetDevice objects
void L7Receive(std::string context, Ptr< const Packet > p, const Address &addr)
Function to trace packets received by the server application.
Give ns3::PacketSocket powers to ns3::Node.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
#define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg)
Test that an actual value is greater than or equal to limit and report if not.
a polymophic address class
WifiMacHeader header
Frame MAC header.
AttributeValue implementation for Time.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
uint16_t m_received
number of packets received by the stations
void Connect(std::string path, const CallbackBase &cb)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetPhysicalAddress(const Address address)
Set the destination address.
keep track of a set of node pointers.
Hold objects of type Ptr<T>.
void DoRun(void) override
Implementation to actually run this TestCase.
void SetList(const std::list< uint32_t > &packetlist)
create MAC layers for a ns3::WifiNetDevice.
WifiTxopTest(bool pifsRecovery)
Constructor.
The IEEE 802.11 SSID Information Element.
NetDeviceContainer m_staDevices
container for stations' NetDevices
Helper class used to assign positions and mobility models to nodes.
Ptr< WifiMac > GetMac(void) const
Information about transmitted frames.
void SetRemote(PacketSocketAddress addr)
set the remote address and protocol to be used
void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
Set the propagation delay model to be used.
Time txStart
Frame start TX time.
Time Seconds(double value)
Construct a Time in the indicated unit.
AttributeValue implementation for Ssid.
void SetDefault(std::string name, const AttributeValue &value)
uint8_t m_aifsn
AIFSN for BE.
void SetProtocol(uint16_t protocol)
Set the protocol.
void Add(Vector v)
Add a position to the list of positions.
#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report if not.
uint16_t m_nStations
number of stations
Time m_txopLimit
TXOP limit.
void Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
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.
static WifiTxopTestSuite g_wifiTxopTestSuite
the test suite
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
void SetStartTime(Time start)
Specify application start time.
#define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg)
Test that an actual value is less than or equal to a limit and report if not.
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
void Transmit(std::string context, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
Callback invoked when PHY receives a PSDU to transmit.
uint32_t m_cwMin
CWmin for BE.
Make it easy to create and manage PHY objects for the spectrum model.