22 #include "ns3/mobility-helper.h"
23 #include "ns3/multi-model-spectrum-channel.h"
24 #include "ns3/config.h"
25 #include "ns3/ap-wifi-mac.h"
26 #include "ns3/packet-socket-address.h"
27 #include "ns3/packet-socket-client.h"
28 #include "ns3/packet-socket-helper.h"
29 #include "ns3/packet-socket-server.h"
31 #include "ns3/double.h"
32 #include "ns3/boolean.h"
33 #include "ns3/pointer.h"
34 #include "ns3/rng-seed-manager.h"
35 #include "ns3/spectrum-wifi-helper.h"
36 #include "ns3/wifi-net-device.h"
37 #include "ns3/wifi-spectrum-value-helper.h"
38 #include "ns3/spectrum-wifi-phy.h"
39 #include "ns3/interference-helper.h"
40 #include "ns3/nist-error-rate-model.h"
41 #include "ns3/wifi-mac-header.h"
42 #include "ns3/ampdu-tag.h"
43 #include "ns3/wifi-spectrum-signal-parameters.h"
44 #include "ns3/wifi-utils.h"
45 #include "ns3/threshold-preamble-detection-model.h"
46 #include "ns3/simple-frame-capture-model.h"
47 #include "ns3/wifi-mac-queue-item.h"
48 #include "ns3/mpdu-aggregator.h"
49 #include "ns3/wifi-psdu.h"
50 #include "ns3/he-ppdu.h"
51 #include "ns3/he-phy.h"
75 void DoSetup (
void)
override;
76 void DoTeardown (
void)
override;
101 void DoRun (
void)
override;
118 void CheckRxPacketCount (uint32_t expectedSuccessCount, uint32_t expectedFailureCount);
124 :
TestCase (
"Threshold preamble detection model test when no frame capture model is applied"),
125 m_countRxSuccess (0),
126 m_countRxFailure (0),
150 txParams->psd = txPowerSpectrum;
152 txParams->duration = txDuration;
153 txParams->ppdu = ppdu;
172 currentState = state->GetState ();
207 m_phy = CreateObject<SpectrumWifiPhy> ();
218 preambleDetectionModel->SetAttribute (
"Threshold",
DoubleValue (4));
219 preambleDetectionModel->SetAttribute (
"MinimumRssi",
DoubleValue (-82));
233 RngSeedManager::SetSeed (1);
234 RngSeedManager::SetRun (1);
235 int64_t streamNumber = 0;
239 double rxPowerDbm = -50;
425 Simulator::Destroy ();
457 WifiTxVector txVector, std::vector<bool> statusPerMpdu);
467 void DoRun (
void)
override;
484 void CheckRxPacketCount (uint32_t expectedSuccessCount, uint32_t expectedFailureCount);
490 :
TestCase (
"Threshold preamble detection model test when simple frame capture model is applied"),
491 m_countRxSuccess (0),
492 m_countRxFailure (0),
516 txParams->psd = txPowerSpectrum;
518 txParams->duration = txDuration;
519 txParams->ppdu = ppdu;
538 currentState = state->GetState ();
573 m_phy = CreateObject<SpectrumWifiPhy> ();
584 preambleDetectionModel->SetAttribute (
"Threshold",
DoubleValue (4));
585 preambleDetectionModel->SetAttribute (
"MinimumRssi",
DoubleValue (-82));
589 frameCaptureModel->SetAttribute (
"Margin",
DoubleValue (5));
604 RngSeedManager::SetSeed (1);
605 RngSeedManager::SetRun (1);
606 int64_t streamNumber = 1;
610 double rxPowerDbm = -50;
931 Simulator::Destroy ();
951 void DoRun (
void)
override;
971 WifiTxVector txVector, std::vector<bool> statusPerMpdu);
1007 :
TestCase (
"Simple frame capture model test"),
1008 m_rxSuccess1000B (false),
1009 m_rxSuccess1500B (false),
1010 m_rxDropped1000B (false),
1011 m_rxDropped1500B (false),
1035 txParams->psd = txPowerSpectrum;
1036 txParams->txPhy = 0;
1037 txParams->duration = txDuration;
1038 txParams->ppdu = ppdu;
1045 WifiTxVector txVector, std::vector<bool> statusPerMpdu)
1053 else if (psdu->
GetSize () == 1530)
1067 else if (p->
GetSize () == 1530)
1113 m_phy = CreateObject<SpectrumWifiPhy> ();
1125 preambleDetectionModel->SetAttribute (
"Threshold",
DoubleValue (2));
1129 frameCaptureModel->SetAttribute (
"Margin",
DoubleValue (5));
1144 RngSeedManager::SetSeed (1);
1145 RngSeedManager::SetRun (1);
1146 int64_t streamNumber = 2;
1147 double rxPowerDbm = -30;
1185 Simulator::Destroy ();
1211 void DoRun (
void)
override;
1228 :
TestCase (
"PHY headers reception test"),
1252 txParams->psd = txPowerSpectrum;
1253 txParams->txPhy = 0;
1254 txParams->duration = txDuration;
1255 txParams->ppdu = ppdu;
1274 currentState = state->GetState ();
1288 m_phy = CreateObject<SpectrumWifiPhy> ();
1307 RngSeedManager::SetSeed (1);
1308 RngSeedManager::SetRun (1);
1309 int64_t streamNumber = 0;
1313 double rxPowerDbm = -50;
1438 Simulator::Destroy ();
1458 void DoRun (
void)
override;
1468 WifiTxVector txVector, std::vector<bool> statusPerMpdu);
1555 :
TestCase (
"A-MPDU reception test"),
1556 m_rxSuccessBitmapAmpdu1 (0),
1557 m_rxSuccessBitmapAmpdu2 (0),
1558 m_rxFailureBitmapAmpdu1 (0),
1559 m_rxFailureBitmapAmpdu2 (0),
1560 m_rxDroppedBitmapAmpdu1 (0),
1561 m_rxDroppedBitmapAmpdu2 (0),
1584 WifiTxVector txVector, std::vector<bool> statusPerMpdu)
1587 if (statusPerMpdu.empty ())
1592 auto rxOkForMpdu = statusPerMpdu.begin ();
1593 for (
auto mpdu = psdu->
begin (); mpdu != psdu->
end (); ++mpdu)
1614 else if (size == 1130)
1618 else if (size == 1230)
1622 else if (size == 1330)
1626 else if (size == 1430)
1630 else if (size == 1530)
1640 for (
auto mpdu = psdu->
begin (); mpdu != psdu->
end (); ++mpdu)
1653 else if (size == 1130)
1657 else if (size == 1230)
1661 else if (size == 1330)
1665 else if (size == 1430)
1669 else if (size == 1530)
1683 else if (p->
GetSize () == 1130)
1687 else if (p->
GetSize () == 1230)
1691 else if (p->
GetSize () == 1330)
1695 else if (p->
GetSize () == 1430)
1699 else if (p->
GetSize () == 1530)
1748 currentState = state->GetState ();
1761 std::vector<Ptr<WifiMacQueueItem>> mpduList;
1762 for (
size_t i = 0; i < 3; ++i)
1764 Ptr<Packet> p = Create<Packet> (referencePacketSize + i * 100);
1765 mpduList.push_back (Create<WifiMacQueueItem> (p, hdr));
1776 txParams->psd = txPowerSpectrum;
1777 txParams->txPhy = 0;
1778 txParams->duration = txDuration;
1779 txParams->ppdu = ppdu;
1787 m_phy = CreateObject<SpectrumWifiPhy> ();
1800 preambleDetectionModel->SetAttribute (
"Threshold",
DoubleValue (2));
1804 frameCaptureModel->SetAttribute (
"Margin",
DoubleValue (5));
1819 RngSeedManager::SetSeed (1);
1820 RngSeedManager::SetRun (2);
1821 int64_t streamNumber = 1;
1822 double rxPowerDbm = -30;
2357 Simulator::Destroy ();
2402 void DoRun (
void)
override;
2407 :
TestCase (
"Check correct behavior when a STA is receiving a transmission using an unsupported modulation"),
2421 if (reason ==
RXING)
2423 std::cout <<
"Dropped a packet because already receiving" << std::endl;
2431 uint16_t m_nStations = 2;
2437 int64_t streamNumber = 100;
2447 spectrumChannel->AddPropagationLossModel (lossModel);
2449 CreateObject<ConstantSpeedPropagationDelayModel> ();
2450 spectrumChannel->SetPropagationDelayModel (delayModel);
2453 phy.SetChannel (spectrumChannel);
2458 wifi.SetRemoteStationManager (
"ns3::IdealWifiManager");
2461 mac.SetType (
"ns3::StaWifiMac",
"QosSupported",
BooleanValue (
true),
"Ssid",
2470 mac.SetType (
"ns3::ApWifiMac",
"QosSupported",
BooleanValue (
true),
"Ssid",
2480 for (uint16_t i = 0; i < m_nStations; i++)
2482 dev = DynamicCast<WifiNetDevice> (m_staDevices.
Get (i));
2483 Simulator::Schedule (init + i *
MicroSeconds (102400), &WifiMac::SetSsid, dev->
GetMac (),
2484 Ssid (
"wifi-backoff-ssid"));
2488 wifi.AssignStreams (m_apDevices, streamNumber);
2493 positionAlloc->Add (Vector (0.0, 0.0, 0.0));
2494 positionAlloc->Add (Vector (1.0, 0.0, 0.0));
2495 positionAlloc->Add (Vector (0.0, 1.0, 0.0));
2496 positionAlloc->Add (Vector (-1.0, 0.0, 0.0));
2497 mobility.SetPositionAllocator (positionAlloc);
2499 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
2504 dev = DynamicCast<WifiNetDevice> (m_apDevices.
Get (0));
2506 dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
2513 for (uint16_t i = 0; i < m_nStations; i++)
2523 client->SetRemote (socket);
2526 client->SetStopTime (
Seconds (1.0));
2528 legacyStaClient->SetAttribute (
"PacketSize",
UintegerValue (1500));
2529 legacyStaClient->SetAttribute (
"MaxPackets",
UintegerValue (200));
2531 legacyStaClient->SetRemote (socket);
2532 wifiStaNodes.Get (i)->AddApplication (legacyStaClient);
2534 legacyStaClient->SetStopTime (
Seconds (1.0));
2536 server->SetLocal (socket);
2538 server->SetStartTime (
Seconds (0.0));
2539 server->SetStopTime (
Seconds (1.0));
2543 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop",
2546 Simulator::Stop (
Seconds (1));
2551 Simulator::Destroy ();
2573 :
TestSuite (
"wifi-phy-reception", UNIT)
void IncrementSuccessBitmap(uint32_t size)
Increment reception success bitmap.
uint8_t m_rxDroppedBitmapAmpdu2
bitmap of dropped MPDUs in A-MPDU #2
void CheckRxSuccessBitmapAmpdu2(uint8_t expected)
Check the RX success bitmap for A-MPDU 2.
void DoTeardown(void) override
Implementation to do any local setup required for this TestCase.
void CheckRxDroppedBitmapAmpdu1(uint8_t expected)
Check the RX dropped bitmap for A-MPDU 1.
uint8_t m_rxSuccessBitmapAmpdu1
bitmap of successfully received MPDUs in A-MPDU #1
uint8_t m_rxFailureBitmapAmpdu1
bitmap of unsuccessfully received MPDUs in A-MPDU #1
void RxFailure(Ptr< WifiPsdu > psdu)
RX failure function.
uint8_t m_rxFailureBitmapAmpdu2
bitmap of unsuccessfully received MPDUs in A-MPDU #2
void DoRun(void) override
Implementation to actually run this TestCase.
void RxDropped(Ptr< const Packet > p, WifiPhyRxfailureReason reason)
RX dropped function.
void SendAmpduWithThreeMpdus(double rxPowerDbm, uint32_t referencePacketSize)
Send A-MPDU with 3 MPDUs of different size (i-th MSDU will have 100 bytes more than (i-1)-th).
void CheckRxFailureBitmapAmpdu2(uint8_t expected)
Check the RX failure bitmap for A-MPDU 2.
uint8_t m_rxDroppedBitmapAmpdu1
bitmap of dropped MPDUs in A-MPDU #1
void IncrementFailureBitmap(uint32_t size)
Increment reception failure bitmap.
void ResetBitmaps()
Reset bitmaps function.
void CheckPhyState(WifiPhyState expectedState)
Check the PHY state.
void DoSetup(void) override
Implementation to do any local setup required for this TestCase.
virtual ~TestAmpduReception()
void RxSuccess(Ptr< WifiPsdu > psdu, RxSignalInfo rxSignalInfo, WifiTxVector txVector, std::vector< bool > statusPerMpdu)
RX success function.
void CheckRxSuccessBitmapAmpdu1(uint8_t expected)
Check the RX success bitmap for A-MPDU 1.
void CheckRxFailureBitmapAmpdu1(uint8_t expected)
Check the RX failure bitmap for A-MPDU 1.
uint8_t m_rxSuccessBitmapAmpdu2
bitmap of successfully received MPDUs in A-MPDU #2
Ptr< SpectrumWifiPhy > m_phy
Phy.
void CheckRxDroppedBitmapAmpdu2(uint8_t expected)
Check the RX dropped bitmap for A-MPDU 2.
Simple frame capture model test.
void Expect1000BPacketReceived()
Verify whether 1000 bytes packet has been received.
bool m_rxDropped1500B
count dropped packets with 1500B payload
void Expect1500BPacketDropped()
Verify whether 1500 bytes packet has been dropped.
void Expect1000BPacketDropped()
Verify whether 1000 bytes packet has been dropped.
void DoRun(void) override
Implementation to actually run this TestCase.
void Reset(void)
Reset function.
void SendPacket(double rxPowerDbm, uint32_t packetSize)
Send packet function.
Ptr< SpectrumWifiPhy > m_phy
Phy.
void RxDropped(Ptr< const Packet > p, WifiPhyRxfailureReason reason)
RX dropped function.
void DoSetup(void) override
Implementation to do any local setup required for this TestCase.
bool m_rxSuccess1000B
count received packets with 1000B payload
void RxSuccess(Ptr< WifiPsdu > psdu, RxSignalInfo rxSignalInfo, WifiTxVector txVector, std::vector< bool > statusPerMpdu)
Spectrum wifi receive success function.
bool m_rxSuccess1500B
count received packets with 1500B payload
void Expect1500BPacketReceived()
Verify whether 1500 bytes packet has been received.
uint64_t m_uid
the UID to use for the PPDU
void DoTeardown(void) override
Implementation to do any local setup required for this TestCase.
TestSimpleFrameCaptureModel()
bool m_rxDropped1000B
count dropped packets with 1000B payload
virtual ~TestSimpleFrameCaptureModel()
Preamble detection test w/o frame capture.
TestThresholdPreambleDetectionWithFrameCapture()
void RxFailure(Ptr< WifiPsdu > psdu)
Spectrum wifi receive failure function.
void CheckPhyState(WifiPhyState expectedState)
Schedule now to check the PHY state.
Ptr< SpectrumWifiPhy > m_phy
Phy.
void SendPacket(double rxPowerDbm)
Send packet function.
void DoTeardown(void) override
Implementation to do any local setup required for this TestCase.
uint32_t m_countRxSuccess
count RX success
void DoCheckPhyState(WifiPhyState expectedState)
Check the PHY state now.
uint32_t m_countRxFailure
count RX failure
void DoSetup(void) override
Implementation to do any local setup required for this TestCase.
void DoRun(void) override
Implementation to actually run this TestCase.
void CheckRxPacketCount(uint32_t expectedSuccessCount, uint32_t expectedFailureCount)
Check the number of received packets.
void RxSuccess(Ptr< WifiPsdu > psdu, RxSignalInfo rxSignalInfo, WifiTxVector txVector, std::vector< bool > statusPerMpdu)
Spectrum wifi receive success function.
virtual ~TestThresholdPreambleDetectionWithFrameCapture()
uint64_t m_uid
the UID to use for the PPDU
Preamble detection test w/o frame capture.
void DoTeardown(void) override
Implementation to do any local setup required for this TestCase.
TestThresholdPreambleDetectionWithoutFrameCapture()
void DoSetup(void) override
Implementation to do any local setup required for this TestCase.
uint32_t m_countRxFailure
count RX failure
void RxSuccess(Ptr< WifiPsdu > psdu, RxSignalInfo rxSignalInfo, WifiTxVector txVector, std::vector< bool > statusPerMpdu)
Spectrum wifi receive success function.
void CheckRxPacketCount(uint32_t expectedSuccessCount, uint32_t expectedFailureCount)
Check the number of received packets.
void DoCheckPhyState(WifiPhyState expectedState)
Check the PHY state now.
uint64_t m_uid
the UID to use for the PPDU
virtual ~TestThresholdPreambleDetectionWithoutFrameCapture()
void DoRun(void) override
Implementation to actually run this TestCase.
void SendPacket(double rxPowerDbm)
Send packet function.
void RxFailure(Ptr< WifiPsdu > psdu)
Spectrum wifi receive failure function.
Ptr< SpectrumWifiPhy > m_phy
Phy.
uint32_t m_countRxSuccess
count RX success
void CheckPhyState(WifiPhyState expectedState)
Schedule now to check the PHY state.
Unsupported Modulation Reception Test This test creates a mixed network, in which an HE STA and a VHT...
virtual ~TestUnsupportedModulationReception()
void DoRun(void) override
Implementation to actually run this TestCase.
void Dropped(std::string context, Ptr< const Packet > packet, WifiPhyRxfailureReason reason)
Callback invoked when PHY drops an incoming packet.
void CheckResults(void)
Check correctness of transmitted frames.
TestUnsupportedModulationReception()
Constructor.
uint16_t m_dropped
number of packets dropped by the AP because it was already receiving
wifi PHY reception Test Suite
WifiPhyReceptionTestSuite()
AttributeValue implementation for Boolean.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
virtual Address GetAddress(void) const =0
virtual uint32_t GetIfIndex(void) const =0
keep track of a set of node pointers.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
void Dispose(void)
Dispose of this Object.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
an address for a packet socket
void SetProtocol(uint16_t protocol)
Set the protocol.
void SetPhysicalAddress(const Address address)
Set the destination address.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
Give ns3::PacketSocket powers to ns3::Node.
void Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
Hold objects of type Ptr<T>.
Make it easy to create and manage PHY objects for the spectrum model.
void StartRx(Ptr< SpectrumSignalParameters > rxParams)
Input method for delivering a signal from the spectrum channel and low-level PHY interface to this Sp...
The IEEE 802.11 SSID Information Element.
AttributeValue implementation for Ssid.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Simulation virtual time values and global simulation resolution.
AttributeValue implementation for Time.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
Ptr< WifiMac > GetMac(void) const
virtual void SetInterferenceHelper(const Ptr< InterferenceHelper > helper)
Sets the interference helper.
void SetErrorRateModel(const Ptr< ErrorRateModel > model)
Sets the error rate model.
WifiPhyBand GetPhyBand(void) const
Get the configured Wi-Fi band.
void SetReceiveErrorCallback(RxErrorCallback callback)
virtual void ConfigureStandard(WifiStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
void SetOperatingChannel(const ChannelTuple &channelTuple)
If the standard for this object has not been set yet, store the given channel settings.
void SetPreambleDetectionModel(const Ptr< PreambleDetectionModel > preambleDetectionModel)
Sets the preamble detection model.
void SetReceiveOkCallback(RxOkCallback callback)
void SetFrameCaptureModel(const Ptr< FrameCaptureModel > frameCaptureModel)
Sets the frame capture model.
std::tuple< uint8_t, uint16_t, int, uint8_t > ChannelTuple
Tuple identifying an operating channel.
virtual int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
This objects implements the PHY state machine of the Wifi device.
uint32_t GetSize(void) const
Return the size of the PSDU in bytes.
std::vector< Ptr< WifiMacQueueItem > >::const_iterator begin(void) const
Return a const iterator to the first MPDU.
std::size_t GetNMpdus(void) const
Return the number of MPDUs constituting the PSDU.
std::vector< Ptr< WifiMacQueueItem > >::const_iterator end(void) const
Return a const iterator to past-the-last MPDU.
bool IsAggregate(void) const
Return true if the PSDU is an S-MPDU or A-MPDU.
bool IsSingle(void) const
Return true if the PSDU is an S-MPDU.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
void SetDefault(std::string name, const AttributeValue &value)
void Connect(std::string path, const CallbackBase &cb)
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
WifiPhyRxfailureReason
Enumeration of the possible reception failure reasons.
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DbmToW(double dBm)
Convert from dBm to Watts.
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...
RxSignalInfo structure containing info on the received signal.
static const uint8_t CHANNEL_NUMBER
static const uint16_t GUARD_WIDTH
static const uint16_t CHANNEL_WIDTH
static WifiPhyReceptionTestSuite wifiPhyReceptionTestSuite
the test suite
static const uint32_t FREQUENCY
WifiPhyState
The state of the PHY layer.
@ CCA_BUSY
The PHY layer has sense the medium busy through the CCA mechanism.
@ RX
The PHY layer is receiving a packet.
@ IDLE
The PHY layer is IDLE.
static const uint32_t packetSize
void SendPacket(Ptr< NetDevice > sourceDevice, Address &destination)
This example (inspired from tv-trans-example) enables to generate the transmitted spectra of Wi-Fi st...