9#include "ns3/command-line.h"
10#include "ns3/internet-stack-helper.h"
11#include "ns3/ipv4-address-helper.h"
13#include "ns3/mobility-helper.h"
14#include "ns3/on-off-helper.h"
15#include "ns3/pointer.h"
16#include "ns3/qos-txop.h"
18#include "ns3/string.h"
19#include "ns3/udp-client-server-helper.h"
20#include "ns3/udp-server.h"
21#include "ns3/wifi-mac.h"
22#include "ns3/wifi-net-device.h"
23#include "ns3/yans-wifi-channel.h"
24#include "ns3/yans-wifi-helper.h"
84main(
int argc,
char* argv[])
87 Time simulationTime{
"10s"};
89 bool enablePcap{
false};
90 bool verifyResults{
false};
91 Time txopLimit{
"4096us"};
94 cmd.AddValue(
"payloadSize",
"Payload size in bytes", payloadSize);
95 cmd.AddValue(
"simulationTime",
"Simulation time", simulationTime);
96 cmd.AddValue(
"distance",
97 "Distance in meters between the station and the access point",
99 cmd.AddValue(
"enablePcap",
"Enable/disable pcap file generation", enablePcap);
100 cmd.AddValue(
"verifyResults",
101 "Enable/disable results verification at the end of the simulation",
103 cmd.Parse(argc, argv);
117 wifi.SetRemoteStationManager(
"ns3::IdealWifiManager");
132 phy.Set(
"ChannelSettings",
StringValue(
"{36, 20, BAND_5GHZ, 0}"));
136 mac.SetType(
"ns3::ApWifiMac",
141 "EnableBeaconJitter",
143 apDeviceA =
wifi.Install(phy, mac, wifiApNodes.
Get(0));
147 phy.Set(
"ChannelSettings",
StringValue(
"{40, 20, BAND_5GHZ, 0}"));
152 mac.SetType(
"ns3::ApWifiMac",
157 "EnableBeaconJitter",
159 apDeviceB =
wifi.Install(phy, mac, wifiApNodes.
Get(1));
167 wifi_mac->GetAttribute(
"BE_Txop", ptr);
169 edca->SetTxopLimit(txopLimit);
174 wifi_mac = wifi_dev->GetMac();
175 wifi_mac->GetAttribute(
"BE_Txop", ptr);
178 edca->TraceConnectWithoutContext(
"TxopTrace",
183 phy.Set(
"ChannelSettings",
StringValue(
"{44, 20, BAND_5GHZ, 0}"));
188 mac.SetType(
"ns3::ApWifiMac",
193 "EnableBeaconJitter",
195 apDeviceC =
wifi.Install(phy, mac, wifiApNodes.
Get(2));
200 wifi_mac = wifi_dev->GetMac();
201 wifi_mac->GetAttribute(
"VI_Txop", ptr);
204 edca->TraceConnectWithoutContext(
"TxopTrace",
209 phy.Set(
"ChannelSettings",
StringValue(
"{48, 20, BAND_5GHZ, 0}"));
214 mac.SetType(
"ns3::ApWifiMac",
219 "EnableBeaconJitter",
221 apDeviceD =
wifi.Install(phy, mac, wifiApNodes.
Get(3));
226 wifi_mac = wifi_dev->GetMac();
227 wifi_mac->GetAttribute(
"VI_Txop", ptr);
234 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
237 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
238 positionAlloc->Add(Vector(10.0, 0.0, 0.0));
239 positionAlloc->Add(Vector(20.0, 0.0, 0.0));
240 positionAlloc->Add(Vector(30.0, 0.0, 0.0));
242 positionAlloc->Add(Vector(distance, 0.0, 0.0));
243 positionAlloc->Add(Vector(10 + distance, 0.0, 0.0));
244 positionAlloc->Add(Vector(20 + distance, 0.0, 0.0));
245 positionAlloc->Add(Vector(30 + distance, 0.0, 0.0));
249 mobility.SetPositionAllocator(positionAlloc);
255 stack.Install(wifiApNodes);
256 stack.Install(wifiStaNodes);
259 address.SetBase(
"192.168.1.0",
"255.255.255.0");
261 StaInterfaceA =
address.Assign(staDeviceA);
263 ApInterfaceA =
address.Assign(apDeviceA);
265 address.SetBase(
"192.168.2.0",
"255.255.255.0");
267 StaInterfaceB =
address.Assign(staDeviceB);
269 ApInterfaceB =
address.Assign(apDeviceB);
271 address.SetBase(
"192.168.3.0",
"255.255.255.0");
273 StaInterfaceC =
address.Assign(staDeviceC);
275 ApInterfaceC =
address.Assign(apDeviceC);
277 address.SetBase(
"192.168.4.0",
"255.255.255.0");
279 StaInterfaceD =
address.Assign(staDeviceD);
281 ApInterfaceD =
address.Assign(apDeviceD);
284 uint16_t
port = 5001;
292 OnOffHelper clientA(
"ns3::UdpSocketFactory", destA);
293 clientA.SetAttribute(
"OnTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
294 clientA.SetAttribute(
"OffTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
295 clientA.SetAttribute(
"DataRate",
StringValue(
"100000kb/s"));
296 clientA.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
310 OnOffHelper clientB(
"ns3::UdpSocketFactory", destB);
311 clientB.SetAttribute(
"OnTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
312 clientB.SetAttribute(
"OffTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
313 clientB.SetAttribute(
"DataRate",
StringValue(
"100000kb/s"));
314 clientB.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
328 OnOffHelper clientC(
"ns3::UdpSocketFactory", destC);
329 clientC.SetAttribute(
"OnTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
330 clientC.SetAttribute(
"OffTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
331 clientC.SetAttribute(
"DataRate",
StringValue(
"100000kb/s"));
332 clientC.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
346 OnOffHelper clientD(
"ns3::UdpSocketFactory", destD);
347 clientD.SetAttribute(
"OnTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
348 clientD.SetAttribute(
"OffTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
349 clientD.SetAttribute(
"DataRate",
StringValue(
"100000kb/s"));
350 clientD.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
359 phy.EnablePcap(
"AP_A", apDeviceA.
Get(0));
360 phy.EnablePcap(
"STA_A", staDeviceA.
Get(0));
361 phy.EnablePcap(
"AP_B", apDeviceB.
Get(0));
362 phy.EnablePcap(
"STA_B", staDeviceB.
Get(0));
363 phy.EnablePcap(
"AP_C", apDeviceC.
Get(0));
364 phy.EnablePcap(
"STA_C", staDeviceC.
Get(0));
365 phy.EnablePcap(
"AP_D", apDeviceD.
Get(0));
366 phy.EnablePcap(
"STA_D", staDeviceD.
Get(0));
380 auto throughput = totalPacketsThroughA * payloadSize * 8 / simulationTime.GetMicroSeconds();
381 std::cout <<
"AC_BE with default TXOP limit (0ms): " <<
'\n'
382 <<
" Throughput = " <<
throughput <<
" Mbit/s" <<
'\n';
389 throughput = totalPacketsThroughB * payloadSize * 8 / simulationTime.GetMicroSeconds();
390 std::cout <<
"AC_BE with non-default TXOP limit (4.096ms): " <<
'\n'
391 <<
" Throughput = " <<
throughput <<
" Mbit/s" <<
'\n';
397 std::cout <<
" Maximum TXOP duration = " << beTxopTracer.m_max.GetMicroSeconds() <<
" us"
400 (beTxopTracer.m_max <
MicroSeconds(3008) || beTxopTracer.m_max > txopLimit))
402 NS_LOG_ERROR(
"Maximum TXOP duration " << beTxopTracer.m_max
403 <<
" is not in the expected boundaries!");
407 throughput = totalPacketsThroughC * payloadSize * 8 / simulationTime.GetMicroSeconds();
408 std::cout <<
"AC_VI with default TXOP limit (4.096ms): " <<
'\n'
409 <<
" Throughput = " <<
throughput <<
" Mbit/s" <<
'\n';
415 std::cout <<
" Maximum TXOP duration = " << viTxopTracer.m_max.GetMicroSeconds() <<
" us"
418 (viTxopTracer.m_max <
MicroSeconds(3008) || viTxopTracer.m_max > txopLimit))
420 NS_LOG_ERROR(
"Maximum TXOP duration " << viTxopTracer.m_max
421 <<
" is not in the expected boundaries!");
425 throughput = totalPacketsThroughD * payloadSize * 8 / simulationTime.GetMicroSeconds();
426 std::cout <<
"AC_VI with non-default TXOP limit (0ms): " <<
'\n'
427 <<
" Throughput = " <<
throughput <<
" Mbit/s" <<
'\n';
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.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Parse command-line arguments.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
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.
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.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
Handles the packet queue and stores DCF/EDCA access parameters (one Txop per AC).
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.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
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
create MAC layers for a ns3::WifiNetDevice.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
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_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 MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
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.
Keeps the maximum duration among all TXOPs.
void Trace(Time startTime, Time duration, uint8_t linkId)
Callback connected to TXOP duration trace source.
Time m_max
maximum TXOP duration