A Discrete-Event Network Simulator
API
wifi-power-adaptation-interference.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Universidad de la República - Uruguay
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Matias Richart <mrichart@fing.edu.uy>
18  */
19 
58 #include "ns3/command-line.h"
59 #include "ns3/config.h"
60 #include "ns3/double.h"
61 #include "ns3/flow-monitor-helper.h"
62 #include "ns3/gnuplot.h"
63 #include "ns3/internet-stack-helper.h"
64 #include "ns3/ipv4-address-helper.h"
65 #include "ns3/ipv4-flow-classifier.h"
66 #include "ns3/log.h"
67 #include "ns3/mobility-helper.h"
68 #include "ns3/on-off-helper.h"
69 #include "ns3/packet-sink-helper.h"
70 #include "ns3/ssid.h"
71 #include "ns3/uinteger.h"
72 #include "ns3/wifi-mac-header.h"
73 #include "ns3/wifi-mac.h"
74 #include "ns3/wifi-net-device.h"
75 #include "ns3/yans-wifi-channel.h"
76 #include "ns3/yans-wifi-helper.h"
77 
78 using namespace ns3;
79 
80 NS_LOG_COMPONENT_DEFINE("PowerAdaptationInterference");
81 
83 static const uint32_t packetSize = 1420;
84 
88 class NodeStatistics
89 {
90  public:
98 
104  void CheckStatistics(double time);
105 
113  void PhyCallback(std::string path, Ptr<const Packet> packet, double powerW);
121  void RxCallback(std::string path, Ptr<const Packet> packet, const Address& from);
130  void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest);
139  void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest);
148  void StateCallback(std::string path, Time init, Time duration, WifiPhyState state);
149 
167  Gnuplot2dDataset GetIdleDatafile();
173  Gnuplot2dDataset GetBusyDatafile();
179  Gnuplot2dDataset GetTxDatafile();
185  Gnuplot2dDataset GetRxDatafile();
186 
192  double GetBusyTime() const;
193 
194  private:
196  typedef std::vector<std::pair<Time, DataRate>> TxTime;
210 
211  std::map<Mac48Address, double> m_currentPower;
212  std::map<Mac48Address, DataRate> m_currentRate;
213  uint32_t m_bytesTotal;
214  double m_totalEnergy;
215  double m_totalTime;
216  double busyTime;
217  double idleTime;
218  double txTime;
219  double rxTime;
222  double m_totalTxTime;
223  double m_totalRxTime;
224  TxTime m_timeTable;
225  Gnuplot2dDataset m_output;
226  Gnuplot2dDataset m_output_power;
231 };
232 
234 {
235  Ptr<NetDevice> device = aps.Get(0);
236  Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice>(device);
237  Ptr<WifiPhy> phy = wifiDevice->GetPhy();
238  SetupPhy(phy);
239  DataRate dataRate = DataRate(phy->GetDefaultMode().GetDataRate(phy->GetChannelWidth()));
240  double power = phy->GetTxPowerEnd();
241  for (uint32_t j = 0; j < stas.GetN(); j++)
242  {
243  Ptr<NetDevice> staDevice = stas.Get(j);
244  Ptr<WifiNetDevice> wifiStaDevice = DynamicCast<WifiNetDevice>(staDevice);
245  Mac48Address addr = wifiStaDevice->GetMac()->GetAddress();
246  m_currentPower[addr] = power;
247  m_currentRate[addr] = dataRate;
248  }
249  m_currentRate[Mac48Address("ff:ff:ff:ff:ff:ff")] = dataRate;
250  m_totalEnergy = 0;
251  m_totalTime = 0;
252  busyTime = 0;
253  idleTime = 0;
254  txTime = 0;
255  rxTime = 0;
256  m_totalBusyTime = 0;
257  m_totalIdleTime = 0;
258  m_totalTxTime = 0;
259  m_totalRxTime = 0;
260  m_bytesTotal = 0;
261  m_output.SetTitle("Throughput Mbits/s");
262  m_output_idle.SetTitle("Idle Time");
263  m_output_busy.SetTitle("Busy Time");
264  m_output_rx.SetTitle("RX Time");
265  m_output_tx.SetTitle("TX Time");
266 }
267 
268 void
270 {
271  for (const auto& mode : phy->GetModeList())
272  {
273  WifiTxVector txVector;
274  txVector.SetMode(mode);
276  txVector.SetChannelWidth(phy->GetChannelWidth());
277  DataRate dataRate(mode.GetDataRate(phy->GetChannelWidth()));
278  Time time = phy->CalculateTxDuration(packetSize, txVector, phy->GetPhyBand());
279  NS_LOG_DEBUG(mode.GetUniqueName() << " " << time.GetSeconds() << " " << dataRate);
280  m_timeTable.emplace_back(time, dataRate);
281  }
282 }
283 
284 Time
286 {
287  for (auto i = m_timeTable.begin(); i != m_timeTable.end(); i++)
288  {
289  if (rate == i->second)
290  {
291  return i->first;
292  }
293  }
294  NS_ASSERT(false);
295  return Seconds(0);
296 }
297 
298 void
299 NodeStatistics::PhyCallback(std::string path, Ptr<const Packet> packet, double powerW)
300 {
301  WifiMacHeader head;
302  packet->PeekHeader(head);
303  Mac48Address dest = head.GetAddr1();
304 
305  if (head.GetType() == WIFI_MAC_DATA)
306  {
307  m_totalEnergy += pow(10.0, m_currentPower[dest] / 10.0) *
308  GetCalcTxTime(m_currentRate[dest]).GetSeconds();
309  m_totalTime += GetCalcTxTime(m_currentRate[dest]).GetSeconds();
310  }
311 }
312 
313 void
314 NodeStatistics::PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
315 {
316  m_currentPower[dest] = newPower;
317 }
318 
319 void
320 NodeStatistics::RateCallback(std::string path,
321  DataRate oldRate,
322  DataRate newRate,
323  Mac48Address dest)
324 {
325  m_currentRate[dest] = newRate;
326 }
327 
328 void
329 NodeStatistics::StateCallback(std::string path, Time init, Time duration, WifiPhyState state)
330 {
331  if (state == WifiPhyState::CCA_BUSY)
332  {
333  busyTime += duration.GetSeconds();
334  m_totalBusyTime += duration.GetSeconds();
335  }
336  else if (state == WifiPhyState::IDLE)
337  {
338  idleTime += duration.GetSeconds();
339  m_totalIdleTime += duration.GetSeconds();
340  }
341  else if (state == WifiPhyState::TX)
342  {
343  txTime += duration.GetSeconds();
344  m_totalTxTime += duration.GetSeconds();
345  }
346  else if (state == WifiPhyState::RX)
347  {
348  rxTime += duration.GetSeconds();
349  m_totalRxTime += duration.GetSeconds();
350  }
351 }
352 
353 void
354 NodeStatistics::RxCallback(std::string path, Ptr<const Packet> packet, const Address& from)
355 {
356  m_bytesTotal += packet->GetSize();
357 }
358 
359 void
361 {
362  double mbs = ((m_bytesTotal * 8.0) / (1000000 * time));
363  m_bytesTotal = 0;
364  double atp = m_totalEnergy / time;
365  m_totalEnergy = 0;
366  m_totalTime = 0;
367  m_output_power.Add((Simulator::Now()).GetSeconds(), atp);
368  m_output.Add((Simulator::Now()).GetSeconds(), mbs);
369 
370  m_output_idle.Add((Simulator::Now()).GetSeconds(), idleTime * 100);
371  m_output_busy.Add((Simulator::Now()).GetSeconds(), busyTime * 100);
372  m_output_tx.Add((Simulator::Now()).GetSeconds(), txTime * 100);
373  m_output_rx.Add((Simulator::Now()).GetSeconds(), rxTime * 100);
374  busyTime = 0;
375  idleTime = 0;
376  txTime = 0;
377  rxTime = 0;
378 
380 }
381 
384 {
385  return m_output;
386 }
387 
390 {
391  return m_output_power;
392 }
393 
396 {
397  return m_output_idle;
398 }
399 
402 {
403  return m_output_busy;
404 }
405 
408 {
409  return m_output_rx;
410 }
411 
414 {
415  return m_output_tx;
416 }
417 
418 double
420 {
421  return m_totalBusyTime + m_totalRxTime;
422 }
423 
432 void
433 PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
434 {
435  NS_LOG_INFO((Simulator::Now()).GetSeconds()
436  << " " << dest << " Old power=" << oldPower << " New power=" << newPower);
437 }
438 
447 void
448 RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
449 {
450  NS_LOG_INFO((Simulator::Now()).GetSeconds()
451  << " " << dest << " Old rate=" << oldRate << " New rate=" << newRate);
452 }
453 
454 int
455 main(int argc, char* argv[])
456 {
457  // LogComponentEnable("ConstantRateWifiManager", LOG_LEVEL_FUNCTION);
458 
459  double maxPower = 17;
460  double minPower = 0;
461  uint32_t powerLevels = 18;
462 
463  uint32_t rtsThreshold = 2346;
464  std::string manager = "ns3::ParfWifiManager";
465  std::string outputFileName = "parf";
466  int ap1_x = 0;
467  int ap1_y = 0;
468  int sta1_x = 10;
469  int sta1_y = 0;
470  int ap2_x = 200;
471  int ap2_y = 0;
472  int sta2_x = 180;
473  int sta2_y = 0;
474  uint32_t simuTime = 100;
475 
476  CommandLine cmd(__FILE__);
477  cmd.AddValue("manager", "PRC Manager", manager);
478  cmd.AddValue("rtsThreshold", "RTS threshold", rtsThreshold);
479  cmd.AddValue("outputFileName", "Output filename", outputFileName);
480  cmd.AddValue("simuTime", "Total simulation time (sec)", simuTime);
481  cmd.AddValue("maxPower", "Maximum available transmission level (dbm).", maxPower);
482  cmd.AddValue("minPower", "Minimum available transmission level (dbm).", minPower);
483  cmd.AddValue("powerLevels",
484  "Number of transmission power levels available between "
485  "TxPowerStart and TxPowerEnd included.",
486  powerLevels);
487  cmd.AddValue("AP1_x", "Position of AP1 in x coordinate", ap1_x);
488  cmd.AddValue("AP1_y", "Position of AP1 in y coordinate", ap1_y);
489  cmd.AddValue("STA1_x", "Position of STA1 in x coordinate", sta1_x);
490  cmd.AddValue("STA1_y", "Position of STA1 in y coordinate", sta1_y);
491  cmd.AddValue("AP2_x", "Position of AP2 in x coordinate", ap2_x);
492  cmd.AddValue("AP2_y", "Position of AP2 in y coordinate", ap2_y);
493  cmd.AddValue("STA2_x", "Position of STA2 in x coordinate", sta2_x);
494  cmd.AddValue("STA2_y", "Position of STA2 in y coordinate", sta2_y);
495  cmd.Parse(argc, argv);
496 
497  // Define the APs
498  NodeContainer wifiApNodes;
499  wifiApNodes.Create(2);
500 
501  // Define the STAs
503  wifiStaNodes.Create(2);
504 
506  wifi.SetStandard(WIFI_STANDARD_80211a);
507  WifiMacHelper wifiMac;
508  YansWifiPhyHelper wifiPhy;
510 
511  wifiPhy.SetChannel(wifiChannel.Create());
512 
513  NetDeviceContainer wifiApDevices;
514  NetDeviceContainer wifiStaDevices;
515  NetDeviceContainer wifiDevices;
516 
517  // Configure the STA nodes
518  wifi.SetRemoteStationManager("ns3::AarfWifiManager",
519  "RtsCtsThreshold",
520  UintegerValue(rtsThreshold));
521  wifiPhy.Set("TxPowerStart", DoubleValue(maxPower));
522  wifiPhy.Set("TxPowerEnd", DoubleValue(maxPower));
523 
524  Ssid ssid = Ssid("AP0");
525  wifiMac.SetType("ns3::StaWifiMac",
526  "Ssid",
527  SsidValue(ssid),
528  "MaxMissedBeacons",
529  UintegerValue(1000));
530  wifiStaDevices.Add(wifi.Install(wifiPhy, wifiMac, wifiStaNodes.Get(0)));
531 
532  ssid = Ssid("AP1");
533  wifiMac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
534  wifiStaDevices.Add(wifi.Install(wifiPhy, wifiMac, wifiStaNodes.Get(1)));
535 
536  // Configure the AP nodes
537  wifi.SetRemoteStationManager(manager,
538  "DefaultTxPowerLevel",
539  UintegerValue(powerLevels - 1),
540  "RtsCtsThreshold",
541  UintegerValue(rtsThreshold));
542  wifiPhy.Set("TxPowerStart", DoubleValue(minPower));
543  wifiPhy.Set("TxPowerEnd", DoubleValue(maxPower));
544  wifiPhy.Set("TxPowerLevels", UintegerValue(powerLevels));
545 
546  ssid = Ssid("AP0");
547  wifiMac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
548  wifiApDevices.Add(wifi.Install(wifiPhy, wifiMac, wifiApNodes.Get(0)));
549 
550  ssid = Ssid("AP1");
551  wifiMac.SetType("ns3::ApWifiMac",
552  "Ssid",
553  SsidValue(ssid),
554  "BeaconInterval",
555  TimeValue(MicroSeconds(103424))); // for avoiding collisions);
556  wifiApDevices.Add(wifi.Install(wifiPhy, wifiMac, wifiApNodes.Get(1)));
557 
558  wifiDevices.Add(wifiStaDevices);
559  wifiDevices.Add(wifiApDevices);
560 
561  // Configure the mobility.
563  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
564  positionAlloc->Add(Vector(ap1_x, ap1_y, 0.0));
565  positionAlloc->Add(Vector(sta1_x, sta1_y, 0.0));
566  positionAlloc->Add(Vector(ap2_x, ap2_y, 0.0));
567  positionAlloc->Add(Vector(sta2_x, sta2_y, 0.0));
568  mobility.SetPositionAllocator(positionAlloc);
569  mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
570  mobility.Install(wifiApNodes.Get(0));
571  mobility.Install(wifiStaNodes.Get(0));
572  mobility.Install(wifiApNodes.Get(1));
573  mobility.Install(wifiStaNodes.Get(1));
574 
575  // Configure the IP stack
577  stack.Install(wifiApNodes);
578  stack.Install(wifiStaNodes);
580  address.SetBase("10.1.1.0", "255.255.255.0");
581  Ipv4InterfaceContainer i = address.Assign(wifiDevices);
582  Ipv4Address sinkAddress = i.GetAddress(0);
583  Ipv4Address sinkAddress1 = i.GetAddress(1);
584  uint16_t port = 9;
585 
586  // Configure the CBR generator
587  PacketSinkHelper sink("ns3::UdpSocketFactory", InetSocketAddress(sinkAddress, port));
588  ApplicationContainer apps_sink = sink.Install(wifiStaNodes.Get(0));
589 
590  OnOffHelper onoff("ns3::UdpSocketFactory", InetSocketAddress(sinkAddress, port));
591  onoff.SetConstantRate(DataRate("54Mb/s"), packetSize);
592  onoff.SetAttribute("StartTime", TimeValue(Seconds(0.0)));
593  onoff.SetAttribute("StopTime", TimeValue(Seconds(100.0)));
594  ApplicationContainer apps_source = onoff.Install(wifiApNodes.Get(0));
595 
596  PacketSinkHelper sink1("ns3::UdpSocketFactory", InetSocketAddress(sinkAddress1, port));
597  apps_sink.Add(sink1.Install(wifiStaNodes.Get(1)));
598 
599  OnOffHelper onoff1("ns3::UdpSocketFactory", InetSocketAddress(sinkAddress1, port));
600  onoff1.SetConstantRate(DataRate("54Mb/s"), packetSize);
601  onoff1.SetAttribute("StartTime", TimeValue(Seconds(0.0)));
602  onoff1.SetAttribute("StopTime", TimeValue(Seconds(100.0)));
603  apps_source.Add(onoff1.Install(wifiApNodes.Get(1)));
604 
605  apps_sink.Start(Seconds(0.5));
606  apps_sink.Stop(Seconds(simuTime));
607 
608  //------------------------------------------------------------
609  //-- Setup stats and data collection
610  //--------------------------------------------
611 
612  // Statistics counters
613  NodeStatistics statisticsAp0 = NodeStatistics(wifiApDevices, wifiStaDevices);
614  NodeStatistics statisticsAp1 = NodeStatistics(wifiApDevices, wifiStaDevices);
615 
616  // Register packet receptions to calculate throughput
617  Config::Connect("/NodeList/2/ApplicationList/*/$ns3::PacketSink/Rx",
618  MakeCallback(&NodeStatistics::RxCallback, &statisticsAp0));
619  Config::Connect("/NodeList/3/ApplicationList/*/$ns3::PacketSink/Rx",
620  MakeCallback(&NodeStatistics::RxCallback, &statisticsAp1));
621 
622  // Register power and rate changes to calculate the Average Transmit Power
623  Config::Connect("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
624  manager + "/PowerChange",
625  MakeCallback(&NodeStatistics::PowerCallback, &statisticsAp0));
626  Config::Connect("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
627  manager + "/RateChange",
628  MakeCallback(&NodeStatistics::RateCallback, &statisticsAp0));
629  Config::Connect("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
630  manager + "/PowerChange",
631  MakeCallback(&NodeStatistics::PowerCallback, &statisticsAp1));
632  Config::Connect("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
633  manager + "/RateChange",
634  MakeCallback(&NodeStatistics::RateCallback, &statisticsAp1));
635 
636  Config::Connect("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
637  MakeCallback(&NodeStatistics::PhyCallback, &statisticsAp0));
638  Config::Connect("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
639  MakeCallback(&NodeStatistics::PhyCallback, &statisticsAp1));
640 
641  // Register States
643  "/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
644  MakeCallback(&NodeStatistics::StateCallback, &statisticsAp0));
646  "/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
647  MakeCallback(&NodeStatistics::StateCallback, &statisticsAp1));
648 
649  statisticsAp0.CheckStatistics(1);
650  statisticsAp1.CheckStatistics(1);
651 
652  // Callbacks to print every change of power and rate
653  Config::Connect("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
654  manager + "/PowerChange",
656  Config::Connect("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
657  manager + "/RateChange",
659 
660  // Calculate Throughput using Flowmonitor
661 
662  FlowMonitorHelper flowmon;
663  Ptr<FlowMonitor> monitor = flowmon.InstallAll();
664 
665  Simulator::Stop(Seconds(simuTime));
666  Simulator::Run();
667 
668  Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmon.GetClassifier());
669  std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
670  for (auto i = stats.begin(); i != stats.end(); ++i)
671  {
672  Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(i->first);
673  if (t.sourceAddress == "10.1.1.3" && t.destinationAddress == "10.1.1.1")
674  {
675  NS_LOG_INFO("Flow " << i->first << " (" << t.sourceAddress << " -> "
676  << t.destinationAddress << ")\n");
677  NS_LOG_INFO(" Tx Bytes: " << i->second.txBytes << "\n");
678  NS_LOG_INFO(" Rx Bytes: " << i->second.rxBytes << "\n");
679  NS_LOG_UNCOND(" Throughput to 10.1.1.1: "
680  << i->second.rxBytes * 8.0 /
681  (i->second.timeLastRxPacket.GetSeconds() -
682  i->second.timeFirstTxPacket.GetSeconds()) /
683  1024 / 1024
684  << " Mbps\n");
685  NS_LOG_INFO(" Mean delay: " << i->second.delaySum.GetSeconds() / i->second.rxPackets
686  << "\n");
687  NS_LOG_INFO(" Mean jitter: "
688  << i->second.jitterSum.GetSeconds() / (i->second.rxPackets - 1) << "\n");
689  NS_LOG_INFO(" Tx Opp: " << 1 - (statisticsAp0.GetBusyTime() / simuTime));
690  }
691  if (t.sourceAddress == "10.1.1.4" && t.destinationAddress == "10.1.1.2")
692  {
693  NS_LOG_INFO("Flow " << i->first << " (" << t.sourceAddress << " -> "
694  << t.destinationAddress << ")\n");
695  NS_LOG_INFO(" Tx Bytes: " << i->second.txBytes << "\n");
696  NS_LOG_INFO(" Rx Bytes: " << i->second.rxBytes << "\n");
697  NS_LOG_UNCOND(" Throughput to 10.1.1.2: "
698  << i->second.rxBytes * 8.0 /
699  (i->second.timeLastRxPacket.GetSeconds() -
700  i->second.timeFirstTxPacket.GetSeconds()) /
701  1024 / 1024
702  << " Mbps\n");
703  NS_LOG_INFO(" Mean delay: " << i->second.delaySum.GetSeconds() / i->second.rxPackets
704  << "\n");
705  NS_LOG_INFO(" Mean jitter: "
706  << i->second.jitterSum.GetSeconds() / (i->second.rxPackets - 1) << "\n");
707  NS_LOG_INFO(" Tx Opp: " << 1 - (statisticsAp1.GetBusyTime() / simuTime));
708  }
709  }
710 
711  // Plots for AP0
712  std::ofstream outfileTh0("throughput-" + outputFileName + "-0.plt");
713  Gnuplot gnuplot = Gnuplot("throughput-" + outputFileName + "-0.eps", "Throughput");
714  gnuplot.SetTerminal("post eps color enhanced");
715  gnuplot.SetLegend("Time (seconds)", "Throughput (Mb/s)");
716  gnuplot.SetTitle("Throughput (AP0 to STA) vs time");
717  gnuplot.AddDataset(statisticsAp0.GetDatafile());
718  gnuplot.GenerateOutput(outfileTh0);
719 
720  if (manager == "ns3::ParfWifiManager" || manager == "ns3::AparfWifiManager" ||
721  manager == "ns3::RrpaaWifiManager")
722  {
723  std::ofstream outfilePower0("power-" + outputFileName + "-0.plt");
724  gnuplot = Gnuplot("power-" + outputFileName + "-0.eps", "Average Transmit Power");
725  gnuplot.SetTerminal("post eps color enhanced");
726  gnuplot.SetLegend("Time (seconds)", "Power (mW)");
727  gnuplot.SetTitle("Average transmit power (AP0 to STA) vs time");
728  gnuplot.AddDataset(statisticsAp0.GetPowerDatafile());
729  gnuplot.GenerateOutput(outfilePower0);
730  }
731 
732  std::ofstream outfileTx0("tx-" + outputFileName + "-0.plt");
733  gnuplot = Gnuplot("tx-" + outputFileName + "-0.eps", "Time in TX State");
734  gnuplot.SetTerminal("post eps color enhanced");
735  gnuplot.SetLegend("Time (seconds)", "Percent");
736  gnuplot.SetTitle("Percentage time AP0 in TX state vs time");
737  gnuplot.AddDataset(statisticsAp0.GetTxDatafile());
738  gnuplot.GenerateOutput(outfileTx0);
739 
740  std::ofstream outfileRx0("rx-" + outputFileName + "-0.plt");
741  gnuplot = Gnuplot("rx-" + outputFileName + "-0.eps", "Time in RX State");
742  gnuplot.SetTerminal("post eps color enhanced");
743  gnuplot.SetLegend("Time (seconds)", "Percent");
744  gnuplot.SetTitle("Percentage time AP0 in RX state vs time");
745  gnuplot.AddDataset(statisticsAp0.GetRxDatafile());
746  gnuplot.GenerateOutput(outfileRx0);
747 
748  std::ofstream outfileBusy0("busy-" + outputFileName + "-0.plt");
749  gnuplot = Gnuplot("busy-" + outputFileName + "-0.eps", "Time in Busy State");
750  gnuplot.SetTerminal("post eps color enhanced");
751  gnuplot.SetLegend("Time (seconds)", "Percent");
752  gnuplot.SetTitle("Percentage time AP0 in Busy state vs time");
753  gnuplot.AddDataset(statisticsAp0.GetBusyDatafile());
754  gnuplot.GenerateOutput(outfileBusy0);
755 
756  std::ofstream outfileIdle0("idle-" + outputFileName + "-0.plt");
757  gnuplot = Gnuplot("idle-" + outputFileName + "-0.eps", "Time in Idle State");
758  gnuplot.SetTerminal("post eps color enhanced");
759  gnuplot.SetLegend("Time (seconds)", "Percent");
760  gnuplot.SetTitle("Percentage time AP0 in Idle state vs time");
761  gnuplot.AddDataset(statisticsAp0.GetIdleDatafile());
762  gnuplot.GenerateOutput(outfileIdle0);
763 
764  // Plots for AP1
765  std::ofstream outfileTh1("throughput-" + outputFileName + "-1.plt");
766  gnuplot = Gnuplot("throughput-" + outputFileName + "-1.eps", "Throughput");
767  gnuplot.SetTerminal("post eps color enhanced");
768  gnuplot.SetLegend("Time (seconds)", "Throughput (Mb/s)");
769  gnuplot.SetTitle("Throughput (AP1 to STA) vs time");
770  gnuplot.AddDataset(statisticsAp1.GetDatafile());
771  gnuplot.GenerateOutput(outfileTh1);
772 
773  if (manager == "ns3::ParfWifiManager" || manager == "ns3::AparfWifiManager" ||
774  manager == "ns3::RrpaaWifiManager")
775  {
776  std::ofstream outfilePower1("power-" + outputFileName + "-1.plt");
777  gnuplot = Gnuplot("power-" + outputFileName + "-1.eps", "Average Transmit Power");
778  gnuplot.SetTerminal("post eps color enhanced");
779  gnuplot.SetLegend("Time (seconds)", "Power (mW)");
780  gnuplot.SetTitle("Average transmit power (AP1 to STA) vs time");
781  gnuplot.AddDataset(statisticsAp1.GetPowerDatafile());
782  gnuplot.GenerateOutput(outfilePower1);
783  }
784 
785  std::ofstream outfileTx1("tx-" + outputFileName + "-1.plt");
786  gnuplot = Gnuplot("tx-" + outputFileName + "-1.eps", "Time in TX State");
787  gnuplot.SetTerminal("post eps color enhanced");
788  gnuplot.SetLegend("Time (seconds)", "Percent");
789  gnuplot.SetTitle("Percentage time AP1 in TX state vs time");
790  gnuplot.AddDataset(statisticsAp1.GetTxDatafile());
791  gnuplot.GenerateOutput(outfileTx1);
792 
793  std::ofstream outfileRx1("rx-" + outputFileName + "-1.plt");
794  gnuplot = Gnuplot("rx-" + outputFileName + "-1.eps", "Time in RX State");
795  gnuplot.SetTerminal("post eps color enhanced");
796  gnuplot.SetLegend("Time (seconds)", "Percent");
797  gnuplot.SetTitle("Percentage time AP1 in RX state vs time");
798  gnuplot.AddDataset(statisticsAp1.GetRxDatafile());
799  gnuplot.GenerateOutput(outfileRx1);
800 
801  std::ofstream outfileBusy1("busy-" + outputFileName + "-1.plt");
802  gnuplot = Gnuplot("busy-" + outputFileName + "-1.eps", "Time in Busy State");
803  gnuplot.SetTerminal("post eps color enhanced");
804  gnuplot.SetLegend("Time (seconds)", "Percent");
805  gnuplot.SetTitle("Percentage time AP1 in Busy state vs time");
806  gnuplot.AddDataset(statisticsAp1.GetBusyDatafile());
807  gnuplot.GenerateOutput(outfileBusy1);
808 
809  std::ofstream outfileIdle1("idle-" + outputFileName + "-1.plt");
810  gnuplot = Gnuplot("idle-" + outputFileName + "-1.eps", "Time in Idle State");
811  gnuplot.SetTerminal("post eps color enhanced");
812  gnuplot.SetLegend("Time (seconds)", "Percent");
813  gnuplot.SetTitle("Percentage time AP1 in Idle state vs time");
814  gnuplot.AddDataset(statisticsAp1.GetIdleDatafile());
815  gnuplot.GenerateOutput(outfileIdle1);
816 
818 
819  return 0;
820 }
Class to collect node statistics.
Gnuplot2dDataset m_output_busy
BUSY output data.
double m_totalIdleTime
Total time in IDLE state.
double m_totalTxTime
Total time in TX state.
Gnuplot2dDataset GetPowerDatafile()
Get the Power output data.
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.
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
Callback called by WifiNetDevice/RemoteStationManager/x/PowerChange.
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.
void CheckStatistics(double time)
Collects the statistics at a given 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.
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
Definition: address.h:101
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.
Definition: command-line.h:232
Class for representing data rates.
Definition: data-rate.h:89
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
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.
Definition: gnuplot.h:118
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:373
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:759
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:739
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:727
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:765
void SetTitle(const std::string &title)
Definition: gnuplot.cc:733
an Inet address class
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.
Definition: ipv4-address.h:42
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
an EUI-48 address
Definition: mac48-address.h:46
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.
Definition: on-off-helper.h:44
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:861
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:305
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
Hold an unsigned integer type.
Definition: uinteger.h:45
helps to create WifiNetDevice objects
Definition: wifi-helper.h:324
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr1() const
Return the address in the Address 1 field.
virtual WifiMacType GetType() const
Return the type (WifiMacType)
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
Mac48Address GetAddress() const
Definition: wifi-mac.cc:452
Ptr< WifiMac > GetMac() const
Ptr< WifiPhy > GetPhy() const
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:163
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
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)
uint16_t port
Definition: dsdv-manet.cc:44
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:974
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:327
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
@ WIFI_STANDARD_80211a
@ WIFI_PREAMBLE_LONG
address
Definition: first.py:47
stack
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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...
Definition: callback.h:704
@ WIFI_MAC_DATA
cmd
Definition: second.py:40
ssid
Definition: third.py:93
wifi
Definition: third.py:95
mobility
Definition: third.py:105
wifiStaNodes
Definition: third.py:84
phy
Definition: third.py:89
Structure to classify a packet.
Ipv4Address sourceAddress
Source address.
Ipv4Address destinationAddress
Destination address.
WifiPhyState
The state of the PHY layer.
@ CCA_BUSY
The PHY layer has sense the medium busy through the CCA mechanism.
@ RX
The PHY layer is receiving a packet.
@ TX
The PHY layer is sending a packet.
@ IDLE
The PHY layer is IDLE.
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.
Definition: wifi-tcp.cc:55