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);
106 wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
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!");
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.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
static void Run(void)
Run the simulation.
The IEEE 802.11 SSID Information Element.
AttributeValue implementation for Ssid.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
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(void) const
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
manage and create wifi channel objects for the YANS model.
static YansWifiChannelHelper Default(void)
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.