10#include "ns3/attribute-container.h"
11#include "ns3/boolean.h"
12#include "ns3/command-line.h"
13#include "ns3/config.h"
14#include "ns3/double.h"
16#include "ns3/ht-phy.h"
17#include "ns3/internet-stack-helper.h"
18#include "ns3/ipv4-address-helper.h"
19#include "ns3/ipv4-global-routing-helper.h"
21#include "ns3/mobility-helper.h"
22#include "ns3/neighbor-cache-helper.h"
23#include "ns3/on-off-helper.h"
24#include "ns3/packet-sink-helper.h"
25#include "ns3/packet-sink.h"
27#include "ns3/string.h"
29#include "ns3/udp-client-server-helper.h"
30#include "ns3/udp-server.h"
31#include "ns3/uinteger.h"
32#include "ns3/wifi-static-setup-helper.h"
33#include "ns3/yans-wifi-channel.h"
34#include "ns3/yans-wifi-helper.h"
60main(
int argc,
char* argv[])
64 Time simulationTime{
"10s"};
65 bool staticSetup{
true};
66 auto clientAppStartTime =
Seconds(1);
70 std::vector<uint64_t> mcsValues;
72 int guardInterval{-1};
73 double minExpectedThroughput{0.0};
74 double maxExpectedThroughput{0.0};
77 cmd.AddValue(
"staticSetup",
78 "Whether devices are configured using the static setup helper",
80 cmd.AddValue(
"frequency",
81 "Whether working in the 2.4 or 5.0 GHz band (other values gets rejected)",
83 cmd.AddValue(
"distance",
84 "Distance in meters between the station and the access point",
86 cmd.AddValue(
"simulationTime",
"Simulation time", simulationTime);
87 cmd.AddValue(
"udp",
"UDP if set to 1, TCP otherwise", udp);
88 cmd.AddValue(
"useRts",
"Enable/disable RTS/CTS", useRts);
91 "list of comma separated MCS values to test; if unset, all MCS values (0-7) are tested",
95 "if set, limit testing to a specific channel width expressed in MHz (20 or 40 MHz)",
97 cmd.AddValue(
"guardInterval",
98 "if set, limit testing to a specific guard interval duration expressed in "
99 "nanoseconds (800 or 400 ns)",
101 cmd.AddValue(
"minExpectedThroughput",
102 "if set, simulation fails if the lowest throughput is below this value",
103 minExpectedThroughput);
104 cmd.AddValue(
"maxExpectedThroughput",
105 "if set, simulation fails if the highest throughput is above this value",
106 maxExpectedThroughput);
107 cmd.Parse(argc, argv);
114 double prevThroughput[8] = {0};
116 std::cout <<
"MCS value"
122 <<
"Throughput" <<
'\n';
128 for (uint8_t mcs = minMcs; mcs <= maxMcs; ++mcs)
130 mcsValues.push_back(mcs);
138 attr.DeserializeFromString(mcsStr, checker);
139 mcsValues = attr.Get();
140 std::sort(mcsValues.begin(), mcsValues.end());
143 int minChannelWidth = 20;
144 int maxChannelWidth = 40;
145 if ((channelWidth != -1) &&
146 ((channelWidth < minChannelWidth) || (channelWidth > maxChannelWidth)))
148 NS_FATAL_ERROR(
"Invalid channel width: " << channelWidth <<
" MHz");
150 if (channelWidth >= minChannelWidth && channelWidth <= maxChannelWidth)
152 minChannelWidth = channelWidth;
153 maxChannelWidth = channelWidth;
157 if (guardInterval >= minGi && guardInterval <= maxGi)
159 minGi = guardInterval;
160 maxGi = guardInterval;
163 for (
const auto mcs : mcsValues)
167 for (
int width = minChannelWidth;
width <= maxChannelWidth;
width *= 2)
169 for (
int gi = maxGi; gi >= minGi; gi /= 2)
171 const auto sgi = (gi == 400);
194 std::ostringstream ossControlMode;
196 if (frequency == 5.0)
198 ossControlMode <<
"OfdmRate";
201 else if (frequency == 2.4)
204 ossControlMode <<
"ErpOfdmRate";
214 ossControlMode << nonHtRefRateMbps <<
"Mbps";
216 std::ostringstream ossDataMode;
217 ossDataMode <<
"HtMcs" << mcs;
218 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
234 mac.SetType(
"ns3::StaWifiMac",
"Ssid",
SsidValue(ssid));
235 phy.Set(
"ChannelSettings", channelValue);
238 staDevice =
wifi.Install(phy, mac, wifiStaNode);
240 mac.SetType(
"ns3::ApWifiMac",
241 "EnableBeaconJitter",
249 apDevice =
wifi.Install(phy, mac, wifiApNode);
251 int64_t streamNumber = 150;
259 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
260 positionAlloc->Add(Vector(distance, 0.0, 0.0));
261 mobility.SetPositionAllocator(positionAlloc);
263 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
280 stack.Install(wifiApNode);
281 stack.Install(wifiStaNode);
282 streamNumber +=
stack.AssignStreams(wifiApNode, streamNumber);
283 streamNumber +=
stack.AssignStreams(wifiStaNode, streamNumber);
286 address.SetBase(
"192.168.1.0",
"255.255.255.0");
290 staNodeInterface =
address.Assign(staDevice);
291 apNodeInterface =
address.Assign(apDevice);
311 serverApp =
server.Install(wifiStaNode.
Get(0));
312 streamNumber +=
server.AssignStreams(wifiStaNode.
Get(0), streamNumber);
315 serverApp.Stop(simulationTime + clientAppStartTime);
316 const auto packetInterval = payloadSize * 8.0 / maxLoad;
325 clientApp.
Start(clientAppStartTime);
326 clientApp.
Stop(simulationTime + clientAppStartTime);
331 uint16_t
port = 50000;
339 serverApp.Stop(simulationTime + clientAppStartTime);
342 onoff.SetAttribute(
"OnTime",
343 StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
344 onoff.SetAttribute(
"OffTime",
345 StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
350 onoff.SetAttribute(
"Remote", remoteAddress);
354 clientApp.
Start(clientAppStartTime);
355 clientApp.
Stop(simulationTime + clientAppStartTime);
372 auto throughput = (rxBytes * 8) / simulationTime.GetMicroSeconds();
376 std::cout << mcs <<
"\t\t\t" <<
width <<
" MHz\t\t\t" << std::boolalpha << sgi
377 <<
"\t\t\t" <<
throughput <<
" Mbit/s" << std::endl;
380 if (mcs == minMcs && width == 20 && !sgi)
388 if (mcs == maxMcs && width == 40 && sgi)
390 if (maxExpectedThroughput > 0 &&
throughput > maxExpectedThroughput)
a polymophic address class
AttributeValue implementation for Address.
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
A container for one type of attribute.
void Set(const T &c)
Copy items from container c.
AttributeValue implementation for Boolean.
Parse command-line arguments.
AttributeValue implementation for DataRate.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
static uint64_t GetNonHtReferenceRate(uint8_t mcsValue)
Calculate the rate in bps of the non-HT Reference Rate corresponding to the supplied HT MCS index.
static uint64_t GetDataRate(uint8_t mcsValue, MHz_u channelWidth, Time guardInterval, uint8_t nss)
Return the data rate corresponding to the supplied HT MCS index, channel width, guard interval,...
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()
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
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.
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.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
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.
The IEEE 802.11 SSID Information Element.
AttributeValue implementation for Ssid.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
AttributeValue implementation for Time.
AttributeValue implementation for Tuple.
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
Create a server application which waits for input UDP packets and uses the information carried into t...
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.
std::list< WifiChannelConfig::TupleWithoutUnits > ChannelSegments
segments identifying an operating channel
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.
manage and create wifi channel objects for the YANS model.
static YansWifiChannelHelper Default()
Create a channel helper in a default working state.
Make it easy to create and manage PHY objects for the YANS model.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< AttributeChecker > MakeAttributeContainerChecker()
Make uninitialized AttributeContainerChecker using explicit types.
Ptr< const AttributeChecker > MakeUintegerChecker()
void SetDefault(std::string name, const AttributeValue &value)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#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 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.
WifiPhyBand
Identifies the PHY band.
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double MHz_u
MHz weak type.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
double meter_u
meter weak type