A Discrete-Event Network Simulator
API
wifi-power-adaptation-interference.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Universidad de la Rep├║blica - Uruguay
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Matias Richart <mrichart@fing.edu.uy>
19  */
20 
58 #include "ns3/gnuplot.h"
59 #include "ns3/command-line.h"
60 #include "ns3/config.h"
61 #include "ns3/uinteger.h"
62 #include "ns3/double.h"
63 #include "ns3/log.h"
64 #include "ns3/yans-wifi-helper.h"
65 #include "ns3/ssid.h"
66 #include "ns3/mobility-helper.h"
67 #include "ns3/internet-stack-helper.h"
68 #include "ns3/ipv4-address-helper.h"
69 #include "ns3/packet-sink-helper.h"
70 #include "ns3/on-off-helper.h"
71 #include "ns3/yans-wifi-channel.h"
72 #include "ns3/wifi-net-device.h"
73 #include "ns3/wifi-mac.h"
74 #include "ns3/wifi-mac-header.h"
75 #include "ns3/flow-monitor-helper.h"
76 #include "ns3/ipv4-flow-classifier.h"
77 
78 using namespace ns3;
79 using namespace std;
80 
81 NS_LOG_COMPONENT_DEFINE ("PowerAdaptationInterference");
82 
83 //Packet size generated at the AP.
84 static const uint32_t packetSize = 1420;
85 
86 class NodeStatistics
87 {
88 public:
90 
91  void CheckStatistics (double time);
92 
93  void PhyCallback (std::string path, Ptr<const Packet> packet, double powerW);
94  void RxCallback (std::string path, Ptr<const Packet> packet, const Address &from);
95  void PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest);
96  void RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest);
97  void StateCallback (std::string path, Time init, Time duration, WifiPhyState state);
98 
99  Gnuplot2dDataset GetDatafile ();
100  Gnuplot2dDataset GetPowerDatafile ();
101  Gnuplot2dDataset GetIdleDatafile ();
102  Gnuplot2dDataset GetBusyDatafile ();
103  Gnuplot2dDataset GetTxDatafile ();
104  Gnuplot2dDataset GetRxDatafile ();
105 
106  double GetBusyTime ();
107 
108 private:
109  typedef std::vector<std::pair<Time, DataRate> > TxTime;
110  void SetupPhy (Ptr<WifiPhy> phy);
111  Time GetCalcTxTime (DataRate rate);
112 
113  std::map<Mac48Address, double> currentPower;
114  std::map<Mac48Address, DataRate> currentRate;
115  uint32_t m_bytesTotal;
116  double totalEnergy;
117  double totalTime;
118  double busyTime;
119  double idleTime;
120  double txTime;
121  double rxTime;
124  double totalTxTime;
125  double totalRxTime;
126  Ptr<WifiPhy> myPhy;
127  TxTime timeTable;
128  Gnuplot2dDataset m_output;
129  Gnuplot2dDataset m_output_power;
134 };
135 
137 {
138  Ptr<NetDevice> device = aps.Get (0);
139  Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device);
140  Ptr<WifiPhy> phy = wifiDevice->GetPhy ();
141  myPhy = phy;
142  SetupPhy (phy);
143  DataRate dataRate = DataRate (phy->GetMode (0).GetDataRate (phy->GetChannelWidth ()));
144  double power = phy->GetTxPowerEnd ();
145  for (uint32_t j = 0; j < stas.GetN (); j++)
146  {
147  Ptr<NetDevice> staDevice = stas.Get (j);
148  Ptr<WifiNetDevice> wifiStaDevice = DynamicCast<WifiNetDevice> (staDevice);
149  Mac48Address addr = wifiStaDevice->GetMac ()->GetAddress ();
150  currentPower[addr] = power;
151  currentRate[addr] = dataRate;
152  }
153  currentRate[Mac48Address ("ff:ff:ff:ff:ff:ff")] = dataRate;
154  totalEnergy = 0;
155  totalTime = 0;
156  busyTime = 0;
157  idleTime = 0;
158  txTime = 0;
159  rxTime = 0;
160  totalBusyTime = 0;
161  totalIdleTime = 0;
162  totalTxTime = 0;
163  totalRxTime = 0;
164  m_bytesTotal = 0;
165  m_output.SetTitle ("Throughput Mbits/s");
166  m_output_idle.SetTitle ("Idle Time");
167  m_output_busy.SetTitle ("Busy Time");
168  m_output_rx.SetTitle ("RX Time");
169  m_output_tx.SetTitle ("TX Time");
170 }
171 
172 void
174 {
175  uint32_t nModes = phy->GetNModes ();
176  for (uint32_t i = 0; i < nModes; i++)
177  {
178  WifiMode mode = phy->GetMode (i);
179  WifiTxVector txVector;
180  txVector.SetMode (mode);
182  txVector.SetChannelWidth (phy->GetChannelWidth ());
183  DataRate dataRate = DataRate (mode.GetDataRate (phy->GetChannelWidth ()));
184  Time time = phy->CalculateTxDuration (packetSize, txVector, phy->GetFrequency ());
185  NS_LOG_DEBUG (i << " " << time.GetSeconds () << " " << dataRate);
186  timeTable.push_back (std::make_pair (time, dataRate));
187  }
188 }
189 
190 Time
192 {
193  for (TxTime::const_iterator i = timeTable.begin (); i != timeTable.end (); i++)
194  {
195  if (rate == i->second)
196  {
197  return i->first;
198  }
199  }
200  NS_ASSERT (false);
201  return Seconds (0);
202 }
203 
204 void
205 NodeStatistics::PhyCallback (std::string path, Ptr<const Packet> packet, double powerW)
206 {
207  WifiMacHeader head;
208  packet->PeekHeader (head);
209  Mac48Address dest = head.GetAddr1 ();
210 
211  if (head.GetType () == WIFI_MAC_DATA)
212  {
213  totalEnergy += pow (10.0, currentPower[dest] / 10.0) * GetCalcTxTime (currentRate[dest]).GetSeconds ();
214  totalTime += GetCalcTxTime (currentRate[dest]).GetSeconds ();
215  }
216 }
217 
218 void
219 NodeStatistics::PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest)
220 {
221  currentPower[dest] = newPower;
222 }
223 
224 void
225 NodeStatistics::RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
226 {
227  currentRate[dest] = newRate;
228 }
229 
230 void
231 NodeStatistics::StateCallback (std::string path, Time init, Time duration, WifiPhyState state)
232 {
233  if (state == WifiPhyState::CCA_BUSY)
234  {
235  busyTime += duration.GetSeconds ();
236  totalBusyTime += duration.GetSeconds ();
237  }
238  else if (state == WifiPhyState::IDLE)
239  {
240  idleTime += duration.GetSeconds ();
241  totalIdleTime += duration.GetSeconds ();
242  }
243  else if (state == WifiPhyState::TX)
244  {
245  txTime += duration.GetSeconds ();
246  totalTxTime += duration.GetSeconds ();
247  }
248  else if (state == WifiPhyState::RX)
249  {
250  rxTime += duration.GetSeconds ();
251  totalRxTime += duration.GetSeconds ();
252  }
253 }
254 
255 void
256 NodeStatistics::RxCallback (std::string path, Ptr<const Packet> packet, const Address &from)
257 {
258  m_bytesTotal += packet->GetSize ();
259 }
260 
261 void
263 {
264  double mbs = ((m_bytesTotal * 8.0) / (1000000 * time));
265  m_bytesTotal = 0;
266  double atp = totalEnergy / time;
267  totalEnergy = 0;
268  totalTime = 0;
269  m_output_power.Add ((Simulator::Now ()).GetSeconds (), atp);
270  m_output.Add ((Simulator::Now ()).GetSeconds (), mbs);
271 
272  m_output_idle.Add ((Simulator::Now ()).GetSeconds (), idleTime * 100);
273  m_output_busy.Add ((Simulator::Now ()).GetSeconds (), busyTime * 100);
274  m_output_tx.Add ((Simulator::Now ()).GetSeconds (), txTime * 100);
275  m_output_rx.Add ((Simulator::Now ()).GetSeconds (), rxTime * 100);
276  busyTime = 0;
277  idleTime = 0;
278  txTime = 0;
279  rxTime = 0;
280 
282 }
283 
286 {
287  return m_output;
288 }
289 
292 {
293  return m_output_power;
294 }
295 
298 {
299  return m_output_idle;
300 }
301 
304 {
305  return m_output_busy;
306 }
307 
310 {
311  return m_output_rx;
312 }
313 
316 {
317  return m_output_tx;
318 }
319 
320 double
322 {
323  return totalBusyTime + totalRxTime;
324 }
325 
326 void PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest)
327 {
328  NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Old power=" << oldPower << " New power=" << newPower);
329 }
330 
331 void RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
332 {
333  NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Old rate=" << oldRate << " New rate=" << newRate);
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 
385  wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
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  wifiPhy.Set ("TxPowerStart", DoubleValue (maxPower));
399  wifiPhy.Set ("TxPowerEnd", DoubleValue (maxPower));
400 
401  Ssid ssid = Ssid ("AP0");
402  wifiMac.SetType ("ns3::StaWifiMac",
403  "Ssid", SsidValue (ssid),
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  wifiStaDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiStaNodes.Get (1)));
411 
412  //Configure the AP nodes
413  wifi.SetRemoteStationManager (manager, "DefaultTxPowerLevel", UintegerValue (powerLevels - 1), "RtsCtsThreshold", UintegerValue (rtsThreshold));
414  wifiPhy.Set ("TxPowerStart", DoubleValue (minPower));
415  wifiPhy.Set ("TxPowerEnd", DoubleValue (maxPower));
416  wifiPhy.Set ("TxPowerLevels", UintegerValue (powerLevels));
417 
418  ssid = Ssid ("AP0");
419  wifiMac.SetType ("ns3::ApWifiMac",
420  "Ssid", SsidValue (ssid));
421  wifiApDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiApNodes.Get (0)));
422 
423  ssid = Ssid ("AP1");
424  wifiMac.SetType ("ns3::ApWifiMac",
425  "Ssid", SsidValue (ssid),
426  "BeaconInterval", TimeValue (MicroSeconds (103424))); //for avoiding collisions);
427  wifiApDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiApNodes.Get (1)));
428 
429  wifiDevices.Add (wifiStaDevices);
430  wifiDevices.Add (wifiApDevices);
431 
432  //Configure the mobility.
434  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
435  positionAlloc->Add (Vector (ap1_x, ap1_y, 0.0));
436  positionAlloc->Add (Vector (sta1_x, sta1_y, 0.0));
437  positionAlloc->Add (Vector (ap2_x, ap2_y, 0.0));
438  positionAlloc->Add (Vector (sta2_x, sta2_y, 0.0));
439  mobility.SetPositionAllocator (positionAlloc);
440  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
441  mobility.Install (wifiApNodes.Get (0));
442  mobility.Install (wifiStaNodes.Get (0));
443  mobility.Install (wifiApNodes.Get (1));
444  mobility.Install (wifiStaNodes.Get (1));
445 
446 
447  //Configure the IP stack
449  stack.Install (wifiApNodes);
450  stack.Install (wifiStaNodes);
452  address.SetBase ("10.1.1.0", "255.255.255.0");
453  Ipv4InterfaceContainer i = address.Assign (wifiDevices);
454  Ipv4Address sinkAddress = i.GetAddress (0);
455  Ipv4Address sinkAddress1 = i.GetAddress (1);
456  uint16_t port = 9;
457 
458  //Configure the CBR generator
459  PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress, port));
460  ApplicationContainer apps_sink = sink.Install (wifiStaNodes.Get (0));
461 
462  OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress, port));
463  onoff.SetConstantRate (DataRate ("54Mb/s"), packetSize);
464  onoff.SetAttribute ("StartTime", TimeValue (Seconds (0.0)));
465  onoff.SetAttribute ("StopTime", TimeValue (Seconds (100.0)));
466  ApplicationContainer apps_source = onoff.Install (wifiApNodes.Get (0));
467 
468  PacketSinkHelper sink1 ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress1, port));
469  apps_sink.Add (sink1.Install (wifiStaNodes.Get (1)));
470 
471  OnOffHelper onoff1 ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress1, port));
472  onoff1.SetConstantRate (DataRate ("54Mb/s"), packetSize);
473  onoff1.SetAttribute ("StartTime", TimeValue (Seconds (0.0)));
474  onoff1.SetAttribute ("StopTime", TimeValue (Seconds (100.0)));
475  apps_source.Add (onoff1.Install (wifiApNodes.Get (1)));
476 
477  apps_sink.Start (Seconds (0.5));
478  apps_sink.Stop (Seconds (simuTime));
479 
480  //------------------------------------------------------------
481  //-- Setup stats and data collection
482  //--------------------------------------------
483 
484  //Statistics counters
485  NodeStatistics statisticsAp0 = NodeStatistics (wifiApDevices, wifiStaDevices);
486  NodeStatistics statisticsAp1 = NodeStatistics (wifiApDevices, wifiStaDevices);
487 
488  //Register packet receptions to calculate throughput
489  Config::Connect ("/NodeList/2/ApplicationList/*/$ns3::PacketSink/Rx",
490  MakeCallback (&NodeStatistics::RxCallback, &statisticsAp0));
491  Config::Connect ("/NodeList/3/ApplicationList/*/$ns3::PacketSink/Rx",
492  MakeCallback (&NodeStatistics::RxCallback, &statisticsAp1));
493 
494  //Register power and rate changes to calculate the Average Transmit Power
495  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
496  MakeCallback (&NodeStatistics::PowerCallback, &statisticsAp0));
497  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
498  MakeCallback (&NodeStatistics::RateCallback, &statisticsAp0));
499  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
500  MakeCallback (&NodeStatistics::PowerCallback, &statisticsAp1));
501  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
502  MakeCallback (&NodeStatistics::RateCallback, &statisticsAp1));
503 
504  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
505  MakeCallback (&NodeStatistics::PhyCallback, &statisticsAp0));
506  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
507  MakeCallback (&NodeStatistics::PhyCallback, &statisticsAp1));
508 
509  //Register States
510  Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
511  MakeCallback (&NodeStatistics::StateCallback, &statisticsAp0));
512  Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
513  MakeCallback (&NodeStatistics::StateCallback, &statisticsAp1));
514 
515  statisticsAp0.CheckStatistics (1);
516  statisticsAp1.CheckStatistics (1);
517 
518  //Callbacks to print every change of power and rate
519  Config::Connect ("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
521  Config::Connect ("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
523 
524 
525  //Calculate Throughput using Flowmonitor
526 
527  FlowMonitorHelper flowmon;
528  Ptr<FlowMonitor> monitor = flowmon.InstallAll ();
529 
530  Simulator::Stop (Seconds (simuTime));
531  Simulator::Run ();
532 
533  Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
534  std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
535  for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
536  {
537  Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
538  if ((t.sourceAddress == "10.1.1.3" && t.destinationAddress == "10.1.1.1"))
539  {
540  NS_LOG_INFO ("Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n");
541  NS_LOG_INFO (" Tx Bytes: " << i->second.txBytes << "\n");
542  NS_LOG_INFO (" Rx Bytes: " << i->second.rxBytes << "\n");
543  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");
544  NS_LOG_INFO (" Mean delay: " << i->second.delaySum.GetSeconds () / i->second.rxPackets << "\n");
545  NS_LOG_INFO (" Mean jitter: " << i->second.jitterSum.GetSeconds () / (i->second.rxPackets - 1) << "\n");
546  NS_LOG_INFO (" Tx Opp: " << 1 - (statisticsAp0.GetBusyTime () / simuTime));
547  }
548  if ((t.sourceAddress == "10.1.1.4" && t.destinationAddress == "10.1.1.2"))
549  {
550  NS_LOG_INFO ("Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n");
551  NS_LOG_INFO (" Tx Bytes: " << i->second.txBytes << "\n");
552  NS_LOG_INFO (" Rx Bytes: " << i->second.rxBytes << "\n");
553  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");
554  NS_LOG_INFO (" Mean delay: " << i->second.delaySum.GetSeconds () / i->second.rxPackets << "\n");
555  NS_LOG_INFO (" Mean jitter: " << i->second.jitterSum.GetSeconds () / (i->second.rxPackets - 1) << "\n");
556  NS_LOG_INFO (" Tx Opp: " << 1 - (statisticsAp1.GetBusyTime () / simuTime));
557  }
558  }
559 
560  //Plots for AP0
561  std::ofstream outfileTh0 (("throughput-" + outputFileName + "-0.plt").c_str ());
562  Gnuplot gnuplot = Gnuplot (("throughput-" + outputFileName + "-0.eps").c_str (), "Throughput");
563  gnuplot.SetTerminal ("post eps color enhanced");
564  gnuplot.SetLegend ("Time (seconds)", "Throughput (Mb/s)");
565  gnuplot.SetTitle ("Throughput (AP0 to STA) vs time");
566  gnuplot.AddDataset (statisticsAp0.GetDatafile ());
567  gnuplot.GenerateOutput (outfileTh0);
568 
569  if (manager.compare ("ns3::ParfWifiManager") == 0
570  || manager.compare ("ns3::AparfWifiManager") == 0
571  || manager.compare ("ns3::RrpaaWifiManager") == 0)
572  {
573  std::ofstream outfilePower0 (("power-" + outputFileName + "-0.plt").c_str ());
574  gnuplot = Gnuplot (("power-" + outputFileName + "-0.eps").c_str (), "Average Transmit Power");
575  gnuplot.SetTerminal ("post eps color enhanced");
576  gnuplot.SetLegend ("Time (seconds)", "Power (mW)");
577  gnuplot.SetTitle ("Average transmit power (AP0 to STA) vs time");
578  gnuplot.AddDataset (statisticsAp0.GetPowerDatafile ());
579  gnuplot.GenerateOutput (outfilePower0);
580  }
581 
582  std::ofstream outfileTx0 (("tx-" + outputFileName + "-0.plt").c_str ());
583  gnuplot = Gnuplot (("tx-" + outputFileName + "-0.eps").c_str (), "Time in TX State");
584  gnuplot.SetTerminal ("post eps color enhanced");
585  gnuplot.SetLegend ("Time (seconds)", "Percent");
586  gnuplot.SetTitle ("Percentage time AP0 in TX state vs time");
587  gnuplot.AddDataset (statisticsAp0.GetTxDatafile ());
588  gnuplot.GenerateOutput (outfileTx0);
589 
590  std::ofstream outfileRx0 (("rx-" + outputFileName + "-0.plt").c_str ());
591  gnuplot = Gnuplot (("rx-" + outputFileName + "-0.eps").c_str (), "Time in RX State");
592  gnuplot.SetTerminal ("post eps color enhanced");
593  gnuplot.SetLegend ("Time (seconds)", "Percent");
594  gnuplot.SetTitle ("Percentage time AP0 in RX state vs time");
595  gnuplot.AddDataset (statisticsAp0.GetRxDatafile ());
596  gnuplot.GenerateOutput (outfileRx0);
597 
598  std::ofstream outfileBusy0 (("busy-" + outputFileName + "-0.plt").c_str ());
599  gnuplot = Gnuplot (("busy-" + outputFileName + "-0.eps").c_str (), "Time in Busy State");
600  gnuplot.SetTerminal ("post eps color enhanced");
601  gnuplot.SetLegend ("Time (seconds)", "Percent");
602  gnuplot.SetTitle ("Percentage time AP0 in Busy state vs time");
603  gnuplot.AddDataset (statisticsAp0.GetBusyDatafile ());
604  gnuplot.GenerateOutput (outfileBusy0);
605 
606  std::ofstream outfileIdle0 (("idle-" + outputFileName + "-0.plt").c_str ());
607  gnuplot = Gnuplot (("idle-" + outputFileName + "-0.eps").c_str (), "Time in Idle State");
608  gnuplot.SetTerminal ("post eps color enhanced");
609  gnuplot.SetLegend ("Time (seconds)", "Percent");
610  gnuplot.SetTitle ("Percentage time AP0 in Idle state vs time");
611  gnuplot.AddDataset (statisticsAp0.GetIdleDatafile ());
612  gnuplot.GenerateOutput (outfileIdle0);
613 
614  //Plots for AP1
615  std::ofstream outfileTh1 (("throughput-" + outputFileName + "-1.plt").c_str ());
616  gnuplot = Gnuplot (("throughput-" + outputFileName + "-1.eps").c_str (), "Throughput");
617  gnuplot.SetTerminal ("post eps color enhanced");
618  gnuplot.SetLegend ("Time (seconds)", "Throughput (Mb/s)");
619  gnuplot.SetTitle ("Throughput (AP1 to STA) vs time");
620  gnuplot.AddDataset (statisticsAp1.GetDatafile ());
621  gnuplot.GenerateOutput (outfileTh1);
622 
623  if (manager.compare ("ns3::ParfWifiManager") == 0
624  || manager.compare ("ns3::AparfWifiManager") == 0
625  || manager.compare ("ns3::RrpaaWifiManager") == 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:56
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:143
holds a vector of ns3::Application pointers.
void SetupPhy(Ptr< WifiPhy > phy)
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
an Inet address class
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<Ipv4> and interface index.
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
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. ...
Ipv4Address destinationAddress
Destination address.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
#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:170
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
const FlowStatsContainer & GetFlowStats() const
Retrieve all collected the flow statistics.
aggregate IP/TCP/UDP functionality to existing Nodes.
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:280
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
cmd
Definition: second.py:35
WifiMacType GetType(void) const
Return the type (enum WifiMacType)
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
STL namespace.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:300
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
stack
Definition: first.py:34
Gnuplot2dDataset GetPowerDatafile()
uint16_t port
Definition: dsdv-manet.cc:45
a polymophic address class
Definition: address.h:90
Ptr< YansWifiChannel > Create(void) const
mobility
Definition: third.py:108
phy
Definition: third.py:93
void RxCallback(std::string path, Ptr< const Packet > packet, const Address &from)
void StateCallback(std::string path, Time init, Time duration, WifiPhyState state)
Class for representing data rates.
Definition: data-rate.h:88
void SetChannel(Ptr< YansWifiChannel > channel)
Time GetCalcTxTime(DataRate rate)
void PhyCallback(std::string path, Ptr< const Packet > packet, double powerW)
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1389
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:1124
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
void SetTitle(const std::string &title)
Definition: gnuplot.cc:730
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
ssid
Definition: third.py:100
holds a vector of ns3::NetDevice pointers
The PHY layer has sense the medium busy through the CCA mechanism.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
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
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:213
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:871
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:134
Ptr< WifiPhy > GetPhy(void) const
Ptr< FlowClassifier > GetClassifier()
Retrieve the FlowClassifier object for IPv4 created by the Install* methods.
void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
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.
address
Definition: first.py:37
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
The PHY layer is IDLE.
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
WifiPhyState
The state of the PHY layer.
std::vector< std::pair< Time, DataRate > > TxTime
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
an EUI-48 address
Definition: mac48-address.h:43
Helper to enable IP flow monitoring on a set of Nodes.
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:193
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
static const uint32_t packetSize
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())
wifi
Definition: third.py:96
Helper class used to assign positions and mobility models to nodes.
FiveTuple FindFlow(FlowId flowId) const
Searches for the FiveTuple corresponding to the given flowId.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ptr< WifiMac > GetMac(void) const
The PHY layer is sending a packet.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:178
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:272
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
uint32_t GetN(void) const
Get the number of Ptr<NetDevice> stored in this container.
AttributeValue implementation for Ssid.
Definition: ssid.h:110
The PHY layer is receiving a packet.
void Add(Vector v)
Add a position to the list of positions.
NodeStatistics(NetDeviceContainer aps, NetDeviceContainer stas)
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
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:1078
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
wifiStaNodes
Definition: third.py:88
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:724
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
Ipv4Address sourceAddress
Source address.
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:150
Implements the IEEE 802.11 MAC header.