21#include "ns3/command-line.h"
22#include "ns3/config.h"
23#include "ns3/uinteger.h"
24#include "ns3/boolean.h"
25#include "ns3/string.h"
26#include "ns3/pointer.h"
28#include "ns3/yans-wifi-helper.h"
30#include "ns3/mobility-helper.h"
31#include "ns3/internet-stack-helper.h"
32#include "ns3/ipv4-address-helper.h"
33#include "ns3/udp-client-server-helper.h"
34#include "ns3/packet-sink-helper.h"
35#include "ns3/yans-wifi-channel.h"
36#include "ns3/wifi-net-device.h"
37#include "ns3/wifi-mac.h"
38#include "ns3/qos-txop.h"
101int main (
int argc,
char *argv[])
104 double simulationTime = 10;
105 double txopLimit = 3520;
109 bool verifyResults = 0;
112 cmd.AddValue (
"payloadSize",
"Payload size in bytes", payloadSize);
113 cmd.AddValue (
"enableRts",
"Enable or disable RTS/CTS", enableRts);
114 cmd.AddValue (
"txopLimit",
"TXOP duration in microseconds", txopLimit);
115 cmd.AddValue (
"simulationTime",
"Simulation time in seconds", simulationTime);
116 cmd.AddValue (
"distance",
"Distance in meters between the station and the access point", distance);
117 cmd.AddValue (
"enablePcap",
"Enable/disable pcap file generation", enablePcap);
118 cmd.AddValue (
"verifyResults",
"Enable/disable results verification at the end of the simulation", verifyResults);
119 cmd.Parse (argc, argv);
130 phy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
135 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
"DataMode",
StringValue (
"HtMcs7"),
"ControlMode",
StringValue (
"HtMcs0"));
138 NetDeviceContainer staDeviceA, staDeviceB, staDeviceC, staDeviceD, apDeviceA, apDeviceB, apDeviceC, apDeviceD;
143 phy.Set (
"ChannelSettings",
StringValue (
"{36, 0, BAND_5GHZ, 0}"));
144 mac.SetType (
"ns3::StaWifiMac",
148 mac.SetType (
"ns3::ApWifiMac",
158 wifi_dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
168 phy.Set (
"ChannelSettings",
StringValue (
"{40, 0, BAND_5GHZ, 0}"));
169 mac.SetType (
"ns3::StaWifiMac",
176 wifi_dev = DynamicCast<WifiNetDevice> (dev);
179 mac.SetType (
"ns3::ApWifiMac",
186 wifi_dev = DynamicCast<WifiNetDevice> (dev);
190 wifi_dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
200 phy.Set (
"ChannelSettings",
StringValue (
"{44, 0, BAND_5GHZ, 0}"));
201 mac.SetType (
"ns3::StaWifiMac",
208 wifi_dev = DynamicCast<WifiNetDevice> (dev);
212 mac.SetType (
"ns3::ApWifiMac",
219 wifi_dev = DynamicCast<WifiNetDevice> (dev);
224 wifi_dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
234 phy.Set (
"ChannelSettings",
StringValue (
"{48, 0, BAND_5GHZ, 0}"));
235 mac.SetType (
"ns3::StaWifiMac",
243 wifi_dev = DynamicCast<WifiNetDevice> (dev);
247 mac.SetType (
"ns3::ApWifiMac",
255 wifi_dev = DynamicCast<WifiNetDevice> (dev);
260 wifi_dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
271 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
274 positionAlloc->Add (
Vector (0.0, 0.0, 0.0));
275 positionAlloc->Add (
Vector (10.0, 0.0, 0.0));
276 positionAlloc->Add (
Vector (20.0, 0.0, 0.0));
277 positionAlloc->Add (
Vector (30.0, 0.0, 0.0));
279 positionAlloc->Add (
Vector (distance, 0.0, 0.0));
280 positionAlloc->Add (
Vector (10 + distance, 0.0, 0.0));
281 positionAlloc->Add (
Vector (20 + distance, 0.0, 0.0));
282 positionAlloc->Add (
Vector (30 + distance, 0.0, 0.0));
284 mobility.SetPositionAllocator (positionAlloc);
290 stack.Install (wifiApNodes);
294 address.SetBase (
"192.168.1.0",
"255.255.255.0");
296 StaInterfaceA =
address.Assign (staDeviceA);
298 ApInterfaceA =
address.Assign (apDeviceA);
300 address.SetBase (
"192.168.2.0",
"255.255.255.0");
302 StaInterfaceB =
address.Assign (staDeviceB);
304 ApInterfaceB =
address.Assign (apDeviceB);
306 address.SetBase (
"192.168.3.0",
"255.255.255.0");
308 StaInterfaceC =
address.Assign (staDeviceC);
310 ApInterfaceC =
address.Assign (apDeviceC);
312 address.SetBase (
"192.168.4.0",
"255.255.255.0");
314 StaInterfaceD =
address.Assign (staDeviceD);
316 ApInterfaceD =
address.Assign (apDeviceD);
326 clientA.SetAttribute (
"MaxPackets",
UintegerValue (4294967295u));
327 clientA.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
328 clientA.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
340 clientB.SetAttribute (
"MaxPackets",
UintegerValue (4294967295u));
341 clientB.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
342 clientB.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
354 clientC.SetAttribute (
"MaxPackets",
UintegerValue (4294967295u));
355 clientC.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
356 clientC.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
368 clientD.SetAttribute (
"MaxPackets",
UintegerValue (4294967295u));
369 clientD.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
370 clientD.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
378 phy.EnablePcap (
"AP_A", apDeviceA.
Get (0));
379 phy.EnablePcap (
"STA_A", staDeviceA.
Get (0));
380 phy.EnablePcap (
"AP_B", apDeviceB.
Get (0));
381 phy.EnablePcap (
"STA_B", staDeviceB.
Get (0));
382 phy.EnablePcap (
"AP_C", apDeviceC.
Get (0));
383 phy.EnablePcap (
"STA_C", staDeviceC.
Get (0));
384 phy.EnablePcap (
"AP_D", apDeviceD.
Get (0));
385 phy.EnablePcap (
"STA_D", staDeviceD.
Get (0));
388 Simulator::Stop (
Seconds (simulationTime + 1));
392 uint64_t totalPacketsThroughA = DynamicCast<UdpServer> (serverAppA.
Get (0))->GetReceived ();
393 uint64_t totalPacketsThroughB = DynamicCast<UdpServer> (serverAppB.
Get (0))->GetReceived ();
394 uint64_t totalPacketsThroughC = DynamicCast<UdpServer> (serverAppC.
Get (0))->GetReceived ();
395 uint64_t totalPacketsThroughD = DynamicCast<UdpServer> (serverAppD.
Get (0))->GetReceived ();
397 Simulator::Destroy ();
399 double throughput = totalPacketsThroughA * payloadSize * 8 / (simulationTime * 1000000.0);
400 std::cout <<
"Default configuration (A-MPDU aggregation enabled, 65kB): " <<
'\n'
401 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
402 if (verifyResults && (throughput < 57.5 || throughput > 58.5))
404 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
409 std::cout <<
" Maximum TXOP duration (TXOP limit = " << txopLimit <<
"us): "
413 NS_LOG_ERROR (
"Maximum TXOP duration " << netA.
m_max <<
" is not in the expected boundaries!");
418 throughput = totalPacketsThroughB * payloadSize * 8 / (simulationTime * 1000000.0);
419 std::cout <<
"Aggregation disabled: " <<
'\n'
420 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
421 if (verifyResults && (throughput < 38 || throughput > 39))
423 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
428 std::cout <<
" Maximum TXOP duration (TXOP limit = " << txopLimit <<
"us): "
432 NS_LOG_ERROR (
"Maximum TXOP duration " << netB.
m_max <<
" is not in the expected boundaries!");
437 throughput = totalPacketsThroughC * payloadSize * 8 / (simulationTime * 1000000.0);
438 std::cout <<
"A-MPDU disabled and A-MSDU enabled (8kB): " <<
'\n'
439 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
440 if (verifyResults && (throughput < 52 || throughput > 53))
442 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
447 std::cout <<
" Maximum TXOP duration (TXOP limit = " << txopLimit <<
"us): "
451 NS_LOG_ERROR (
"Maximum TXOP duration " << netC.
m_max <<
" is not in the expected boundaries!");
456 throughput = totalPacketsThroughD * payloadSize * 8 / (simulationTime * 1000000.0);
457 std::cout <<
"A-MPDU enabled (32kB) and A-MSDU enabled (4kB): " <<
'\n'
458 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
459 if (verifyResults && (throughput < 58 || throughput > 59))
461 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
466 std::cout <<
" Maximum TXOP duration (TXOP limit = " << txopLimit <<
"us): "
470 NS_LOG_ERROR (
"Maximum TXOP duration " << netD.
m_max <<
" 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.
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.
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
AttributeValue implementation for Time.
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
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.
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.
void SetDefault(std::string name, const AttributeValue &value)
#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.