A Discrete-Event Network Simulator
API
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 <sstream>
59 #include <fstream>
60 
61 #include "ns3/core-module.h"
62 #include "ns3/network-module.h"
63 #include "ns3/internet-module.h"
64 #include "ns3/mobility-module.h"
65 #include "ns3/wifi-module.h"
66 #include "ns3/applications-module.h"
67 #include "ns3/stats-module.h"
68 #include "ns3/flow-monitor-module.h"
69 
70 using namespace ns3;
71 using namespace std;
72 
73 NS_LOG_COMPONENT_DEFINE ("PowerAdaptationInterference");
74 
75 // packet size generated at the AP
76 static const uint32_t packetSize = 1420;
77 
78 class NodeStatistics
79 {
80 public:
82 
83  void CheckStatistics (double time);
84 
85  void PhyCallback (std::string path, Ptr<const Packet> packet);
86  void RxCallback (std::string path, Ptr<const Packet> packet, const Address &from);
87  void PowerCallback (std::string path, uint8_t power, Mac48Address dest);
88  void RateCallback (std::string path, uint32_t rate, Mac48Address dest);
89  void StateCallback (std::string path, Time init, Time duration, enum WifiPhy::State state);
90 
91  Gnuplot2dDataset GetDatafile ();
92  Gnuplot2dDataset GetPowerDatafile ();
93  Gnuplot2dDataset GetIdleDatafile ();
94  Gnuplot2dDataset GetBusyDatafile ();
95  Gnuplot2dDataset GetTxDatafile ();
96  Gnuplot2dDataset GetRxDatafile ();
97 
98  double GetBusyTime ();
99 
100 private:
101  typedef std::vector<std::pair<Time,WifiMode> > TxTime;
102  void SetupPhy (Ptr<WifiPhy> phy);
103  Time GetCalcTxTime (WifiMode mode);
104 
105  std::map<Mac48Address, double> actualPower;
106  std::map<Mac48Address, WifiMode> actualMode;
107  uint32_t m_bytesTotal;
108  double totalEnergy;
109  double totalTime;
110  double busyTime;
111  double idleTime;
112  double txTime;
113  double rxTime;
116  double totalTxTime;
117  double totalRxTime;
118  Ptr<WifiPhy> myPhy;
119  TxTime timeTable;
120  Gnuplot2dDataset m_output;
121  Gnuplot2dDataset m_output_power;
126 };
127 
129 {
130  Ptr<NetDevice> device = aps.Get (0);
131  Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device);
132  Ptr<WifiPhy> phy = wifiDevice->GetPhy ();
133  myPhy = phy;
134  SetupPhy (phy);
135  for (uint32_t j = 0; j < stas.GetN (); j++)
136  {
137  Ptr<NetDevice> staDevice = stas.Get (j);
138  Ptr<WifiNetDevice> wifiStaDevice = DynamicCast<WifiNetDevice> (staDevice);
139  Mac48Address addr = wifiStaDevice->GetMac ()->GetAddress ();
140  actualPower[addr] = 17;
141  actualMode[addr] = phy->GetMode (0);
142  }
143  actualMode[Mac48Address ("ff:ff:ff:ff:ff:ff")] = phy->GetMode (0);
144  totalEnergy = 0;
145  totalTime = 0;
146  busyTime = 0;
147  idleTime = 0;
148  txTime = 0;
149  rxTime = 0;
150  totalBusyTime = 0;
151  totalIdleTime = 0;
152  totalTxTime = 0;
153  totalRxTime = 0;
154  m_bytesTotal = 0;
155  m_output.SetTitle ("Throughput Mbits/s");
156  m_output_idle.SetTitle ("Idle Time");
157  m_output_busy.SetTitle ("Busy Time");
158  m_output_rx.SetTitle ("RX Time");
159  m_output_tx.SetTitle ("TX Time");
160 }
161 
162 void
164 {
165  uint32_t nModes = phy->GetNModes ();
166  for (uint32_t i = 0; i < nModes; i++)
167  {
168  WifiMode mode = phy->GetMode (i);
169  WifiTxVector txVector;
170  txVector.SetMode (mode);
171  timeTable.push_back (std::make_pair (phy->CalculateTxDuration (packetSize, txVector, WIFI_PREAMBLE_LONG, phy->GetFrequency ()), mode));
172  }
173 }
174 
175 Time
177 {
178  for (TxTime::const_iterator i = timeTable.begin (); i != timeTable.end (); i++)
179  {
180  if (mode == i->second)
181  {
182  return i->first;
183  }
184  }
185  NS_ASSERT (false);
186  return Seconds (0);
187 }
188 
189 void
190 NodeStatistics::PhyCallback (std::string path, Ptr<const Packet> packet)
191 {
192  WifiMacHeader head;
193  packet->PeekHeader (head);
194  Mac48Address dest = head.GetAddr1 ();
195 
196  if (head.GetType() == WIFI_MAC_DATA)
197  {
198  totalEnergy += pow (10.0, actualPower[dest] / 10.0) * GetCalcTxTime (actualMode[dest]).GetSeconds ();
199  totalTime += GetCalcTxTime (actualMode[dest]).GetSeconds ();
200  }
201 }
202 
203 void
204 NodeStatistics::PowerCallback (std::string path, uint8_t power, Mac48Address dest)
205 {
206  double txPowerBaseDbm = myPhy->GetTxPowerStart ();
207  double txPowerEndDbm = myPhy->GetTxPowerEnd ();
208  uint32_t nTxPower = myPhy->GetNTxPower ();
209  double dbm;
210  if (nTxPower > 1)
211  {
212  dbm = txPowerBaseDbm + power * (txPowerEndDbm - txPowerBaseDbm) / (nTxPower - 1);
213  }
214  else
215  {
216  NS_ASSERT_MSG (txPowerBaseDbm == txPowerEndDbm, "cannot have TxPowerEnd != TxPowerStart with TxPowerLevels == 1");
217  dbm = txPowerBaseDbm;
218  }
219  actualPower[dest] = dbm;
220 }
221 
222 void
223 NodeStatistics::RateCallback (std::string path, uint32_t rate, Mac48Address dest)
224 {
225  actualMode[dest] = myPhy->GetMode (rate);
226 }
227 
228 void
229 NodeStatistics::StateCallback (std::string path, Time init, Time duration, enum WifiPhy::State state)
230 {
231  if (state == WifiPhy::CCA_BUSY)
232  {
233  busyTime += duration.GetSeconds ();
234  totalBusyTime += duration.GetSeconds ();
235  }
236  else if (state == WifiPhy::IDLE)
237  {
238  idleTime += duration.GetSeconds ();
239  totalIdleTime += duration.GetSeconds ();
240  }
241  else if (state == WifiPhy::TX)
242  {
243  txTime += duration.GetSeconds ();
244  totalTxTime += duration.GetSeconds ();
245  }
246  else if (state == WifiPhy::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, uint8_t power, Mac48Address dest)
325 {
326  NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Power " << (int)power);
327  // end PowerCallback
328 }
329 
330 void RateCallback (std::string path, uint32_t rate, Mac48Address dest)
331 {
332  NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Rate " << rate);
333  // end PowerCallback
334 }
335 
336 int main (int argc, char *argv[])
337 {
338  //LogComponentEnable("ConstantRateWifiManager", LOG_LEVEL_FUNCTION);
339 
340  double maxPower = 17;
341  double minPower = 0;
342  uint32_t powerLevels = 18;
343 
344  uint32_t rtsThreshold = 2346;
345  std::string manager = "ns3::ParfWifiManager";
346  std::string outputFileName = "parf";
347  int ap1_x = 0;
348  int ap1_y = 0;
349  int sta1_x = 10;
350  int sta1_y = 0;
351  int ap2_x = 200;
352  int ap2_y = 0;
353  int sta2_x = 180;
354  int sta2_y = 0;
355  uint32_t simuTime = 100;
356 
358  cmd.AddValue ("manager", "PRC Manager", manager);
359  cmd.AddValue ("rtsThreshold", "RTS threshold", rtsThreshold);
360  cmd.AddValue ("outputFileName", "Output filename", outputFileName);
361  cmd.AddValue ("simuTime", "Total simulation time (sec)", simuTime);
362  cmd.AddValue ("maxPower", "Maximum available transmission level (dbm).", maxPower);
363  cmd.AddValue ("minPower", "Minimum available transmission level (dbm).", minPower);
364  cmd.AddValue ("powerLevels", "Number of transmission power levels available between "
365  "TxPowerStart and TxPowerEnd included.", powerLevels);
366  cmd.AddValue ("AP1_x", "Position of AP1 in x coordinate", ap1_x);
367  cmd.AddValue ("AP1_y", "Position of AP1 in y coordinate", ap1_y);
368  cmd.AddValue ("STA1_x", "Position of STA1 in x coordinate", sta1_x);
369  cmd.AddValue ("STA1_y", "Position of STA1 in y coordinate", sta1_y);
370  cmd.AddValue ("AP2_x", "Position of AP2 in x coordinate", ap2_x);
371  cmd.AddValue ("AP2_y", "Position of AP2 in y coordinate", ap2_y);
372  cmd.AddValue ("STA2_x", "Position of STA2 in x coordinate", sta2_x);
373  cmd.AddValue ("STA2_y", "Position of STA2 in y coordinate", sta2_y);
374  cmd.Parse (argc, argv);
375 
376  // Define the APs
377  NodeContainer wifiApNodes;
378  wifiApNodes.Create (2);
379 
380  //Define the STAs
382  wifiStaNodes.Create (2);
383 
386  WifiMacHelper wifiMac;
389 
390  wifiPhy.SetChannel (wifiChannel.Create ());
391 
392  NetDeviceContainer wifiApDevices;
393  NetDeviceContainer wifiStaDevices;
394  NetDeviceContainer wifiDevices;
395 
396  //Configure the STA nodes
397  wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "RtsCtsThreshold", UintegerValue (rtsThreshold));
398  //wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",StringValue ("ErpOfdmRate6Mbps"),"ControlMode",StringValue ("ErpOfdmRate6Mbps"));
399  wifiPhy.Set ("TxPowerStart", DoubleValue (maxPower));
400  wifiPhy.Set ("TxPowerEnd", DoubleValue (maxPower));
401 
402  Ssid ssid = Ssid ("AP0");
403  wifiMac.SetType ("ns3::StaWifiMac",
404  "Ssid", SsidValue (ssid),
405  "MaxMissedBeacons", UintegerValue (1000));
406  wifiStaDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiStaNodes.Get (0)));
407 
408  ssid = Ssid ("AP1");
409  wifiMac.SetType ("ns3::StaWifiMac",
410  "Ssid", SsidValue (ssid));
411  wifiStaDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiStaNodes.Get (1)));
412 
413  //Configure the AP nodes
414  wifi.SetRemoteStationManager (manager, "DefaultTxPowerLevel", UintegerValue (maxPower), "RtsCtsThreshold", UintegerValue (rtsThreshold));
415  wifiPhy.Set ("TxPowerStart", DoubleValue (minPower));
416  wifiPhy.Set ("TxPowerEnd", DoubleValue (maxPower));
417  wifiPhy.Set ("TxPowerLevels", UintegerValue (powerLevels));
418 
419  ssid = Ssid ("AP0");
420  wifiMac.SetType ("ns3::ApWifiMac",
421  "Ssid", SsidValue (ssid));
422  wifiApDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiApNodes.Get (0)));
423 
424  ssid = Ssid ("AP1");
425  wifiMac.SetType ("ns3::ApWifiMac",
426  "Ssid", SsidValue (ssid),
427  "BeaconInterval", TimeValue (MicroSeconds (103424))); //for avoiding collisions);
428  wifiApDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiApNodes.Get (1)));
429 
430  wifiDevices.Add (wifiStaDevices);
431  wifiDevices.Add (wifiApDevices);
432 
433  // Configure the mobility.
435  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
436  positionAlloc->Add (Vector (ap1_x, ap1_y, 0.0));
437  positionAlloc->Add (Vector (sta1_x, sta1_y, 0.0));
438  positionAlloc->Add (Vector (ap2_x, ap2_y, 0.0));
439  positionAlloc->Add (Vector (sta2_x, sta2_y, 0.0));
440  mobility.SetPositionAllocator (positionAlloc);
441  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
442  mobility.Install (wifiApNodes.Get (0));
443  mobility.Install (wifiStaNodes.Get (0));
444  mobility.Install (wifiApNodes.Get (1));
445  mobility.Install (wifiStaNodes.Get (1));
446 
447 
448  //Configure the IP stack
450  stack.Install (wifiApNodes);
451  stack.Install (wifiStaNodes);
453  address.SetBase ("10.1.1.0", "255.255.255.0");
454  Ipv4InterfaceContainer i = address.Assign (wifiDevices);
455  Ipv4Address sinkAddress = i.GetAddress (0);
456  Ipv4Address sinkAddress1 = i.GetAddress (1);
457  uint16_t port = 9;
458 
459  //Configure the CBR generator
460  PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress, port));
461  ApplicationContainer apps_sink = sink.Install (wifiStaNodes.Get (0));
462 
463  OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress, port));
464  onoff.SetConstantRate (DataRate ("54Mb/s"), packetSize);
465  onoff.SetAttribute ("StartTime", TimeValue (Seconds (0.0)));
466  onoff.SetAttribute ("StopTime", TimeValue (Seconds (100.0)));
467  ApplicationContainer apps_source = onoff.Install (wifiApNodes.Get (0));
468 
469  PacketSinkHelper sink1 ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress1, port));
470  apps_sink.Add (sink1.Install (wifiStaNodes.Get (1)));
471 
472  OnOffHelper onoff1 ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress1, port));
473  onoff1.SetConstantRate (DataRate ("54Mb/s"), packetSize);
474  onoff1.SetAttribute ("StartTime", TimeValue (Seconds (0.0)));
475  onoff1.SetAttribute ("StopTime", TimeValue (Seconds (100.0)));
476  apps_source.Add (onoff1.Install (wifiApNodes.Get (1)));
477 
478  apps_sink.Start (Seconds (0.5));
479  apps_sink.Stop (Seconds (simuTime));
480 
481  //------------------------------------------------------------
482  //-- Setup stats and data collection
483  //--------------------------------------------
484 
485  //Statistics counters
486  NodeStatistics statisticsAp0 = NodeStatistics (wifiApDevices, wifiStaDevices);
487  NodeStatistics statisticsAp1 = NodeStatistics (wifiApDevices, wifiStaDevices);
488 
489  //Register packet receptions to calculate throughput
490  Config::Connect ("/NodeList/2/ApplicationList/*/$ns3::PacketSink/Rx",
491  MakeCallback (&NodeStatistics::RxCallback, &statisticsAp0));
492  Config::Connect ("/NodeList/3/ApplicationList/*/$ns3::PacketSink/Rx",
493  MakeCallback (&NodeStatistics::RxCallback, &statisticsAp1));
494 
495  //Register power and rate changes to calculate the Average Transmit Power
496  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
497  MakeCallback (&NodeStatistics::PowerCallback, &statisticsAp0));
498  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
499  MakeCallback (&NodeStatistics::RateCallback, &statisticsAp0));
500  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
501  MakeCallback (&NodeStatistics::PowerCallback, &statisticsAp1));
502  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
503  MakeCallback (&NodeStatistics::RateCallback, &statisticsAp1));
504 
505  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
506  MakeCallback (&NodeStatistics::PhyCallback, &statisticsAp0));
507  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
508  MakeCallback (&NodeStatistics::PhyCallback, &statisticsAp1));
509 
510  //Register States
511  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
512  MakeCallback (&NodeStatistics::StateCallback, &statisticsAp0));
513  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
514  MakeCallback (&NodeStatistics::StateCallback, &statisticsAp1));
515 
516  statisticsAp0.CheckStatistics (1);
517  statisticsAp1.CheckStatistics (1);
518 
519  //Callbacks to print every change of power and rate
520  Config::Connect ("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
522  Config::Connect ("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
524 
525 
526  // Calculate Throughput using Flowmonitor
527  //
528 
529  FlowMonitorHelper flowmon;
530  Ptr<FlowMonitor> monitor = flowmon.InstallAll ();
531 
532  Simulator::Stop (Seconds (simuTime));
533  Simulator::Run ();
534 
535  Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
536  std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
537  for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
538  {
539  Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
540  if ((t.sourceAddress == "10.1.1.3" && t.destinationAddress == "10.1.1.1"))
541  {
542  NS_LOG_INFO ("Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n");
543  NS_LOG_INFO (" Tx Bytes: " << i->second.txBytes << "\n");
544  NS_LOG_INFO (" Rx Bytes: " << i->second.rxBytes << "\n");
545  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");
546  NS_LOG_INFO (" Mean delay: " << i->second.delaySum.GetSeconds () / i->second.rxPackets << "\n");
547  NS_LOG_INFO (" Mean jitter: " << i->second.jitterSum.GetSeconds () / (i->second.rxPackets - 1) << "\n");
548  NS_LOG_INFO (" Tx Opp: " << 1 - (statisticsAp0.GetBusyTime () / simuTime));
549  }
550  if ((t.sourceAddress == "10.1.1.4" && t.destinationAddress == "10.1.1.2"))
551  {
552  NS_LOG_INFO ("Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n");
553  NS_LOG_INFO (" Tx Bytes: " << i->second.txBytes << "\n");
554  NS_LOG_INFO (" Rx Bytes: " << i->second.rxBytes << "\n");
555  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");
556  NS_LOG_INFO (" Mean delay: " << i->second.delaySum.GetSeconds () / i->second.rxPackets << "\n");
557  NS_LOG_INFO (" Mean jitter: " << i->second.jitterSum.GetSeconds () / (i->second.rxPackets - 1) << "\n");
558  NS_LOG_INFO (" Tx Opp: " << 1 - (statisticsAp1.GetBusyTime () / simuTime));
559  }
560  }
561 
562  //Plots for AP0
563  std::ofstream outfileTh0 (("throughput-" + outputFileName + "-0.plt").c_str ());
564  Gnuplot gnuplot = Gnuplot (("throughput-" + outputFileName + "-0.eps").c_str (), "Throughput");
565  gnuplot.SetTerminal ("post eps color enhanced");
566  gnuplot.SetLegend ("Time (seconds)", "Throughput (Mb/s)");
567  gnuplot.SetTitle ("Throughput (AP0 to STA) vs time");
568  gnuplot.AddDataset (statisticsAp0.GetDatafile ());
569  gnuplot.GenerateOutput (outfileTh0);
570 
571  if (manager.compare ("ns3::ParfWifiManager") == 0 ||
572  manager.compare ("ns3::AparfWifiManager") == 0)
573  {
574  std::ofstream outfilePower0 (("power-" + outputFileName + "-0.plt").c_str ());
575  gnuplot = Gnuplot (("power-" + outputFileName + "-0.eps").c_str (), "Average Transmit Power");
576  gnuplot.SetTerminal ("post eps color enhanced");
577  gnuplot.SetLegend ("Time (seconds)", "Power (mW)");
578  gnuplot.SetTitle ("Average transmit power (AP0 to STA) vs time");
579  gnuplot.AddDataset (statisticsAp0.GetPowerDatafile ());
580  gnuplot.GenerateOutput (outfilePower0);
581  }
582 
583  std::ofstream outfileTx0 (("tx-" + outputFileName + "-0.plt").c_str ());
584  gnuplot = Gnuplot (("tx-" + outputFileName + "-0.eps").c_str (), "Time in TX State");
585  gnuplot.SetTerminal ("post eps color enhanced");
586  gnuplot.SetLegend ("Time (seconds)", "Percent");
587  gnuplot.SetTitle ("Percentage time AP0 in TX state vs time");
588  gnuplot.AddDataset (statisticsAp0.GetTxDatafile ());
589  gnuplot.GenerateOutput (outfileTx0);
590 
591  std::ofstream outfileRx0 (("rx-" + outputFileName + "-0.plt").c_str ());
592  gnuplot = Gnuplot (("rx-" + outputFileName + "-0.eps").c_str (), "Time in RX State");
593  gnuplot.SetTerminal ("post eps color enhanced");
594  gnuplot.SetLegend ("Time (seconds)", "Percent");
595  gnuplot.SetTitle ("Percentage time AP0 in RX state vs time");
596  gnuplot.AddDataset (statisticsAp0.GetRxDatafile ());
597  gnuplot.GenerateOutput (outfileRx0);
598 
599  std::ofstream outfileBusy0 (("busy-" + outputFileName + "-0.plt").c_str ());
600  gnuplot = Gnuplot (("busy-" + outputFileName + "-0.eps").c_str (), "Time in Busy State");
601  gnuplot.SetTerminal ("post eps color enhanced");
602  gnuplot.SetLegend ("Time (seconds)", "Percent");
603  gnuplot.SetTitle ("Percentage time AP0 in Busy state vs time");
604  gnuplot.AddDataset (statisticsAp0.GetBusyDatafile ());
605  gnuplot.GenerateOutput (outfileBusy0);
606 
607  std::ofstream outfileIdle0 (("idle-" + outputFileName + "-0.plt").c_str ());
608  gnuplot = Gnuplot (("idle-" + outputFileName + "-0.eps").c_str (), "Time in Idle State");
609  gnuplot.SetTerminal ("post eps color enhanced");
610  gnuplot.SetLegend ("Time (seconds)", "Percent");
611  gnuplot.SetTitle ("Percentage time AP0 in Idle state vs time");
612  gnuplot.AddDataset (statisticsAp0.GetIdleDatafile ());
613  gnuplot.GenerateOutput (outfileIdle0);
614 
615  //Plots for AP1
616  std::ofstream outfileTh1 (("throughput-" + outputFileName + "-1.plt").c_str ());
617  gnuplot = Gnuplot (("throughput-" + outputFileName + "-1.eps").c_str (), "Throughput");
618  gnuplot.SetTerminal ("post eps color enhanced");
619  gnuplot.SetLegend ("Time (seconds)", "Throughput (Mb/s)");
620  gnuplot.SetTitle ("Throughput (AP1 to STA) vs time");
621  gnuplot.AddDataset (statisticsAp1.GetDatafile ());
622  gnuplot.GenerateOutput (outfileTh1);
623 
624  if (manager.compare ("ns3::ParfWifiManager") == 0 ||
625  manager.compare ("ns3::AparfWifiManager") == 0)
626  {
627  std::ofstream outfilePower1 (("power-" + outputFileName + "-1.plt").c_str ());
628  gnuplot = Gnuplot (("power-" + outputFileName + "-1.eps").c_str (), "Average Transmit Power");
629  gnuplot.SetTerminal ("post eps color enhanced");
630  gnuplot.SetLegend ("Time (seconds)", "Power (mW)");
631  gnuplot.SetTitle ("Average transmit power (AP1 to STA) vs time");
632  gnuplot.AddDataset (statisticsAp1.GetPowerDatafile ());
633  gnuplot.GenerateOutput (outfilePower1);
634  }
635 
636  std::ofstream outfileTx1 (("tx-" + outputFileName + "-1.plt").c_str ());
637  gnuplot = Gnuplot (("tx-" + outputFileName + "-1.eps").c_str (), "Time in TX State");
638  gnuplot.SetTerminal ("post eps color enhanced");
639  gnuplot.SetLegend ("Time (seconds)", "Percent");
640  gnuplot.SetTitle ("Percentage time AP1 in TX state vs time");
641  gnuplot.AddDataset (statisticsAp1.GetTxDatafile ());
642  gnuplot.GenerateOutput (outfileTx1);
643 
644  std::ofstream outfileRx1 (("rx-" + outputFileName + "-1.plt").c_str ());
645  gnuplot = Gnuplot (("rx-" + outputFileName + "-1.eps").c_str (), "Time in RX State");
646  gnuplot.SetTerminal ("post eps color enhanced");
647  gnuplot.SetLegend ("Time (seconds)", "Percent");
648  gnuplot.SetTitle ("Percentage time AP1 in RX state vs time");
649  gnuplot.AddDataset (statisticsAp1.GetRxDatafile ());
650  gnuplot.GenerateOutput (outfileRx1);
651 
652  std::ofstream outfileBusy1 (("busy-" + outputFileName + "-1.plt").c_str ());
653  gnuplot = Gnuplot (("busy-" + outputFileName + "-1.eps").c_str (), "Time in Busy State");
654  gnuplot.SetTerminal ("post eps color enhanced");
655  gnuplot.SetLegend ("Time (seconds)", "Percent");
656  gnuplot.SetTitle ("Percentage time AP1 in Busy state vs time");
657  gnuplot.AddDataset (statisticsAp1.GetBusyDatafile ());
658  gnuplot.GenerateOutput (outfileBusy1);
659 
660  std::ofstream outfileIdle1 (("idle-" + outputFileName + "-1.plt").c_str ());
661  gnuplot = Gnuplot (("idle-" + outputFileName + "-1.eps").c_str (), "Time in Idle State");
662  gnuplot.SetTerminal ("post eps color enhanced");
663  gnuplot.SetLegend ("Time (seconds)", "Percent");
664  gnuplot.SetTitle ("Percentage time AP1 in Idle state vs time");
665  gnuplot.AddDataset (statisticsAp1.GetIdleDatafile ());
666  gnuplot.GenerateOutput (outfileIdle1);
667 
669 
670  return 0;
671 }
Ptr< PacketSink > sink
Definition: wifi-tcp.cc:47
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:112
holds a vector of ns3::Application pointers.
void SetupPhy(Ptr< WifiPhy > phy)
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
an Inet address class
const FlowStatsContainer & GetFlowStats() const
Retrieve all collected the flow statistics.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Class to represent a 2D points plot.
Definition: gnuplot.h:113
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())
Definition: wifi-helper.cc:683
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.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
The PHY layer has sense the medium busy through the CCA mechanism.
Definition: wifi-phy.h:177
Ipv4Address destinationAddress
Destination address.
#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
static void Run(void)
Run the simulation.
Definition: simulator.cc:201
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
enum WifiMacType GetType(void) const
Return the type (enum WifiMacType)
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).
Definition: packet.h:792
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:756
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.
Definition: log.h:244
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
STL namespace.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:231
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:99
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
tuple cmd
Definition: second.py:35
Gnuplot2dDataset GetPowerDatafile()
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:712
uint16_t port
Definition: dsdv-manet.cc:44
a polymophic address class
Definition: address.h:90
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.
Definition: data-rate.h:88
void SetChannel(Ptr< YansWifiChannel > channel)
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
Ptr< WifiPhy > GetPhy(void) const
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
tuple mobility
Definition: third.py:101
tuple phy
Definition: third.py:86
Gnuplot2dDataset GetRxDatafile()
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1238
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:367
AttributeValue implementation for Time.
Definition: nstime.h:957
void SetTitle(const std::string &title)
Definition: gnuplot.cc:730
FiveTuple FindFlow(FlowId flowId) const
Searches for the FiveTuple corresponding to the given flowId.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Hold an unsigned integer type.
Definition: uinteger.h:44
The PHY layer is IDLE.
Definition: wifi-phy.h:173
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:706
static const uint32_t packetSize
Time CalculateTxDuration(uint32_t size, WifiTxVector txVector, enum WifiPreamble preamble, double frequency)
Definition: wifi-phy.cc:1942
The PHY layer is receiving a packet.
Definition: wifi-phy.h:185
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:762
void StateCallback(std::string path, Time init, Time duration, enum WifiPhy::State state)
Time GetCalcTxTime(WifiMode mode)
virtual uint32_t GetFrequency(void) const
Definition: wifi-phy.cc:1143
The PHY layer is sending a packet.
Definition: wifi-phy.h:181
virtual uint32_t GetNModes(void) const
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
Definition: wifi-phy.cc:2850
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
void PowerCallback(std::string path, uint8_t power, Mac48Address dest)
Parse command-line arguments.
Definition: command-line.h:205
void RateCallback(std::string path, uint32_t rate, Mac48Address dest)
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:835
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:736
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:165
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:278
Ptr< FlowClassifier > GetClassifier()
Retrieve the FlowClassifier object for IPv4 created by the Install* methods.
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.
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())
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionaly.
an EUI-48 address
Definition: mac48-address.h:43
Helper to enable IP flow monitoring on a set of Nodes.
tuple ssid
Definition: third.py:93
manage and create wifi channel objects for the yans model.
create MAC layers for a ns3::WifiNetDevice.
Structure to classify a packet.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
Gnuplot2dDataset GetIdleDatafile()
tuple stack
Definition: first.py:34
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:38
void PowerCallback(std::string path, uint8_t power, Mac48Address dest)
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void PhyCallback(std::string path, Ptr< const Packet > packet)
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(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue())
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
Helper class used to assign positions and mobility models to nodes.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
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...
Gnuplot2dDataset GetBusyDatafile()
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:495
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:209
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.
Definition: nstime.h:895
AttributeValue implementation for Ssid.
Definition: ssid.h:95
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.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:911
tuple wifi
Definition: third.py:89
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
tuple address
Definition: first.py:37
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
State
The state of the PHY layer.
Definition: wifi-phy.h:168
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:724
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
Gnuplot2dDataset GetTxDatafile()
Ipv4Address sourceAddress
Source address.
Implements the IEEE 802.11 MAC header.
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
virtual WifiMode GetMode(uint32_t mode) const
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
Definition: wifi-phy.cc:2856
tuple wifiStaNodes
Definition: third.py:81