20#include "ns3/command-line.h"
21#include "ns3/internet-stack-helper.h"
22#include "ns3/ipv4-address-helper.h"
24#include "ns3/mobility-helper.h"
25#include "ns3/on-off-helper.h"
26#include "ns3/pointer.h"
27#include "ns3/qos-txop.h"
29#include "ns3/string.h"
30#include "ns3/udp-client-server-helper.h"
31#include "ns3/wifi-mac.h"
32#include "ns3/wifi-net-device.h"
33#include "ns3/yans-wifi-channel.h"
34#include "ns3/yans-wifi-helper.h"
94main(
int argc,
char* argv[])
97 double simulationTime = 10;
100 bool verifyResults = 0;
104 cmd.AddValue(
"payloadSize",
"Payload size in bytes", payloadSize);
105 cmd.AddValue(
"simulationTime",
"Simulation time in seconds", simulationTime);
106 cmd.AddValue(
"distance",
107 "Distance in meters between the station and the access point",
109 cmd.AddValue(
"enablePcap",
"Enable/disable pcap file generation", enablePcap);
110 cmd.AddValue(
"verifyResults",
111 "Enable/disable results verification at the end of the simulation",
113 cmd.Parse(argc, argv);
116 wifiStaNodes.Create(4);
123 phy.SetChannel(channel.Create());
127 wifi.SetRemoteStationManager(
"ns3::IdealWifiManager");
141 ssid =
Ssid(
"network-A");
142 phy.Set(
"ChannelSettings",
StringValue(
"{36, 20, BAND_5GHZ, 0}"));
144 staDeviceA = wifi.Install(phy, mac, wifiStaNodes.Get(0));
146 mac.SetType(
"ns3::ApWifiMac",
151 "EnableBeaconJitter",
153 apDeviceA = wifi.Install(phy, mac, wifiApNodes.
Get(0));
156 ssid =
Ssid(
"network-B");
157 phy.Set(
"ChannelSettings",
StringValue(
"{40, 20, BAND_5GHZ, 0}"));
160 staDeviceB = wifi.Install(phy, mac, wifiStaNodes.Get(1));
162 mac.SetType(
"ns3::ApWifiMac",
167 "EnableBeaconJitter",
169 apDeviceB = wifi.Install(phy, mac, wifiApNodes.
Get(1));
177 wifi_mac->GetAttribute(
"BE_Txop", ptr);
179 edca->SetTxopLimit(txopLimit);
182 dev = wifiStaNodes.Get(1)->GetDevice(0);
183 wifi_dev = DynamicCast<WifiNetDevice>(dev);
184 wifi_mac = wifi_dev->GetMac();
185 wifi_mac->GetAttribute(
"BE_Txop", ptr);
188 edca->TraceConnectWithoutContext(
"TxopTrace",
192 ssid =
Ssid(
"network-C");
193 phy.Set(
"ChannelSettings",
StringValue(
"{44, 20, BAND_5GHZ, 0}"));
196 staDeviceC = wifi.Install(phy, mac, wifiStaNodes.Get(2));
198 mac.SetType(
"ns3::ApWifiMac",
203 "EnableBeaconJitter",
205 apDeviceC = wifi.Install(phy, mac, wifiApNodes.
Get(2));
208 dev = wifiStaNodes.Get(2)->GetDevice(0);
209 wifi_dev = DynamicCast<WifiNetDevice>(dev);
210 wifi_mac = wifi_dev->GetMac();
211 wifi_mac->GetAttribute(
"VI_Txop", ptr);
214 edca->TraceConnectWithoutContext(
"TxopTrace",
218 ssid =
Ssid(
"network-D");
219 phy.Set(
"ChannelSettings",
StringValue(
"{48, 20, BAND_5GHZ, 0}"));
222 staDeviceD = wifi.Install(phy, mac, wifiStaNodes.Get(3));
224 mac.SetType(
"ns3::ApWifiMac",
229 "EnableBeaconJitter",
231 apDeviceD = wifi.Install(phy, mac, wifiApNodes.
Get(3));
235 wifi_dev = DynamicCast<WifiNetDevice>(dev);
236 wifi_mac = wifi_dev->GetMac();
237 wifi_mac->GetAttribute(
"VI_Txop", ptr);
244 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
247 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
248 positionAlloc->Add(Vector(10.0, 0.0, 0.0));
249 positionAlloc->Add(Vector(20.0, 0.0, 0.0));
250 positionAlloc->Add(Vector(30.0, 0.0, 0.0));
252 positionAlloc->Add(Vector(distance, 0.0, 0.0));
253 positionAlloc->Add(Vector(10 + distance, 0.0, 0.0));
254 positionAlloc->Add(Vector(20 + distance, 0.0, 0.0));
255 positionAlloc->Add(Vector(30 + distance, 0.0, 0.0));
259 mobility.SetPositionAllocator(positionAlloc);
260 mobility.Install(wifiApNodes);
261 mobility.Install(wifiStaNodes);
265 stack.Install(wifiApNodes);
266 stack.Install(wifiStaNodes);
269 address.SetBase(
"192.168.1.0",
"255.255.255.0");
271 StaInterfaceA = address.Assign(staDeviceA);
273 ApInterfaceA = address.Assign(apDeviceA);
275 address.SetBase(
"192.168.2.0",
"255.255.255.0");
277 StaInterfaceB = address.Assign(staDeviceB);
279 ApInterfaceB = address.Assign(apDeviceB);
281 address.SetBase(
"192.168.3.0",
"255.255.255.0");
283 StaInterfaceC = address.Assign(staDeviceC);
285 ApInterfaceC = address.Assign(apDeviceC);
287 address.SetBase(
"192.168.4.0",
"255.255.255.0");
289 StaInterfaceD = address.Assign(staDeviceD);
291 ApInterfaceD = address.Assign(apDeviceD);
294 uint16_t
port = 5001;
303 OnOffHelper clientA(
"ns3::UdpSocketFactory", destA);
304 clientA.SetAttribute(
"OnTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
305 clientA.SetAttribute(
"OffTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
306 clientA.SetAttribute(
"DataRate",
StringValue(
"100000kb/s"));
307 clientA.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
321 OnOffHelper clientB(
"ns3::UdpSocketFactory", destB);
322 clientB.SetAttribute(
"OnTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
323 clientB.SetAttribute(
"OffTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
324 clientB.SetAttribute(
"DataRate",
StringValue(
"100000kb/s"));
325 clientB.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
339 OnOffHelper clientC(
"ns3::UdpSocketFactory", destC);
340 clientC.SetAttribute(
"OnTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
341 clientC.SetAttribute(
"OffTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
342 clientC.SetAttribute(
"DataRate",
StringValue(
"100000kb/s"));
343 clientC.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
357 OnOffHelper clientD(
"ns3::UdpSocketFactory", destD);
358 clientD.SetAttribute(
"OnTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
359 clientD.SetAttribute(
"OffTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
360 clientD.SetAttribute(
"DataRate",
StringValue(
"100000kb/s"));
361 clientD.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
369 phy.EnablePcap(
"AP_A", apDeviceA.
Get(0));
370 phy.EnablePcap(
"STA_A", staDeviceA.
Get(0));
371 phy.EnablePcap(
"AP_B", apDeviceB.
Get(0));
372 phy.EnablePcap(
"STA_B", staDeviceB.
Get(0));
373 phy.EnablePcap(
"AP_C", apDeviceC.
Get(0));
374 phy.EnablePcap(
"STA_C", staDeviceC.
Get(0));
375 phy.EnablePcap(
"AP_D", apDeviceD.
Get(0));
376 phy.EnablePcap(
"STA_D", staDeviceD.
Get(0));
383 uint64_t totalPacketsThroughA = DynamicCast<UdpServer>(serverAppA.
Get(0))->GetReceived();
384 uint64_t totalPacketsThroughB = DynamicCast<UdpServer>(serverAppB.
Get(0))->GetReceived();
385 uint64_t totalPacketsThroughC = DynamicCast<UdpServer>(serverAppC.
Get(0))->GetReceived();
386 uint64_t totalPacketsThroughD = DynamicCast<UdpServer>(serverAppD.
Get(0))->GetReceived();
390 double throughput = totalPacketsThroughA * payloadSize * 8 / (simulationTime * 1000000.0);
391 std::cout <<
"AC_BE with default TXOP limit (0ms): " <<
'\n'
392 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
393 if (verifyResults && (throughput < 28 || throughput > 29))
395 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
399 throughput = totalPacketsThroughB * payloadSize * 8 / (simulationTime * 1000000.0);
400 std::cout <<
"AC_BE with non-default TXOP limit (4.096ms): " <<
'\n'
401 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
402 if (verifyResults && (throughput < 36.5 || throughput > 37))
404 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
407 std::cout <<
" Maximum TXOP duration = " << beTxopTracer.m_max.GetMicroSeconds() <<
" us"
410 (beTxopTracer.m_max <
MicroSeconds(3008) || beTxopTracer.m_max > txopLimit))
412 NS_LOG_ERROR(
"Maximum TXOP duration " << beTxopTracer.m_max
413 <<
" is not in the expected boundaries!");
417 throughput = totalPacketsThroughC * payloadSize * 8 / (simulationTime * 1000000.0);
418 std::cout <<
"AC_VI with default TXOP limit (4.096ms): " <<
'\n'
419 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
420 if (verifyResults && (throughput < 36.5 || throughput > 37.5))
422 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
425 std::cout <<
" Maximum TXOP duration = " << viTxopTracer.m_max.GetMicroSeconds() <<
" us"
428 (viTxopTracer.m_max <
MicroSeconds(3008) || viTxopTracer.m_max > txopLimit))
430 NS_LOG_ERROR(
"Maximum TXOP duration " << viTxopTracer.m_max
431 <<
" is not in the expected boundaries!");
435 throughput = totalPacketsThroughD * payloadSize * 8 / (simulationTime * 1000000.0);
436 std::cout <<
"AC_VI with non-default TXOP limit (0ms): " <<
'\n'
437 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
438 if (verifyResults && (throughput < 31.5 || throughput > 32.5))
440 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
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.
AttributeValue implementation for Boolean.
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.
Hold objects of type Ptr<T>.
Smart pointer class similar to boost::intrusive_ptr.
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
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.
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.
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...
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