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