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"
95 int main (
int argc,
char *argv[])
97 uint32_t payloadSize = 1472;
98 double simulationTime = 10;
99 double txopLimit = 3520;
103 bool verifyResults = 0;
106 cmd.AddValue (
"payloadSize",
"Payload size in bytes", payloadSize);
107 cmd.AddValue (
"enableRts",
"Enable or disable RTS/CTS", enableRts);
108 cmd.AddValue (
"txopLimit",
"TXOP duration in microseconds", txopLimit);
109 cmd.AddValue (
"simulationTime",
"Simulation time in seconds", simulationTime);
110 cmd.AddValue (
"distance",
"Distance in meters between the station and the access point", distance);
111 cmd.AddValue (
"enablePcap",
"Enable/disable pcap file generation",
enablePcap);
112 cmd.AddValue (
"verifyResults",
"Enable/disable results verification at the end of the simulation", verifyResults);
113 cmd.Parse (argc, argv);
128 wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
129 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
"DataMode",
StringValue (
"HtMcs7"),
"ControlMode",
StringValue (
"HtMcs0"));
132 NetDeviceContainer staDeviceA, staDeviceB, staDeviceC, staDeviceD, apDeviceA, apDeviceB, apDeviceC, apDeviceD;
138 mac.SetType (
"ns3::StaWifiMac",
142 mac.SetType (
"ns3::ApWifiMac",
152 wifi_dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
163 mac.SetType (
"ns3::StaWifiMac",
170 wifi_dev = DynamicCast<WifiNetDevice> (dev);
173 mac.SetType (
"ns3::ApWifiMac",
180 wifi_dev = DynamicCast<WifiNetDevice> (dev);
184 wifi_dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
195 mac.SetType (
"ns3::StaWifiMac",
202 wifi_dev = DynamicCast<WifiNetDevice> (dev);
206 mac.SetType (
"ns3::ApWifiMac",
213 wifi_dev = DynamicCast<WifiNetDevice> (dev);
218 wifi_dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
229 mac.SetType (
"ns3::StaWifiMac",
237 wifi_dev = DynamicCast<WifiNetDevice> (dev);
241 mac.SetType (
"ns3::ApWifiMac",
249 wifi_dev = DynamicCast<WifiNetDevice> (dev);
254 wifi_dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
265 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
268 positionAlloc->Add (Vector (0.0, 0.0, 0.0));
269 positionAlloc->Add (Vector (10.0, 0.0, 0.0));
270 positionAlloc->Add (Vector (20.0, 0.0, 0.0));
271 positionAlloc->Add (Vector (30.0, 0.0, 0.0));
273 positionAlloc->Add (Vector (distance, 0.0, 0.0));
274 positionAlloc->Add (Vector (10 + distance, 0.0, 0.0));
275 positionAlloc->Add (Vector (20 + distance, 0.0, 0.0));
276 positionAlloc->Add (Vector (30 + distance, 0.0, 0.0));
278 mobility.SetPositionAllocator (positionAlloc);
284 stack.Install (wifiApNodes);
288 address.SetBase (
"192.168.1.0",
"255.255.255.0");
290 StaInterfaceA =
address.Assign (staDeviceA);
292 ApInterfaceA =
address.Assign (apDeviceA);
294 address.SetBase (
"192.168.2.0",
"255.255.255.0");
296 StaInterfaceB =
address.Assign (staDeviceB);
298 ApInterfaceB =
address.Assign (apDeviceB);
300 address.SetBase (
"192.168.3.0",
"255.255.255.0");
302 StaInterfaceC =
address.Assign (staDeviceC);
304 ApInterfaceC =
address.Assign (apDeviceC);
306 address.SetBase (
"192.168.4.0",
"255.255.255.0");
308 StaInterfaceD =
address.Assign (staDeviceD);
310 ApInterfaceD =
address.Assign (apDeviceD);
320 clientA.SetAttribute (
"MaxPackets",
UintegerValue (4294967295u));
321 clientA.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
322 clientA.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
334 clientB.SetAttribute (
"MaxPackets",
UintegerValue (4294967295u));
335 clientB.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
336 clientB.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
348 clientC.SetAttribute (
"MaxPackets",
UintegerValue (4294967295u));
349 clientC.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
350 clientC.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
362 clientD.SetAttribute (
"MaxPackets",
UintegerValue (4294967295u));
363 clientD.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
364 clientD.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
372 phy.EnablePcap (
"AP_A", apDeviceA.
Get (0));
373 phy.EnablePcap (
"STA_A", staDeviceA.
Get (0));
374 phy.EnablePcap (
"AP_B", apDeviceB.
Get (0));
375 phy.EnablePcap (
"STA_B", staDeviceB.
Get (0));
376 phy.EnablePcap (
"AP_C", apDeviceC.
Get (0));
377 phy.EnablePcap (
"STA_C", staDeviceC.
Get (0));
378 phy.EnablePcap (
"AP_D", apDeviceD.
Get (0));
379 phy.EnablePcap (
"STA_D", staDeviceD.
Get (0));
386 uint64_t totalPacketsThroughA = DynamicCast<UdpServer> (serverAppA.
Get (0))->GetReceived ();
387 uint64_t totalPacketsThroughB = DynamicCast<UdpServer> (serverAppB.
Get (0))->GetReceived ();
388 uint64_t totalPacketsThroughC = DynamicCast<UdpServer> (serverAppC.
Get (0))->GetReceived ();
389 uint64_t totalPacketsThroughD = DynamicCast<UdpServer> (serverAppD.
Get (0))->GetReceived ();
393 double throughput = totalPacketsThroughA * payloadSize * 8 / (simulationTime * 1000000.0);
394 std::cout <<
"Default configuration (A-MPDU aggregation enabled, 65kB): " <<
'\n'
395 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
396 if (verifyResults && (throughput < 57.5 || throughput > 58.5))
398 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
403 std::cout <<
" Maximum TXOP duration (TXOP limit = " << txopLimit <<
"us): "
407 NS_LOG_ERROR (
"Maximum TXOP duration " << netA.
m_max <<
" is not in the expected boundaries!");
412 throughput = totalPacketsThroughB * payloadSize * 8 / (simulationTime * 1000000.0);
413 std::cout <<
"Aggregation disabled: " <<
'\n'
414 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
415 if (verifyResults && (throughput < 39 || throughput > 40))
417 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
422 std::cout <<
" Maximum TXOP duration (TXOP limit = " << txopLimit <<
"us): "
426 NS_LOG_ERROR (
"Maximum TXOP duration " << netB.
m_max <<
" is not in the expected boundaries!");
431 throughput = totalPacketsThroughC * payloadSize * 8 / (simulationTime * 1000000.0);
432 std::cout <<
"A-MPDU disabled and A-MSDU enabled (8kB): " <<
'\n'
433 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
434 if (verifyResults && (throughput < 53 || throughput > 54))
436 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
441 std::cout <<
" Maximum TXOP duration (TXOP limit = " << txopLimit <<
"us): "
445 NS_LOG_ERROR (
"Maximum TXOP duration " << netC.
m_max <<
" is not in the expected boundaries!");
450 throughput = totalPacketsThroughD * payloadSize * 8 / (simulationTime * 1000000.0);
451 std::cout <<
"A-MPDU enabled (32kB) and A-MSDU enabled (4kB): " <<
'\n'
452 <<
" Throughput = " << throughput <<
" Mbit/s" <<
'\n';
453 if (verifyResults && (throughput < 58 || throughput > 59))
455 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
460 std::cout <<
" Maximum TXOP duration (TXOP limit = " << txopLimit <<
"us): "
464 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...
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.
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.
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 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.
void Trace(Time startTime, Time duration)