78#include "ns3/command-line.h"
79#include "ns3/config.h"
80#include "ns3/double.h"
81#include "ns3/gnuplot.h"
82#include "ns3/internet-stack-helper.h"
83#include "ns3/ipv4-address-helper.h"
85#include "ns3/mobility-helper.h"
86#include "ns3/mobility-model.h"
87#include "ns3/on-off-helper.h"
88#include "ns3/packet-sink-helper.h"
90#include "ns3/uinteger.h"
91#include "ns3/wifi-mac-header.h"
92#include "ns3/wifi-mac.h"
93#include "ns3/wifi-net-device.h"
94#include "ns3/yans-wifi-channel.h"
95#include "ns3/yans-wifi-helper.h"
189 typedef std::vector<std::pair<Time, DataRate>>
TxTime;
220 DataRate dataRate =
DataRate(phy->GetDefaultMode().GetDataRate(phy->GetChannelWidth()));
221 const auto power = phy->GetTxPowerEnd();
226 Mac48Address addr = wifiStaDevice->GetMac()->GetAddress();
234 m_output.SetTitle(
"Throughput Mbits/s");
241 for (
const auto& mode : phy->GetModeList())
247 DataRate dataRate(mode.GetDataRate(phy->GetChannelWidth()));
259 if (rate == i->second)
272 packet->PeekHeader(head);
308 mobility->SetPosition(position);
315 return mobility->GetPosition();
365 <<
" " << dest <<
" Old power=" << oldPower <<
" New power=" << newPower);
380 <<
" " << dest <<
" Old rate=" << oldRate <<
" New rate=" << newRate);
384main(
int argc,
char* argv[])
391 std::string manager{
"ns3::ParfWifiManager"};
392 std::string outputFileName{
"parf"};
399 Time stepsTime{
"1s"};
402 cmd.AddValue(
"manager",
"PRC Manager", manager);
403 cmd.AddValue(
"rtsThreshold",
"RTS threshold", rtsThreshold);
404 cmd.AddValue(
"outputFileName",
"Output filename", outputFileName);
405 cmd.AddValue(
"steps",
"How many different distances to try", steps);
406 cmd.AddValue(
"stepsTime",
"Time on each step", stepsTime);
407 cmd.AddValue(
"stepsSize",
"Distance between steps", stepsSize);
408 cmd.AddValue(
"maxPower",
"Maximum available transmission level (dbm).", maxPower);
409 cmd.AddValue(
"minPower",
"Minimum available transmission level (dbm).", minPower);
410 cmd.AddValue(
"powerLevels",
411 "Number of transmission power levels available between "
412 "TxPowerStart and TxPowerEnd included.",
414 cmd.AddValue(
"AP1_x",
"Position of AP1 in x coordinate", ap1_x);
415 cmd.AddValue(
"AP1_y",
"Position of AP1 in y coordinate", ap1_y);
416 cmd.AddValue(
"STA1_x",
"Position of STA1 in x coordinate", sta1_x);
417 cmd.AddValue(
"STA1_y",
"Position of STA1 in y coordinate", sta1_y);
418 cmd.Parse(argc, argv);
422 std::cout <<
"Exiting without running simulation; steps value of 0" << std::endl;
425 Time simuTime = (steps + 1) * stepsTime;
448 wifi.SetRemoteStationManager(
"ns3::MinstrelWifiManager",
459 wifi.SetRemoteStationManager(manager,
460 "DefaultTxPowerLevel",
470 wifiApDevices.
Add(
wifi.Install(wifiPhy, wifiMac, wifiApNodes.
Get(0)));
472 wifiDevices.
Add(wifiStaDevices);
473 wifiDevices.
Add(wifiApDevices);
479 positionAlloc->Add(Vector(ap1_x, ap1_y, 0.0));
480 NS_LOG_INFO(
"Setting initial AP position to " << Vector(ap1_x, ap1_y, 0.0));
481 positionAlloc->Add(Vector(sta1_x, sta1_y, 0.0));
482 NS_LOG_INFO(
"Setting initial STA position to " << Vector(sta1_x, sta1_y, 0.0));
483 mobility.SetPositionAllocator(positionAlloc);
484 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
501 stack.Install(wifiApNodes);
502 stack.Install(wifiStaNodes);
504 address.SetBase(
"10.1.1.0",
"255.255.255.0");
520 apps_sink.
Stop(simuTime);
531 Config::Connect(
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
532 manager +
"/PowerChange",
534 Config::Connect(
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
535 manager +
"/RateChange",
538 Config::Connect(
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
542 Config::Connect(
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
543 manager +
"/PowerChange",
545 Config::Connect(
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
546 manager +
"/RateChange",
552 std::ofstream outfile(
"throughput-" + outputFileName +
".plt");
553 Gnuplot gnuplot =
Gnuplot(
"throughput-" + outputFileName +
".eps",
"Throughput");
555 gnuplot.
SetLegend(
"Time (seconds)",
"Throughput (Mb/s)");
556 gnuplot.
SetTitle(
"Throughput (AP to STA) vs time");
560 if (manager ==
"ns3::ParfWifiManager" || manager ==
"ns3::AparfWifiManager" ||
561 manager ==
"ns3::RrpaaWifiManager")
563 std::ofstream outfile2(
"power-" + outputFileName +
".plt");
564 gnuplot =
Gnuplot(
"power-" + outputFileName +
".eps",
"Average Transmit Power");
566 gnuplot.
SetLegend(
"Time (seconds)",
"Power (mW)");
567 gnuplot.
SetTitle(
"Average transmit power (AP to STA) vs time");
Class to collect node statistics.
void SetPosition(Ptr< Node > node, Vector position)
Set the Position of a node.
Gnuplot2dDataset m_output_power
Power output data.
Gnuplot2dDataset GetPowerDatafile()
Get the Power output data.
TxTime m_timeTable
Time, DataRate table.
void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
Callback called by WifiNetDevice/RemoteStationManager/x/RateChange.
Gnuplot2dDataset GetDatafile()
Get the Throughput output data.
void RxCallback(std::string path, Ptr< const Packet > packet, const Address &from)
Callback called by PacketSink/Rx.
NodeStatistics(NetDeviceContainer aps, NetDeviceContainer stas)
Constructor.
Time GetCalcTxTime(DataRate rate)
Get the time at which a given datarate has been recorded.
double m_totalTime
Time spent on a given state.
uint32_t m_bytesTotal
Number of received bytes on a given state.
void SetupPhy(Ptr< WifiPhy > phy)
Setup the WifiPhy object.
std::vector< std::pair< Time, DataRate > > TxTime
Time, DataRate pair vector.
void AdvancePosition(Ptr< Node > node, int stepsSize, Time stepsTime)
Move a node.
Vector GetPosition(Ptr< Node > node)
Get the Position of a node.
double m_totalEnergy
Energy used on a given state.
Gnuplot2dDataset m_output
Throughput output data.
void PowerCallback(std::string path, dBm_u oldPower, dBm_u newPower, Mac48Address dest)
Callback called by WifiNetDevice/RemoteStationManager/x/PowerChange.
std::map< Mac48Address, DataRate > m_currentRate
Current Tx rate for each sender.
std::map< Mac48Address, dBm_u > m_currentPower
Current Tx power for each sender.
void PhyCallback(std::string path, Ptr< const Packet > packet, double powerW)
Callback called by WifiNetDevice/Phy/PhyTxBegin.
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
uint32_t GetN() const
Get the number of Ptr<NetDevice> stored in this container.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
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.
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 Time Now()
Return the current simulation virtual time.
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.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
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)
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetChannelWidth(MHz_u channelWidth)
Sets the selected channelWidth.
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
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)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
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 Connect(std::string path, const CallbackBase &cb)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#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.
static constexpr uint8_t WIFI_MIN_TX_PWR_LEVEL
minimum TX power level value
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
double dBm_u
dBm weak type
Watt_u DbmToW(dBm_u val)
Convert from dBm to Watts.
double meter_u
meter weak type
void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
Callback called by WifiNetDevice/RemoteStationManager/x/RateChange.
static const uint32_t packetSize
Packet size generated at the AP.
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
Callback called by WifiNetDevice/RemoteStationManager/x/PowerChange.
Ptr< PacketSink > sink
Pointer to the packet sink application.