45#include "ns3/boolean.h"
46#include "ns3/command-line.h"
47#include "ns3/config.h"
48#include "ns3/double.h"
49#include "ns3/gnuplot.h"
50#include "ns3/internet-stack-helper.h"
51#include "ns3/ipv4-address-helper.h"
53#include "ns3/mobility-helper.h"
54#include "ns3/mobility-model.h"
55#include "ns3/on-off-helper.h"
56#include "ns3/packet-sink-helper.h"
58#include "ns3/string.h"
59#include "ns3/uinteger.h"
60#include "ns3/yans-wifi-channel.h"
61#include "ns3/yans-wifi-helper.h"
143 double mbs = ((
m_bytesTotal * 8.0) / (1000000 * stepsTime));
171 NS_LOG_INFO(
"Rate " << newRate / 1000000.0 <<
" Mbps");
175main(
int argc,
char* argv[])
178 std::string staManager{
"ns3::MinstrelHtWifiManager"};
179 std::string apManager{
"ns3::MinstrelHtWifiManager"};
180 std::string standard{
"802.11n-5GHz"};
181 std::string outputFileName{
"minstrelHT"};
183 bool shortGuardInterval{
false};
194 cmd.AddValue(
"staManager",
"Rate adaptation manager of the STA", staManager);
195 cmd.AddValue(
"apManager",
"Rate adaptation manager of the AP", apManager);
196 cmd.AddValue(
"standard",
"Wifi standard (a/b/g/n/ac only)", standard);
197 cmd.AddValue(
"shortGuardInterval",
198 "Enable Short Guard Interval in all stations",
200 cmd.AddValue(
"channelWidth",
"Channel width of all the stations", chWidth);
201 cmd.AddValue(
"rtsThreshold",
"RTS threshold", rtsThreshold);
202 cmd.AddValue(
"BeMaxAmpduSize",
"BE Mac A-MPDU size", BeMaxAmpduSize);
203 cmd.AddValue(
"outputFileName",
"Output filename", outputFileName);
204 cmd.AddValue(
"steps",
"How many different distances to try", steps);
205 cmd.AddValue(
"stepsTime",
"Time on each step", stepsTime);
206 cmd.AddValue(
"stepsSize",
"Distance between steps", stepsSize);
207 cmd.AddValue(
"AP1_x",
"Position of AP1 in x coordinate", ap1_x);
208 cmd.AddValue(
"AP1_y",
"Position of AP1 in y coordinate", ap1_y);
209 cmd.AddValue(
"STA1_x",
"Position of STA1 in x coordinate", sta1_x);
210 cmd.AddValue(
"STA1_y",
"Position of STA1 in y coordinate", sta1_y);
211 cmd.Parse(argc, argv);
213 int simuTime = steps * stepsTime;
215 if (standard !=
"802.11a" && standard !=
"802.11b" && standard !=
"802.11g" &&
216 standard !=
"802.11n-2.4GHz" && standard !=
"802.11n-5GHz" && standard !=
"802.11ac")
218 NS_FATAL_ERROR(
"Standard " << standard <<
" is not supported by this program");
233 std::string frequencyBand;
234 if (standard ==
"802.11b" || standard ==
"802.11g" || standard ==
"802.11n-2.4GHz")
236 frequencyBand =
"BAND_2_4GHZ";
240 frequencyBand =
"BAND_5GHZ";
242 wifiPhy.
Set(
"ChannelSettings",
243 StringValue(
"{0, " + std::to_string(chWidth) +
", " + frequencyBand +
", 0}"));
262 if (standard ==
"802.11a" || standard ==
"802.11b" || standard ==
"802.11g")
264 if (standard ==
"802.11a")
268 else if (standard ==
"802.11b")
272 else if (standard ==
"802.11g")
279 wifi.SetRemoteStationManager(staManager,
"RtsCtsThreshold",
UintegerValue(rtsThreshold));
286 wifi.SetRemoteStationManager(apManager,
"RtsCtsThreshold",
UintegerValue(rtsThreshold));
290 wifiApDevices.
Add(
wifi.Install(wifiPhy, wifiMac, wifiApNodes.
Get(0)));
292 else if (standard ==
"802.11n-2.4GHz" || standard ==
"802.11n-5GHz" || standard ==
"802.11ac")
294 if (standard ==
"802.11n-2.4GHz" || standard ==
"802.11n-5GHz")
298 else if (standard ==
"802.11ac")
306 wifi.SetRemoteStationManager(staManager,
"RtsCtsThreshold",
UintegerValue(rtsThreshold));
313 wifi.SetRemoteStationManager(apManager,
"RtsCtsThreshold",
UintegerValue(rtsThreshold));
317 wifiApDevices.
Add(
wifi.Install(wifiPhy, wifiMac, wifiApNodes.
Get(0)));
319 Config::Set(
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/BE_MaxAmpduSize",
323 wifiDevices.
Add(wifiStaDevices);
324 wifiDevices.
Add(wifiApDevices);
328 "/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/HtConfiguration/ShortGuardIntervalSupported",
335 positionAlloc->Add(Vector(ap1_x, ap1_y, 0.0));
336 positionAlloc->Add(Vector(sta1_x, sta1_y, 0.0));
337 mobility.SetPositionAllocator(positionAlloc);
338 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
355 stack.Install(wifiApNodes);
356 stack.Install(wifiStaNodes);
358 address.SetBase(
"10.1.1.0",
"255.255.255.0");
386 "/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + apManager +
"/Rate",
392 std::ofstream outfile(
"throughput-" + outputFileName +
".plt");
393 Gnuplot gnuplot =
Gnuplot(
"throughput-" + outputFileName +
".eps",
"Throughput");
395 gnuplot.
SetLegend(
"Distance (meters)",
"Throughput (Mb/s)");
396 gnuplot.
SetTitle(
"Throughput (AP to STA) vs distance");
Class to collect node statistics.
void SetPosition(Ptr< Node > node, Vector position)
Set node position.
Gnuplot2dDataset GetDatafile()
void RxCallback(std::string path, Ptr< const Packet > packet, const Address &from)
RX callback.
NodeStatistics(NetDeviceContainer aps, NetDeviceContainer stas)
Constructor.
uint32_t m_bytesTotal
Number of received bytes on a given state.
void AdvancePosition(Ptr< Node > node, int stepsSize, Time stepsTime)
Move a node.
Vector GetPosition(Ptr< Node > node)
Get node position.
Gnuplot2dDataset m_output
Throughput output data.
a polymophic address class
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.
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.
Class for representing data rates.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Class to represent a 2D points plot.
void Add(double x, double y)
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
void AddDataset(const GnuplotDataset &dataset)
void SetLegend(const std::string &xLegend, const std::string &yLegend)
void SetTerminal(const std::string &terminal)
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
void SetTitle(const std::string &title)
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
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.
Keep track of the current position and velocity of an object.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
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.
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.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
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.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
void Set(std::string name, const AttributeValue &v)
void DisablePreambleDetectionModel()
Disable the preamble detection model on all links.
manage and create wifi channel objects for the YANS model.
static YansWifiChannelHelper Default()
Create a channel helper in a default working state.
Ptr< YansWifiChannel > Create() const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
void Connect(std::string path, const CallbackBase &cb)
void Set(std::string path, const AttributeValue &value)
bool ConnectWithoutContextFailSafe(std::string path, const CallbackBase &cb)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
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, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
void RateCallback(uint64_t oldRate, uint64_t newRate)
Callback for 'Rate' trace source.
Ptr< PacketSink > sink
Pointer to the packet sink application.