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, uint32_t> 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 (), 0, 0), 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  totalEnergy += actualPower[dest] * GetCalcTxTime (actualMode[dest]).GetSeconds ();
197  totalTime += GetCalcTxTime (actualMode[dest]).GetSeconds ();
198 
199 }
200 
201 void
202 NodeStatistics::PowerCallback (std::string path, uint8_t power, Mac48Address dest)
203 {
204  double txPowerBaseDbm = myPhy->GetTxPowerStart ();
205  double txPowerEndDbm = myPhy->GetTxPowerEnd ();
206  uint32_t nTxPower = myPhy->GetNTxPower ();
207  double dbm;
208  if (nTxPower > 1)
209  {
210  dbm = txPowerBaseDbm + power * (txPowerEndDbm - txPowerBaseDbm) / (nTxPower - 1);
211  }
212  else
213  {
214  NS_ASSERT_MSG (txPowerBaseDbm == txPowerEndDbm, "cannot have TxPowerEnd != TxPowerStart with TxPowerLevels == 1");
215  dbm = txPowerBaseDbm;
216  }
217  actualPower[dest] = dbm;
218 }
219 
220 void
221 NodeStatistics::RateCallback (std::string path, uint32_t rate, Mac48Address dest)
222 {
223  actualMode[dest] = myPhy->GetMode (rate);
224 }
225 
226 void
227 NodeStatistics::StateCallback (std::string path, Time init, Time duration, enum WifiPhy::State state)
228 {
229  if (state == WifiPhy::CCA_BUSY)
230  {
231  busyTime += duration.GetSeconds ();
232  totalBusyTime += duration.GetSeconds ();
233  }
234  else if (state == WifiPhy::IDLE)
235  {
236  idleTime += duration.GetSeconds ();
237  totalIdleTime += duration.GetSeconds ();
238  }
239  else if (state == WifiPhy::TX)
240  {
241  txTime += duration.GetSeconds ();
242  totalTxTime += duration.GetSeconds ();
243  }
244  else if (state == WifiPhy::RX)
245  {
246  rxTime += duration.GetSeconds ();
247  totalRxTime += duration.GetSeconds ();
248  }
249 }
250 
251 void
252 NodeStatistics::RxCallback (std::string path, Ptr<const Packet> packet, const Address &from)
253 {
254  m_bytesTotal += packet->GetSize ();
255 }
256 
257 void
259 {
260  double mbs = ((m_bytesTotal * 8.0) / (1000000 * time));
261  m_bytesTotal = 0;
262  double atm = pow (10, ((totalEnergy / time) / 10));
263  totalEnergy = 0;
264  totalTime = 0;
265  m_output_power.Add ((Simulator::Now ()).GetSeconds (), atm);
266  m_output.Add ((Simulator::Now ()).GetSeconds (), mbs);
267 
268  m_output_idle.Add ((Simulator::Now ()).GetSeconds (), idleTime * 100);
269  m_output_busy.Add ((Simulator::Now ()).GetSeconds (), busyTime * 100);
270  m_output_tx.Add ((Simulator::Now ()).GetSeconds (), txTime * 100);
271  m_output_rx.Add ((Simulator::Now ()).GetSeconds (), rxTime * 100);
272  busyTime = 0;
273  idleTime = 0;
274  txTime = 0;
275  rxTime = 0;
276 
278 }
279 
282 {
283  return m_output;
284 }
285 
288 {
289  return m_output_power;
290 }
291 
294 {
295  return m_output_idle;
296 }
297 
300 {
301  return m_output_busy;
302 }
303 
306 {
307  return m_output_rx;
308 }
309 
312 {
313  return m_output_tx;
314 }
315 
316 double
318 {
319  return totalBusyTime + totalRxTime;
320 }
321 
322 void PowerCallback (std::string path, uint8_t power, Mac48Address dest)
323 {
324  NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Power " << (int)power);
325  // end PowerCallback
326 }
327 
328 void RateCallback (std::string path, uint32_t rate, Mac48Address dest)
329 {
330  NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Rate " << rate);
331  // end PowerCallback
332 }
333 
334 int main (int argc, char *argv[])
335 {
336  //LogComponentEnable("ConstantRateWifiManager", LOG_LEVEL_FUNCTION);
337 
338  double maxPower = 17;
339  double minPower = 0;
340  uint32_t powerLevels = 18;
341 
342  uint32_t rtsThreshold = 2346;
343  std::string manager = "ns3::ParfWifiManager";
344  std::string outputFileName = "parf";
345  int ap1_x = 0;
346  int ap1_y = 0;
347  int sta1_x = 10;
348  int sta1_y = 0;
349  int ap2_x = 200;
350  int ap2_y = 0;
351  int sta2_x = 180;
352  int sta2_y = 0;
353  uint32_t simuTime = 100;
354 
355  CommandLine cmd;
356  cmd.AddValue ("manager", "PRC Manager", manager);
357  cmd.AddValue ("rtsThreshold", "RTS threshold", rtsThreshold);
358  cmd.AddValue ("outputFileName", "Output filename", outputFileName);
359  cmd.AddValue ("simuTime", "Total simulation time (sec)", simuTime);
360  cmd.AddValue ("maxPower", "Maximum available transmission level (dbm).", maxPower);
361  cmd.AddValue ("minPower", "Minimum available transmission level (dbm).", minPower);
362  cmd.AddValue ("powerLevels", "Number of transmission power levels available between "
363  "TxPowerStart and TxPowerEnd included.", powerLevels);
364  cmd.AddValue ("AP1_x", "Position of AP1 in x coordinate", ap1_x);
365  cmd.AddValue ("AP1_y", "Position of AP1 in y coordinate", ap1_y);
366  cmd.AddValue ("STA1_x", "Position of STA1 in x coordinate", sta1_x);
367  cmd.AddValue ("STA1_y", "Position of STA1 in y coordinate", sta1_y);
368  cmd.AddValue ("AP2_x", "Position of AP2 in x coordinate", ap2_x);
369  cmd.AddValue ("AP2_y", "Position of AP2 in y coordinate", ap2_y);
370  cmd.AddValue ("STA2_x", "Position of STA2 in x coordinate", sta2_x);
371  cmd.AddValue ("STA2_y", "Position of STA2 in y coordinate", sta2_y);
372  cmd.Parse (argc, argv);
373 
374  // Define the APs
375  NodeContainer wifiApNodes;
376  wifiApNodes.Create (2);
377 
378  //Define the STAs
379  NodeContainer wifiStaNodes;
380  wifiStaNodes.Create (2);
381 
387 
388  wifiPhy.SetChannel (wifiChannel.Create ());
389 
390  NetDeviceContainer wifiApDevices;
391  NetDeviceContainer wifiStaDevices;
392  NetDeviceContainer wifiDevices;
393 
394  //Configure the STA nodes
395  wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "RtsCtsThreshold", UintegerValue (rtsThreshold));
396  //wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",StringValue ("ErpOfdmRate6Mbps"),"ControlMode",StringValue ("ErpOfdmRate6Mbps"));
397  wifiPhy.Set ("TxPowerStart", DoubleValue (maxPower));
398  wifiPhy.Set ("TxPowerEnd", DoubleValue (maxPower));
399 
400  Ssid ssid = Ssid ("AP0");
401  wifiMac.SetType ("ns3::StaWifiMac",
402  "Ssid", SsidValue (ssid),
403  "ActiveProbing", BooleanValue (false),
404  "MaxMissedBeacons", UintegerValue (1000));
405  wifiStaDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiStaNodes.Get (0)));
406 
407  ssid = Ssid ("AP1");
408  wifiMac.SetType ("ns3::StaWifiMac",
409  "Ssid", SsidValue (ssid),
410  "ActiveProbing", BooleanValue (false));
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.
434  MobilityHelper 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 }
holds a vector of ns3::Application pointers.
virtual uint32_t GetFrequency(void) const =0
void SetupPhy(Ptr< WifiPhy > phy)
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
an Inet address class
const FlowStatsContainer & GetFlowStats() const
Retrieve all collected the flow statistics.
AttributeValue implementation for Boolean.
Definition: boolean.h:34
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:73
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. ...
virtual uint32_t GetNModes(void) const =0
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
The PHY layer has sense the medium busy through the CCA mechanism.
Definition: wifi-phy.h:141
Ipv4Address destinationAddress
Destination address.
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())
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
static void Run(void)
Run the simulation.
Definition: simulator.cc:200
#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:766
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...
void Set(std::string name, const AttributeValue &v)
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:819
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:738
STL namespace.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:92
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:93
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
Gnuplot2dDataset GetPowerDatafile()
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:102
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:87
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:327
Ptr< WifiPhy > GetPhy(void) const
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
Gnuplot2dDataset GetRxDatafile()
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:921
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:137
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:96
static const uint32_t packetSize
The PHY layer is receiving a packet.
Definition: wifi-phy.h:149
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1290
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)
static NqosWifiMacHelper Default(void)
Create a mac helper in a default working state.
The PHY layer is sending a packet.
Definition: wifi-phy.h:145
Time CalculateTxDuration(uint32_t size, WifiTxVector txvector, enum WifiPreamble preamble, double frequency, uint8_t packetType, uint8_t incFlag)
Definition: wifi-phy.cc:576
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...
create non QoS-enabled MAC layers for a ns3::WifiNetDevice.
void PowerCallback(std::string path, uint8_t power, Mac48Address dest)
Parse command-line arguments.
Definition: command-line.h:201
void RateCallback(std::string path, uint32_t rate, Mac48Address dest)
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:164
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 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.
virtual WifiMode GetMode(uint32_t mode) const =0
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
manage and create wifi channel objects for the yans model.
Structure to classify a packet.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:223
Gnuplot2dDataset GetIdleDatafile()
tuple stack
Definition: first.py:34
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:37
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)
#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:84
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:491
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:208
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:859
AttributeValue implementation for Ssid.
Definition: ssid.h:93
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:875
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:132
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
static WifiHelper Default(void)
Definition: wifi-helper.cc:65