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"
27 #include "ns3/yans-wifi-helper.h"
29 #include "ns3/mobility-helper.h"
30 #include "ns3/internet-stack-helper.h"
31 #include "ns3/ipv4-address-helper.h"
32 #include "ns3/udp-client-server-helper.h"
33 #include "ns3/packet-sink-helper.h"
34 #include "ns3/yans-wifi-channel.h"
35 #include "ns3/wifi-net-device.h"
36 #include "ns3/wifi-mac.h"
75 int main (
int argc,
char *argv[])
77 uint32_t payloadSize = 1472;
78 double simulationTime = 10;
82 bool verifyResults = 0;
85 cmd.AddValue (
"payloadSize",
"Payload size in bytes", payloadSize);
86 cmd.AddValue (
"enableRts",
"Enable or disable RTS/CTS", enableRts);
87 cmd.AddValue (
"simulationTime",
"Simulation time in seconds", simulationTime);
88 cmd.AddValue (
"distance",
"Distance in meters between the station and the access point", distance);
89 cmd.AddValue (
"enablePcap",
"Enable/disable pcap file generation",
enablePcap);
90 cmd.AddValue (
"verifyResults",
"Enable/disable results verification at the end of the simulation", verifyResults);
91 cmd.Parse (argc, argv);
107 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
"DataMode",
StringValue (
"HtMcs7"),
"ControlMode",
StringValue (
"HtMcs0"));
110 NetDeviceContainer staDeviceA, staDeviceB, staDeviceC, staDeviceD, apDeviceA, apDeviceB, apDeviceC, apDeviceD;
116 mac.SetType (
"ns3::StaWifiMac",
120 mac.SetType (
"ns3::ApWifiMac",
128 mac.SetType (
"ns3::StaWifiMac",
138 mac.SetType (
"ns3::ApWifiMac",
145 wifi_dev = DynamicCast<WifiNetDevice> (dev);
151 mac.SetType (
"ns3::StaWifiMac",
158 wifi_dev = DynamicCast<WifiNetDevice> (dev);
162 mac.SetType (
"ns3::ApWifiMac",
169 wifi_dev = DynamicCast<WifiNetDevice> (dev);
176 mac.SetType (
"ns3::StaWifiMac",
184 wifi_dev = DynamicCast<WifiNetDevice> (dev);
188 mac.SetType (
"ns3::ApWifiMac",
196 wifi_dev = DynamicCast<WifiNetDevice> (dev);
203 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
206 positionAlloc->
Add (Vector (0.0, 0.0, 0.0));
207 positionAlloc->
Add (Vector (10.0, 0.0, 0.0));
208 positionAlloc->
Add (Vector (20.0, 0.0, 0.0));
209 positionAlloc->
Add (Vector (30.0, 0.0, 0.0));
211 positionAlloc->
Add (Vector (distance, 0.0, 0.0));
212 positionAlloc->
Add (Vector (10 + distance, 0.0, 0.0));
213 positionAlloc->
Add (Vector (20 + distance, 0.0, 0.0));
214 positionAlloc->
Add (Vector (30 + distance, 0.0, 0.0));
216 mobility.SetPositionAllocator (positionAlloc);
222 stack.Install (wifiApNodes);
226 address.SetBase (
"192.168.1.0",
"255.255.255.0");
228 StaInterfaceA =
address.Assign (staDeviceA);
230 ApInterfaceA =
address.Assign (apDeviceA);
232 address.SetBase (
"192.168.2.0",
"255.255.255.0");
234 StaInterfaceB =
address.Assign (staDeviceB);
236 ApInterfaceB =
address.Assign (apDeviceB);
238 address.SetBase (
"192.168.3.0",
"255.255.255.0");
240 StaInterfaceC =
address.Assign (staDeviceC);
242 ApInterfaceC =
address.Assign (apDeviceC);
244 address.SetBase (
"192.168.4.0",
"255.255.255.0");
246 StaInterfaceD =
address.Assign (staDeviceD);
248 ApInterfaceD =
address.Assign (apDeviceD);
258 clientA.SetAttribute (
"MaxPackets",
UintegerValue (4294967295u));
259 clientA.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
260 clientA.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
272 clientB.SetAttribute (
"MaxPackets",
UintegerValue (4294967295u));
273 clientB.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
274 clientB.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
286 clientC.SetAttribute (
"MaxPackets",
UintegerValue (4294967295u));
287 clientC.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
288 clientC.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
300 clientD.SetAttribute (
"MaxPackets",
UintegerValue (4294967295u));
301 clientD.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
302 clientD.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
310 phy.EnablePcap (
"AP_A", apDeviceA.
Get (0));
311 phy.EnablePcap (
"STA_A", staDeviceA.
Get (0));
312 phy.EnablePcap (
"AP_B", apDeviceB.
Get (0));
313 phy.EnablePcap (
"STA_B", staDeviceB.
Get (0));
314 phy.EnablePcap (
"AP_C", apDeviceC.
Get (0));
315 phy.EnablePcap (
"STA_C", staDeviceC.
Get (0));
316 phy.EnablePcap (
"AP_D", apDeviceD.
Get (0));
317 phy.EnablePcap (
"STA_D", staDeviceD.
Get (0));
324 uint64_t totalPacketsThroughA = DynamicCast<UdpServer> (serverAppA.
Get (0))->GetReceived ();
325 uint64_t totalPacketsThroughB = DynamicCast<UdpServer> (serverAppB.
Get (0))->GetReceived ();
326 uint64_t totalPacketsThroughC = DynamicCast<UdpServer> (serverAppC.
Get (0))->GetReceived ();
327 uint64_t totalPacketsThroughD = DynamicCast<UdpServer> (serverAppD.
Get (0))->GetReceived ();
331 double throughput = totalPacketsThroughA * payloadSize * 8 / (simulationTime * 1000000.0);
332 std::cout <<
"Throughput with default configuration (A-MPDU aggregation enabled, 65kB): " << throughput <<
" Mbit/s" <<
'\n';
333 if (verifyResults && (throughput < 58.5 || throughput > 59.5))
335 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
339 throughput = totalPacketsThroughB * payloadSize * 8 / (simulationTime * 1000000.0);
340 std::cout <<
"Throughput with aggregation disabled: " << throughput <<
" Mbit/s" <<
'\n';
341 if (verifyResults && (throughput < 30 || throughput > 31))
343 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
347 throughput = totalPacketsThroughC * payloadSize * 8 / (simulationTime * 1000000.0);
348 std::cout <<
"Throughput with A-MPDU disabled and A-MSDU enabled (8kB): " << throughput <<
" Mbit/s" <<
'\n';
349 if (verifyResults && (throughput < 51 || throughput > 52))
351 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
355 throughput = totalPacketsThroughD * payloadSize * 8 / (simulationTime * 1000000.0);
356 std::cout <<
"Throughput with A-MPDU enabled (32kB) and A-MSDU enabled (4kB): " << throughput <<
" Mbit/s" <<
'\n';
357 if (verifyResults && (throughput < 58 || throughput > 59))
359 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");