| 
	      
		 A Discrete-Event Network Simulator 
		
	       | 
	      
	      
		API
	       | 
	    
	  
	
	
       
 
Go to the documentation of this file.
   88 #include "ns3/gnuplot.h" 
   89 #include "ns3/command-line.h" 
   90 #include "ns3/config.h" 
   91 #include "ns3/uinteger.h" 
   92 #include "ns3/double.h" 
   94 #include "ns3/yans-wifi-helper.h" 
   96 #include "ns3/mobility-helper.h" 
   97 #include "ns3/internet-stack-helper.h" 
   98 #include "ns3/ipv4-address-helper.h" 
   99 #include "ns3/packet-sink-helper.h" 
  100 #include "ns3/on-off-helper.h" 
  101 #include "ns3/yans-wifi-channel.h" 
  102 #include "ns3/wifi-net-device.h" 
  103 #include "ns3/wifi-mac.h" 
  104 #include "ns3/wifi-mac-header.h" 
  105 #include "ns3/mobility-model.h" 
  133   typedef std::vector<std::pair<Time, DataRate> > 
TxTime;
 
  156   double power = 
phy->GetTxPowerEnd ();
 
  157   for (uint32_t j = 0; j < stas.
GetN (); j++)
 
  162       currentPower[addr] = power;
 
  163       currentRate[addr] = dataRate;
 
  165   currentRate[
Mac48Address (
"ff:ff:ff:ff:ff:ff")] = dataRate;
 
  169   m_output.SetTitle (
"Throughput Mbits/s");
 
  170   m_output_power.SetTitle (
"Average Transmit Power");
 
  176   for (
const auto & mode : 
phy->GetModeList ())
 
  185       timeTable.push_back (std::make_pair (time, dataRate));
 
  192   for (TxTime::const_iterator i = timeTable.begin (); i != timeTable.end (); i++)
 
  194       if (rate == i->second)
 
  212       totalEnergy += pow (10.0, currentPower[dest] / 10.0) * GetCalcTxTime (currentRate[dest]).GetSeconds ();
 
  213       totalTime += GetCalcTxTime (currentRate[dest]).GetSeconds ();
 
  220   currentPower[dest] = newPower;
 
  226   currentRate[dest] = newRate;
 
  232   m_bytesTotal += packet->
GetSize ();
 
  253   double mbs = ((m_bytesTotal * 8.0) / (1000000 * stepsTime));
 
  255   double atp = totalEnergy / stepsTime;
 
  258   m_output_power.Add (pos.x, atp);
 
  259   m_output.Add (pos.x, mbs);
 
  275   return m_output_power;
 
  280   NS_LOG_INFO ((
Simulator::Now ()).GetSeconds () << 
" " << dest << 
" Old power=" << oldPower << 
" New power=" << newPower);
 
  288 int main (
int argc, 
char *argv[])
 
  290   double maxPower = 17;
 
  292   uint32_t powerLevels = 18;
 
  294   uint32_t rtsThreshold = 2346;
 
  295   std::string manager = 
"ns3::ParfWifiManager";
 
  296   std::string outputFileName = 
"parf";
 
  301   uint32_t steps = 200;
 
  302   uint32_t stepsSize = 1;
 
  303   uint32_t stepsTime = 1;
 
  306   cmd.AddValue (
"manager", 
"PRC Manager", manager);
 
  307   cmd.AddValue (
"rtsThreshold", 
"RTS threshold", rtsThreshold);
 
  308   cmd.AddValue (
"outputFileName", 
"Output filename", outputFileName);
 
  309   cmd.AddValue (
"steps", 
"How many different distances to try", steps);
 
  310   cmd.AddValue (
"stepsTime", 
"Time on each step", stepsTime);
 
  311   cmd.AddValue (
"stepsSize", 
"Distance between steps", stepsSize);
 
  312   cmd.AddValue (
"maxPower", 
"Maximum available transmission level (dbm).", maxPower);
 
  313   cmd.AddValue (
"minPower", 
"Minimum available transmission level (dbm).", minPower);
 
  314   cmd.AddValue (
"powerLevels", 
"Number of transmission power levels available between " 
  315                 "TxPowerStart and TxPowerEnd included.", powerLevels);
 
  316   cmd.AddValue (
"AP1_x", 
"Position of AP1 in x coordinate", ap1_x);
 
  317   cmd.AddValue (
"AP1_y", 
"Position of AP1 in y coordinate", ap1_y);
 
  318   cmd.AddValue (
"STA1_x", 
"Position of STA1 in x coordinate", sta1_x);
 
  319   cmd.AddValue (
"STA1_y", 
"Position of STA1 in y coordinate", sta1_y);
 
  320   cmd.Parse (argc, argv);
 
  324       std::cout << 
"Exiting without running simulation; steps value of 0" << std::endl;
 
  327   uint32_t simuTime = (steps + 1) * stepsTime;
 
  350   wifi.SetRemoteStationManager (
"ns3::MinstrelWifiManager", 
"RtsCtsThreshold", 
UintegerValue (rtsThreshold));
 
  355   wifiMac.
