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 "ns3/core-module.h"
59 #include "ns3/internet-module.h"
60 #include "ns3/mobility-module.h"
61 #include "ns3/wifi-module.h"
62 #include "ns3/applications-module.h"
63 #include "ns3/stats-module.h"
64 #include "ns3/flow-monitor-module.h"
65 
66 using namespace ns3;
67 using namespace std;
68 
69 NS_LOG_COMPONENT_DEFINE ("PowerAdaptationInterference");
70 
71 //Packet size generated at the AP.
72 static const uint32_t packetSize = 1420;
73 
74 class NodeStatistics
75 {
76 public:
78 
79  void CheckStatistics (double time);
80 
81  void PhyCallback (std::string path, Ptr<const Packet> packet);
82  void RxCallback (std::string path, Ptr<const Packet> packet, const Address &from);
83  void PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest);
84  void RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest);
85  void StateCallback (std::string path, Time init, Time duration, enum WifiPhy::State state);
86 
87  Gnuplot2dDataset GetDatafile ();
88  Gnuplot2dDataset GetPowerDatafile ();
89  Gnuplot2dDataset GetIdleDatafile ();
90  Gnuplot2dDataset GetBusyDatafile ();
91  Gnuplot2dDataset GetTxDatafile ();
92  Gnuplot2dDataset GetRxDatafile ();
93 
94  double GetBusyTime ();
95 
96 private:
97  typedef std::vector<std::pair<Time, DataRate> > TxTime;
98  void SetupPhy (Ptr<WifiPhy> phy);
99  Time GetCalcTxTime (DataRate rate);
100 
101  std::map<Mac48Address, double> currentPower;
102  std::map<Mac48Address, DataRate> currentRate;
103  uint32_t m_bytesTotal;
104  double totalEnergy;
105  double totalTime;
106  double busyTime;
107  double idleTime;
108  double txTime;
109  double rxTime;
112  double totalTxTime;
113  double totalRxTime;
114  Ptr<WifiPhy> myPhy;
115  TxTime timeTable;
116  Gnuplot2dDataset m_output;
117  Gnuplot2dDataset m_output_power;
122 };
123 
125 {
126  Ptr<NetDevice> device = aps.Get (0);
127  Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device);
128  Ptr<WifiPhy> phy = wifiDevice->GetPhy ();
129  myPhy = phy;
130  SetupPhy (phy);
131  DataRate dataRate = DataRate (phy->GetMode (0).GetDataRate (phy->GetChannelWidth ()));
132  double power = phy->GetTxPowerEnd ();
133  for (uint32_t j = 0; j < stas.GetN (); j++)
134  {
135  Ptr<NetDevice> staDevice = stas.Get (j);
136  Ptr<WifiNetDevice> wifiStaDevice = DynamicCast<WifiNetDevice> (staDevice);
137  Mac48Address addr = wifiStaDevice->GetMac ()->GetAddress ();
138  currentPower[addr] = power;
139  currentRate[addr] = dataRate;
140  }
141  currentRate[Mac48Address ("ff:ff:ff:ff:ff:ff")] = dataRate;
142  totalEnergy = 0;
143  totalTime = 0;
144  busyTime = 0;
145  idleTime = 0;
146  txTime = 0;
147  rxTime = 0;
148  totalBusyTime = 0;
149  totalIdleTime = 0;
150  totalTxTime = 0;
151  totalRxTime = 0;
152  m_bytesTotal = 0;
153  m_output.SetTitle ("Throughput Mbits/s");
154  m_output_idle.SetTitle ("Idle Time");
155  m_output_busy.SetTitle ("Busy Time");
156  m_output_rx.SetTitle ("RX Time");
157  m_output_tx.SetTitle ("TX Time");
158 }
159 
160 void
162 {
163  uint32_t nModes = phy->GetNModes ();
164  for (uint32_t i = 0; i < nModes; i++)
165  {
166  WifiMode mode = phy->GetMode (i);
167  WifiTxVector txVector;
168  txVector.SetMode (mode);
170  txVector.SetChannelWidth (phy->GetChannelWidth ());
171  DataRate dataRate = DataRate (mode.GetDataRate (phy->GetChannelWidth ()));
172  Time time = phy->CalculateTxDuration (packetSize, txVector, phy->GetFrequency ());
173  NS_LOG_DEBUG (i << " " << time.GetSeconds () << " " << dataRate);
174  timeTable.push_back (std::make_pair (time, dataRate));
175  }
176 }
177 
178 Time
180 {
181  for (TxTime::const_iterator i = timeTable.begin (); i != timeTable.end (); i++)
182  {
183  if (rate == i->second)
184  {
185  return i->first;
186  }
187  }
188  NS_ASSERT (false);
189  return Seconds (0);
190 }
191 
192 void
193 NodeStatistics::PhyCallback (std::string path, Ptr<const Packet> packet)
194 {
195  WifiMacHeader head;
196  packet->PeekHeader (head);
197  Mac48Address dest = head.GetAddr1 ();
198 
199  if (head.GetType () == WIFI_MAC_DATA)
200  {
201  totalEnergy += pow (10.0, currentPower[dest] / 10.0) * GetCalcTxTime (currentRate[dest]).GetSeconds ();
202  totalTime += GetCalcTxTime (currentRate[dest]).GetSeconds ();
203  }
204 }
205 
206 void
207 NodeStatistics::PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest)
208 {
209  currentPower[dest] = newPower;
210 }
211 
212 void
213 NodeStatistics::RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
214 {
215  currentRate[dest] = newRate;
216 }
217 
218 void
219 NodeStatistics::StateCallback (std::string path, Time init, Time duration, enum WifiPhy::State state)
220 {
221  if (state == WifiPhy::CCA_BUSY)
222  {
223  busyTime += duration.GetSeconds ();
224  totalBusyTime += duration.GetSeconds ();
225  }
226  else if (state == WifiPhy::IDLE)
227  {
228  idleTime += duration.GetSeconds ();
229  totalIdleTime += duration.GetSeconds ();
230  }
231  else if (state == WifiPhy::TX)
232  {
233  txTime += duration.GetSeconds ();
234  totalTxTime += duration.GetSeconds ();
235  }
236  else if (state == WifiPhy::RX)
237  {
238  rxTime += duration.GetSeconds ();
239  totalRxTime += duration.GetSeconds ();
240  }
241 }
242 
243 void
244 NodeStatistics::RxCallback (std::string path, Ptr<const Packet> packet, const Address &from)
245 {
246  m_bytesTotal += packet->GetSize ();
247 }
248 
249 void
251 {
252  double mbs = ((m_bytesTotal * 8.0) / (1000000 * time));
253  m_bytesTotal = 0;
254  double atp = totalEnergy / time;
255  totalEnergy = 0;
256  totalTime = 0;
257  m_output_power.Add ((Simulator::Now ()).GetSeconds (), atp);
258  m_output.Add ((Simulator::Now ()).GetSeconds (), mbs);
259 
260  m_output_idle.Add ((Simulator::Now ()).GetSeconds (), idleTime * 100);
261  m_output_busy.Add ((Simulator::Now ()).GetSeconds (), busyTime * 100);
262  m_output_tx.Add ((Simulator::Now ()).GetSeconds (), txTime * 100);
263  m_output_rx.Add ((Simulator::Now ()).GetSeconds (), rxTime * 100);
264  busyTime = 0;
265  idleTime = 0;
266  txTime = 0;
267  rxTime = 0;
268 
270 }
271 
274 {
275  return m_output;
276 }
277 
280 {
281  return m_output_power;
282 }
283 
286 {
287  return m_output_idle;
288 }
289 
292 {
293  return m_output_busy;
294 }
295 
298 {
299  return m_output_rx;
300 }
301 
304 {
305  return m_output_tx;
306 }
307 
308 double
310 {
311  return totalBusyTime + totalRxTime;
312 }
313 
314 void PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest)
315 {
316  NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Old power=" << oldPower << " New power=" << newPower);
317 }
318 
319 void RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
320 {
321  NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Old rate=" << oldRate << " New rate=" << newRate);
322 }
323 
324 int main (int argc, char *argv[])
325 {
326  //LogComponentEnable("ConstantRateWifiManager", LOG_LEVEL_FUNCTION);
327 
328  double maxPower = 17;
329  double minPower = 0;
330  uint32_t powerLevels = 18;
331 
332  uint32_t rtsThreshold = 2346;
333  std::string manager = "ns3::ParfWifiManager";
334  std::string outputFileName = "parf";
335  int ap1_x = 0;
336  int ap1_y = 0;
337  int sta1_x = 10;
338  int sta1_y = 0;
339  int ap2_x = 200;
340  int ap2_y = 0;
341  int sta2_x = 180;
342  int sta2_y = 0;
343  uint32_t simuTime = 100;
344 
346  cmd.AddValue ("manager", "PRC Manager", manager);
347  cmd.AddValue ("rtsThreshold", "RTS threshold", rtsThreshold);
348  cmd.AddValue ("outputFileName", "Output filename", outputFileName);
349  cmd.AddValue ("simuTime", "Total simulation time (sec)", simuTime);
350  cmd.AddValue ("maxPower", "Maximum available transmission level (dbm).", maxPower);
351  cmd.AddValue ("minPower", "Minimum available transmission level (dbm).", minPower);
352  cmd.AddValue ("powerLevels", "Number of transmission power levels available between "
353  "TxPowerStart and TxPowerEnd included.", powerLevels);
354  cmd.AddValue ("AP1_x", "Position of AP1 in x coordinate", ap1_x);
355  cmd.AddValue ("AP1_y", "Position of AP1 in y coordinate", ap1_y);
356  cmd.AddValue ("STA1_x", "Position of STA1 in x coordinate", sta1_x);
357  cmd.AddValue ("STA1_y", "Position of STA1 in y coordinate", sta1_y);
358  cmd.AddValue ("AP2_x", "Position of AP2 in x coordinate", ap2_x);
359  cmd.AddValue ("AP2_y", "Position of AP2 in y coordinate", ap2_y);
360  cmd.AddValue ("STA2_x", "Position of STA2 in x coordinate", sta2_x);
361  cmd.AddValue ("STA2_y", "Position of STA2 in y coordinate", sta2_y);
362  cmd.Parse (argc, argv);
363 
364  //Define the APs
365  NodeContainer wifiApNodes;
366  wifiApNodes.Create (2);
367 
368  //Define the STAs
370  wifiStaNodes.Create (2);
371 
374  WifiMacHelper wifiMac;
377 
378  wifiPhy.SetChannel (wifiChannel.Create ());
379 
380  NetDeviceContainer wifiApDevices;
381  NetDeviceContainer wifiStaDevices;
382  NetDeviceContainer wifiDevices;
383 
384  //Configure the STA nodes
385  wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "RtsCtsThreshold", UintegerValue (rtsThreshold));
386  //wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",StringValue ("ErpOfdmRate6Mbps"),"ControlMode",StringValue ("ErpOfdmRate6Mbps"));
387  wifiPhy.Set ("TxPowerStart", DoubleValue (maxPower));
388  wifiPhy.Set ("TxPowerEnd", DoubleValue (maxPower));
389 
390  Ssid ssid = Ssid ("AP0");
391  wifiMac.SetType ("ns3::StaWifiMac",
392  "Ssid", SsidValue (ssid),
393  "MaxMissedBeacons", UintegerValue (1000));
394  wifiStaDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiStaNodes.Get (0)));
395 
396  ssid = Ssid ("AP1");
397  wifiMac.SetType ("ns3::StaWifiMac",
398  "Ssid", SsidValue (ssid));
399  wifiStaDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiStaNodes.Get (1)));
400 
401  //Configure the AP nodes
402  wifi.SetRemoteStationManager (manager, "DefaultTxPowerLevel", UintegerValue (maxPower), "RtsCtsThreshold", UintegerValue (rtsThreshold));
403  wifiPhy.Set ("TxPowerStart", DoubleValue (minPower));
404  wifiPhy.Set ("TxPowerEnd", DoubleValue (maxPower));
405  wifiPhy.Set ("TxPowerLevels", UintegerValue (powerLevels));
406 
407  ssid = Ssid ("AP0");
408  wifiMac.SetType ("ns3::ApWifiMac",
409  "Ssid", SsidValue (ssid));
410  wifiApDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiApNodes.Get (0)));
411 
412  ssid = Ssid ("AP1");
413  wifiMac.SetType ("ns3::ApWifiMac",
414  "Ssid", SsidValue (ssid),
415  "BeaconInterval", TimeValue (MicroSeconds (103424))); //for avoiding collisions);
416  wifiApDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiApNodes.Get (1)));
417 
418  wifiDevices.Add (wifiStaDevices);
419  wifiDevices.Add (wifiApDevices);
420 
421  //Configure the mobility.
423  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
424  positionAlloc->Add (Vector (ap1_x, ap1_y, 0.0));
425  positionAlloc->Add (Vector (sta1_x, sta1_y, 0.0));
426  positionAlloc->Add (Vector (ap2_x, ap2_y, 0.0));
427  positionAlloc->Add (Vector (sta2_x, sta2_y, 0.0));
428  mobility.SetPositionAllocator (positionAlloc);
429  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
430  mobility.Install (wifiApNodes.Get (0));
431  mobility.Install (wifiStaNodes.Get (0));
432  mobility.Install (wifiApNodes.Get (1));
433  mobility.Install (wifiStaNodes.Get (1));
434 
435 
436  //Configure the IP stack
438  stack.Install (wifiApNodes);
439  stack.Install (wifiStaNodes);
441  address.SetBase ("10.1.1.0", "255.255.255.0");
442  Ipv4InterfaceContainer i = address.Assign (wifiDevices);
443  Ipv4Address sinkAddress = i.GetAddress (0);
444  Ipv4Address sinkAddress1 = i.GetAddress (1);
445  uint16_t port = 9;
446 
447  //Configure the CBR generator
448  PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress, port));
449  ApplicationContainer apps_sink = sink.Install (wifiStaNodes.Get (0));
450 
451  OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress, port));
452  onoff.SetConstantRate (DataRate ("54Mb/s"), packetSize);
453  onoff.SetAttribute ("StartTime", TimeValue (Seconds (0.0)));
454  onoff.SetAttribute ("StopTime", TimeValue (Seconds (100.0)));
455  ApplicationContainer apps_source = onoff.Install (wifiApNodes.Get (0));
456 
457  PacketSinkHelper sink1 ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress1, port));
458  apps_sink.Add (sink1.Install (wifiStaNodes.Get (1)));
459 
460  OnOffHelper onoff1 ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress1, port));
461  onoff1.SetConstantRate (DataRate ("54Mb/s"), packetSize);
462  onoff1.SetAttribute ("StartTime", TimeValue (Seconds (0.0)));
463  onoff1.SetAttribute ("StopTime", TimeValue (Seconds (100.0)));
464  apps_source.Add (onoff1.Install (wifiApNodes.Get (1)));
465 
466  apps_sink.Start (Seconds (0.5));
467  apps_sink.Stop (Seconds (simuTime));
468 
469  //------------------------------------------------------------
470  //-- Setup stats and data collection
471  //--------------------------------------------
472 
473  //Statistics counters
474  NodeStatistics statisticsAp0 = NodeStatistics (wifiApDevices, wifiStaDevices);
475  NodeStatistics statisticsAp1 = NodeStatistics (wifiApDevices, wifiStaDevices);
476 
477  //Register packet receptions to calculate throughput
478  Config::Connect ("/NodeList/2/ApplicationList/*/$ns3::PacketSink/Rx",
479  MakeCallback (&NodeStatistics::RxCallback, &statisticsAp0));
480  Config::Connect ("/NodeList/3/ApplicationList/*/$ns3::PacketSink/Rx",
481  MakeCallback (&NodeStatistics::RxCallback, &statisticsAp1));
482 
483  //Register power and rate changes to calculate the Average Transmit Power
484  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
485  MakeCallback (&NodeStatistics::PowerCallback, &statisticsAp0));
486  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
487  MakeCallback (&NodeStatistics::RateCallback, &statisticsAp0));
488  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
489  MakeCallback (&NodeStatistics::PowerCallback, &statisticsAp1));
490  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
491  MakeCallback (&NodeStatistics::RateCallback, &statisticsAp1));
492 
493  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
494  MakeCallback (&NodeStatistics::PhyCallback, &statisticsAp0));
495  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
496  MakeCallback (&NodeStatistics::PhyCallback, &statisticsAp1));
497 
498  //Register States
499  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
500  MakeCallback (&NodeStatistics::StateCallback, &statisticsAp0));
501  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
502  MakeCallback (&NodeStatistics::StateCallback, &statisticsAp1));
503 
504  statisticsAp0.CheckStatistics (1);
505  statisticsAp1.CheckStatistics (1);
506 
507  //Callbacks to print every change of power and rate
508  Config::Connect ("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
510  Config::Connect ("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
512 
513 
514  //Calculate Throughput using Flowmonitor
515 
516  FlowMonitorHelper flowmon;
517  Ptr<FlowMonitor> monitor = flowmon.InstallAll ();
518 
519  Simulator::Stop (Seconds (simuTime));
520  Simulator::Run ();
521 
522  Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
523  std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
524  for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
525  {
526  Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
527  if ((t.sourceAddress == "10.1.1.3" && t.destinationAddress == "10.1.1.1"))
528  {
529  NS_LOG_INFO ("Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n");
530  NS_LOG_INFO (" Tx Bytes: " << i->second.txBytes << "\n");
531  NS_LOG_INFO (" Rx Bytes: " << i->second.rxBytes << "\n");
532  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");
533  NS_LOG_INFO (" Mean delay: " << i->second.delaySum.GetSeconds () / i->second.rxPackets << "\n");
534  NS_LOG_INFO (" Mean jitter: " << i->second.jitterSum.GetSeconds () / (i->second.rxPackets - 1) << "\n");
535  NS_LOG_INFO (" Tx Opp: " << 1 - (statisticsAp0.GetBusyTime () / simuTime));
536  }
537  if ((t.sourceAddress == "10.1.1.4" && t.destinationAddress == "10.1.1.2"))
538  {
539  NS_LOG_INFO ("Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n");
540  NS_LOG_INFO (" Tx Bytes: " << i->second.txBytes << "\n");
541  NS_LOG_INFO (" Rx Bytes: " << i->second.rxBytes << "\n");
542  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");
543  NS_LOG_INFO (" Mean delay: " << i->second.delaySum.GetSeconds () / i->second.rxPackets << "\n");
544  NS_LOG_INFO (" Mean jitter: " << i->second.jitterSum.GetSeconds () / (i->second.rxPackets - 1) << "\n");
545  NS_LOG_INFO (" Tx Opp: " << 1 - (statisticsAp1.GetBusyTime () / simuTime));
546  }
547  }
548 
549  //Plots for AP0
550  std::ofstream outfileTh0 (("throughput-" + outputFileName + "-0.plt").c_str ());
551  Gnuplot gnuplot = Gnuplot (("throughput-" + outputFileName + "-0.eps").c_str (), "Throughput");
552  gnuplot.SetTerminal ("post eps color enhanced");
553  gnuplot.SetLegend ("Time (seconds)", "Throughput (Mb/s)");
554  gnuplot.SetTitle ("Throughput (AP0 to STA) vs time");
555  gnuplot.AddDataset (statisticsAp0.GetDatafile ());
556  gnuplot.GenerateOutput (outfileTh0);
557 
558  if (manager.compare ("ns3::ParfWifiManager") == 0
559  || manager.compare ("ns3::AparfWifiManager") == 0
560  || manager.compare ("ns3::RrpaaWifiManager") == 0)
561  {
562  std::ofstream outfilePower0 (("power-" + outputFileName + "-0.plt").c_str ());
563  gnuplot = Gnuplot (("power-" + outputFileName + "-0.eps").c_str (), "Average Transmit Power");
564  gnuplot.SetTerminal ("post eps color enhanced");
565  gnuplot.SetLegend ("Time (seconds)", "Power (mW)");
566  gnuplot.SetTitle ("Average transmit power (AP0 to STA) vs time");
567  gnuplot.AddDataset (statisticsAp0.GetPowerDatafile ());
568  gnuplot.GenerateOutput (outfilePower0);
569  }
570 
571  std::ofstream outfileTx0 (("tx-" + outputFileName + "-0.plt").c_str ());
572  gnuplot = Gnuplot (("tx-" + outputFileName + "-0.eps").c_str (), "Time in TX State");
573  gnuplot.SetTerminal ("post eps color enhanced");
574  gnuplot.SetLegend ("Time (seconds)", "Percent");
575  gnuplot.SetTitle ("Percentage time AP0 in TX state vs time");
576  gnuplot.AddDataset (statisticsAp0.GetTxDatafile ());
577  gnuplot.GenerateOutput (outfileTx0);
578 
579  std::ofstream outfileRx0 (("rx-" + outputFileName + "-0.plt").c_str ());
580  gnuplot = Gnuplot (("rx-" + outputFileName + "-0.eps").c_str (), "Time in RX State");
581  gnuplot.SetTerminal ("post eps color enhanced");
582  gnuplot.SetLegend ("Time (seconds)", "Percent");
583  gnuplot.SetTitle ("Percentage time AP0 in RX state vs time");
584  gnuplot.AddDataset (statisticsAp0.GetRxDatafile ());
585  gnuplot.GenerateOutput (outfileRx0);
586 
587  std::ofstream outfileBusy0 (("busy-" + outputFileName + "-0.plt").c_str ());
588  gnuplot = Gnuplot (("busy-" + outputFileName + "-0.eps").c_str (), "Time in Busy State");
589  gnuplot.SetTerminal ("post eps color enhanced");
590  gnuplot.SetLegend ("Time (seconds)", "Percent");
591  gnuplot.SetTitle ("Percentage time AP0 in Busy state vs time");
592  gnuplot.AddDataset (statisticsAp0.GetBusyDatafile ());
593  gnuplot.GenerateOutput (outfileBusy0);
594 
595  std::ofstream outfileIdle0 (("idle-" + outputFileName + "-0.plt").c_str ());
596  gnuplot = Gnuplot (("idle-" + outputFileName + "-0.eps").c_str (), "Time in Idle State");
597  gnuplot.SetTerminal ("post eps color enhanced");
598  gnuplot.SetLegend ("Time (seconds)", "Percent");
599  gnuplot.SetTitle ("Percentage time AP0 in Idle state vs time");
600  gnuplot.AddDataset (statisticsAp0.GetIdleDatafile ());
601  gnuplot.GenerateOutput (outfileIdle0);
602 
603  //Plots for AP1
604  std::ofstream outfileTh1 (("throughput-" + outputFileName + "-1.plt").c_str ());
605  gnuplot = Gnuplot (("throughput-" + outputFileName + "-1.eps").c_str (), "Throughput");
606  gnuplot.SetTerminal ("post eps color enhanced");
607  gnuplot.SetLegend ("Time (seconds)", "Throughput (Mb/s)");
608  gnuplot.SetTitle ("Throughput (AP1 to STA) vs time");
609  gnuplot.AddDataset (statisticsAp1.GetDatafile ());
610  gnuplot.GenerateOutput (outfileTh1);
611 
612  if (manager.compare ("ns3::ParfWifiManager") == 0
613  || manager.compare ("ns3::AparfWifiManager") == 0
614  || manager.compare ("ns3::RrpaaWifiManager") == 0)
615  {
616  std::ofstream outfilePower1 (("power-" + outputFileName + "-1.plt").c_str ());
617  gnuplot = Gnuplot (("power-" + outputFileName + "-1.eps").c_str (), "Average Transmit Power");
618  gnuplot.SetTerminal ("post eps color enhanced");
619  gnuplot.SetLegend ("Time (seconds)", "Power (mW)");
620  gnuplot.SetTitle ("Average transmit power (AP1 to STA) vs time");
621  gnuplot.AddDataset (statisticsAp1.GetPowerDatafile ());
622  gnuplot.GenerateOutput (outfilePower1);
623  }
624 
625  std::ofstream outfileTx1 (("tx-" + outputFileName + "-1.plt").c_str ());
626  gnuplot = Gnuplot (("tx-" + outputFileName + "-1.eps").c_str (), "Time in TX State");
627  gnuplot.SetTerminal ("post eps color enhanced");
628  gnuplot.SetLegend ("Time (seconds)", "Percent");
629  gnuplot.SetTitle ("Percentage time AP1 in TX state vs time");
630  gnuplot.AddDataset (statisticsAp1.GetTxDatafile ());
631  gnuplot.GenerateOutput (outfileTx1);
632 
633  std::ofstream outfileRx1 (("rx-" + outputFileName + "-1.plt").c_str ());
634  gnuplot = Gnuplot (("rx-" + outputFileName + "-1.eps").c_str (), "Time in RX State");
635  gnuplot.SetTerminal ("post eps color enhanced");
636  gnuplot.SetLegend ("Time (seconds)", "Percent");
637  gnuplot.SetTitle ("Percentage time AP1 in RX state vs time");
638  gnuplot.AddDataset (statisticsAp1.GetRxDatafile ());
639  gnuplot.GenerateOutput (outfileRx1);
640 
641  std::ofstream outfileBusy1 (("busy-" + outputFileName + "-1.plt").c_str ());
642  gnuplot = Gnuplot (("busy-" + outputFileName + "-1.eps").c_str (), "Time in Busy State");
643  gnuplot.SetTerminal ("post eps color enhanced");
644  gnuplot.SetLegend ("Time (seconds)", "Percent");
645  gnuplot.SetTitle ("Percentage time AP1 in Busy state vs time");
646  gnuplot.AddDataset (statisticsAp1.GetBusyDatafile ());
647  gnuplot.GenerateOutput (outfileBusy1);
648 
649  std::ofstream outfileIdle1 (("idle-" + outputFileName + "-1.plt").c_str ());
650  gnuplot = Gnuplot (("idle-" + outputFileName + "-1.eps").c_str (), "Time in Idle State");
651  gnuplot.SetTerminal ("post eps color enhanced");
652  gnuplot.SetLegend ("Time (seconds)", "Percent");
653  gnuplot.SetTitle ("Percentage time AP1 in Idle state vs time");
654  gnuplot.AddDataset (statisticsAp1.GetIdleDatafile ());
655  gnuplot.GenerateOutput (outfileIdle1);
656 
658 
659  return 0;
660 }
Ptr< PacketSink > sink
Definition: wifi-tcp.cc:45
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:132
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:117
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:719
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:180
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:226
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
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:796
void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:756
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:277
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:213
uint16_t GetFrequency(void) const
Definition: wifi-phy.cc:1270
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
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()
void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
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
Time CalculateTxDuration(uint32_t size, WifiTxVector txVector, uint16_t frequency)
Definition: wifi-phy.cc:2262
void SetChannel(Ptr< YansWifiChannel > channel)
Time GetCalcTxTime(DataRate rate)
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.
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
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:1375
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:371
AttributeValue implementation for Time.
Definition: nstime.h:1055
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:176
uint64_t GetDataRate(uint8_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:143
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:742
static const uint32_t packetSize
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
Definition: wifi-helper.cc:748
The PHY layer is receiving a packet.
Definition: wifi-phy.h:188
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)
The PHY layer is sending a packet.
Definition: wifi-phy.h:184
uint32_t GetNModes(void) const
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
Definition: wifi-phy.cc:3541
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...
Parse command-line arguments.
Definition: command-line.h:205
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:843
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:190
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:277
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 SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
std::vector< std::pair< Time, DataRate > > TxTime
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.
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
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:249
Gnuplot2dDataset GetIdleDatafile()
tuple stack
Definition: first.py:34
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
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())
uint8_t GetChannelWidth(void) const
Definition: wifi-phy.cc:1304
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:498
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:234
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
WifiMacType GetType(void) const
Return the type (enum WifiMacType)
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
AttributeValue implementation for Ssid.
Definition: ssid.h:117
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 SetChannelWidth(uint8_t channelWidth)
Sets the selected channelWidth (in MHz)
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:1009
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:171
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
WifiMode GetMode(uint32_t mode) const
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
Definition: wifi-phy.cc:3547
tuple wifiStaNodes
Definition: third.py:81