47#include "ns3/command-line.h"
48#include "ns3/config.h"
49#include "ns3/double.h"
50#include "ns3/flow-monitor-helper.h"
51#include "ns3/gnuplot.h"
52#include "ns3/internet-stack-helper.h"
53#include "ns3/ipv4-address-helper.h"
54#include "ns3/ipv4-flow-classifier.h"
56#include "ns3/mobility-helper.h"
57#include "ns3/on-off-helper.h"
58#include "ns3/packet-sink-helper.h"
60#include "ns3/uinteger.h"
61#include "ns3/wifi-mac-header.h"
62#include "ns3/wifi-mac.h"
63#include "ns3/wifi-net-device.h"
64#include "ns3/yans-wifi-channel.h"
65#include "ns3/yans-wifi-helper.h"
185 typedef std::vector<std::pair<Time, DataRate>>
TxTime;
228 DataRate dataRate =
DataRate(phy->GetDefaultMode().GetDataRate(phy->GetChannelWidth()));
229 const auto power = phy->GetTxPowerEnd();
234 Mac48Address addr = wifiStaDevice->GetMac()->GetAddress();
260 for (
const auto& mode :
phy->GetModeList())
266 DataRate dataRate(mode.GetDataRate(
phy->GetChannelWidth()));
278 if (rate == i->second)
291 packet->PeekHeader(head);
320 if (state == WifiPhyState::CCA_BUSY)
325 else if (state == WifiPhyState::IDLE)
330 else if (state == WifiPhyState::TX)
335 else if (state == WifiPhyState::RX)
425 <<
" " << dest <<
" Old power=" << oldPower <<
" New power=" << newPower);
440 <<
" " << dest <<
" Old rate=" << oldRate <<
" New rate=" << newRate);
444main(
int argc,
char* argv[])
453 std::string manager{
"ns3::ParfWifiManager"};
454 std::string outputFileName{
"parf"};
463 Time simuTime{
"100s"};
466 cmd.AddValue(
"manager",
"PRC Manager", manager);
467 cmd.AddValue(
"rtsThreshold",
"RTS threshold", rtsThreshold);
468 cmd.AddValue(
"outputFileName",
"Output filename", outputFileName);
469 cmd.AddValue(
"simuTime",
"Total simulation time (sec)", simuTime);
470 cmd.AddValue(
"maxPower",
"Maximum available transmission level (dbm).", maxPower);
471 cmd.AddValue(
"minPower",
"Minimum available transmission level (dbm).", minPower);
472 cmd.AddValue(
"powerLevels",
473 "Number of transmission power levels available between "
474 "TxPowerStart and TxPowerEnd included.",
476 cmd.AddValue(
"AP1_x",
"Position of AP1 in x coordinate", ap1_x);
477 cmd.AddValue(
"AP1_y",
"Position of AP1 in y coordinate", ap1_y);
478 cmd.AddValue(
"STA1_x",
"Position of STA1 in x coordinate", sta1_x);
479 cmd.AddValue(
"STA1_y",
"Position of STA1 in y coordinate", sta1_y);
480 cmd.AddValue(
"AP2_x",
"Position of AP2 in x coordinate", ap2_x);
481 cmd.AddValue(
"AP2_y",
"Position of AP2 in y coordinate", ap2_y);
482 cmd.AddValue(
"STA2_x",
"Position of STA2 in x coordinate", sta2_x);
483 cmd.AddValue(
"STA2_y",
"Position of STA2 in y coordinate", sta2_y);
484 cmd.Parse(argc, argv);
507 wifi.SetRemoteStationManager(
"ns3::AarfWifiManager",
514 wifiMac.
SetType(
"ns3::StaWifiMac",
526 wifi.SetRemoteStationManager(manager,
527 "DefaultTxPowerLevel",
537 wifiApDevices.
Add(
wifi.Install(wifiPhy, wifiMac, wifiApNodes.
Get(0)));
540 wifiMac.
SetType(
"ns3::ApWifiMac",
545 wifiApDevices.
Add(
wifi.Install(wifiPhy, wifiMac, wifiApNodes.
Get(1)));
547 wifiDevices.
Add(wifiStaDevices);
548 wifiDevices.
Add(wifiApDevices);
553 positionAlloc->Add(Vector(ap1_x, ap1_y, 0.0));
554 positionAlloc->Add(Vector(sta1_x, sta1_y, 0.0));
555 positionAlloc->Add(Vector(ap2_x, ap2_y, 0.0));
556 positionAlloc->Add(Vector(sta2_x, sta2_y, 0.0));
557 mobility.SetPositionAllocator(positionAlloc);
558 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
566 stack.Install(wifiApNodes);
567 stack.Install(wifiStaNodes);
569 address.SetBase(
"10.1.1.0",
"255.255.255.0");
592 apps_source.
Add(onoff1.Install(wifiApNodes.
Get(1)));
595 apps_sink.
Stop(simuTime);
612 Config::Connect(
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
613 manager +
"/PowerChange",
615 Config::Connect(
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
616 manager +
"/RateChange",
618 Config::Connect(
"/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
619 manager +
"/PowerChange",
621 Config::Connect(
"/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
622 manager +
"/RateChange",
625 Config::Connect(
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
627 Config::Connect(
"/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
632 "/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
635 "/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
642 Config::Connect(
"/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
643 manager +
"/PowerChange",
645 Config::Connect(
"/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
646 manager +
"/RateChange",
658 std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
659 for (
auto i = stats.begin(); i != stats.end(); ++i)
666 NS_LOG_INFO(
" Tx Bytes: " << i->second.txBytes <<
"\n");
667 NS_LOG_INFO(
" Rx Bytes: " << i->second.rxBytes <<
"\n");
669 << i->second.rxBytes * 8.0 /
670 (i->second.timeLastRxPacket.GetSeconds() -
671 i->second.timeFirstTxPacket.GetSeconds()) /
674 NS_LOG_INFO(
" Mean delay: " << i->second.delaySum.GetSeconds() / i->second.rxPackets
677 << i->second.jitterSum.GetSeconds() / (i->second.rxPackets - 1) <<
"\n");
684 NS_LOG_INFO(
" Tx Bytes: " << i->second.txBytes <<
"\n");
685 NS_LOG_INFO(
" Rx Bytes: " << i->second.rxBytes <<
"\n");
687 << i->second.rxBytes * 8.0 /
688 (i->second.timeLastRxPacket.GetSeconds() -
689 i->second.timeFirstTxPacket.GetSeconds()) /
692 NS_LOG_INFO(
" Mean delay: " << i->second.delaySum.GetSeconds() / i->second.rxPackets
695 << i->second.jitterSum.GetSeconds() / (i->second.rxPackets - 1) <<
"\n");
701 std::ofstream outfileTh0(
"throughput-" + outputFileName +
"-0.plt");
702 Gnuplot gnuplot =
Gnuplot(
"throughput-" + outputFileName +
"-0.eps",
"Throughput");
704 gnuplot.
SetLegend(
"Time (seconds)",
"Throughput (Mb/s)");
705 gnuplot.
SetTitle(
"Throughput (AP0 to STA) vs time");
709 if (manager ==
"ns3::ParfWifiManager" || manager ==
"ns3::AparfWifiManager" ||
710 manager ==
"ns3::RrpaaWifiManager")
712 std::ofstream outfilePower0(
"power-" + outputFileName +
"-0.plt");
713 gnuplot =
Gnuplot(
"power-" + outputFileName +
"-0.eps",
"Average Transmit Power");
715 gnuplot.
SetLegend(
"Time (seconds)",
"Power (mW)");
716 gnuplot.
SetTitle(
"Average transmit power (AP0 to STA) vs time");
721 std::ofstream outfileTx0(
"tx-" + outputFileName +
"-0.plt");
722 gnuplot =
Gnuplot(
"tx-" + outputFileName +
"-0.eps",
"Time in TX State");
724 gnuplot.
SetLegend(
"Time (seconds)",
"Percent");
725 gnuplot.
SetTitle(
"Percentage time AP0 in TX state vs time");
729 std::ofstream outfileRx0(
"rx-" + outputFileName +
"-0.plt");
730 gnuplot =
Gnuplot(
"rx-" + outputFileName +
"-0.eps",
"Time in RX State");
732 gnuplot.
SetLegend(
"Time (seconds)",
"Percent");
733 gnuplot.
SetTitle(
"Percentage time AP0 in RX state vs time");
737 std::ofstream outfileBusy0(
"busy-" + outputFileName +
"-0.plt");
738 gnuplot =
Gnuplot(
"busy-" + outputFileName +
"-0.eps",
"Time in Busy State");
740 gnuplot.
SetLegend(
"Time (seconds)",
"Percent");
741 gnuplot.
SetTitle(
"Percentage time AP0 in Busy state vs time");
745 std::ofstream outfileIdle0(
"idle-" + outputFileName +
"-0.plt");
746 gnuplot =
Gnuplot(
"idle-" + outputFileName +
"-0.eps",
"Time in Idle State");
748 gnuplot.
SetLegend(
"Time (seconds)",
"Percent");
749 gnuplot.
SetTitle(
"Percentage time AP0 in Idle state vs time");
754 std::ofstream outfileTh1(
"throughput-" + outputFileName +
"-1.plt");
755 gnuplot =
Gnuplot(
"throughput-" + outputFileName +
"-1.eps",
"Throughput");
757 gnuplot.
SetLegend(
"Time (seconds)",
"Throughput (Mb/s)");
758 gnuplot.
SetTitle(
"Throughput (AP1 to STA) vs time");
762 if (manager ==
"ns3::ParfWifiManager" || manager ==
"ns3::AparfWifiManager" ||
763 manager ==
"ns3::RrpaaWifiManager")
765 std::ofstream outfilePower1(
"power-" + outputFileName +
"-1.plt");
766 gnuplot =
Gnuplot(
"power-" + outputFileName +
"-1.eps",
"Average Transmit Power");
768 gnuplot.
SetLegend(
"Time (seconds)",
"Power (mW)");
769 gnuplot.
SetTitle(
"Average transmit power (AP1 to STA) vs time");
774 std::ofstream outfileTx1(
"tx-" + outputFileName +
"-1.plt");
775 gnuplot =
Gnuplot(
"tx-" + outputFileName +
"-1.eps",
"Time in TX State");
777 gnuplot.
SetLegend(
"Time (seconds)",
"Percent");
778 gnuplot.
SetTitle(
"Percentage time AP1 in TX state vs time");
782 std::ofstream outfileRx1(
"rx-" + outputFileName +
"-1.plt");
783 gnuplot =
Gnuplot(
"rx-" + outputFileName +
"-1.eps",
"Time in RX State");
785 gnuplot.
SetLegend(
"Time (seconds)",
"Percent");
786 gnuplot.
SetTitle(
"Percentage time AP1 in RX state vs time");
790 std::ofstream outfileBusy1(
"busy-" + outputFileName +
"-1.plt");
791 gnuplot =
Gnuplot(
"busy-" + outputFileName +
"-1.eps",
"Time in Busy State");
793 gnuplot.
SetLegend(
"Time (seconds)",
"Percent");
794 gnuplot.
SetTitle(
"Percentage time AP1 in Busy state vs time");
798 std::ofstream outfileIdle1(
"idle-" + outputFileName +
"-1.plt");
799 gnuplot =
Gnuplot(
"idle-" + outputFileName +
"-1.eps",
"Time in Idle State");
801 gnuplot.
SetLegend(
"Time (seconds)",
"Percent");
802 gnuplot.
SetTitle(
"Percentage time AP1 in Idle state vs time");
Class to collect node statistics.
Gnuplot2dDataset m_output_busy
BUSY output data.
double m_totalIdleTime
Total time in IDLE state.
Gnuplot2dDataset m_output_power
Power output data.
double m_totalTxTime
Total time in TX state.
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.
Gnuplot2dDataset GetTxDatafile()
Get the TX state output data.
double m_totalBusyTime
Total time in BUSY state.
Time GetCalcTxTime(DataRate rate)
Get the time at which a given datarate has been recorded.
double idleTime
IDLE time.
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
Callback called by WifiNetDevice/RemoteStationManager/x/PowerChange.
double m_totalTime
Time spent on a given state.
uint32_t m_bytesTotal
Number of received bytes on a given state.
Gnuplot2dDataset GetRxDatafile()
Get the RX state output data.
void SetupPhy(Ptr< WifiPhy > phy)
Setup the WifiPhy object.
std::vector< std::pair< Time, DataRate > > TxTime
Time, DataRate pair vector.
Gnuplot2dDataset m_output_tx
TX output data.
Gnuplot2dDataset GetBusyDatafile()
Get the BUSY state output data.
double m_totalRxTime
Total time in RX state.
double m_totalEnergy
Energy used on a given state.
Gnuplot2dDataset m_output
Throughput output data.
void CheckStatistics(double time)
Collects the statistics at a given time.
double busyTime
BUSY time.
void StateCallback(std::string path, Time init, Time duration, WifiPhyState state)
Callback called by YansWifiPhy/State/State.
Gnuplot2dDataset m_output_rx
RX output data.
Gnuplot2dDataset m_output_idle
IDLE output data.
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.
Gnuplot2dDataset GetIdleDatafile()
Get the IDLE state output data.
double GetBusyTime() const
Get the Busy time.
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.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
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'.
Helper to enable IP flow monitoring on a set of Nodes.
Ptr< FlowClassifier > GetClassifier()
Retrieve the FlowClassifier object for IPv4 created by the Install* methods.
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
Class to represent a 2D points plot.
void Add(double x, double y)
void SetTitle(const std::string &title)
Change line title.
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.
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.
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.
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)
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,...
void Connect(std::string path, const CallbackBase &cb)
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
#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 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.
WifiPhyState
The state of the PHY layer.
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...
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Structure to classify a packet.
Ipv4Address sourceAddress
Source address.
Ipv4Address destinationAddress
Destination address.
static const uint32_t packetSize
Packet size generated at the AP.
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.