20#include "ns3/command-line.h"
21#include "ns3/config.h"
22#include "ns3/ht-configuration.h"
23#include "ns3/internet-stack-helper.h"
24#include "ns3/ipv4-address-helper.h"
26#include "ns3/mobility-helper.h"
27#include "ns3/on-off-helper.h"
28#include "ns3/packet-sink-helper.h"
29#include "ns3/packet-sink.h"
30#include "ns3/pointer.h"
31#include "ns3/qos-txop.h"
33#include "ns3/string.h"
34#include "ns3/udp-client-server-helper.h"
35#include "ns3/wifi-mac.h"
36#include "ns3/wifi-net-device.h"
37#include "ns3/yans-wifi-channel.h"
38#include "ns3/yans-wifi-helper.h"
105 std::string apTypeString;
108 apTypeString =
"WIFI_STANDARD_80211g";
112 apTypeString =
"WIFI_STANDARD_80211n_2_4GHZ";
115 std::cout <<
"Run: " << params.testName
116 <<
"\n\t enableErpProtection=" << params.enableErpProtection
117 <<
"\n\t erpProtectionMode=" << params.erpProtectionMode
118 <<
"\n\t enableShortSlotTime=" << params.enableShortSlotTime
119 <<
"\n\t enableShortPhyPreamble=" << params.enableShortPhyPreamble
120 <<
"\n\t apType=" << apTypeString <<
"\n\t nWifiB=" << params.nWifiB
121 <<
"\n\t bHasTraffic=" << params.bHasTraffic <<
"\n\t nWifiG=" << params.nWifiG
122 <<
"\n\t gHasTraffic=" << params.gHasTraffic <<
"\n\t nWifiN=" << params.nWifiN
123 <<
"\n\t nHasTraffic=" << params.nHasTraffic << std::endl;
128 double throughput = 0;
132 double simulationTime = params.simulationTime;
133 uint32_t payloadSize = params.payloadSize;
136 wifiBStaNodes.
Create(nWifiB);
138 wifiGStaNodes.
Create(nWifiG);
140 wifiNStaNodes.
Create(nWifiN);
142 wifiApNode.Create(1);
145 channel.AddPropagationLoss(
"ns3::RangePropagationLossModel");
148 phy.SetChannel(channel.Create());
151 wifi.SetRemoteStationManager(
"ns3::IdealWifiManager");
159 mac.SetType(
"ns3::StaWifiMac",
162 "ShortSlotTimeSupported",
166 phy.Set(
"ShortPlcpPreambleSupported",
BooleanValue(params.enableShortPhyPreamble));
169 bStaDevice = wifi.Install(phy, mac, wifiBStaNodes);
174 gStaDevice = wifi.Install(phy, mac, wifiGStaNodes);
179 mac.SetType(
"ns3::StaWifiMac",
182 "BE_BlockAckThreshold",
184 "ShortSlotTimeSupported",
186 nStaDevice = wifi.Install(phy, mac, wifiNStaNodes);
190 wifi.SetStandard(params.apType);
191 mac.SetType(
"ns3::ApWifiMac",
194 "EnableBeaconJitter",
196 "BE_BlockAckThreshold",
198 "EnableNonErpProtection",
200 "ShortSlotTimeSupported",
202 apDevice = wifi.Install(phy, mac, wifiApNode);
211 wifi_mac->GetAttribute(
"BE_Txop", ptr);
221 wifi_mac->GetAttribute(
"BE_Txop", ptr);
226 Config::Set(
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/BE_MaxAmpduSize",
233 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
234 for (
uint32_t i = 0; i < nWifiB; i++)
236 positionAlloc->Add(Vector(5.0, 0.0, 0.0));
238 for (
uint32_t i = 0; i < nWifiG; i++)
240 positionAlloc->Add(Vector(0.0, 5.0, 0.0));
242 for (
uint32_t i = 0; i < nWifiN; i++)
244 positionAlloc->Add(Vector(0.0, 0.0, 5.0));
247 mobility.SetPositionAllocator(positionAlloc);
248 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
249 mobility.Install(wifiApNode);
250 mobility.Install(wifiBStaNodes);
251 mobility.Install(wifiGStaNodes);
252 mobility.Install(wifiNStaNodes);
256 stack.Install(wifiApNode);
257 stack.Install(wifiBStaNodes);
258 stack.Install(wifiGStaNodes);
259 stack.Install(wifiNStaNodes);
262 address.SetBase(
"192.168.1.0",
"255.255.255.0");
264 bStaInterface = address.Assign(bStaDevice);
266 gStaInterface = address.Assign(gStaDevice);
268 nStaInterface = address.Assign(nStaDevice);
270 ApInterface = address.Assign(apDevice);
282 client.SetAttribute(
"MaxPackets",
UintegerValue(4294967295U));
284 client.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
287 if (params.bHasTraffic)
289 clientApps.Add(client.Install(wifiBStaNodes));
291 if (params.gHasTraffic)
293 clientApps.Add(client.Install(wifiGStaNodes));
295 if (params.nHasTraffic)
297 clientApps.Add(client.Install(wifiNStaNodes));
299 clientApps.Start(
Seconds(1.0));
300 clientApps.Stop(
Seconds(simulationTime + 1));
305 uint64_t totalPacketsThrough = DynamicCast<UdpServer>(serverApp.
Get(0))->GetReceived();
306 throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
310 uint16_t
port = 50000;
319 onoff.SetAttribute(
"OnTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
320 onoff.SetAttribute(
"OffTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
321 onoff.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
325 onoff.SetAttribute(
"Remote", remoteAddress);
328 if (params.bHasTraffic)
330 clientApps.Add(onoff.Install(wifiBStaNodes));
332 if (params.gHasTraffic)
334 clientApps.Add(onoff.Install(wifiGStaNodes));
336 if (params.nHasTraffic)
338 clientApps.Add(onoff.Install(wifiNStaNodes));
340 clientApps.Start(
Seconds(1.0));
341 clientApps.Stop(
Seconds(simulationTime + 1));
346 uint64_t totalPacketsThrough = DynamicCast<PacketSink>(serverApp.
Get(0))->GetTotalRx();
347 throughput += totalPacketsThrough * 8 / (simulationTime * 1000000.0);
354main(
int argc,
char* argv[])
357 params.testName =
"";
358 params.enableErpProtection =
false;
359 params.erpProtectionMode =
"Cts-To-Self";
360 params.enableShortSlotTime =
false;
361 params.enableShortPhyPreamble =
false;
364 params.bHasTraffic =
false;
366 params.gHasTraffic =
true;
368 params.nHasTraffic =
false;
370 params.payloadSize = 1472;
371 params.simulationTime = 10;
373 bool verifyResults = 0;
376 cmd.AddValue(
"payloadSize",
"Payload size in bytes", params.payloadSize);
377 cmd.AddValue(
"simulationTime",
"Simulation time in seconds", params.simulationTime);
378 cmd.AddValue(
"isUdp",
"UDP if set to 1, TCP otherwise", params.isUdp);
379 cmd.AddValue(
"verifyResults",
380 "Enable/disable results verification at the end of the simulation",
382 cmd.Parse(argc, argv);
385 double throughput = 0;
387 params.testName =
"g only with all g features disabled";
389 if (verifyResults && (throughput < 22.5 || throughput > 23.5))
391 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
394 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
396 params.testName =
"g only with short slot time enabled";
397 params.enableErpProtection =
false;
398 params.enableShortSlotTime =
true;
399 params.enableShortPhyPreamble =
false;
402 if (verifyResults && (throughput < 29 || throughput > 30))
404 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
407 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
409 params.testName =
"Mixed b/g with all g features disabled";
410 params.enableErpProtection =
false;
411 params.enableShortSlotTime =
false;
412 params.enableShortPhyPreamble =
false;
415 if (verifyResults && (throughput < 22.5 || throughput > 23.5))
417 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
420 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
422 params.testName =
"Mixed b/g with short plcp preamble enabled";
423 params.enableErpProtection =
false;
424 params.enableShortSlotTime =
false;
425 params.enableShortPhyPreamble =
true;
428 if (verifyResults && (throughput < 22.5 || throughput > 23.5))
430 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
433 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
435 params.testName =
"Mixed b/g with short slot time enabled using RTS-CTS protection";
436 params.enableErpProtection =
true;
437 params.erpProtectionMode =
"Rts-Cts";
438 params.enableShortSlotTime =
false;
439 params.enableShortPhyPreamble =
false;
442 if (verifyResults && (throughput < 19 || throughput > 20))
444 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
447 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
449 params.testName =
"Mixed b/g with short plcp preamble enabled using RTS-CTS protection";
450 params.enableErpProtection =
true;
451 params.enableShortSlotTime =
false;
452 params.enableShortPhyPreamble =
true;
455 if (verifyResults && (throughput < 19 || throughput > 20))
457 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
460 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
462 params.testName =
"Mixed b/g with short slot time enabled using CTS-TO-SELF protection";
463 params.enableErpProtection =
true;
464 params.erpProtectionMode =
"Cts-To-Self";
465 params.enableShortSlotTime =
false;
466 params.enableShortPhyPreamble =
false;
469 if (verifyResults && (throughput < 20.5 || throughput > 21.5))
471 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
474 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
476 params.testName =
"Mixed b/g with short plcp preamble enabled using CTS-TO-SELF protection";
477 params.enableErpProtection =
true;
478 params.enableShortSlotTime =
false;
479 params.enableShortPhyPreamble =
true;
482 if (verifyResults && (throughput < 20.5 || throughput > 21.5))
484 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
487 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
489 params.testName =
"HT only";
490 params.enableErpProtection =
false;
491 params.enableShortSlotTime =
false;
492 params.enableShortPhyPreamble =
false;
495 params.bHasTraffic =
false;
497 params.gHasTraffic =
false;
499 params.nHasTraffic =
true;
501 if (verifyResults && (throughput < 44 || throughput > 45))
503 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
506 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
508 params.testName =
"Mixed HT/non-HT";
509 params.enableErpProtection =
false;
510 params.enableShortSlotTime =
false;
511 params.enableShortPhyPreamble =
false;
514 params.bHasTraffic =
false;
516 params.gHasTraffic =
false;
518 params.nHasTraffic =
true;
520 if (verifyResults && (throughput < 44 || throughput > 45))
522 NS_LOG_ERROR(
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
525 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
WiFi adhoc experiment class.
Gnuplot2dDataset Run(const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, const WifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel)
Run an experiment.
a polymophic address class
AttributeValue implementation for Address.
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.
AttributeValue implementation for DataRate.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static Ipv4Address GetAny()
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
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.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Hold objects of type Ptr<T>.
Smart pointer class similar to boost::intrusive_ptr.
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
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.
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.
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 experiment(std::string queue_disc_type)
void SetDefault(std::string name, const AttributeValue &value)
void Set(std::string path, 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.
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
FtrParams params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
WifiStandard apType
Wifi standard for AP.
uint32_t nWifiB
Number of 802.11b stations.
uint32_t nWifiN
Number of 802.11n stations.
bool enableErpProtection
True to enable ERP protection.
bool nHasTraffic
True if 802.11n stations generate traffic.
bool gHasTraffic
True if 802.11g stations generate traffic.
double simulationTime
Simulation time in seconds.
std::string erpProtectionMode
ERP protection mode.
bool enableShortSlotTime
True to enable short slot time.
bool bHasTraffic
True if 802.11b stations generate traffic.
bool isUdp
True to generate UDP traffic.
std::string testName
Test name.
bool enableShortPhyPreamble
True to enable short PHY preamble.
uint32_t nWifiG
Number of 802.11g stations.
uint32_t payloadSize
Payload size in bytes.