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/udp-server.h"
32 #include "ns3/uinteger.h"
33 #include "ns3/wifi-mac.h"
34 #include "ns3/wifi-net-device.h"
35 #include "ns3/yans-wifi-channel.h"
36 #include "ns3/yans-wifi-helper.h"
83 main(
int argc,
char* argv[])
85 uint32_t payloadSize = 1472;
86 double simulationTime = 10;
88 bool enableRts =
false;
89 bool enablePcap =
false;
90 bool verifyResults =
false;
93 cmd.AddValue(
"payloadSize",
"Payload size in bytes", payloadSize);
94 cmd.AddValue(
"enableRts",
"Enable or disable RTS/CTS", enableRts);
95 cmd.AddValue(
"simulationTime",
"Simulation time in seconds", 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);
120 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
140 mac.SetType(
"ns3::StaWifiMac",
"Ssid", SsidValue(
ssid));
143 mac.SetType(
"ns3::ApWifiMac",
146 "EnableBeaconJitter",
153 mac.SetType(
"ns3::StaWifiMac",
"Ssid", SsidValue(
ssid));
162 mac.SetType(
"ns3::ApWifiMac",
165 "EnableBeaconJitter",
171 wifi_dev = DynamicCast<WifiNetDevice>(dev);
177 mac.SetType(
"ns3::StaWifiMac",
"Ssid", SsidValue(
ssid));
184 wifi_dev = DynamicCast<WifiNetDevice>(dev);
188 mac.SetType(
"ns3::ApWifiMac",
191 "EnableBeaconJitter",
198 wifi_dev = DynamicCast<WifiNetDevice>(dev);
205 mac.SetType(
"ns3::StaWifiMac",
"Ssid", SsidValue(
ssid));
212 wifi_dev = DynamicCast<WifiNetDevice>(dev);
216 mac.SetType(
"ns3::ApWifiMac",
219 "EnableBeaconJitter",
226 wifi_dev = DynamicCast<WifiNetDevice>(dev);
233 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
236 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
237 positionAlloc->Add(Vector(10.0, 0.0, 0.0));
238 positionAlloc->Add(Vector(20.0, 0.0, 0.0));
239 positionAlloc->Add(Vector(30.0, 0.0, 0.0));
241 positionAlloc->Add(Vector(distance, 0.0, 0.0));
242 positionAlloc->Add(Vector(10 + distance, 0.0, 0.0));
243 positionAlloc->Add(Vector(20 + distance, 0.0, 0.0));
244 positionAlloc->Add(Vector(30 + distance, 0.0, 0.0));
246 mobility.SetPositionAllocator(positionAlloc);
252 stack.Install(wifiApNodes);
256 address.SetBase(
"192.168.1.0",
"255.255.255.0");
258 StaInterfaceA =
address.Assign(staDeviceA);
260 ApInterfaceA =
address.Assign(apDeviceA);
262 address.SetBase(
"192.168.2.0",
"255.255.255.0");
264 StaInterfaceB =
address.Assign(staDeviceB);
266 ApInterfaceB =
address.Assign(apDeviceB);
268 address.SetBase(
"192.168.3.0",
"255.255.255.0");
270 StaInterfaceC =
address.Assign(staDeviceC);
272 ApInterfaceC =
address.Assign(apDeviceC);
274 address.SetBase(
"192.168.4.0",
"255.255.255.0");
276 StaInterfaceD =
address.Assign(staDeviceD);
278 ApInterfaceD =
address.Assign(apDeviceD);
288 clientA.SetAttribute(
"MaxPackets",
UintegerValue(4294967295U));
290 clientA.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
302 clientB.SetAttribute(
"MaxPackets",
UintegerValue(4294967295U));
304 clientB.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
316 clientC.SetAttribute(
"MaxPackets",
UintegerValue(4294967295U));
318 clientC.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
330 clientD.SetAttribute(
"MaxPackets",
UintegerValue(4294967295U));
332 clientD.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
340 phy.EnablePcap(
"AP_A", apDeviceA.
Get(0));
341 phy.EnablePcap(
"STA_A", staDeviceA.
Get(0));
342 phy.EnablePcap(
"AP_B", apDeviceB.
Get(0));
343 phy.EnablePcap(
"STA_B", staDeviceB.
Get(0));
344 phy.EnablePcap(
"AP_C", apDeviceC.
Get(0));
345 phy.EnablePcap(
"STA_C", staDeviceC.
Get(0));
346 phy.EnablePcap(
"AP_D", apDeviceD.
Get(0));
347 phy.EnablePcap(
"STA_D", staDeviceD.
Get(0));
354 uint64_t totalPacketsThroughA = DynamicCast<UdpServer>(serverAppA.
Get(0))->GetReceived();
355 uint64_t totalPacketsThroughB = DynamicCast<UdpServer>(serverAppB.
Get(0))->GetReceived();
356 uint64_t totalPacketsThroughC = DynamicCast<UdpServer>(serverAppC.
Get(0))->GetReceived();
357 uint64_t totalPacketsThroughD = DynamicCast<UdpServer>(serverAppD.
Get(0))->GetReceived();
361 double throughput = totalPacketsThroughA * payloadSize * 8 / (simulationTime * 1000000.0);
362 std::cout <<
"Throughput with default configuration (A-MPDU aggregation enabled, 65kB): "
364 if (verifyResults && (throughput < 59.0 || throughput > 60.0))
370 throughput = totalPacketsThroughB * payloadSize * 8 / (simulationTime * 1000000.0);
371 std::cout <<
"Throughput with aggregation disabled: " <<
throughput <<
" Mbit/s" <<
'\n';
372 if (verifyResults && (throughput < 30 || throughput > 31))
378 throughput = totalPacketsThroughC * payloadSize * 8 / (simulationTime * 1000000.0);
379 std::cout <<
"Throughput with A-MPDU disabled and A-MSDU enabled (8kB): " <<
throughput
380 <<
" Mbit/s" <<
'\n';
381 if (verifyResults && (throughput < 51 || throughput > 52))
387 throughput = totalPacketsThroughD * payloadSize * 8 / (simulationTime * 1000000.0);
388 std::cout <<
"Throughput with A-MPDU enabled (32kB) and A-MSDU enabled (4kB): " <<
throughput
389 <<
" Mbit/s" <<
'\n';
390 if (verifyResults && (throughput < 58 || throughput > 59))
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.
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.
Hold variables of type string.
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.