SetType (
"ns3::StaWifiMac",
 
  366   wifiMac.
SetType (
"ns3::ApWifiMac",
 
  368   wifiApDevices.
Add (
wifi.Install (wifiPhy, wifiMac, wifiApNodes.
Get (0)));
 
  370   wifiDevices.
Add (wifiStaDevices);
 
  371   wifiDevices.
Add (wifiApDevices);
 
  377   positionAlloc->
Add (Vector (ap1_x, ap1_y, 0.0));
 
  378   NS_LOG_INFO (
"Setting initial AP position to " << Vector (ap1_x, ap1_y, 0.0));
 
  379   positionAlloc->
Add (Vector (sta1_x, sta1_y, 0.0));
 
  380   NS_LOG_INFO (
"Setting initial STA position to " << Vector (sta1_x, sta1_y, 0.0));
 
  381   mobility.SetPositionAllocator (positionAlloc);
 
  382   mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
 
  394   stack.Install (wifiApNodes);
 
  397   address.SetBase (
"10.1.1.0", 
"255.255.255.0");
 
  424   Config::Connect (
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + 
"/PowerChange",
 
  426   Config::Connect (
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + 
"/RateChange",
 
  429   Config::Connect (
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
 
  433   Config::Connect (
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + 
"/PowerChange",
 
  435   Config::Connect (
"/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + 
"/RateChange",
 
  441   std::ofstream outfile ((
"throughput-" + outputFileName + 
".plt").c_str ());
 
  442   Gnuplot gnuplot = 
Gnuplot ((
"throughput-" + outputFileName + 
".eps").c_str (), 
"Throughput");
 
  444   gnuplot.
SetLegend (
"Time (seconds)", 
"Throughput (Mb/s)");
 
  445   gnuplot.
SetTitle (
"Throughput (AP to STA) vs time");
 
  449   if (manager.compare (
"ns3::ParfWifiManager") == 0
 
  450       || manager.compare (
"ns3::AparfWifiManager") == 0
 
  451       || manager.compare (
"ns3::RrpaaWifiManager") == 0)
 
  453       std::ofstream outfile2 ((
"power-" + outputFileName + 
".plt").c_str ());
 
  454       gnuplot = 
Gnuplot ((
"power-" + outputFileName + 
".eps").c_str (), 
"Average Transmit Power");
 
  456       gnuplot.
SetLegend (
"Time (seconds)", 
"Power (mW)");
 
  457       gnuplot.
SetTitle (
"Average transmit power (AP to STA) vs time");
 
  
 
holds a vector of ns3::NetDevice pointers
 
static Vector GetPosition(Ptr< Node > node)
 
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
 
void AdvancePosition(Ptr< Node > node, int stepsSize, int stepsTime)
 
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
 
Make it easy to create and manage PHY objects for the YANS model.
 
Parse command-line arguments.
 
void RxCallback(std::string path, Ptr< const Packet > packet, const Address &from)
 
void Add(Vector v)
Add a position to the list of positions.
 
void SetLegend(const std::string &xLegend, const std::string &yLegend)
 
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
 
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
 
static void SetPosition(Ptr< Node > node, Vector position)
 
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
 
Ptr< WifiPhy > GetPhy(void) const
 
static Time Now(void)
Return the current simulation virtual time.
 
Every class exported by the ns3 library is enclosed in the ns3 namespace.
 
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
 
helps to create WifiNetDevice objects
 
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
 
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
 
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
 
Ipv4 addresses are stored in host order in this class.
 
void SetTerminal(const std::string &terminal)
 
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
 
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
 
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
 
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
 
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
 
void SetChannel(Ptr< YansWifiChannel > channel)
 
Class to represent a 2D points plot.
 
This class can be used to hold variables of floating point type such as 'double' or 'float'.
 
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
 
AttributeValue implementation for Ssid.
 
The IEEE 802.11 SSID Information Element.
 
std::vector< std::pair< Time, DataRate > > TxTime
 
std::map< Mac48Address, DataRate > currentRate
 
Class for representing data rates.
 
Ptr< YansWifiChannel > Create(void) const
 
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
 
void SetPosition(Ptr< Node > node, Vector position)
 
a polymophic address class
 
void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
 
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
 
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
 
holds a vector of std::pair of Ptr<Ipv4> and interface index.
 
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
 
NodeStatistics(NetDeviceContainer aps, NetDeviceContainer stas)
 
Simulation virtual time values and global simulation resolution.
 
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
 
void AddDataset(const GnuplotDataset &dataset)
 
void PhyCallback(std::string path, Ptr< const Packet > packet, double powerW)
 
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
 
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
 
static void Run(void)
Run the simulation.
 
Gnuplot2dDataset GetPowerDatafile()
 
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
 
Gnuplot2dDataset GetDatafile()
 
void SetupPhy(Ptr< WifiPhy > phy)
 
void Connect(std::string path, const CallbackBase &cb)
 
Vector GetPosition(Ptr< Node > node)
 
Time GetCalcTxTime(DataRate rate)
 
static const uint32_t packetSize
 
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
 
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
 
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
 
Time Seconds(double value)
Construct a Time in the indicated unit.
 
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
 
holds a vector of ns3::Application pointers.
 
void SetTitle(const std::string &title)
 
AttributeValue implementation for Time.
 
Keep track of the current position and velocity of an object.
 
keep track of a set of node pointers.
 
void SetType(std::string type, Args &&... args)
 
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
 
static void AdvancePosition(Ptr< Node > node)
 
Hold an unsigned integer type.
 
manage and create wifi channel objects for the YANS model.
 
create MAC layers for a ns3::WifiNetDevice.
 
std::map< Mac48Address, double > currentPower
 
Gnuplot2dDataset m_output_power
 
uint32_t GetN(void) const
Get the number of Ptr<NetDevice> stored in this container.
 
void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
 
aggregate IP/TCP/UDP functionality to existing Nodes.
 
Gnuplot2dDataset m_output
 
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
 
void Set(std::string name, const AttributeValue &v)
 
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
 
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
 
Helper class used to assign positions and mobility models to nodes.
 
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
 
Ptr< WifiMac > GetMac(void) const