20 #include "ns3/boolean.h"
21 #include "ns3/command-line.h"
22 #include "ns3/config.h"
23 #include "ns3/internet-stack-helper.h"
24 #include "ns3/ipv4-address-helper.h"
26 #include "ns3/mobility-helper.h"
27 #include "ns3/packet-sink-helper.h"
29 #include "ns3/string.h"
30 #include "ns3/udp-client-server-helper.h"
31 #include "ns3/uinteger.h"
32 #include "ns3/wifi-mac.h"
33 #include "ns3/wifi-net-device.h"
34 #include "ns3/yans-wifi-channel.h"
35 #include "ns3/yans-wifi-helper.h"
82 main(
int argc,
char* argv[])
84 uint32_t payloadSize = 1472;
85 double simulationTime = 10;
89 bool verifyResults = 0;
92 cmd.AddValue(
"payloadSize",
"Payload size in bytes", payloadSize);
93 cmd.AddValue(
"enableRts",
"Enable or disable RTS/CTS", enableRts);
94 cmd.AddValue(
"simulationTime",
"Simulation time in seconds", simulationTime);
95 cmd.AddValue(
"distance",
96 "Distance in meters between the station and the access point",
98 cmd.AddValue(
"enablePcap",
"Enable/disable pcap file generation", enablePcap);
99 cmd.AddValue(
"verifyResults",
100 "Enable/disable results verification at the end of the simulation",
102 cmd.Parse(argc, argv);
119 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
142 mac.SetType(
"ns3::ApWifiMac",
145 "EnableBeaconJitter",
161 mac.SetType(
"ns3::ApWifiMac",
164 "EnableBeaconJitter",
170 wifi_dev = DynamicCast<WifiNetDevice>(dev);
183 wifi_dev = DynamicCast<WifiNetDevice>(dev);
187 mac.SetType(
"ns3::ApWifiMac",
190 "EnableBeaconJitter",
197 wifi_dev = DynamicCast<WifiNetDevice>(dev);
211 wifi_dev = DynamicCast<WifiNetDevice>(dev);
215 mac.SetType(
"ns3::ApWifiMac",
218 "EnableBeaconJitter",
225 wifi_dev = DynamicCast<WifiNetDevice>(dev);
232 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
235 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
236 positionAlloc->Add(Vector(10.0, 0.0, 0.0));
237 positionAlloc->Add(Vector(20.0, 0.0, 0.0));
238 positionAlloc->Add(Vector(30.0, 0.0, 0.0));
240 positionAlloc->Add(Vector(distance, 0.0, 0.0));
241 positionAlloc->Add(Vector(10 + distance, 0.0, 0.0));
242 positionAlloc->Add(Vector(20 + distance, 0.0, 0.0));
243 positionAlloc->Add(Vector(30 + distance, 0.0, 0.0));
245 mobility.SetPositionAllocator(positionAlloc);
251 stack.Install(wifiApNodes);
255 address.SetBase(
"192.168.1.0",
"255.255.255.0");
257 StaInterfaceA =
address.Assign(staDeviceA);
259 ApInterfaceA =
address.Assign(apDeviceA);
261 address.SetBase(
"192.168.2.0",
"255.255.255.0");
263 StaInterfaceB =
address.Assign(staDeviceB);
265 ApInterfaceB =
address.Assign(apDeviceB);
267 address.SetBase(
"192.168.3.0",
"255.255.255.0");
269 StaInterfaceC =
address.Assign(staDeviceC);
271 ApInterfaceC =
address.Assign(apDeviceC);
273 address.SetBase(
"192.168.4.0",
"255.255.255.0");
275 StaInterfaceD =
address.Assign(staDeviceD);
277 ApInterfaceD =
address.Assign(apDeviceD);
287 clientA.SetAttribute(
"MaxPackets",
UintegerValue(4294967295U));
289 clientA.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
301 clientB.SetAttribute(
"MaxPackets",
UintegerValue(4294967295U));
303 clientB.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
315 clientC.SetAttribute(
"MaxPackets",
UintegerValue(4294967295U));
317 clientC.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
329 clientD.SetAttribute(
"MaxPackets",
UintegerValue(4294967295U));
331 clientD.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
339 phy.EnablePcap(
"AP_A", apDeviceA.
Get(0));
340 phy.EnablePcap(
"STA_A", staDeviceA.
Get(0));
341 phy.EnablePcap(
"AP_B", apDeviceB.
Get(0));
342 phy.EnablePcap(
"STA_B", staDeviceB.
Get(0));
343 phy.EnablePcap(
"AP_C", apDeviceC.
Get(0));
344 phy.EnablePcap(
"STA_C", staDeviceC.
Get(0));
345 phy.EnablePcap(
"AP_D", apDeviceD.
Get(0));
346 phy.EnablePcap(
"STA_D", staDeviceD.
Get(0));
353 uint64_t totalPacketsThroughA = DynamicCast<UdpServer>(serverAppA.
Get(0))->GetReceived();
354 uint64_t totalPacketsThroughB = DynamicCast<UdpServer>(serverAppB.
Get(0))->GetReceived();
355 uint64_t totalPacketsThroughC = DynamicCast<UdpServer>(serverAppC.
Get(0))->GetReceived();
356 uint64_t totalPacketsThroughD = DynamicCast<UdpServer>(serverAppD.
Get(0))->GetReceived();
360 double throughput = totalPacketsThroughA * payloadSize * 8 / (simulationTime * 1000000.0);
361 std::cout <<
"Throughput with default configuration (A-MPDU aggregation enabled, 65kB): "
362 << throughput <<
" Mbit/s" <<
'\n';
363 if (verifyResults && (throughput < 59.0 || throughput > 60.0))
365 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
369 throughput = totalPacketsThroughB * payloadSize * 8 / (simulationTime * 1000000.0);
370 std::cout <<
"Throughput with aggregation disabled: " << throughput <<
" Mbit/s" <<
'\n';
371 if (verifyResults && (throughput < 30 || throughput > 31))
373 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
377 throughput = totalPacketsThroughC * payloadSize * 8 / (simulationTime * 1000000.0);
378 std::cout <<
"Throughput with A-MPDU disabled and A-MSDU enabled (8kB): " << throughput
379 <<
" Mbit/s" <<
'\n';
380 if (verifyResults && (throughput < 51 || throughput > 52))
382 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
386 throughput = totalPacketsThroughD * payloadSize * 8 / (simulationTime * 1000000.0);
387 std::cout <<
"Throughput with A-MPDU enabled (32kB) and A-MSDU enabled (4kB): " << throughput
388 <<
" Mbit/s" <<
'\n';
389 if (verifyResults && (throughput < 58 || throughput > 59))
391 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.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
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.
AttributeValue implementation for Time.
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
create MAC layers for a ns3::WifiNetDevice.
Ptr< WifiMac > GetMac() const
@ 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.
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 Seconds(double value)
Construct a Time in the indicated unit.
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.