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
78using namespace ns3;
79using namespace std;
80
81NS_LOG_COMPONENT_DEFINE ("PowerAdaptationInterference");
82
84static const uint32_t packetSize = 1420;
85
90{
91public:
99
105 void CheckStatistics (double time);
106
114 void PhyCallback (std::string path, Ptr<const Packet> packet, double powerW);
122 void RxCallback (std::string path, Ptr<const Packet> packet, const Address &from);
131 void PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest);
140 void RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest);
149 void StateCallback (std::string path, Time init, Time duration, WifiPhyState state);
150
187
193 double GetBusyTime ();
194
195private:
197 typedef std::vector<std::pair<Time, DataRate> > TxTime;
211
212 std::map<Mac48Address, double> m_currentPower;
213 std::map<Mac48Address, DataRate> m_currentRate;
215 double m_totalEnergy;
216 double m_totalTime;
217 double busyTime;
218 double idleTime;
219 double txTime;
220 double rxTime;
232};
233
235{
236 Ptr<NetDevice> device = aps.Get (0);
237 Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device);
238 Ptr<WifiPhy> phy = wifiDevice->GetPhy ();
239 SetupPhy (phy);
240 DataRate dataRate = DataRate (phy->GetDefaultMode ().GetDataRate (phy->GetChannelWidth ()));
241 double power = phy->GetTxPowerEnd ();
242 for (uint32_t j = 0; j < stas.GetN (); j++)
243 {
244 Ptr<NetDevice> staDevice = stas.Get (j);
245 Ptr<WifiNetDevice> wifiStaDevice = DynamicCast<WifiNetDevice> (staDevice);
246 Mac48Address addr = wifiStaDevice->GetMac ()->GetAddress ();
247 m_currentPower[addr] = power;
248 m_currentRate[addr] = dataRate;
249 }
250 m_currentRate[Mac48Address ("ff:ff:ff:ff:ff:ff")] = dataRate;
251 m_totalEnergy = 0;
252 m_totalTime = 0;
253 busyTime = 0;
254 idleTime = 0;
255 txTime = 0;
256 rxTime = 0;
257 m_totalBusyTime = 0;
258 m_totalIdleTime = 0;
259 m_totalTxTime = 0;
260 m_totalRxTime = 0;
261 m_bytesTotal = 0;
262 m_output.SetTitle ("Throughput Mbits/s");
263 m_output_idle.SetTitle ("Idle Time");
264 m_output_busy.SetTitle ("Busy Time");
265 m_output_rx.SetTitle ("RX Time");
266 m_output_tx.SetTitle ("TX Time");
267}
268
269void
271{
272 for (const auto & mode : phy->GetModeList ())
273 {
274 WifiTxVector txVector;
275 txVector.SetMode (mode);
277 txVector.SetChannelWidth (phy->GetChannelWidth ());
278 DataRate dataRate = DataRate (mode.GetDataRate (phy->GetChannelWidth ()));
279 Time time = phy->CalculateTxDuration (packetSize, txVector, phy->GetPhyBand ());
280 NS_LOG_DEBUG (mode.GetUniqueName () << " " << time.GetSeconds () << " " << dataRate);
281 m_timeTable.push_back (std::make_pair (time, dataRate));
282 }
283}
284
285Time
287{
288 for (TxTime::const_iterator i = m_timeTable.begin (); i != m_timeTable.end (); i++)
289 {
290 if (rate == i->second)
291 {
292 return i->first;
293 }
294 }
295 NS_ASSERT (false);
296 return Seconds (0);
297}
298
299void
300NodeStatistics::PhyCallback (std::string path, Ptr<const Packet> packet, double powerW)
301{
302 WifiMacHeader head;
303 packet->PeekHeader (head);
304 Mac48Address dest = head.GetAddr1 ();
305
306 if (head.GetType () == WIFI_MAC_DATA)
307 {
308 m_totalEnergy += pow (10.0, m_currentPower[dest] / 10.0) * GetCalcTxTime (m_currentRate[dest]).GetSeconds ();
310 }
311}
312
313void
314NodeStatistics::PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest)
315{
316 m_currentPower[dest] = newPower;
317}
318
319void
320NodeStatistics::RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
321{
322 m_currentRate[dest] = newRate;
323}
324
325void
326NodeStatistics::StateCallback (std::string path, Time init, Time duration, WifiPhyState state)
327{
328 if (state == WifiPhyState::CCA_BUSY)
329 {
330 busyTime += duration.GetSeconds ();
331 m_totalBusyTime += duration.GetSeconds ();
332 }
333 else if (state == WifiPhyState::IDLE)
334 {
335 idleTime += duration.GetSeconds ();
336 m_totalIdleTime += duration.GetSeconds ();
337 }
338 else if (state == WifiPhyState::TX)
339 {
340 txTime += duration.GetSeconds ();
341 m_totalTxTime += duration.GetSeconds ();
342 }
343 else if (state == WifiPhyState::RX)
344 {
345 rxTime += duration.GetSeconds ();
346 m_totalRxTime += duration.GetSeconds ();
347 }
348}
349
350void
351NodeStatistics::RxCallback (std::string path, Ptr<const Packet> packet, const Address &from)
352{
353 m_bytesTotal += packet->GetSize ();
354}
355
356void
358{
359 double mbs = ((m_bytesTotal * 8.0) / (1000000 * time));
360 m_bytesTotal = 0;
361 double atp = m_totalEnergy / time;
362 m_totalEnergy = 0;
363 m_totalTime = 0;
364 m_output_power.Add ((Simulator::Now ()).GetSeconds (), atp);
365 m_output.Add ((Simulator::Now ()).GetSeconds (), mbs);
366
367 m_output_idle.Add ((Simulator::Now ()).GetSeconds (), idleTime * 100);
368 m_output_busy.Add ((Simulator::Now ()).GetSeconds (), busyTime * 100);
369 m_output_tx.Add ((Simulator::Now ()).GetSeconds (), txTime * 100);
370 m_output_rx.Add ((Simulator::Now ()).GetSeconds (), rxTime * 100);
371 busyTime = 0;
372 idleTime = 0;
373 txTime = 0;
374 rxTime = 0;
375
376 Simulator::Schedule (Seconds (time), &NodeStatistics::CheckStatistics, this, time);
377}
378
381{
382 return m_output;
383}
384
387{
388 return m_output_power;
389}
390
393{
394 return m_output_idle;
395}
396
399{
400 return m_output_busy;
401}
402
405{
406 return m_output_rx;
407}
408
411{
412 return m_output_tx;
413}
414
415double
417{
419}
420
421void PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest)
422{
423 NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Old power=" << oldPower << " New power=" << newPower);
424}
425
426void RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
427{
428 NS_LOG_INFO ((Simulator::Now ()).GetSeconds () << " " << dest << " Old rate=" << oldRate << " New rate=" << newRate);
429}
430
431int main (int argc, char *argv[])
432{
433 //LogComponentEnable("ConstantRateWifiManager", LOG_LEVEL_FUNCTION);
434
435 double maxPower = 17;
436 double minPower = 0;
437 uint32_t powerLevels = 18;
438
439 uint32_t rtsThreshold = 2346;
440 std::string manager = "ns3::ParfWifiManager";
441 std::string outputFileName = "parf";
442 int ap1_x = 0;
443 int ap1_y = 0;
444 int sta1_x = 10;
445 int sta1_y = 0;
446 int ap2_x = 200;
447 int ap2_y = 0;
448 int sta2_x = 180;
449 int sta2_y = 0;
450 uint32_t simuTime = 100;
451
452 CommandLine cmd (__FILE__);
453 cmd.AddValue ("manager", "PRC Manager", manager);
454 cmd.AddValue ("rtsThreshold", "RTS threshold", rtsThreshold);
455 cmd.AddValue ("outputFileName", "Output filename", outputFileName);
456 cmd.AddValue ("simuTime", "Total simulation time (sec)", simuTime);
457 cmd.AddValue ("maxPower", "Maximum available transmission level (dbm).", maxPower);
458 cmd.AddValue ("minPower", "Minimum available transmission level (dbm).", minPower);
459 cmd.AddValue ("powerLevels", "Number of transmission power levels available between "
460 "TxPowerStart and TxPowerEnd included.", powerLevels);
461 cmd.AddValue ("AP1_x", "Position of AP1 in x coordinate", ap1_x);
462 cmd.AddValue ("AP1_y", "Position of AP1 in y coordinate", ap1_y);
463 cmd.AddValue ("STA1_x", "Position of STA1 in x coordinate", sta1_x);
464 cmd.AddValue ("STA1_y", "Position of STA1 in y coordinate", sta1_y);
465 cmd.AddValue ("AP2_x", "Position of AP2 in x coordinate", ap2_x);
466 cmd.AddValue ("AP2_y", "Position of AP2 in y coordinate", ap2_y);
467 cmd.AddValue ("STA2_x", "Position of STA2 in x coordinate", sta2_x);
468 cmd.AddValue ("STA2_y", "Position of STA2 in y coordinate", sta2_y);
469 cmd.Parse (argc, argv);
470
471 //Define the APs
472 NodeContainer wifiApNodes;
473 wifiApNodes.Create (2);
474
475 //Define the STAs
477 wifiStaNodes.Create (2);
478
480 wifi.SetStandard (WIFI_STANDARD_80211a);
481 WifiMacHelper wifiMac;
482 YansWifiPhyHelper wifiPhy;
483 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
484
485 wifiPhy.SetChannel (wifiChannel.Create ());
486
487 NetDeviceContainer wifiApDevices;
488 NetDeviceContainer wifiStaDevices;
489 NetDeviceContainer wifiDevices;
490
491 //Configure the STA nodes
492 wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "RtsCtsThreshold", UintegerValue (rtsThreshold));
493 wifiPhy.Set ("TxPowerStart", DoubleValue (maxPower));
494 wifiPhy.Set ("TxPowerEnd", DoubleValue (maxPower));
495
496 Ssid ssid = Ssid ("AP0");
497 wifiMac.SetType ("ns3::StaWifiMac",
498 "Ssid", SsidValue (ssid),
499 "MaxMissedBeacons", UintegerValue (1000));
500 wifiStaDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiStaNodes.Get (0)));
501
502 ssid = Ssid ("AP1");
503 wifiMac.SetType ("ns3::StaWifiMac",
504 "Ssid", SsidValue (ssid));
505 wifiStaDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiStaNodes.Get (1)));
506
507 //Configure the AP nodes
508 wifi.SetRemoteStationManager (manager, "DefaultTxPowerLevel", UintegerValue (powerLevels - 1), "RtsCtsThreshold", UintegerValue (rtsThreshold));
509 wifiPhy.Set ("TxPowerStart", DoubleValue (minPower));
510 wifiPhy.Set ("TxPowerEnd", DoubleValue (maxPower));
511 wifiPhy.Set ("TxPowerLevels", UintegerValue (powerLevels));
512
513 ssid = Ssid ("AP0");
514 wifiMac.SetType ("ns3::ApWifiMac",
515 "Ssid", SsidValue (ssid));
516 wifiApDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiApNodes.Get (0)));
517
518 ssid = Ssid ("AP1");
519 wifiMac.SetType ("ns3::ApWifiMac",
520 "Ssid", SsidValue (ssid),
521 "BeaconInterval", TimeValue (MicroSeconds (103424))); //for avoiding collisions);
522 wifiApDevices.Add (wifi.Install (wifiPhy, wifiMac, wifiApNodes.Get (1)));
523
524 wifiDevices.Add (wifiStaDevices);
525 wifiDevices.Add (wifiApDevices);
526
527 //Configure the mobility.
529 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
530 positionAlloc->Add (Vector (ap1_x, ap1_y, 0.0));
531 positionAlloc->Add (Vector (sta1_x, sta1_y, 0.0));
532 positionAlloc->Add (Vector (ap2_x, ap2_y, 0.0));
533 positionAlloc->Add (Vector (sta2_x, sta2_y, 0.0));
534 mobility.SetPositionAllocator (positionAlloc);
535 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
536 mobility.Install (wifiApNodes.Get (0));
537 mobility.Install (wifiStaNodes.Get (0));
538 mobility.Install (wifiApNodes.Get (1));
539 mobility.Install (wifiStaNodes.Get (1));
540
541
542 //Configure the IP stack
544 stack.Install (wifiApNodes);
545 stack.Install (wifiStaNodes);
547 address.SetBase ("10.1.1.0", "255.255.255.0");
548 Ipv4InterfaceContainer i = address.Assign (wifiDevices);
549 Ipv4Address sinkAddress = i.GetAddress (0);
550 Ipv4Address sinkAddress1 = i.GetAddress (1);
551 uint16_t port = 9;
552
553 //Configure the CBR generator
554 PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress, port));
555 ApplicationContainer apps_sink = sink.Install (wifiStaNodes.Get (0));
556
557 OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress, port));
558 onoff.SetConstantRate (DataRate ("54Mb/s"), packetSize);
559 onoff.SetAttribute ("StartTime", TimeValue (Seconds (0.0)));
560 onoff.SetAttribute ("StopTime", TimeValue (Seconds (100.0)));
561 ApplicationContainer apps_source = onoff.Install (wifiApNodes.Get (0));
562
563 PacketSinkHelper sink1 ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress1, port));
564 apps_sink.Add (sink1.Install (wifiStaNodes.Get (1)));
565
566 OnOffHelper onoff1 ("ns3::UdpSocketFactory", InetSocketAddress (sinkAddress1, port));
567 onoff1.SetConstantRate (DataRate ("54Mb/s"), packetSize);
568 onoff1.SetAttribute ("StartTime", TimeValue (Seconds (0.0)));
569 onoff1.SetAttribute ("StopTime", TimeValue (Seconds (100.0)));
570 apps_source.Add (onoff1.Install (wifiApNodes.Get (1)));
571
572 apps_sink.Start (Seconds (0.5));
573 apps_sink.Stop (Seconds (simuTime));
574
575 //------------------------------------------------------------
576 //-- Setup stats and data collection
577 //--------------------------------------------
578
579 //Statistics counters
580 NodeStatistics statisticsAp0 = NodeStatistics (wifiApDevices, wifiStaDevices);
581 NodeStatistics statisticsAp1 = NodeStatistics (wifiApDevices, wifiStaDevices);
582
583 //Register packet receptions to calculate throughput
584 Config::Connect ("/NodeList/2/ApplicationList/*/$ns3::PacketSink/Rx",
585 MakeCallback (&NodeStatistics::RxCallback, &statisticsAp0));
586 Config::Connect ("/NodeList/3/ApplicationList/*/$ns3::PacketSink/Rx",
587 MakeCallback (&NodeStatistics::RxCallback, &statisticsAp1));
588
589 //Register power and rate changes to calculate the Average Transmit Power
590 Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
592 Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
593 MakeCallback (&NodeStatistics::RateCallback, &statisticsAp0));
594 Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
596 Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
597 MakeCallback (&NodeStatistics::RateCallback, &statisticsAp1));
598
599 Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
600 MakeCallback (&NodeStatistics::PhyCallback, &statisticsAp0));
601 Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
602 MakeCallback (&NodeStatistics::PhyCallback, &statisticsAp1));
603
604 //Register States
605 Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
607 Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
609
610 statisticsAp0.CheckStatistics (1);
611 statisticsAp1.CheckStatistics (1);
612
613 //Callbacks to print every change of power and rate
614 Config::Connect ("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/PowerChange",
616 Config::Connect ("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" + manager + "/RateChange",
618
619
620 //Calculate Throughput using Flowmonitor
621
622 FlowMonitorHelper flowmon;
623 Ptr<FlowMonitor> monitor = flowmon.InstallAll ();
624
625 Simulator::Stop (Seconds (simuTime));
626 Simulator::Run ();
627
628 Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
629 std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
630 for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
631 {
632 Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
633 if ((t.sourceAddress == "10.1.1.3" && t.destinationAddress == "10.1.1.1"))
634 {
635 NS_LOG_INFO ("Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n");
636 NS_LOG_INFO (" Tx Bytes: " << i->second.txBytes << "\n");
637 NS_LOG_INFO (" Rx Bytes: " << i->second.rxBytes << "\n");
638 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");
639 NS_LOG_INFO (" Mean delay: " << i->second.delaySum.GetSeconds () / i->second.rxPackets << "\n");
640 NS_LOG_INFO (" Mean jitter: " << i->second.jitterSum.GetSeconds () / (i->second.rxPackets - 1) << "\n");
641 NS_LOG_INFO (" Tx Opp: " << 1 - (statisticsAp0.GetBusyTime () / simuTime));
642 }
643 if ((t.sourceAddress == "10.1.1.4" && t.destinationAddress == "10.1.1.2"))
644 {
645 NS_LOG_INFO ("Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n");
646 NS_LOG_INFO (" Tx Bytes: " << i->second.txBytes << "\n");
647 NS_LOG_INFO (" Rx Bytes: " << i->second.rxBytes << "\n");
648 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");
649 NS_LOG_INFO (" Mean delay: " << i->second.delaySum.GetSeconds () / i->second.rxPackets << "\n");
650 NS_LOG_INFO (" Mean jitter: " << i->second.jitterSum.GetSeconds () / (i->second.rxPackets - 1) << "\n");
651 NS_LOG_INFO (" Tx Opp: " << 1 - (statisticsAp1.GetBusyTime () / simuTime));
652 }
653 }
654
655 //Plots for AP0
656 std::ofstream outfileTh0 (("throughput-" + outputFileName + "-0.plt").c_str ());
657 Gnuplot gnuplot = Gnuplot (("throughput-" + outputFileName + "-0.eps").c_str (), "Throughput");
658 gnuplot.SetTerminal ("post eps color enhanced");
659 gnuplot.SetLegend ("Time (seconds)", "Throughput (Mb/s)");
660 gnuplot.SetTitle ("Throughput (AP0 to STA) vs time");
661 gnuplot.AddDataset (statisticsAp0.GetDatafile ());
662 gnuplot.GenerateOutput (outfileTh0);
663
664 if (manager.compare ("ns3::ParfWifiManager") == 0
665 || manager.compare ("ns3::AparfWifiManager") == 0
666 || manager.compare ("ns3::RrpaaWifiManager") == 0)
667 {
668 std::ofstream outfilePower0 (("power-" + outputFileName + "-0.plt").c_str ());
669 gnuplot = Gnuplot (("power-" + outputFileName + "-0.eps").c_str (), "Average Transmit Power");
670 gnuplot.SetTerminal ("post eps color enhanced");
671 gnuplot.SetLegend ("Time (seconds)", "Power (mW)");
672 gnuplot.SetTitle ("Average transmit power (AP0 to STA) vs time");
673 gnuplot.AddDataset (statisticsAp0.GetPowerDatafile ());
674 gnuplot.GenerateOutput (outfilePower0);
675 }
676
677 std::ofstream outfileTx0 (("tx-" + outputFileName + "-0.plt").c_str ());
678 gnuplot = Gnuplot (("tx-" + outputFileName + "-0.eps").c_str (), "Time in TX State");
679 gnuplot.SetTerminal ("post eps color enhanced");
680 gnuplot.SetLegend ("Time (seconds)", "Percent");
681 gnuplot.SetTitle ("Percentage time AP0 in TX state vs time");
682 gnuplot.AddDataset (statisticsAp0.GetTxDatafile ());
683 gnuplot.GenerateOutput (outfileTx0);
684
685 std::ofstream outfileRx0 (("rx-" + outputFileName + "-0.plt").c_str ());
686 gnuplot = Gnuplot (("rx-" + outputFileName + "-0.eps").c_str (), "Time in RX State");
687 gnuplot.SetTerminal ("post eps color enhanced");
688 gnuplot.SetLegend ("Time (seconds)", "Percent");
689 gnuplot.SetTitle ("Percentage time AP0 in RX state vs time");
690 gnuplot.AddDataset (statisticsAp0.GetRxDatafile ());
691 gnuplot.GenerateOutput (outfileRx0);
692
693 std::ofstream outfileBusy0 (("busy-" + outputFileName + "-0.plt").c_str ());
694 gnuplot = Gnuplot (("busy-" + outputFileName + "-0.eps").c_str (), "Time in Busy State");
695 gnuplot.SetTerminal ("post eps color enhanced");
696 gnuplot.SetLegend ("Time (seconds)", "Percent");
697 gnuplot.SetTitle ("Percentage time AP0 in Busy state vs time");
698 gnuplot.AddDataset (statisticsAp0.GetBusyDatafile ());
699 gnuplot.GenerateOutput (outfileBusy0);
700
701 std::ofstream outfileIdle0 (("idle-" + outputFileName + "-0.plt").c_str ());
702 gnuplot = Gnuplot (("idle-" + outputFileName + "-0.eps").c_str (), "Time in Idle State");
703 gnuplot.SetTerminal ("post eps color enhanced");
704 gnuplot.SetLegend ("Time (seconds)", "Percent");
705 gnuplot.SetTitle ("Percentage time AP0 in Idle state vs time");
706 gnuplot.AddDataset (statisticsAp0.GetIdleDatafile ());
707 gnuplot.GenerateOutput (outfileIdle0);
708
709 //Plots for AP1
710 std::ofstream outfileTh1 (("throughput-" + outputFileName + "-1.plt").c_str ());
711 gnuplot = Gnuplot (("throughput-" + outputFileName + "-1.eps").c_str (), "Throughput");
712 gnuplot.SetTerminal ("post eps color enhanced");
713 gnuplot.SetLegend ("Time (seconds)", "Throughput (Mb/s)");
714 gnuplot.SetTitle ("Throughput (AP1 to STA) vs time");
715 gnuplot.AddDataset (statisticsAp1.GetDatafile ());
716 gnuplot.GenerateOutput (outfileTh1);
717
718 if (manager.compare ("ns3::ParfWifiManager") == 0
719 || manager.compare ("ns3::AparfWifiManager") == 0
720 || manager.compare ("ns3::RrpaaWifiManager") == 0)
721 {
722 std::ofstream outfilePower1 (("power-" + outputFileName + "-1.plt").c_str ());
723 gnuplot = Gnuplot (("power-" + outputFileName + "-1.eps").c_str (), "Average Transmit Power");
724 gnuplot.SetTerminal ("post eps color enhanced");
725 gnuplot.SetLegend ("Time (seconds)", "Power (mW)");
726 gnuplot.SetTitle ("Average transmit power (AP1 to STA) vs time");
727 gnuplot.AddDataset (statisticsAp1.GetPowerDatafile ());
728 gnuplot.GenerateOutput (outfilePower1);
729 }
730
731 std::ofstream outfileTx1 (("tx-" + outputFileName + "-1.plt").c_str ());
732 gnuplot = Gnuplot (("tx-" + outputFileName + "-1.eps").c_str (), "Time in TX State");
733 gnuplot.SetTerminal ("post eps color enhanced");
734 gnuplot.SetLegend ("Time (seconds)", "Percent");
735 gnuplot.SetTitle ("Percentage time AP1 in TX state vs time");
736 gnuplot.AddDataset (statisticsAp1.GetTxDatafile ());
737 gnuplot.GenerateOutput (outfileTx1);
738
739 std::ofstream outfileRx1 (("rx-" + outputFileName + "-1.plt").c_str ());
740 gnuplot = Gnuplot (("rx-" + outputFileName + "-1.eps").c_str (), "Time in RX State");
741 gnuplot.SetTerminal ("post eps color enhanced");
742 gnuplot.SetLegend ("Time (seconds)", "Percent");
743 gnuplot.SetTitle ("Percentage time AP1 in RX state vs time");
744 gnuplot.AddDataset (statisticsAp1.GetRxDatafile ());
745 gnuplot.GenerateOutput (outfileRx1);
746
747 std::ofstream outfileBusy1 (("busy-" + outputFileName + "-1.plt").c_str ());
748 gnuplot = Gnuplot (("busy-" + outputFileName + "-1.eps").c_str (), "Time in Busy State");
749 gnuplot.SetTerminal ("post eps color enhanced");
750 gnuplot.SetLegend ("Time (seconds)", "Percent");
751 gnuplot.SetTitle ("Percentage time AP1 in Busy state vs time");
752 gnuplot.AddDataset (statisticsAp1.GetBusyDatafile ());
753 gnuplot.GenerateOutput (outfileBusy1);
754
755 std::ofstream outfileIdle1 (("idle-" + outputFileName + "-1.plt").c_str ());
756 gnuplot = Gnuplot (("idle-" + outputFileName + "-1.eps").c_str (), "Time in Idle State");
757 gnuplot.SetTerminal ("post eps color enhanced");
758 gnuplot.SetLegend ("Time (seconds)", "Percent");
759 gnuplot.SetTitle ("Percentage time AP1 in Idle state vs time");
760 gnuplot.AddDataset (statisticsAp1.GetIdleDatafile ());
761 gnuplot.GenerateOutput (outfileIdle1);
762
763 Simulator::Destroy ();
764
765 return 0;
766}
Class to collect node statistics.
Gnuplot2dDataset m_output_busy
BUSY output data.
double m_totalIdleTime
Total time in IDLE state.
Gnuplot2dDataset m_output_power
Power output data.
double m_totalTxTime
Total time in TX state.
Gnuplot2dDataset GetPowerDatafile()
Get the Power output data.
TxTime m_timeTable
Time, DataRate table.
void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
Callback called by WifiNetDevice/RemoteStationManager/x/RateChange.
Gnuplot2dDataset GetDatafile()
Get the Throughput output data.
void RxCallback(std::string path, Ptr< const Packet > packet, const Address &from)
Callback called by PacketSink/Rx.
NodeStatistics(NetDeviceContainer aps, NetDeviceContainer stas)
Constructor.
Gnuplot2dDataset GetTxDatafile()
Get the TX state output data.
double m_totalBusyTime
Total time in BUSY state.
Time GetCalcTxTime(DataRate rate)
Get the time at which a given datarate has been recorded.
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
Callback called by WifiNetDevice/RemoteStationManager/x/PowerChange.
double m_totalTime
Time spent on a given state.
uint32_t m_bytesTotal
Number of received bytes on a given state.
Gnuplot2dDataset GetRxDatafile()
Get the RX state output data.
void SetupPhy(Ptr< WifiPhy > phy)
Setup the WifiPhy object.
std::vector< std::pair< Time, DataRate > > TxTime
Time, DataRate pair vector.
Gnuplot2dDataset m_output_tx
TX output data.
Gnuplot2dDataset GetBusyDatafile()
Get the BUSY state output data.
double m_totalRxTime
Total time in RX state.
double GetBusyTime()
Get the Busy time.
std::map< Mac48Address, double > m_currentPower
Current Tx power for each sender.
double m_totalEnergy
Energy used on a given state.
Gnuplot2dDataset m_output
Throughput output data.
void CheckStatistics(double time)
Collects the statistics at a given time.
void StateCallback(std::string path, Time init, Time duration, WifiPhyState state)
Callback called by YansWifiPhy/State/State.
Gnuplot2dDataset m_output_rx
RX output data.
Gnuplot2dDataset m_output_idle
IDLE output data.
std::map< Mac48Address, DataRate > m_currentRate
Current Tx rate for each sender.
Gnuplot2dDataset GetIdleDatafile()
Get the IDLE state output data.
void PhyCallback(std::string path, Ptr< const Packet > packet, double powerW)
Callback called by WifiNetDevice/Phy/PhyTxBegin.
a polymophic address class
Definition: address.h:91
holds a vector of ns3::Application pointers.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Parse command-line arguments.
Definition: command-line.h:229
Class for representing data rates.
Definition: data-rate.h:89
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
Helper to enable IP flow monitoring on a set of Nodes.
Ptr< FlowClassifier > GetClassifier()
Retrieve the FlowClassifier object for IPv4 created by the Install* methods.
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
Class to represent a 2D points plot.
Definition: gnuplot.h:118
void Add(double x, double y)
Definition: gnuplot.cc:361
void SetTitle(const std::string &title)
Change line title.
Definition: gnuplot.cc:141
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:372
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:758
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:738
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:726
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:764
void SetTitle(const std::string &title)
Definition: gnuplot.cc:732
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
an EUI-48 address
Definition: mac48-address.h:44
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
uint32_t GetN(void) const
Get the number of Ptr<NetDevice> stored in this container.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:43
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
AttributeValue implementation for Ssid.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
AttributeValue implementation for Time.
Definition: nstime.h:1308
Hold an unsigned integer type.
Definition: uinteger.h:44
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:324
helps to create WifiNetDevice objects
Definition: wifi-helper.h:323
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
WifiMacType GetType(void) const
Return the type (enum WifiMacType)
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
Ptr< WifiMac > GetMac(void) const
Ptr< WifiPhy > GetPhy(void) const
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:141
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
manage and create wifi channel objects for the YANS model.
Ptr< YansWifiChannel > Create(void) const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
uint16_t port
Definition: dsdv-manet.cc:45
#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
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:329
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1260
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
@ WIFI_STANDARD_80211a
@ WIFI_PREAMBLE_LONG
address
Definition: first.py:44
stack
Definition: first.py:41
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ WIFI_MAC_DATA
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
cmd
Definition: second.py:35
STL namespace.
ssid
Definition: third.py:97
wifi
Definition: third.py:99
mobility
Definition: third.py:107
wifiStaNodes
Definition: third.py:88
phy
Definition: third.py:93
Structure to classify a packet.
Ipv4Address sourceAddress
Source address.
Ipv4Address destinationAddress
Destination address.
WifiPhyState
The state of the PHY layer.
@ CCA_BUSY
The PHY layer has sense the medium busy through the CCA mechanism.
@ RX
The PHY layer is receiving a packet.
@ TX
The PHY layer is sending a packet.
@ IDLE
The PHY layer is IDLE.
void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
static const uint32_t packetSize
Packet size generated at the AP.
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
Ptr< PacketSink > sink
Definition: wifi-tcp.cc:56