A Discrete-Event Network Simulator
API
wifi-power-adaptation-interference.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Universidad de la República - Uruguay
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Matias Richart <mrichart@fing.edu.uy>
19  */
20 
58 #include "ns3/gnuplot.h"
59 #include "ns3/command-line.h"
60 #include "ns3/config.h"
61 #include "ns3/uinteger.h"
62 #include "ns3/double.h"
63 #include "ns3/log.h"
64 #include "ns3/yans-wifi-helper.h"
65 #include "ns3/ssid.h"
66 #include "ns3/mobility-helper.h"
67 #include "ns3/internet-stack-helper.h"
68 #include "ns3/ipv4-address-helper.h"
69 #include "ns3/packet-sink-helper.h"
70 #include "ns3/on-off-helper.h"
71 #include "ns3/yans-wifi-channel.h"
72 #include "ns3/wifi-net-device.h"
73 #include "ns3/wifi-mac.h"
74 #include "ns3/wifi-mac-header.h"
75 #include "ns3/flow-monitor-helper.h"
76 #include "ns3/ipv4-flow-classifier.h"
77 
78 using namespace ns3;
79 using namespace std;
80 
81 NS_LOG_COMPONENT_DEFINE ("PowerAdaptationInterference");
82 
83 //Packet size generated at the AP.
84 static const uint32_t packetSize = 1420;
85 
86 class NodeStatistics
87 {
88 public:
90 
91  void CheckStatistics (double time);
92 
93  void PhyCallback (std::string path, Ptr<const Packet> packet, double powerW);
94  void RxCallback (std::string path, Ptr<const Packet> packet, const Address &from);
95  void PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest);
96  void RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest);
97  void StateCallback (std::string path, Time init, Time duration, WifiPhyState state);
98 
101  Gnuplot2dDataset GetIdleDatafile ();
102  Gnuplot2dDataset GetBusyDatafile ();
103  Gnuplot2dDataset GetTxDatafile ();
104  Gnuplot2dDataset GetRxDatafile ();
105 
106  double GetBusyTime ();
107 
108 private:
109  typedef std::vector<std::pair<Time, DataRate> > TxTime;
112 
113  std::map<Mac48Address, double> currentPower;
114  std::map<Mac48Address, DataRate> currentRate;
115  uint32_t m_bytesTotal;
116  double totalEnergy;
117  double totalTime;
118  double busyTime;
119  double idleTime;
120  double txTime;
121  double rxTime;
124  double totalTxTime;
125  double totalRxTime;
126  Ptr<WifiPhy> myPhy;
127  TxTime timeTable;
128  Gnuplot2dDataset m_output;
129  Gnuplot2dDataset m_output_power;
134 };
135 
137 {
138  Ptr<NetDevice> device = aps.Get (0);
139  Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device);
140  Ptr<WifiPhy> phy = wifiDevice->GetPhy ();
141  myPhy = phy;
142  SetupPhy (phy);
143  DataRate dataRate = DataRate (phy->GetDefaultMode ().GetDataRate (phy->GetChannelWidth ()));
144  double power = phy->GetTxPowerEnd ();
145  for (uint32_t j = 0; j < stas.GetN (); j++)
146  {
147  Ptr<NetDevice> staDevice = stas.Get (j);
148  Ptr<WifiNetDevice> wifiStaDevice = DynamicCast<WifiNetDevice> (staDevice);
149  Mac48Address addr = wifiStaDevice->GetMac ()->GetAddress ();
150  currentPower[addr] = power;
151  currentRate[addr] = dataRate;
152  }
153  currentRate[Mac48Address ("ff:ff:ff:ff:ff:ff")] = dataRate;
154  totalEnergy = 0;
155  totalTime = 0;
156  busyTime = 0;
157  idleTime = 0;
158  txTime = 0;
159  rxTime = 0;
160  totalBusyTime = 0;
161  totalIdleTime = 0;
162  totalTxTime = 0;
163  totalRxTime = 0;
164  m_bytesTotal = 0;
165  m_output.SetTitle ("Throughput Mbits/s");
166  m_output_idle.SetTitle ("Idle Time");
167  m_output_busy.SetTitle ("Busy Time");
168  m_output_rx.SetTitle ("RX Time");
169  m_output_tx.SetTitle ("TX Time");
170 }
171 
172 void
174 {
175  for (const auto & mode : phy->GetModeList ())
176  {
177  WifiTxVector txVector;
178  txVector.SetMode (mode);
180  txVector.SetChannelWidth (phy->GetChannelWidth ());
181  DataRate dataRate = DataRate (mode.GetDataRate (phy->GetChannelWidth ()));
182  Time time = phy->CalculateTxDuration (packetSize, txVector, phy->GetPhyBand ());
183  NS_LOG_DEBUG (mode.GetUniqueName () << " " << time.GetSeconds () << " " << dataRate);
184  timeTable.push_back (std::make_pair (time, dataRate));
185  }
186 }
187 
188 Time
190 {
191  for (TxTime::const_iterator i = timeTable.begin (); i != timeTable.end (); i++)
192  {
193  if (rate == i->second)
194  {
195  return i->first;
196  }
197  }
198  NS_ASSERT (false);
199  return Seconds (0);
200 }
201 
202 void
203 NodeStatistics::PhyCallback (std::string path, Ptr<const Packet> packet, double powerW)
204 {
205  WifiMacHeader head;
206  packet->PeekHeader (head);
207  Mac48Address dest = head.GetAddr1 ();
208 
209  if (head.GetType () == WIFI_MAC_DATA)
210  {
211  totalEnergy += pow (10.0, currentPower[dest] / 10.0) * GetCalcTxTime (currentRate[dest]).GetSeconds ();
212  totalTime += GetCalcTxTime (currentRate[dest]).GetSeconds ();
213  }
214 }
215 
216 void
217 NodeStatistics::PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest)
218 {
219  currentPower[dest] = newPower;
220 }
221 
222 void
223 NodeStatistics::RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
224 {
225  currentRate[dest] = newRate;
226 }
227 
228 void
229 NodeStatistics::StateCallback (std::string path, Time init, Time duration, WifiPhyState state)
230 {
231  if (state == WifiPhyState::CCA_BUSY)
232  {
233  busyTime += duration.GetSeconds ();
234  totalBusyTime += duration.GetSeconds ();
235  }
236  else if (state == WifiPhyState::IDLE)
237  {
238  idleTime += duration.GetSeconds ();
239  totalIdleTime += duration.GetSeconds ();
240  }
241  else if (state == WifiPhyState::TX)
242  {
243  txTime += duration.GetSeconds ();
244  totalTxTime += duration.GetSeconds ();
245  }
246  else if (state == WifiPhyState::RX)
247  {
248  rxTime += duration.GetSeconds ();
249  totalRxTime += duration.GetSeconds ();
250  }
251 }
252 
253 void
254 NodeStatistics::RxCallback (std::string path, Ptr<const Packet> packet, const Address &from)
255 {
256  m_bytesTotal += packet->GetSize ();
257 }
258 
259 void
261 {
262  double mbs = ((m_bytesTotal * 8.0) / (1000000 * time));
263  m_bytesTotal = 0;
264  double atp = totalEnergy / time;
265  totalEnergy = 0;
266  totalTime = 0;
267  m_output_power.Add ((Simulator::Now ()).GetSeconds (), atp);
268  m_output.Add ((Simulator::Now ()).GetSeconds (), mbs);
269 
270  m_output_idle.Add ((Simulator::Now ()).GetSeconds (), idleTime * 100);
271  m_output_busy.Add ((Simulator::Now ()).GetSeconds (), busyTime * 100);
272  m_output_tx.Add ((Simulator::Now ()).GetSeconds (), txTime * 100);
273  m_output_rx.Add ((Simulator::Now ()).GetSeconds (), rxTime * 100);
274  busyTime = 0;
275  idleTime = 0;
276  txTime = 0;
277  rxTime = 0;
278 
280 }
281 
284 {
285  return m_output;
286 }
287 
290 {
291  return m_output_power;
292 }
293 
296 {
297  return m_output_idle;
298 }
299 
302 {
303  return m_output_busy;
304 }
305 
308 {
309  return m_output_rx;
310 }
311 
314 {
315  return m_output_tx;
316 }
317 
318 double
320 {
321  return totalBusyTime + totalRxTime;
322 }
323 
324 void PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest)
325 {
326  NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Old power=" << oldPower << " New power=" << newPower);
327 }
328 
329 void RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
330 {
331  NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Old rate=" << oldRate << " New rate=" << newRate);
332 }
333 
334 int main (int argc, char *argv[])
335 {
336  //LogComponentEnable("ConstantRateWifiManager", LOG_LEVEL_FUNCTION);
337 
338  double maxPower = 17;
339  double minPower = 0;
340  uint32_t powerLevels = 18;
341 
342  uint32_t rtsThreshold = 2346;
343  std::string manager = "ns3::ParfWifiManager";
344  std::string outputFileName = "parf";
345  int ap1_x = 0;
346  int ap1_y = 0;
347  int sta1_x = 10;
348  int sta1_y = 0;
349  int ap2_x = 200;
350  int ap2_y = 0;
351  int sta2_x = 180;
352  int sta2_y = 0;
353  uint32_t simuTime = 100;
354 
355  CommandLine cmd (__FILE__);
356  cmd.AddValue ("manager", "PRC Manager", manager);
357  cmd.AddValue ("rtsThreshold", "RTS threshold", rtsThreshold);
358  cmd.AddValue ("outputFileName", "Output filename", outputFileName);
359  cmd.AddValue ("simuTime", "Total simulation time (sec)", simuTime);
360  cmd.AddValue ("maxPower", "Maximum available transmission level (dbm).", maxPower);
361  cmd.AddValue ("minPower", "Minimum available transmission level (dbm).", minPower);
362  cmd.AddValue ("powerLevels", "Number of transmission power levels available between "
363  "TxPowerStart and TxPowerEnd included.", powerLevels);
364  cmd.AddValue ("AP1_x", "Position of AP1 in x coordinate", ap1_x);
365  cmd.AddValue ("AP1_y", "Position of AP1 in y coordinate", ap1_y);
366  cmd.AddValue ("STA1_x", "Position of STA1 in x coordinate", sta1_x);
367  cmd.AddValue ("STA1_y", "Position of STA1 in y coordinate", sta1_y);
368  cmd.AddValue ("AP2_x", "Position of AP2 in x coordinate", ap2_x);
369  cmd.AddValue ("AP2_y", "Position of AP2 in y coordinate", ap2_y);
370  cmd.AddValue ("STA2_x", "Position of STA2 in x coordinate", sta2_x);
371  cmd.AddValue ("STA2_y", "Position of STA2 in y coordinate", sta2_y);
372  cmd.Parse (argc, argv);
373 
374  //Define the APs
375  NodeContainer wifiApNodes;
376  wifiApNodes.Create (2);
377 
378  //Define the STAs
380  wifiStaNodes.Create (2);
381 
383  wifi.SetStandard (WIFI_STANDARD_80211a);
384  WifiMacHelper wifiMac;
385  YansWifiPhyHelper wifiPhy;
387 
388  wifiPhy.SetChannel (wifiChannel.Create ());
389 
390  NetDeviceContainer wifiApDevices;
391  NetDeviceContainer wifiStaDevices;
392  NetDeviceContainer wifiDevices;
393 
394  //Configure the STA nodes
395  wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "RtsCtsThreshold", UintegerValue (rtsThreshold));
396  wifiPhy.Set ("TxPowerStart", DoubleValue (maxPower));
397  wifiPhy.Set ("TxPowerEnd", DoubleValue (maxPower));
398 
399  Ssid ssid = Ssid ("AP0");
400  wifiMac.SetType ("ns3::StaWifiMac",
401  "Ssid", SsidValue (ssid),
402  "MaxMissedBeacons", UintegerValue (1000));
403  wifiStaDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiStaNodes.Get (0)));
404 
405  ssid = Ssid ("AP1");
406  wifiMac.SetType ("ns3::StaWifiMac",
407  "Ssid", SsidValue (ssid));
408  wifiStaDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiStaNodes.Get (1)));
409 
410  //Configure the AP nodes
411  wifi.SetRemoteStationManager (manager, "DefaultTxPowerLevel", UintegerValue (powerLevels - 1), "RtsCtsThreshold", UintegerValue (rtsThreshold));
412  wifiPhy.Set ("TxPowerStart", DoubleValue (minPower));
413  wifiPhy.Set ("TxPowerEnd", DoubleValue (maxPower));
414  wifiPhy.Set ("TxPowerLevels", UintegerValue (powerLevels));
415 
416  ssid = Ssid ("AP0");
417  wifiMac.SetType ("ns3::ApWifiMac",
418  "Ssid", SsidValue (ssid));
419  wifiApDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiApNodes.Get (0)));
420 
421  ssid = Ssid ("AP1");
422  wifiMac.SetType ("ns3::ApWifiMac",
423  "Ssid", SsidValue (ssid),
424  "BeaconInterval", TimeValue (MicroSeconds (103424))); //for avoiding collisions);
425  wifiApDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiApNodes.Get (1)));
426 
427  wifiDevices.Add (wifiStaDevices);
428  wifiDevices.Add (wifiApDevices);
429 
430  //Configure the mobility.
432  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
433  positionAlloc->Add (Vector (ap1_x, ap1_y, 0.0));
434  positionAlloc->Add (Vector (sta1_x, sta1_y, 0.0));
435  positionAlloc->Add (Vector (ap2_x, ap2_y, 0.0));
436  positionAlloc->Add (Vector (sta2_x, sta2_y, 0.0));
437  mobility.SetPositionAllocator (positionAlloc);
438  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
439  mobility.Install (wifiApNodes.Get (0));
440  mobility.Install (wifiStaNodes.Get (0));
441  mobility.Install (wifiApNodes.Get (1));
442  mobility.Install (wifiStaNodes.Get (1));
443 
444 
445  //Configure the IP stack
447  stack.Install (wifiApNodes);
448  stack.Install (wifiStaNodes);
450  address.SetBase ("10.1.1.0", "255.255.255.0");
451  Ipv4InterfaceContainer i = address.Assign (wifiDevices);
452  Ipv4Address sinkAddress = i.GetAddress (0);
453  Ipv4Address sinkAddress1 = i.GetAddress (1);
454  uint16_t port = 9;
455 
456  //Configure the CBR generator
457  PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress, port));
458  ApplicationContainer apps_sink = sink.Install (wifiStaNodes.Get (0));
459 
460  OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress, port));
461  onoff.SetConstantRate (DataRate ("54Mb/s"), packetSize);
462  onoff.SetAttribute ("StartTime", TimeValue (Seconds (0.0)));
463  onoff.SetAttribute ("StopTime", TimeValue (Seconds (100.0)));
464  ApplicationContainer apps_source = onoff.Install (wifiApNodes.Get (0));
465 
466  PacketSinkHelper sink1 ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress1, port));
467  apps_sink.Add (sink1.Install (wifiStaNodes.Get (1)));
468 
469  OnOffHelper onoff1 ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress1, port));
470  onoff1.SetConstantRate (DataRate ("54Mb/s"), packetSize);
471  onoff1.SetAttribute ("StartTime", TimeValue (Seconds (0.0)));
472  onoff1.SetAttribute ("StopTime", TimeValue (Seconds (100.0)));
473  apps_source.Add (onoff1.Install (wifiApNodes.Get (1)));
474 
475  apps_sink.Start (Seconds (0.5));
476  apps_sink.Stop (Seconds (simuTime));
477 
478  //------------------------------------------------------------
479  //-- Setup stats and data collection
480  //--------------------------------------------
481 
482  //Statistics counters
483  NodeStatistics statisticsAp0 = NodeStatistics (wifiApDevices, wifiStaDevices);
484  NodeStatistics statisticsAp1 = NodeStatistics (wifiApDevices, wifiStaDevices);
485 
486  //Register packet receptions to calculate throughput
487  Config::Connect ("/NodeList/2/ApplicationList/*/$ns3::PacketSink/Rx",
488  MakeCallback (&NodeStatistics::RxCallback, &statisticsAp0));
489  Config::Connect ("/NodeList/3/ApplicationList/*/$ns3::PacketSink/Rx",
490  MakeCallback (&NodeStatistics::RxCallback, &statisticsAp1));
491 
492  //Register power and rate changes to calculate the Average Transmit Power
493  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
494  MakeCallback (&NodeStatistics::PowerCallback, &statisticsAp0));
495  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
496  MakeCallback (&NodeStatistics::RateCallback, &statisticsAp0));
497  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
498  MakeCallback (&NodeStatistics::PowerCallback, &statisticsAp1));
499  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
500  MakeCallback (&NodeStatistics::RateCallback, &statisticsAp1));
501 
502  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
503  MakeCallback (&NodeStatistics::PhyCallback, &statisticsAp0));
504  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
505  MakeCallback (&NodeStatistics::PhyCallback, &statisticsAp1));
506 
507  //Register States
508  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
509  MakeCallback (&NodeStatistics::StateCallback, &statisticsAp0));
510  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
511  MakeCallback (&NodeStatistics::StateCallback, &statisticsAp1));
512 
513  statisticsAp0.CheckStatistics (1);
514  statisticsAp1.CheckStatistics (1);
515 
516  //Callbacks to print every change of power and rate
517  Config::Connect ("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
519  Config::Connect ("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
521 
522 
523  //Calculate Throughput using Flowmonitor
524 
525  FlowMonitorHelper flowmon;
526  Ptr<FlowMonitor> monitor = flowmon.InstallAll ();
527 
528  Simulator::Stop (Seconds (simuTime));
529  Simulator::Run ();
530 
531  Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
532  std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
533  for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
534  {
535  Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
536  if ((t.sourceAddress == "10.1.1.3" && t.destinationAddress == "10.1.1.1"))
537  {
538  NS_LOG_INFO ("Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n");
539  NS_LOG_INFO (" Tx Bytes: " << i->second.txBytes << "\n");
540  NS_LOG_INFO (" Rx Bytes: " << i->second.rxBytes << "\n");
541  NS_LOG_UNCOND (" Throughput to 10.1.1.1: " << i->second.rxBytes * 8.0 / (i->second.timeLastRxPacket.GetSeconds () - i->second.timeFirstTxPacket.GetSeconds ()) / 1024 / 1024 << " Mbps\n");
542  NS_LOG_INFO (" Mean delay: " << i->second.delaySum.GetSeconds () / i->second.rxPackets << "\n");
543  NS_LOG_INFO (" Mean jitter: " << i->second.jitterSum.GetSeconds () / (i->second.rxPackets - 1) << "\n");
544  NS_LOG_INFO (" Tx Opp: " << 1 - (statisticsAp0.GetBusyTime () / simuTime));
545  }
546  if ((t.sourceAddress == "10.1.1.4" && t.destinationAddress == "10.1.1.2"))
547  {
548  NS_LOG_INFO ("Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n");
549  NS_LOG_INFO (" Tx Bytes: " << i->second.txBytes << "\n");
550  NS_LOG_INFO (" Rx Bytes: " << i->second.rxBytes << "\n");
551  NS_LOG_UNCOND (" Throughput to 10.1.1.2: " << i->second.rxBytes * 8.0 / (i->second.timeLastRxPacket.GetSeconds () - i->second.timeFirstTxPacket.GetSeconds ()) / 1024 / 1024 << " Mbps\n");
552  NS_LOG_INFO (" Mean delay: " << i->second.delaySum.GetSeconds () / i->second.rxPackets << "\n");
553  NS_LOG_INFO (" Mean jitter: " << i->second.jitterSum.GetSeconds () / (i->second.rxPackets - 1) << "\n");
554  NS_LOG_INFO (" Tx Opp: " << 1 - (statisticsAp1.GetBusyTime () / simuTime));
555  }
556  }
557 
558  //Plots for AP0
559  std::ofstream outfileTh0 (("throughput-" + outputFileName + "-0.plt").c_str ());
560  Gnuplot gnuplot = Gnuplot (("throughput-" + outputFileName + "-0.eps").c_str (), "Throughput");
561  gnuplot.SetTerminal ("post eps color enhanced");
562  gnuplot.SetLegend ("Time (seconds)", "Throughput (Mb/s)");
563  gnuplot.SetTitle ("Throughput (AP0 to STA) vs time");
564  gnuplot.AddDataset (statisticsAp0.GetDatafile ());
565  gnuplot.GenerateOutput (outfileTh0);
566 
567  if (manager.compare ("ns3::ParfWifiManager") == 0
568  || manager.compare ("ns3::AparfWifiManager") == 0
569  || manager.compare ("ns3::RrpaaWifiManager") == 0)
570  {
571  std::ofstream outfilePower0 (("power-" + outputFileName + "-0.plt").c_str ());
572  gnuplot = Gnuplot (("power-" + outputFileName + "-0.eps").c_str (), "Average Transmit Power");
573  gnuplot.SetTerminal ("post eps color enhanced");
574  gnuplot.SetLegend ("Time (seconds)", "Power (mW)");
575  gnuplot.SetTitle ("Average transmit power (AP0 to STA) vs time");
576  gnuplot.AddDataset (statisticsAp0.GetPowerDatafile ());
577  gnuplot.GenerateOutput (outfilePower0);
578  }
579 
580  std::ofstream outfileTx0 (("tx-" + outputFileName + "-0.plt").c_str ());
581  gnuplot = Gnuplot (("tx-" + outputFileName + "-0.eps").c_str (), "Time in TX State");
582  gnuplot.SetTerminal ("post eps color enhanced");
583  gnuplot.SetLegend ("Time (seconds)", "Percent");
584  gnuplot.SetTitle ("Percentage time AP0 in TX state vs time");
585  gnuplot.AddDataset (statisticsAp0.GetTxDatafile ());
586  gnuplot.GenerateOutput (outfileTx0);
587 
588  std::ofstream outfileRx0 (("rx-" + outputFileName + "-0.plt").c_str ());
589  gnuplot = Gnuplot (("rx-" + outputFileName + "-0.eps").c_str (), "Time in RX State");
590  gnuplot.SetTerminal ("post eps color enhanced");
591  gnuplot.SetLegend ("Time (seconds)", "Percent");
592  gnuplot.SetTitle ("Percentage time AP0 in RX state vs time");
593  gnuplot.AddDataset (statisticsAp0.GetRxDatafile ());
594  gnuplot.GenerateOutput (outfileRx0);
595 
596  std::ofstream outfileBusy0 (("busy-" + outputFileName + "-0.plt").c_str ());
597  gnuplot = Gnuplot (("busy-" + outputFileName + "-0.eps").c_str (), "Time in Busy State");
598  gnuplot.SetTerminal ("post eps color enhanced");
599  gnuplot.SetLegend ("Time (seconds)", "Percent");
600  gnuplot.SetTitle ("Percentage time AP0 in Busy state vs time");
601  gnuplot.AddDataset (statisticsAp0.GetBusyDatafile ());
602  gnuplot.GenerateOutput (outfileBusy0);
603 
604  std::ofstream outfileIdle0 (("idle-" + outputFileName + "-0.plt").c_str ());
605  gnuplot = Gnuplot (("idle-" + outputFileName + "-0.eps").c_str (), "Time in Idle State");
606  gnuplot.SetTerminal ("post eps color enhanced");
607  gnuplot.SetLegend ("Time (seconds)", "Percent");
608  gnuplot.SetTitle ("Percentage time AP0 in Idle state vs time");
609  gnuplot.AddDataset (statisticsAp0.GetIdleDatafile ());
610  gnuplot.GenerateOutput (outfileIdle0);
611 
612  //Plots for AP1
613  std::ofstream outfileTh1 (("throughput-" + outputFileName + "-1.plt").c_str ());
614  gnuplot = Gnuplot (("throughput-" + outputFileName + "-1.eps").c_str (), "Throughput");
615  gnuplot.SetTerminal ("post eps color enhanced");
616  gnuplot.SetLegend ("Time (seconds)", "Throughput (Mb/s)");
617  gnuplot.SetTitle ("Throughput (AP1 to STA) vs time");
618  gnuplot.AddDataset (statisticsAp1.GetDatafile ());
619  gnuplot.GenerateOutput (outfileTh1);
620 
621  if (manager.compare ("ns3::ParfWifiManager") == 0
622  || manager.compare ("ns3::AparfWifiManager") == 0
623  || manager.compare ("ns3::RrpaaWifiManager") == 0)
624  {
625  std::ofstream outfilePower1 (("power-" + outputFileName + "-1.plt").c_str ());
626  gnuplot = Gnuplot (("power-" + outputFileName + "-1.eps").c_str (), "Average Transmit Power");
627  gnuplot.SetTerminal ("post eps color enhanced");
628  gnuplot.SetLegend ("Time (seconds)", "Power (mW)");
629  gnuplot.SetTitle ("Average transmit power (AP1 to STA) vs time");
630  gnuplot.AddDataset (statisticsAp1.GetPowerDatafile ());
631  gnuplot.GenerateOutput (outfilePower1);
632  }
633 
634  std::ofstream outfileTx1 (("tx-" + outputFileName + "-1.plt").c_str ());
635  gnuplot = Gnuplot (("tx-" + outputFileName + "-1.eps").c_str (), "Time in TX State");
636  gnuplot.SetTerminal ("post eps color enhanced");
637  gnuplot.SetLegend ("Time (seconds)", "Percent");
638  gnuplot.SetTitle ("Percentage time AP1 in TX state vs time");
639  gnuplot.AddDataset (statisticsAp1.GetTxDatafile ());
640  gnuplot.GenerateOutput (outfileTx1);
641 
642  std::ofstream outfileRx1 (("rx-" + outputFileName + "-1.plt").c_str ());
643  gnuplot = Gnuplot (("rx-" + outputFileName + "-1.eps").c_str (), "Time in RX State");
644  gnuplot.SetTerminal ("post eps color enhanced");
645  gnuplot.SetLegend ("Time (seconds)", "Percent");
646  gnuplot.SetTitle ("Percentage time AP1 in RX state vs time");
647  gnuplot.AddDataset (statisticsAp1.GetRxDatafile ());
648  gnuplot.GenerateOutput (outfileRx1);
649 
650  std::ofstream outfileBusy1 (("busy-" + outputFileName + "-1.plt").c_str ());
651  gnuplot = Gnuplot (("busy-" + outputFileName + "-1.eps").c_str (), "Time in Busy State");
652  gnuplot.SetTerminal ("post eps color enhanced");
653  gnuplot.SetLegend ("Time (seconds)", "Percent");
654  gnuplot.SetTitle ("Percentage time AP1 in Busy state vs time");
655  gnuplot.AddDataset (statisticsAp1.GetBusyDatafile ());
656  gnuplot.GenerateOutput (outfileBusy1);
657 
658  std::ofstream outfileIdle1 (("idle-" + outputFileName + "-1.plt").c_str ());
659  gnuplot = Gnuplot (("idle-" + outputFileName + "-1.eps").c_str (), "Time in Idle State");
660  gnuplot.SetTerminal ("post eps color enhanced");
661  gnuplot.SetLegend ("Time (seconds)", "Percent");
662  gnuplot.SetTitle ("Percentage time AP1 in Idle state vs time");
663  gnuplot.AddDataset (statisticsAp1.GetIdleDatafile ());
664  gnuplot.GenerateOutput (outfileIdle1);
665 
667 
668  return 0;
669 }
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::InetSocketAddress
an Inet address class
Definition: inet-socket-address.h:41
ns3::YansWifiChannelHelper::Default
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
Definition: yans-wifi-helper.cc:41
ns3::YansWifiPhyHelper
Make it easy to create and manage PHY objects for the YANS model.
Definition: yans-wifi-helper.h:161
ns3::CommandLine
Parse command-line arguments.
Definition: command-line.h:228
NodeStatistics::RxCallback
void RxCallback(std::string path, Ptr< const Packet > packet, const Address &from)
ns3::ListPositionAllocator::Add
void Add(Vector v)
Add a position to the list of positions.
Definition: position-allocator.cc:70
ns3::Gnuplot::SetLegend
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:736
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
ns3::Packet::PeekHeader
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
NodeStatistics::totalBusyTime
double totalBusyTime
Definition: wifi-power-adaptation-interference.cc:122
ns3::Packet::GetSize
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
NodeStatistics::GetBusyDatafile
Gnuplot2dDataset GetBusyDatafile()
Definition: wifi-power-adaptation-interference.cc:301
PowerCallback
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
Definition: wifi-power-adaptation-interference.cc:324
ns3::WifiNetDevice::GetPhy
Ptr< WifiPhy > GetPhy(void) const
Definition: wifi-net-device.cc:207
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ApplicationContainer::Stop
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Definition: application-container.cc:107
RX
@ RX
The PHY layer is receiving a packet.
Definition: wifi-phy-state.h:48
ns3::WifiHelper
helps to create WifiNetDevice objects
Definition: wifi-helper.h:327
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition: ipv4-address-helper.h:48
ns3::MicroSeconds
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
IDLE
@ IDLE
The PHY layer is IDLE.
Definition: wifi-phy-state.h:36
ns3::Ipv4FlowClassifier::FiveTuple::sourceAddress
Ipv4Address sourceAddress
Source address.
Definition: ipv4-flow-classifier.h:45
ns3::Ipv4FlowClassifier::FindFlow
FiveTuple FindFlow(FlowId flowId) const
Searches for the FiveTuple corresponding to the given flowId.
Definition: ipv4-flow-classifier.cc:186
ns3::Gnuplot
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:372
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
ns3::Gnuplot::SetTerminal
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:724
ns3::WifiTxVector::SetMode
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
Definition: wifi-tx-vector.cc:226
ns3::WifiTxVector
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Definition: wifi-tx-vector.h:71
ns3::Gnuplot::GenerateOutput
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:762
ns3::WifiMacHeader::GetAddr1
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
Definition: wifi-mac-header.cc:424
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
ns3::Ipv4FlowClassifier::FiveTuple
Structure to classify a packet.
Definition: ipv4-flow-classifier.h:44
CCA_BUSY
@ CCA_BUSY
The PHY layer has sense the medium busy through the CCA mechanism.
Definition: wifi-phy-state.h:40
ns3::YansWifiPhyHelper::SetChannel
void SetChannel(Ptr< YansWifiChannel > channel)
Definition: yans-wifi-helper.cc:134
ns3::Gnuplot2dDataset
Class to represent a 2D points plot.
Definition: gnuplot.h:118
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition: node-container.cc:98
NodeStatistics::m_output_busy
Gnuplot2dDataset m_output_busy
Definition: wifi-power-adaptation-interference.cc:131
NodeStatistics::totalTxTime
double totalTxTime
Definition: wifi-power-adaptation-interference.cc:124
ns3::SsidValue
AttributeValue implementation for Ssid.
Definition: ssid.h:105
ns3::Ssid
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
NodeStatistics::TxTime
std::vector< std::pair< Time, DataRate > > TxTime
Definition: wifi-power-adaptation-interference.cc:109
NodeStatistics::totalIdleTime
double totalIdleTime
Definition: wifi-power-adaptation-interference.cc:123
ns3::ApplicationContainer::Add
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Definition: application-container.cc:67
NodeStatistics::m_output_idle
Gnuplot2dDataset m_output_idle
Definition: wifi-power-adaptation-interference.cc:130
ns3::WifiMacHeader
Implements the IEEE 802.11 MAC header.
Definition: wifi-mac-header.h:85
NodeStatistics::busyTime
double busyTime
Definition: wifi-power-adaptation-interference.cc:118
third.wifi
wifi
Definition: third.py:96
ns3::Ptr< const Packet >
ns3::DataRate
Class for representing data rates.
Definition: data-rate.h:89
ns3::FlowMonitorHelper
Helper to enable IP flow monitoring on a set of Nodes.
Definition: flow-monitor-helper.h:40
ns3::Ipv4FlowClassifier::FiveTuple::destinationAddress
Ipv4Address destinationAddress
Destination address.
Definition: ipv4-flow-classifier.h:46
ns3::WifiMacHeader::GetType
WifiMacType GetType(void) const
Return the type (enum WifiMacType)
Definition: wifi-mac-header.cc:448
ns3::YansWifiChannelHelper::Create
Ptr< YansWifiChannel > Create(void) const
Definition: yans-wifi-helper.cc:98
first.stack
stack
Definition: first.py:41
ns3::Simulator::Stop
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
RateCallback
void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
Definition: wifi-power-adaptation-interference.cc:329
ns3::FlowMonitorHelper::InstallAll
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
Definition: flow-monitor-helper.cc:135
ns3::Address
a polymophic address class
Definition: address.h:91
NodeStatistics::RateCallback
void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
ns3::OnOffHelper
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:43
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
ns3::WIFI_STANDARD_80211a
@ WIFI_STANDARD_80211a
Definition: wifi-standards.h:127
ns3::Ipv4InterfaceContainer
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Definition: ipv4-interface-container.h:55
NodeStatistics::idleTime
double idleTime
Definition: wifi-power-adaptation-interference.cc:119
ns3::NodeContainer::Get
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Definition: node-container.cc:93
first.address
address
Definition: first.py:44
NodeStatistics::NodeStatistics
NodeStatistics(NetDeviceContainer aps, NetDeviceContainer stas)
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::WifiTxVector::SetChannelWidth
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
Definition: wifi-tx-vector.cc:254
ns3::FlowMonitorHelper::GetClassifier
Ptr< FlowClassifier > GetClassifier()
Retrieve the FlowClassifier object for IPv4 created by the Install* methods.
Definition: flow-monitor-helper.cc:75
second.cmd
cmd
Definition: second.py:35
packetSize
static const uint32_t packetSize
Definition: wifi-power-adaptation-interference.cc:84
NS_LOG_UNCOND
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
Definition: log-macros-enabled.h:269
NodeStatistics::CheckStatistics
void CheckStatistics(double time)
Definition: wifi-power-adaptation-interference.cc:260
ns3::Gnuplot::AddDataset
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:756
NodeStatistics::PhyCallback
void PhyCallback(std::string path, Ptr< const Packet > packet, double powerW)
sink
Ptr< PacketSink > sink
Definition: wifi-tcp.cc:56
NodeStatistics::PowerCallback
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
ns3::MakeCallback
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...
Definition: callback.h:1642
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
NodeStatistics::GetPowerDatafile
Gnuplot2dDataset GetPowerDatafile()
ns3::PacketSinkHelper
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Definition: packet-sink-helper.h:36
WifiPhyState
WifiPhyState
The state of the PHY layer.
Definition: wifi-phy-state.h:32
NodeStatistics::GetTxDatafile
Gnuplot2dDataset GetTxDatafile()
Definition: wifi-power-adaptation-interference.cc:313
ns3::WIFI_PREAMBLE_LONG
@ WIFI_PREAMBLE_LONG
Definition: wifi-phy-common.h:69
NodeStatistics::GetDatafile
Gnuplot2dDataset GetDatafile()
NodeStatistics::SetupPhy
void SetupPhy(Ptr< WifiPhy > phy)
ns3::Config::Connect
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
NodeStatistics
Definition: wifi-power-adaptation-distance.cc:116
NodeStatistics::GetCalcTxTime
Time GetCalcTxTime(DataRate rate)
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
NodeStatistics::m_output_tx
Gnuplot2dDataset m_output_tx
Definition: wifi-power-adaptation-interference.cc:133
NodeStatistics::GetRxDatafile
Gnuplot2dDataset GetRxDatafile()
Definition: wifi-power-adaptation-interference.cc:307
ns3::TracedValueCallback::DataRate
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:329
ns3::ApplicationContainer::Start
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Definition: application-container.cc:87
NodeStatistics::rxTime
double rxTime
Definition: wifi-power-adaptation-interference.cc:121
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition: application-container.h:43
ns3::WIFI_MAC_DATA
@ WIFI_MAC_DATA
Definition: wifi-mac-header.h:62
ns3::Gnuplot::SetTitle
void SetTitle(const std::string &title)
Definition: gnuplot.cc:730
third.ssid
ssid
Definition: third.py:100
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1353
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
ns3::WifiMacHelper::SetType
void SetType(std::string type, Args &&... args)
Definition: wifi-mac-helper.h:130
third.wifiStaNodes
wifiStaNodes
Definition: third.py:88
ns3::Ipv4InterfaceContainer::GetAddress
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Definition: ipv4-interface-container.cc:59
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::YansWifiChannelHelper
manage and create wifi channel objects for the YANS model.
Definition: yans-wifi-helper.h:37
ns3::WifiMacHelper
create MAC layers for a ns3::WifiNetDevice.
Definition: wifi-mac-helper.h:48
NodeStatistics::GetBusyTime
double GetBusyTime()
Definition: wifi-power-adaptation-interference.cc:319
ns3::NetDeviceContainer::GetN
uint32_t GetN(void) const
Get the number of Ptr<NetDevice> stored in this container.
Definition: net-device-container.cc:57
NodeStatistics::totalRxTime
double totalRxTime
Definition: wifi-power-adaptation-interference.cc:125
TX
@ TX
The PHY layer is sending a packet.
Definition: wifi-phy-state.h:44
ns3::FlowMonitor::GetFlowStats
const FlowStatsContainer & GetFlowStats() const
Retrieve all collected the flow statistics.
Definition: flow-monitor.cc:296
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition: internet-stack-helper.h:88
NodeStatistics::GetIdleDatafile
Gnuplot2dDataset GetIdleDatafile()
Definition: wifi-power-adaptation-interference.cc:295
ns3::NetDeviceContainer::Get
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Definition: net-device-container.cc:62
ns3::WifiPhyHelper::Set
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:140
ns3::WifiTxVector::SetPreambleType
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
Definition: wifi-tx-vector.cc:248
ns3::NetDeviceContainer::Add
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Definition: net-device-container.cc:67
NodeStatistics::StateCallback
void StateCallback(std::string path, Time init, Time duration, WifiPhyState state)
Definition: wifi-power-adaptation-interference.cc:229
NodeStatistics::txTime
double txTime
Definition: wifi-power-adaptation-interference.cc:120
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition: mobility-helper.h:43
ns3::Time::GetSeconds
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:380
third.mobility
mobility
Definition: third.py:108
NodeStatistics::m_output_rx
Gnuplot2dDataset m_output_rx
Definition: wifi-power-adaptation-interference.cc:132
third.phy
phy
Definition: third.py:93
port
uint16_t port
Definition: dsdv-manet.cc:45
ns3::WifiNetDevice::GetMac
Ptr< WifiMac > GetMac(void) const
Definition: wifi-net-device.cc:201