9#include "ns3/ap-wifi-mac.h"
10#include "ns3/boolean.h"
11#include "ns3/config.h"
12#include "ns3/double.h"
13#include "ns3/mobility-helper.h"
14#include "ns3/multi-model-spectrum-channel.h"
15#include "ns3/packet-socket-client.h"
16#include "ns3/packet-socket-helper.h"
17#include "ns3/packet-socket-server.h"
18#include "ns3/rng-seed-manager.h"
19#include "ns3/spectrum-wifi-helper.h"
20#include "ns3/sta-wifi-mac.h"
21#include "ns3/string.h"
23#include "ns3/wifi-net-device.h"
24#include "ns3/wifi-standards.h"
69 std::ostringstream oss;
88 void DoRun()
override;
115 :
TestCase(
"Check correct behaviour for scenario: " + params.
Print()),
123 NS_LOG_INFO(
"Received " << p->GetSize() <<
" bytes");
139 int64_t streamNumber = 100;
146 spectrumChannel->AddPropagationLossModel(lossModel);
148 spectrumChannel->SetPropagationDelayModel(delayModel);
151 phy.SetChannel(spectrumChannel);
154 wifi.SetRemoteStationManager(
"ns3::IdealWifiManager");
160 mac.SetType(
"ns3::ApWifiMac",
"Ssid",
SsidValue(
Ssid(
"ns-3-ssid")));
161 auto apDevice = wifi.Install(phy, mac, wifiApNode);
168 mac.SetType(
"ns3::StaWifiMac",
"Ssid",
SsidValue(
Ssid(
"ns-3-ssid")));
171 "ns3::WifiDefaultAssocManager",
172 "AllowAssocAllChannelWidths",
174 "SkipAssocIncompatibleChannelWidth",
178 std::vector<std::string> tmp;
179 for (std::string val; std::getline(split, val,
',');)
181 tmp.emplace_back(val);
183 const auto staBw = std::stold(tmp.at(1));
185 auto invalidConfig{
false};
188 staDevice = wifi.Install(phy, mac, wifiStaNode);
190 catch (
const std::runtime_error&)
192 invalidConfig =
true;
197 "Configuration should " << (expectInvalidConfig ?
"not " :
"")
198 <<
"have been allowed");
213 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
214 positionAlloc->Add(Vector(10.0, 0.0, 0.0));
215 mobility.SetPositionAllocator(positionAlloc);
217 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
218 mobility.Install(wifiApNode);
219 mobility.Install(wifiStaNode);
222 packetSocket.
Install(wifiStaNode);
223 packetSocket.
Install(wifiApNode);
234 dlClient->SetRemote(dlSocket);
235 wifiApNode.Get(0)->AddApplication(dlClient);
236 dlClient->SetStartTime(
Seconds(0.15));
237 dlClient->SetStopTime(
Seconds(0.25));
240 dlServer->SetLocal(dlSocket);
242 dlServer->SetStartTime(
Seconds(0.0));
243 dlServer->SetStopTime(
Seconds(0.25));
254 ulClient->SetRemote(ulSocket);
256 ulClient->SetStartTime(
Seconds(0.2));
257 ulClient->SetStopTime(
Seconds(0.25));
260 ulServer->SetLocal(ulSocket);
261 wifiApNode.Get(0)->AddApplication(ulServer);
262 ulServer->SetStartTime(
Seconds(0.0));
263 ulServer->SetStopTime(
Seconds(0.25));
279 const auto staPhy =
m_staWifiMac->GetDevice()->GetPhy();
280 const auto staBw = staPhy->GetChannelWidth();
281 const auto compatibleBw =
283 (staBw >=
m_apWifiMac->GetDevice()->GetPhy()->GetChannelWidth());
287 m_apWifiMac->GetDevice()->GetPhy()->GetChannelWidth(),
288 "Incorrect AP channel width information received by STA");
292 const uint32_t expectedRxDl = compatibleBw ? 1 : 0;
295 "Unexpected number of received packets in downlink direction");
303 "Unexpected number of received packets in uplink direction");
321 const std::map<std::pair<MHz_u, WifiPhyBand>, std::string> channelSettingsMap{
341 for (
const auto& [apWidthBandPair, apChannel] : channelSettingsMap)
343 for (
const auto& [staWidthBandPair, staChannel] : channelSettingsMap)
345 if (apWidthBandPair.second != staWidthBandPair.second)
350 std::find(allowedBands.cbegin(),
352 apWidthBandPair.second) == allowedBands.cend())
356 if (
const auto maxWidth =
357 std::max(apWidthBandPair.first, staWidthBandPair.first);
362 for (
const auto skipAssocIfIncompatible : {
false,
true})
366 {.apStandard = standard,
367 .staStandard = standard,
368 .apChannelSettings = apChannel,
369 .staChannelSettings = staChannel,
370 .staLargestSupportedChWidth = maxSupportedBw,
371 .skipAssocIncompatibleChannelWidth = skipAssocIfIncompatible}),
372 TestCase::Duration::QUICK);
Test initial channel settings for AP and non-AP STAs when those are not necessarily identical.
~WifiChannelSettingsTest() override=default
void CheckResults()
Check results.
uint32_t m_receivedDl
received DL packets
Params m_params
test parameters
uint32_t m_receivedUl
received UL packets
Ptr< StaWifiMac > m_staWifiMac
STA wifi MAC.
WifiChannelSettingsTest(const Params ¶ms)
Constructor.
const uint32_t m_ulPacketSize
UL packet size (bytes)
void DoRun() override
Implementation to actually run this TestCase.
void AppRx(Ptr< const Packet > p, const Address &adr)
Callback invoked when a packet is received by the server application.
Ptr< ApWifiMac > m_apWifiMac
AP wifi MAC.
const uint32_t m_dlPacketSize
DL packet size (bytes)
wifi channel settings test suite
WifiChannelSettingsTestSuite()
a polymophic address class
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
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
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.
Smart pointer class similar to boost::intrusive_ptr.
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Make it easy to create and manage PHY objects for the spectrum model.
The IEEE 802.11 SSID Information Element.
AttributeValue implementation for Ssid.
Hold variables of type string.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
static int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by the PHY and MAC aspects ...
create MAC layers for a ns3::WifiNetDevice.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#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 Seconds(double value)
Construct a Time in the indicated unit.
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
@ WIFI_PHY_BAND_6GHZ
The 6 GHz band.
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
void Print(ComponentCarrier cc)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
MHz_u GetMaximumChannelWidth(WifiModulationClass modulation)
Get the maximum channel width allowed for the given modulation class.
WifiModulationClass GetModulationClassForStandard(WifiStandard standard)
Return the modulation class corresponding to a given standard.
const std::map< WifiStandard, std::list< WifiPhyBand > > wifiStandards
map a given standard configured by the user to the allowed PHY bands
std::set< MHz_u > GetSupportedChannelWidthSet(WifiStandard standard, WifiPhyBand band)
Get the supported channel width set that can be advertised in PHY capabilities.
WifiStandard apStandard
wifi standard for AP STA
WifiStandard staStandard
wifi standard for non-AP STA
std::string apChannelSettings
channel setting string for AP STA
std::string staChannelSettings
channel setting string for non-AP STA
MHz_u staLargestSupportedChWidth
largest supported channel width by the non-AP STA
bool skipAssocIncompatibleChannelWidth
flag to skip association when STA channel width is incompatible with AP
std::string Print() const
Print the parameters.
static WifiChannelSettingsTestSuite g_wifiChannelSettingsTestSuite
the test suite