92 #include "ns3/core-module.h"
93 #include "ns3/network-module.h"
94 #include "ns3/internet-module.h"
95 #include "ns3/mobility-module.h"
96 #include "ns3/wifi-module.h"
97 #include "ns3/applications-module.h"
98 #include "ns3/stats-module.h"
99 #include "ns3/flow-monitor-module.h"
114 void CheckStatistics (
double time);
128 typedef std::vector<std::pair<Time,WifiMode> >
TxTime;
150 for (uint32_t j = 0; j < stas.
GetN (); j++)
155 actualPower[addr] = 17;
156 actualMode[addr] = phy->GetMode (0);
158 actualMode[
Mac48Address (
"ff:ff:ff:ff:ff:ff")] = phy->GetMode (0);
162 m_output.SetTitle (
"Throughput Mbits/s");
163 m_output_power.SetTitle (
"Average Transmit Power");
170 for (uint32_t i = 0; i < nModes; i++)
182 for (TxTime::const_iterator i = timeTable.begin (); i != timeTable.end (); i++)
184 if (mode == i->second)
200 totalEnergy += actualPower[dest] * GetCalcTxTime (actualMode[dest]).GetSeconds ();
201 totalTime += GetCalcTxTime (actualMode[dest]).GetSeconds ();
208 double txPowerBaseDbm = myPhy->GetTxPowerStart ();
209 double txPowerEndDbm = myPhy->GetTxPowerEnd ();
210 uint32_t nTxPower = myPhy->GetNTxPower ();
214 dbm = txPowerBaseDbm + power * (txPowerEndDbm - txPowerBaseDbm) / (nTxPower - 1);
218 NS_ASSERT_MSG (txPowerBaseDbm == txPowerEndDbm,
"cannot have TxPowerEnd != TxPowerStart with TxPowerLevels == 1");
219 dbm = txPowerBaseDbm;
221 actualPower[dest] = dbm;
227 actualMode[dest] = myPhy->GetMode (rate);
233 m_bytesTotal += packet->
GetSize ();
260 double mbs = ((m_bytesTotal * 8.0) / (1000000 * stepsTime));
262 double atm = pow (10, ((totalEnergy / stepsTime) / 10));
265 m_output_power.Add (pos.x, atm);
266 m_output.Add (pos.x, mbs);
282 return m_output_power;
295 int main (
int argc,
char *argv[])
297 double maxPower = 17;
299 uint32_t powerLevels = 18;
301 uint32_t rtsThreshold = 2346;
302 std::string manager =
"ns3::ParfWifiManager";
303 std::string outputFileName =
"parf";
308 uint32_t steps = 200;
309 uint32_t stepsSize = 1;
310 uint32_t stepsTime = 1;
313 cmd.
AddValue (
"manager",
"PRC Manager", manager);
314 cmd.
AddValue (
"rtsThreshold",
"RTS threshold", rtsThreshold);
315 cmd.
AddValue (
"outputFileName",
"Output filename", outputFileName);
316 cmd.
AddValue (
"steps",
"How many different distances to try", steps);
317 cmd.
AddValue (
"stepsTime",
"Time on each step", stepsTime);
318 cmd.
AddValue (
"stepsSize",
"Distance between steps", stepsSize);
319 cmd.
AddValue (
"maxPower",
"Maximum available transmission level (dbm).", maxPower);
320 cmd.
AddValue (
"minPower",
"Minimum available transmission level (dbm).", minPower);
321 cmd.
AddValue (
"powerLevels",
"Number of transmission power levels available between "
322 "TxPowerStart and TxPowerEnd included.", powerLevels);
323 cmd.
AddValue (
"AP1_x",
"Position of AP1 in x coordinate", ap1_x);
324 cmd.
AddValue (
"AP1_y",
"Position of AP1 in y coordinate", ap1_y);
325 cmd.
AddValue (
"STA1_x",
"Position of STA1 in x coordinate", sta1_x);
326 cmd.
AddValue (
"STA1_y",
"Position of STA1 in y coordinate", sta1_y);
327 cmd.
Parse (argc, argv);
331 std::cout <<
"Exiting without running simulation; steps value of 0" << std::endl;
334 uint32_t simuTime = (steps + 1) * stepsTime;
362 wifiMac.
SetType (
"ns3::StaWifiMac",
365 wifiStaDevices.
Add (wifi.
Install (wifiPhy, wifiMac, wifiStaNodes.
Get (0)));
374 wifiMac.
SetType (
"ns3::ApWifiMac",
376 wifiApDevices.
Add (wifi.
Install (wifiPhy, wifiMac, wifiApNodes.
Get (0)));
378 wifiDevices.
Add (wifiStaDevices);
379 wifiDevices.
Add (wifiApDevices);
385 positionAlloc->
Add (Vector (ap1_x, ap1_y, 0.0));
386 NS_LOG_INFO (
"Setting initial AP position to " << Vector (ap1_x, ap1_y, 0.0));
387 positionAlloc->
Add (Vector (sta1_x, sta1_y, 0.0));
388 NS_LOG_INFO (
"Setting initial STA position to " << Vector (sta1_x, sta1_y, 0.0));
402 stack.Install (wifiApNodes);
403 stack.Install (wifiStaNodes);
405 address.
SetBase (
"10.1.1.0",
"255.255.255.0");
432 Config::Connect (
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager +
"/PowerChange",
434 Config::Connect (
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager +
"/RateChange",
437 Config::Connect (
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
441 Config::Connect (
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager +
"/PowerChange",
443 Config::Connect (
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager +
"/RateChange",
449 std::ofstream outfile ((
"throughput-" + outputFileName +
".plt").c_str ());
450 Gnuplot gnuplot =
Gnuplot ((
"throughput-" + outputFileName +
".eps").c_str (),
"Throughput");
452 gnuplot.
SetLegend (
"Time (seconds)",
"Throughput (Mb/s)");
453 gnuplot.
SetTitle (
"Throughput (AP to STA) vs time");
457 if (manager.compare (
"ns3::ParfWifiManager") == 0 ||
458 manager.compare (
"ns3::AparfWifiManager") == 0)
460 std::ofstream outfile2 ((
"power-" + outputFileName +
".plt").c_str ());
461 gnuplot =
Gnuplot ((
"power-" + outputFileName +
".eps").c_str (),
"Average Transmit Power");
463 gnuplot.
SetLegend (
"Time (seconds)",
"Power (mW)");
464 gnuplot.
SetTitle (
"Average transmit power (AP to STA) vs time");
holds a vector of ns3::Application pointers.
virtual uint32_t GetFrequency(void) const =0
void SetupPhy(Ptr< WifiPhy > phy)
Simulation virtual time values and global simulation resolution.
AttributeValue implementation for Boolean.
void PowerCallback(std::string path, uint8_t power, Mac48Address dest)
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetPosition(Ptr< Node > node, Vector position)
static void AdvancePosition(Ptr< Node > node)
Class to represent a 2D points plot.
holds a vector of std::pair of Ptr and interface index.
Ptr< YansWifiChannel > Create(void) const
void SetRemoteStationManager(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Make it easy to create and manage PHY objects for the yans model.
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
virtual uint32_t GetNModes(void) const =0
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
static Vector GetPosition(Ptr< Node > node)
virtual void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
aggregate IP/TCP/UDP functionality to existing Nodes.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Vector GetPosition(void) const
void AddDataset(const GnuplotDataset &dataset)
void RateCallback(std::string path, uint32_t rate, Mac48Address dest)
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
void Set(std::string name, const AttributeValue &v)
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
void Connect(std::string path, const CallbackBase &cb)
helps to create WifiNetDevice objects
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Gnuplot2dDataset GetPowerDatafile()
void AdvancePosition(Ptr< Node > node, int stepsSize, int stepsTime)
static void SetPosition(Ptr< Node > node, Vector position)
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
a polymophic address class
Gnuplot2dDataset GetDatafile()
void RxCallback(std::string path, Ptr< const Packet > packet, const Address &from)
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
Class for representing data rates.
Keep track of the current position and velocity of an object.
void SetChannel(Ptr< YansWifiChannel > channel)
Ptr< WifiPhy > GetPhy(void) const
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
AttributeValue implementation for Time.
void SetTitle(const std::string &title)
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Hold an unsigned integer type.
std::map< Mac48Address, uint32_t > actualPower
void RateCallback(std::string path, uint32_t rate, Mac48Address dest)
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Time GetCalcTxTime(WifiMode mode)
static NqosWifiMacHelper Default(void)
Create a mac helper in a default working state.
Time CalculateTxDuration(uint32_t size, WifiTxVector txvector, enum WifiPreamble preamble, double frequency, uint8_t packetType, uint8_t incFlag)
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
create non QoS-enabled MAC layers for a ns3::WifiNetDevice.
void PowerCallback(std::string path, uint8_t power, Mac48Address dest)
Parse command-line arguments.
void SetLegend(const std::string &xLegend, const std::string &yLegend)
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Gnuplot2dDataset m_output_power
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
virtual WifiMode GetMode(uint32_t mode) const =0
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
manage and create wifi channel objects for the yans model.
Gnuplot2dDataset m_output
static Time Now(void)
Return the current simulation virtual time.
void SetPosition(const Vector &position)
The IEEE 802.11 SSID Information Element.
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void PhyCallback(std::string path, Ptr< const Packet > packet)
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Helper class used to assign positions and mobility models to nodes.
Ipv4 addresses are stored in host order in this class.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
std::map< Mac48Address, WifiMode > actualMode
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
std::vector< std::pair< Time, WifiMode > > TxTime
Time Seconds(double value)
Construct a Time in the indicated unit.
AttributeValue implementation for Ssid.
void Add(Vector v)
Add a position to the list of positions.
NodeStatistics(NetDeviceContainer aps, NetDeviceContainer stas)
Ptr< WifiMac > GetMac(void) const
void CheckStatistics(double time)
void Parse(int argc, char *argv[])
Parse the program arguments.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
static const uint32_t packetSize
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
void SetTerminal(const std::string &terminal)
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Vector GetPosition(Ptr< Node > node)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
static WifiHelper Default(void)