60#include "ns3/boolean.h"
61#include "ns3/command-line.h"
62#include "ns3/config.h"
63#include "ns3/data-rate.h"
64#include "ns3/flow-monitor-helper.h"
65#include "ns3/internet-stack-helper.h"
66#include "ns3/ipv4-address-helper.h"
67#include "ns3/ipv4-flow-classifier.h"
69#include "ns3/mobility-helper.h"
70#include "ns3/multi-model-spectrum-channel.h"
71#include "ns3/neighbor-cache-helper.h"
72#include "ns3/on-off-helper.h"
73#include "ns3/packet-sink-helper.h"
74#include "ns3/packet-sink.h"
75#include "ns3/spectrum-wifi-helper.h"
77#include "ns3/string.h"
78#include "ns3/uinteger.h"
79#include "ns3/wifi-mac-queue.h"
80#include "ns3/wifi-mac.h"
81#include "ns3/wifi-net-device.h"
82#include "ns3/wifi-static-setup-helper.h"
85#include <unordered_map>
92main(
int argc,
char* argv[])
94 std::string standard{
"11be"};
95 std::string channels{
"36,0,BAND_5GHZ,0"};
97 std::string psMode{
"0:true"};
98 std::string raa{
"ThompsonSamplingWifiManager"};
100 bool enableRts{
false};
101 bool enablePcap{
false};
105 bool staticSetup{
true};
107 double tolerance{0.15};
110 cmd.AddValue(
"standard",
"Supported standard (11n, 11ac, 11ax, 11be)", standard);
111 cmd.AddValue(
"channels",
112 "Colon separated (no spaces) list of channel settings for the links of both "
113 "the AP and the STAs",
115 cmd.AddValue(
"nStas",
"the number of non-AP devices", nStas);
116 cmd.AddValue(
"psMode",
117 "Comma separated (no spaces) list of pairs indicating whether PM mode must be "
118 "enabled on a given link for all non-AP devices (e.g., \"0:true,1:false\" enables "
119 "PM mode only on link 0)",
121 cmd.AddValue(
"raa",
"TypeId of the rate adaptation algorithm to use", raa);
122 cmd.AddValue(
"payloadSize",
"Payload size in bytes", payloadSize);
123 cmd.AddValue(
"enableRts",
"Enable or disable RTS/CTS", enableRts);
124 cmd.AddValue(
"enablePcap",
"Enable/disable pcap file generation", enablePcap);
125 cmd.AddValue(
"useUdp",
"true to use UDP, false to use TCP", useUdp);
126 cmd.AddValue(
"dlLoad",
"Rate of the total downlink load to generate", dlLoad);
127 cmd.AddValue(
"ulLoad",
"Rate of the total uplink load to generate", ulLoad);
128 cmd.AddValue(
"staticSetup",
"whether to use the static setup helper", staticSetup);
129 cmd.AddValue(
"simulationTime",
"Simulation time", simulationTime);
130 cmd.AddValue(
"tolerance",
131 "simulation fails if the throughput of every flow is not within this ratio "
132 "of the offered traffic load",
134 cmd.Parse(argc, argv);
144 wifi.SetRemoteStationManager(
"ns3::" + raa);
146 if (standard ==
"11be")
150 else if (standard ==
"11ax")
154 else if (standard ==
"11ac")
158 else if (standard ==
"11n")
165 <<
"), valid values are 11n, 11ac, 11ax or 11be");
168 std::unordered_map<WifiPhyBand, Ptr<MultiModelSpectrumChannel>> channelMap = {
177 for (
auto& str : strings)
179 str =
"{" + str +
"}";
183 auto phyBand = channelConfig.front().band;
185 phy.AddPhyToFreqRangeMapping(linkId, freqRange);
186 phy.AddChannel(channelMap.at(phyBand), freqRange);
195 auto apDevice =
wifi.Install(phy, mac, wifiApNode);
197 mac.SetType(
"ns3::StaWifiMac",
"Ssid",
SsidValue(ssid));
199 std::replace(psMode.begin(), psMode.end(),
':',
' ');
200 mac.SetPowerSaveManager(
"ns3::DefaultPowerSaveManager",
"PowerSaveMode",
StringValue(psMode));
203 int64_t streamNumber = 150;
210 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
212 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
213 positionAlloc->Add(Vector(1.0, 0.0, 0.0));
215 mobility.SetPositionAllocator(positionAlloc);
230 stack.Install(wifiApNode);
231 stack.Install(wifiStaNodes);
234 address.SetBase(
"192.168.1.0",
"255.255.255.0");
235 auto apInterface =
address.Assign(apDevice);
236 auto staInterfaces =
address.Assign(staDevices);
238 std::cout <<
"The IP address of the AP is " << apInterface.GetAddress(0) <<
"\n\n";
249 const uint16_t
port = 9;
250 auto socketFactory = useUdp ?
"ns3::UdpSocketFactory" :
"ns3::TcpSocketFactory";
257 onoff.SetConstantRate(ulLoad * (1. / nStas), payloadSize);
262 clientApp.Start(startTime);
263 clientApp.Stop(startTime + simulationTime);
270 serverApp.Start(
Time{0});
276 for (
uint32_t i = 0; i < staInterfaces.GetN(); ++i)
280 onoff.SetConstantRate(dlLoad * (1. / nStas), payloadSize);
283 clientApp.Start(startTime);
284 clientApp.Stop(startTime + simulationTime);
290 serverApp.Start(
Time{0});
296 phy.EnablePcap(
"wifi_PS_mode_AP", apDevice);
297 phy.EnablePcap(
"wifi_PS_mode_STA", staDevices);
306 monitor->CheckForLostPackets();
308 auto stats = monitor->GetFlowStats();
309 for (
const auto& [flowId, flowStats] : stats)
311 auto t = classifier->FindFlow(flowId);
316 std::cout <<
"Flow " << flowId <<
" (" << t.sourceAddress <<
" -> " << t.destinationAddress
318 std::cout <<
" Tx Packets: " << flowStats.txPackets <<
"\n";
319 std::cout <<
" Tx Bytes: " << flowStats.txBytes <<
"\n";
320 std::cout <<
" TxOffered: " << load <<
"\n";
321 std::cout <<
" Rx Packets: " << flowStats.rxPackets <<
"\n";
322 std::cout <<
" Rx Bytes: " << flowStats.rxBytes <<
"\n";
323 std::cout <<
" Throughput: " << tput <<
"\n";
325 const auto minExpectedTput = load * (1.0 - tolerance);
326 const auto maxExpectedTput = load * (1.0 + tolerance);
327 if (tput < minExpectedTput || tput > maxExpectedTput)
329 NS_LOG_ERROR(
"Throughput " << tput <<
" is outside expected range [" << minExpectedTput
330 <<
", " << maxExpectedTput <<
"]");
a polymophic address class
Parse command-line arguments.
Class for representing data rates.
uint64_t GetBitRate() const
Get the underlying bitrate.
Helper to enable IP flow monitoring on a set of Nodes.
Ptr< FlowClassifier > GetClassifier()
Retrieve the FlowClassifier object for IPv4 created by the Install* methods.
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static Ipv4Address GetAny()
Helper class used to assign positions and mobility models to nodes.
A helper class to populate neighbor cache.
void PopulateNeighborCache()
Populate neighbor ARP and NDISC caches for all devices.
keep track of a set of node pointers.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Smart pointer class similar to boost::intrusive_ptr.
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.
Simulation virtual time values and global simulation resolution.
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.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
static void SetStaticAssociation(Ptr< WifiNetDevice > bssDev, const NetDeviceContainer &clientDevs)
Bypass static capabilities exchange for input devices.
static void SetStaticBlockAck(Ptr< WifiNetDevice > apDev, const NetDeviceContainer &clientDevs, const std::set< tid_t > &tids, std::optional< Mac48Address > gcrGroupAddr=std::nullopt)
Bypass ADDBA Request-Response exchange sequence between AP and STAs for given TIDs.
#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)
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
@ 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.
const auto simulationTime
The simulation time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
FrequencyRange GetFrequencyRange(WifiPhyBand band)
Get the frequency range corresponding to the given PHY band.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
StringVector SplitString(const std::string &str, const std::string &delim)
Split a string on a delimiter.
uint8_t linkId_t
IEEE 802.11be D7.0 Figure 9-207e—Link ID Info field format.
static constexpr uint32_t WIFI_MAX_RTS_THRESHOLD
The maximum value for dot11RTSThreshold (C.3 MIB detail in IEEE Std 802.11-2020).
static WifiChannelConfig FromString(const std::string &settings, WifiStandard standard=WIFI_STANDARD_UNSPECIFIED)
Get the wifi channel config from a WifiPhy::ChannelSettings string.
Ptr< PacketSink > sink
Pointer to the packet sink application.