21#include "ns3/command-line.h"
22#include "ns3/string.h"
23#include "ns3/pointer.h"
25#include "ns3/yans-wifi-helper.h"
27#include "ns3/mobility-helper.h"
28#include "ns3/internet-stack-helper.h"
29#include "ns3/ipv4-address-helper.h"
30#include "ns3/udp-client-server-helper.h"
31#include "ns3/on-off-helper.h"
32#include "ns3/yans-wifi-channel.h"
33#include "ns3/wifi-net-device.h"
34#include "ns3/qos-txop.h"
35#include "ns3/wifi-mac.h"
92int main (
int argc,
char *argv[])
95 double simulationTime = 10;
98 bool verifyResults = 0;
101 cmd.AddValue (
"payloadSize",
"Payload size in bytes", payloadSize);
102 cmd.AddValue (
"simulationTime",
"Simulation time in seconds", simulationTime);
103 cmd.AddValue (
"distance",
"Distance in meters between the station and the access point", distance);
104 cmd.AddValue (
"enablePcap",
"Enable/disable pcap file generation", enablePcap);
105 cmd.AddValue (
"verifyResults",
"Enable/disable results verification at the end of the simulation", verifyResults);
106 cmd.Parse (argc, argv);
115 phy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
120 wifi.SetRemoteStationManager (
"ns3::IdealWifiManager");
123 NetDeviceContainer staDeviceA, staDeviceB, staDeviceC, staDeviceD, apDeviceA, apDeviceB, apDeviceC, apDeviceD;
128 phy.Set (
"ChannelSettings",
StringValue (
"{36, 20, BAND_5GHZ, 0}"));
129 mac.SetType (
"ns3::StaWifiMac",
134 mac.SetType (
"ns3::ApWifiMac",
142 phy.Set (
"ChannelSettings",
StringValue (
"{40, 20, BAND_5GHZ, 0}"));
143 mac.SetType (
"ns3::StaWifiMac",
149 mac.SetType (
"ns3::ApWifiMac",
161 wifi_mac->GetAttribute (
"BE_Txop", ptr);
167 wifi_dev = DynamicCast<WifiNetDevice> (dev);
168 wifi_mac = wifi_dev->
GetMac ();
169 wifi_mac->GetAttribute (
"BE_Txop", ptr);
176 phy.Set (
"ChannelSettings",
StringValue (
"{44, 20, BAND_5GHZ, 0}"));
177 mac.SetType (
"ns3::StaWifiMac",
183 mac.SetType (
"ns3::ApWifiMac",
191 wifi_dev = DynamicCast<WifiNetDevice> (dev);
192 wifi_mac = wifi_dev->
GetMac ();
193 wifi_mac->GetAttribute (
"VI_Txop", ptr);
200 phy.Set (
"ChannelSettings",
StringValue (
"{48, 20, BAND_5GHZ, 0}"));
201 mac.SetType (
"ns3::StaWifiMac",
207 mac.SetType (
"ns3::ApWifiMac",
215 wifi_dev = DynamicCast<WifiNetDevice> (dev);
216 wifi_mac = wifi_dev->
GetMac ();
217 wifi_mac->GetAttribute (
"VI_Txop", ptr);
224 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
227 positionAlloc->Add (
Vector (0.0, 0.0, 0.0));
228 positionAlloc->Add (
Vector (10.0, 0.0, 0.0));
229 positionAlloc->Add (
Vector (20.0, 0.0, 0.0));
230 positionAlloc->Add (
Vector (30.0, 0.0, 0.0));
232 positionAlloc->Add (
Vector (distance, 0.0, 0.0));
233 positionAlloc->Add (
Vector (10 + distance, 0.0, 0.0));
234 positionAlloc->Add (
Vector (20 + distance, 0.0, 0.0));
235 positionAlloc->Add (
Vector (30 + distance, 0.0, 0.0));
239 mobility.SetPositionAllocator (positionAlloc);
245 stack.Install (wifiApNodes);
249 address.SetBase (
"192.168.1.0",
"255.255.255.0");
251 StaInterfaceA =
address.Assign (staDeviceA);
253 ApInterfaceA =
address.Assign (apDeviceA);
255 address.SetBase (
"192.168.2.0",
"255.255.255.0");
257 StaInterfaceB =
address.Assign (staDeviceB);
259 ApInterfaceB =
address.Assign (apDeviceB);
261 address.SetBase (
"192.168.3.0",
"255.255.255.0");
263 StaInterfaceC =
address.Assign (staDeviceC);
265 ApInterfaceC =
address.Assign (apDeviceC);
267 address.SetBase (
"192.168.4.0",
"255.255.255.0");
269 StaInterfaceD =
address.Assign (staDeviceD);
271 ApInterfaceD =
address.Assign (apDeviceD);
274 uint16_t
port = 5001;
283 OnOffHelper clientA (
"ns3::UdpSocketFactory", destA);
284 clientA.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
285 clientA.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
286 clientA.SetAttribute (
"DataRate",
StringValue (
"100000kb/s"));
287 clientA.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
301 OnOffHelper clientB (
"ns3::UdpSocketFactory", destB);
302 clientB.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
303 clientB.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
304 clientB.SetAttribute (
"DataRate",
StringValue (
"100000kb/s"));
305 clientB.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
319 OnOffHelper clientC (
"ns3::UdpSocketFactory", destC);
320 clientC.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
321 clientC.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
322 clientC.SetAttribute (
"DataRate",
StringValue (
"100000kb/s"));
323 clientC.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
337 OnOffHelper clientD (
"ns3::UdpSocketFactory", destD);
338 clientD.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
339 clientD.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
340 clientD.SetAttribute (
"DataRate",
StringValue (
"100000kb/s"));
341 clientD.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
349 phy.EnablePcap (
"AP_A", apDeviceA.
Get (0));
350 phy.EnablePcap (
"STA_A", staDeviceA.
Get (0));
351 phy.EnablePcap (
"AP_B", apDeviceB.
Get (0));
352 phy.EnablePcap (
"STA_B", staDeviceB.
Get (0));
353 phy.EnablePcap (
"AP_C", apDeviceC.
Get (0));
354 phy.EnablePcap (
"STA_C", staDeviceC.
Get (0));
355 phy.EnablePcap (
"AP_D", apDeviceD.
Get (0));
356 phy.EnablePcap (
"STA_D", staDeviceD.
Get (0));
359 Simulator::Stop (
Seconds (simulationTime + 1));
363 uint64_t totalPacketsThroughA = DynamicCast<UdpServer> (serverAppA.
Get (0))->GetReceived ();
364 uint64_t totalPacketsThroughB = DynamicCast<UdpServer> (serverAppB.
Get (0))->GetReceived ();
365 uint64_t totalPacketsThroughC = DynamicCast<UdpServer> (serverAppC.
Get (0))->GetReceived ();
366 uint64_t totalPacketsThroughD = DynamicCast<UdpServer> (serverAppD.
Get (0))->GetReceived ();
368 Simulator::Destroy ();
370 double throughput = totalPacketsThroughA * payloadSize * 8 / (simulationTime * 1000000.0);
371 std::cout <<
"AC_BE with default TXOP limit (0ms): " <<
'\n'
372 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
373 if (verifyResults && (throughput < 28 || throughput > 29))
375 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
379 throughput = totalPacketsThroughB * payloadSize * 8 / (simulationTime * 1000000.0);
380 std::cout <<
"AC_BE with non-default TXOP limit (3.008ms): " <<
'\n'
381 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
382 if (verifyResults && (throughput < 35 || throughput > 36))
384 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
387 std::cout <<
" Maximum TXOP duration = " << beTxopTracer.m_max.GetMicroSeconds () <<
" us" <<
'\n';
390 NS_LOG_ERROR (
"Maximum TXOP duration " << beTxopTracer.m_max <<
" is not in the expected boundaries!");
394 throughput = totalPacketsThroughC * payloadSize * 8 / (simulationTime * 1000000.0);
395 std::cout <<
"AC_VI with default TXOP limit (3.008ms): " <<
'\n'
396 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
397 if (verifyResults && (throughput < 35.5 || throughput > 36.5))
399 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
402 std::cout <<
" Maximum TXOP duration = " << viTxopTracer.m_max.GetMicroSeconds () <<
" us" <<
'\n';
405 NS_LOG_ERROR (
"Maximum TXOP duration " << viTxopTracer.m_max <<
" is not in the expected boundaries!");
409 throughput = totalPacketsThroughD * payloadSize * 8 / (simulationTime * 1000000.0);
410 std::cout <<
"AC_VI with non-default TXOP limit (0ms): " <<
'\n'
411 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
412 if (verifyResults && (throughput < 31.5 || throughput > 32.5))
414 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
holds a vector of ns3::Application pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Stop(Time stop)
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.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Hold objects of type Ptr<T>.
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
The IEEE 802.11 SSID Information Element.
AttributeValue implementation for Ssid.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
Create a server application which waits for input UDP packets and uses the information carried into t...
Hold an unsigned integer type.
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
Ptr< WifiMac > GetMac(void) const
manage and create wifi channel objects for the YANS model.
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, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Keeps the maximum duration among all TXOPs.
Time m_max
maximum TXOP duration
void Trace(Time startTime, Time duration)
Callback connected to TXOP duration trace source.