A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-power-adaptation-interference.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 Universidad de la República - Uruguay
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Matias Richart <mrichart@fing.edu.uy>
18 */
19
58#include "ns3/command-line.h"
59#include "ns3/config.h"
60#include "ns3/double.h"
61#include "ns3/flow-monitor-helper.h"
62#include "ns3/gnuplot.h"
63#include "ns3/internet-stack-helper.h"
64#include "ns3/ipv4-address-helper.h"
65#include "ns3/ipv4-flow-classifier.h"
66#include "ns3/log.h"
67#include "ns3/mobility-helper.h"
68#include "ns3/on-off-helper.h"
69#include "ns3/packet-sink-helper.h"
70#include "ns3/ssid.h"
71#include "ns3/uinteger.h"
72#include "ns3/wifi-mac-header.h"
73#include "ns3/wifi-mac.h"
74#include "ns3/wifi-net-device.h"
75#include "ns3/yans-wifi-channel.h"
76#include "ns3/yans-wifi-helper.h"
77
78using namespace ns3;
79
80NS_LOG_COMPONENT_DEFINE("PowerAdaptationInterference");
81
83static const uint32_t packetSize = 1420;
84
89{
90 public:
98
104 void CheckStatistics(double time);
105
113 void PhyCallback(std::string path, Ptr<const Packet> packet, double powerW);
121 void RxCallback(std::string path, Ptr<const Packet> packet, const Address& from);
130 void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest);
139 void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest);
148 void StateCallback(std::string path, Time init, Time duration, WifiPhyState state);
149
186
192 double GetBusyTime() const;
193
194 private:
196 typedef std::vector<std::pair<Time, DataRate>> TxTime;
210
211 std::map<Mac48Address, double> m_currentPower;
212 std::map<Mac48Address, DataRate> m_currentRate;
214 double m_totalEnergy;
215 double m_totalTime;
216 double busyTime;
217 double idleTime;
218 double txTime;
219 double rxTime;
231};
232
234{
235 Ptr<NetDevice> device = aps.Get(0);
236 Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice>(device);
237 Ptr<WifiPhy> phy = wifiDevice->GetPhy();
238 SetupPhy(phy);
239 DataRate dataRate = DataRate(phy->GetDefaultMode().GetDataRate(phy->GetChannelWidth()));
240 double power = phy->GetTxPowerEnd();
241 for (uint32_t j = 0; j < stas.GetN(); j++)
242 {
243 Ptr<NetDevice> staDevice = stas.Get(j);
244 Ptr<WifiNetDevice> wifiStaDevice = DynamicCast<WifiNetDevice>(staDevice);
245 Mac48Address addr = wifiStaDevice->GetMac()->GetAddress();
246 m_currentPower[addr] = power;
247 m_currentRate[addr] = dataRate;
248 }
249 m_currentRate[Mac48Address("ff:ff:ff:ff:ff:ff")] = dataRate;
250 m_totalEnergy = 0;
251 m_totalTime = 0;
252 busyTime = 0;
253 idleTime = 0;
254 txTime = 0;
255 rxTime = 0;
256 m_totalBusyTime = 0;
257 m_totalIdleTime = 0;
258 m_totalTxTime = 0;
259 m_totalRxTime = 0;
260 m_bytesTotal = 0;
261 m_output.SetTitle("Throughput Mbits/s");
262 m_output_idle.SetTitle("Idle Time");
263 m_output_busy.SetTitle("Busy Time");
264 m_output_rx.SetTitle("RX Time");
265 m_output_tx.SetTitle("TX Time");
266}
267
268void
270{
271 for (const auto& mode : phy->GetModeList())
272 {
273 WifiTxVector txVector;
274 txVector.SetMode(mode);
276 txVector.SetChannelWidth(phy->GetChannelWidth());
277 DataRate dataRate = DataRate(mode.GetDataRate(phy->GetChannelWidth()));
278 Time time = phy->CalculateTxDuration(packetSize, txVector, phy->GetPhyBand());
279 NS_LOG_DEBUG(mode.GetUniqueName() << " " << time.GetSeconds() << " " << dataRate);
280 m_timeTable.emplace_back(time, dataRate);
281 }
282}
283
284Time
286{
287 for (TxTime::const_iterator i = m_timeTable.begin(); i != m_timeTable.end(); i++)
288 {
289 if (rate == i->second)
290 {
291 return i->first;
292 }
293 }
294 NS_ASSERT(false);
295 return Seconds(0);
296}
297
298void
299NodeStatistics::PhyCallback(std::string path, Ptr<const Packet> packet, double powerW)
300{
301 WifiMacHeader head;
302 packet->PeekHeader(head);
303 Mac48Address dest = head.GetAddr1();
304
305 if (head.GetType() == WIFI_MAC_DATA)
306 {
307 m_totalEnergy += pow(10.0, m_currentPower[dest] / 10.0) *
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,
321 DataRate oldRate,
322 DataRate newRate,
323 Mac48Address dest)
324{
325 m_currentRate[dest] = newRate;
326}
327
328void
329NodeStatistics::StateCallback(std::string path, Time init, Time duration, WifiPhyState state)
330{
331 if (state == WifiPhyState::CCA_BUSY)
332 {
333 busyTime += duration.GetSeconds();
334 m_totalBusyTime += duration.GetSeconds();
335 }
336 else if (state == WifiPhyState::IDLE)
337 {
338 idleTime += duration.GetSeconds();
339 m_totalIdleTime += duration.GetSeconds();
340 }
341 else if (state == WifiPhyState::TX)
342 {
343 txTime += duration.GetSeconds();
344 m_totalTxTime += duration.GetSeconds();
345 }
346 else if (state == WifiPhyState::RX)
347 {
348 rxTime += duration.GetSeconds();
349 m_totalRxTime += duration.GetSeconds();
350 }
351}
352
353void
354NodeStatistics::RxCallback(std::string path, Ptr<const Packet> packet, const Address& from)
355{
356 m_bytesTotal += packet->GetSize();
357}
358
359void
361{
362 double mbs = ((m_bytesTotal * 8.0) / (1000000 * time));
363 m_bytesTotal = 0;
364 double atp = m_totalEnergy / time;
365 m_totalEnergy = 0;
366 m_totalTime = 0;
367 m_output_power.Add((Simulator::Now()).GetSeconds(), atp);
368 m_output.Add((Simulator::Now()).GetSeconds(), mbs);
369
370 m_output_idle.Add((Simulator::Now()).GetSeconds(), idleTime * 100);
371 m_output_busy.Add((Simulator::Now()).GetSeconds(), busyTime * 100);
372 m_output_tx.Add((Simulator::Now()).GetSeconds(), txTime * 100);
373 m_output_rx.Add((Simulator::Now()).GetSeconds(), rxTime * 100);
374 busyTime = 0;
375 idleTime = 0;
376 txTime = 0;
377 rxTime = 0;
378
380}
381
384{
385 return m_output;
386}
387
390{
391 return m_output_power;
392}
393
396{
397 return m_output_idle;
398}
399
402{
403 return m_output_busy;
404}
405
408{
409 return m_output_rx;
410}
411
414{
415 return m_output_tx;
416}
417
418double
420{
422}
423
432void
433PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
434{
435 NS_LOG_INFO((Simulator::Now()).GetSeconds()
436 << " " << dest << " Old power=" << oldPower << " New power=" << newPower);
437}
438
447void
448RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
449{
450 NS_LOG_INFO((Simulator::Now()).GetSeconds()
451 << " " << dest << " Old rate=" << oldRate << " New rate=" << newRate);
452}
453
454int
455main(int argc, char* argv[])
456{
457 // LogComponentEnable("ConstantRateWifiManager", LOG_LEVEL_FUNCTION);
458
459 double maxPower = 17;
460 double minPower = 0;
461 uint32_t powerLevels = 18;
462
463 uint32_t rtsThreshold = 2346;
464 std::string manager = "ns3::ParfWifiManager";
465 std::string outputFileName = "parf";
466 int ap1_x = 0;
467 int ap1_y = 0;
468 int sta1_x = 10;
469 int sta1_y = 0;
470 int ap2_x = 200;
471 int ap2_y = 0;
472 int sta2_x = 180;
473 int sta2_y = 0;
474 uint32_t simuTime = 100;
475
476 CommandLine cmd(__FILE__);
477 cmd.AddValue("manager", "PRC Manager", manager);
478 cmd.AddValue("rtsThreshold", "RTS threshold", rtsThreshold);
479 cmd.AddValue("outputFileName", "Output filename", outputFileName);
480 cmd.AddValue("simuTime", "Total simulation time (sec)", simuTime);
481 cmd.AddValue("maxPower", "Maximum available transmission level (dbm).", maxPower);
482 cmd.AddValue("minPower", "Minimum available transmission level (dbm).", minPower);
483 cmd.AddValue("powerLevels",
484 "Number of transmission power levels available between "
485 "TxPowerStart and TxPowerEnd included.",
486 powerLevels);
487 cmd.AddValue("AP1_x", "Position of AP1 in x coordinate", ap1_x);
488 cmd.AddValue("AP1_y", "Position of AP1 in y coordinate", ap1_y);
489 cmd.AddValue("STA1_x", "Position of STA1 in x coordinate", sta1_x);
490 cmd.AddValue("STA1_y", "Position of STA1 in y coordinate", sta1_y);
491 cmd.AddValue("AP2_x", "Position of AP2 in x coordinate", ap2_x);
492 cmd.AddValue("AP2_y", "Position of AP2 in y coordinate", ap2_y);
493 cmd.AddValue("STA2_x", "Position of STA2 in x coordinate", sta2_x);
494 cmd.AddValue("STA2_y", "Position of STA2 in y coordinate", sta2_y);
495 cmd.Parse(argc, argv);
496
497 // Define the APs
498 NodeContainer wifiApNodes;
499 wifiApNodes.Create(2);
500
501 // Define the STAs
503 wifiStaNodes.Create(2);
504
506 wifi.SetStandard(WIFI_STANDARD_80211a);
507 WifiMacHelper wifiMac;
508 YansWifiPhyHelper wifiPhy;
510
511 wifiPhy.SetChannel(wifiChannel.Create());
512
513 NetDeviceContainer wifiApDevices;
514 NetDeviceContainer wifiStaDevices;
515 NetDeviceContainer wifiDevices;
516
517 // Configure the STA nodes
518 wifi.SetRemoteStationManager("ns3::AarfWifiManager",
519 "RtsCtsThreshold",
520 UintegerValue(rtsThreshold));
521 wifiPhy.Set("TxPowerStart", DoubleValue(maxPower));
522 wifiPhy.Set("TxPowerEnd", DoubleValue(maxPower));
523
524 Ssid ssid = Ssid("AP0");
525 wifiMac.SetType("ns3::StaWifiMac",
526 "Ssid",
527 SsidValue(ssid),
528 "MaxMissedBeacons",
529 UintegerValue(1000));
530 wifiStaDevices.Add(wifi.Install(wifiPhy, wifiMac, wifiStaNodes.Get(0)));
531
532 ssid = Ssid("AP1");
533 wifiMac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
534 wifiStaDevices.Add(wifi.Install(wifiPhy, wifiMac, wifiStaNodes.Get(1)));
535
536 // Configure the AP nodes
537 wifi.SetRemoteStationManager(manager,
538 "DefaultTxPowerLevel",
539 UintegerValue(powerLevels - 1),
540 "RtsCtsThreshold",
541 UintegerValue(rtsThreshold));
542 wifiPhy.Set("TxPowerStart", DoubleValue(minPower));
543 wifiPhy.Set("TxPowerEnd", DoubleValue(maxPower));
544 wifiPhy.Set("TxPowerLevels", UintegerValue(powerLevels));
545
546 ssid = Ssid("AP0");
547 wifiMac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
548 wifiApDevices.Add(wifi.Install(wifiPhy, wifiMac, wifiApNodes.Get(0)));
549
550 ssid = Ssid("AP1");
551 wifiMac.SetType("ns3::ApWifiMac",
552 "Ssid",
553 SsidValue(ssid),
554 "BeaconInterval",
555 TimeValue(MicroSeconds(103424))); // for avoiding collisions);
556 wifiApDevices.Add(wifi.Install(wifiPhy, wifiMac, wifiApNodes.Get(1)));
557
558 wifiDevices.Add(wifiStaDevices);
559 wifiDevices.Add(wifiApDevices);
560
561 // Configure the mobility.
563 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
564 positionAlloc->Add(Vector(ap1_x, ap1_y, 0.0));
565 positionAlloc->Add(Vector(sta1_x, sta1_y, 0.0));
566 positionAlloc->Add(Vector(ap2_x, ap2_y, 0.0));
567 positionAlloc->Add(Vector(sta2_x, sta2_y, 0.0));
568 mobility.SetPositionAllocator(positionAlloc);
569 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
570 mobility.Install(wifiApNodes.Get(0));
571 mobility.Install(wifiStaNodes.Get(0));
572 mobility.Install(wifiApNodes.Get(1));
573 mobility.Install(wifiStaNodes.Get(1));
574
575 // Configure the IP stack
577 stack.Install(wifiApNodes);
578 stack.Install(wifiStaNodes);
580 address.SetBase("10.1.1.0", "255.255.255.0");
581 Ipv4InterfaceContainer i = address.Assign(wifiDevices);
582 Ipv4Address sinkAddress = i.GetAddress(0);
583 Ipv4Address sinkAddress1 = i.GetAddress(1);
584 uint16_t port = 9;
585
586 // Configure the CBR generator
587 PacketSinkHelper sink("ns3::UdpSocketFactory", InetSocketAddress(sinkAddress, port));
588 ApplicationContainer apps_sink = sink.Install(wifiStaNodes.Get(0));
589
590 OnOffHelper onoff("ns3::UdpSocketFactory", InetSocketAddress(sinkAddress, port));
591 onoff.SetConstantRate(DataRate("54Mb/s"), packetSize);
592 onoff.SetAttribute("StartTime", TimeValue(Seconds(0.0)));
593 onoff.SetAttribute("StopTime", TimeValue(Seconds(100.0)));
594 ApplicationContainer apps_source = onoff.Install(wifiApNodes.Get(0));
595
596 PacketSinkHelper sink1("ns3::UdpSocketFactory", InetSocketAddress(sinkAddress1, port));
597 apps_sink.Add(sink1.Install(wifiStaNodes.Get(1)));
598
599 OnOffHelper onoff1("ns3::UdpSocketFactory", InetSocketAddress(sinkAddress1, port));
600 onoff1.SetConstantRate(DataRate("54Mb/s"), packetSize);
601 onoff1.SetAttribute("StartTime", TimeValue(Seconds(0.0)));
602 onoff1.SetAttribute("StopTime", TimeValue(Seconds(100.0)));
603 apps_source.Add(onoff1.Install(wifiApNodes.Get(1)));
604
605 apps_sink.Start(Seconds(0.5));
606 apps_sink.Stop(Seconds(simuTime));
607
608 //------------------------------------------------------------
609 //-- Setup stats and data collection
610 //--------------------------------------------
611
612 // Statistics counters
613 NodeStatistics statisticsAp0 = NodeStatistics(wifiApDevices, wifiStaDevices);
614 NodeStatistics statisticsAp1 = NodeStatistics(wifiApDevices, wifiStaDevices);
615
616 // Register packet receptions to calculate throughput
617 Config::Connect("/NodeList/2/ApplicationList/*/$ns3::PacketSink/Rx",
618 MakeCallback(&NodeStatistics::RxCallback, &statisticsAp0));
619 Config::Connect("/NodeList/3/ApplicationList/*/$ns3::PacketSink/Rx",
620 MakeCallback(&NodeStatistics::RxCallback, &statisticsAp1));
621
622 // Register power and rate changes to calculate the Average Transmit Power
623 Config::Connect("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
624 manager + "/PowerChange",
626 Config::Connect("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
627 manager + "/RateChange",
629 Config::Connect("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
630 manager + "/PowerChange",
632 Config::Connect("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
633 manager + "/RateChange",
635
636 Config::Connect("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
637 MakeCallback(&NodeStatistics::PhyCallback, &statisticsAp0));
638 Config::Connect("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
639 MakeCallback(&NodeStatistics::PhyCallback, &statisticsAp1));
640
641 // Register States
643 "/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
646 "/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
648
649 statisticsAp0.CheckStatistics(1);
650 statisticsAp1.CheckStatistics(1);
651
652 // Callbacks to print every change of power and rate
653 Config::Connect("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
654 manager + "/PowerChange",
656 Config::Connect("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
657 manager + "/RateChange",
659
660 // Calculate Throughput using Flowmonitor
661
662 FlowMonitorHelper flowmon;
663 Ptr<FlowMonitor> monitor = flowmon.InstallAll();
664
665 Simulator::Stop(Seconds(simuTime));
667
668 Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmon.GetClassifier());
669 std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
670 for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin();
671 i != stats.end();
672 ++i)
673 {
674 Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(i->first);
675 if ((t.sourceAddress == "10.1.1.3" && t.destinationAddress == "10.1.1.1"))
676 {
677 NS_LOG_INFO("Flow " << i->first << " (" << t.sourceAddress << " -> "
678 << t.destinationAddress << ")\n");
679 NS_LOG_INFO(" Tx Bytes: " << i->second.txBytes << "\n");
680 NS_LOG_INFO(" Rx Bytes: " << i->second.rxBytes << "\n");
681 NS_LOG_UNCOND(" Throughput to 10.1.1.1: "
682 << i->second.rxBytes * 8.0 /
683 (i->second.timeLastRxPacket.GetSeconds() -
684 i->second.timeFirstTxPacket.GetSeconds()) /
685 1024 / 1024
686 << " Mbps\n");
687 NS_LOG_INFO(" Mean delay: " << i->second.delaySum.GetSeconds() / i->second.rxPackets
688 << "\n");
689 NS_LOG_INFO(" Mean jitter: "
690 << i->second.jitterSum.GetSeconds() / (i->second.rxPackets - 1) << "\n");
691 NS_LOG_INFO(" Tx Opp: " << 1 - (statisticsAp0.GetBusyTime() / simuTime));
692 }
693 if ((t.sourceAddress == "10.1.1.4" && t.destinationAddress == "10.1.1.2"))
694 {
695 NS_LOG_INFO("Flow " << i->first << " (" << t.sourceAddress << " -> "
696 << t.destinationAddress << ")\n");
697 NS_LOG_INFO(" Tx Bytes: " << i->second.txBytes << "\n");
698 NS_LOG_INFO(" Rx Bytes: " << i->second.rxBytes << "\n");
699 NS_LOG_UNCOND(" Throughput to 10.1.1.2: "
700 << i->second.rxBytes * 8.0 /
701 (i->second.timeLastRxPacket.GetSeconds() -
702 i->second.timeFirstTxPacket.GetSeconds()) /
703 1024 / 1024
704 << " Mbps\n");
705 NS_LOG_INFO(" Mean delay: " << i->second.delaySum.GetSeconds() / i->second.rxPackets
706 << "\n");
707 NS_LOG_INFO(" Mean jitter: "
708 << i->second.jitterSum.GetSeconds() / (i->second.rxPackets - 1) << "\n");
709 NS_LOG_INFO(" Tx Opp: " << 1 - (statisticsAp1.GetBusyTime() / simuTime));
710 }
711 }
712
713 // Plots for AP0
714 std::ofstream outfileTh0("throughput-" + outputFileName + "-0.plt");
715 Gnuplot gnuplot = Gnuplot("throughput-" + outputFileName + "-0.eps", "Throughput");
716 gnuplot.SetTerminal("post eps color enhanced");
717 gnuplot.SetLegend("Time (seconds)", "Throughput (Mb/s)");
718 gnuplot.SetTitle("Throughput (AP0 to STA) vs time");
719 gnuplot.AddDataset(statisticsAp0.GetDatafile());
720 gnuplot.GenerateOutput(outfileTh0);
721
722 if (manager == "ns3::ParfWifiManager" || manager == "ns3::AparfWifiManager" ||
723 manager == "ns3::RrpaaWifiManager")
724 {
725 std::ofstream outfilePower0("power-" + outputFileName + "-0.plt");
726 gnuplot = Gnuplot("power-" + outputFileName + "-0.eps", "Average Transmit Power");
727 gnuplot.SetTerminal("post eps color enhanced");
728 gnuplot.SetLegend("Time (seconds)", "Power (mW)");
729 gnuplot.SetTitle("Average transmit power (AP0 to STA) vs time");
730 gnuplot.AddDataset(statisticsAp0.GetPowerDatafile());
731 gnuplot.GenerateOutput(outfilePower0);
732 }
733
734 std::ofstream outfileTx0("tx-" + outputFileName + "-0.plt");
735 gnuplot = Gnuplot("tx-" + outputFileName + "-0.eps", "Time in TX State");
736 gnuplot.SetTerminal("post eps color enhanced");
737 gnuplot.SetLegend("Time (seconds)", "Percent");
738 gnuplot.SetTitle("Percentage time AP0 in TX state vs time");
739 gnuplot.AddDataset(statisticsAp0.GetTxDatafile());
740 gnuplot.GenerateOutput(outfileTx0);
741
742 std::ofstream outfileRx0("rx-" + outputFileName + "-0.plt");
743 gnuplot = Gnuplot("rx-" + outputFileName + "-0.eps", "Time in RX State");
744 gnuplot.SetTerminal("post eps color enhanced");
745 gnuplot.SetLegend("Time (seconds)", "Percent");
746 gnuplot.SetTitle("Percentage time AP0 in RX state vs time");
747 gnuplot.AddDataset(statisticsAp0.GetRxDatafile());
748 gnuplot.GenerateOutput(outfileRx0);
749
750 std::ofstream outfileBusy0("busy-" + outputFileName + "-0.plt");
751 gnuplot = Gnuplot("busy-" + outputFileName + "-0.eps", "Time in Busy State");
752 gnuplot.SetTerminal("post eps color enhanced");
753 gnuplot.SetLegend("Time (seconds)", "Percent");
754 gnuplot.SetTitle("Percentage time AP0 in Busy state vs time");
755 gnuplot.AddDataset(statisticsAp0.GetBusyDatafile());
756 gnuplot.GenerateOutput(outfileBusy0);
757
758 std::ofstream outfileIdle0("idle-" + outputFileName + "-0.plt");
759 gnuplot = Gnuplot("idle-" + outputFileName + "-0.eps", "Time in Idle State");
760 gnuplot.SetTerminal("post eps color enhanced");
761 gnuplot.SetLegend("Time (seconds)", "Percent");
762 gnuplot.SetTitle("Percentage time AP0 in Idle state vs time");
763 gnuplot.AddDataset(statisticsAp0.GetIdleDatafile());
764 gnuplot.GenerateOutput(outfileIdle0);
765
766 // Plots for AP1
767 std::ofstream outfileTh1("throughput-" + outputFileName + "-1.plt");
768 gnuplot = Gnuplot("throughput-" + outputFileName + "-1.eps", "Throughput");
769 gnuplot.SetTerminal("post eps color enhanced");
770 gnuplot.SetLegend("Time (seconds)", "Throughput (Mb/s)");
771 gnuplot.SetTitle("Throughput (AP1 to STA) vs time");
772 gnuplot.AddDataset(statisticsAp1.GetDatafile());
773 gnuplot.GenerateOutput(outfileTh1);
774
775 if (manager == "ns3::ParfWifiManager" || manager == "ns3::AparfWifiManager" ||
776 manager == "ns3::RrpaaWifiManager")
777 {
778 std::ofstream outfilePower1("power-" + outputFileName + "-1.plt");
779 gnuplot = Gnuplot("power-" + outputFileName + "-1.eps", "Average Transmit Power");
780 gnuplot.SetTerminal("post eps color enhanced");
781 gnuplot.SetLegend("Time (seconds)", "Power (mW)");
782 gnuplot.SetTitle("Average transmit power (AP1 to STA) vs time");
783 gnuplot.AddDataset(statisticsAp1.GetPowerDatafile());
784 gnuplot.GenerateOutput(outfilePower1);
785 }
786
787 std::ofstream outfileTx1("tx-" + outputFileName + "-1.plt");
788 gnuplot = Gnuplot("tx-" + outputFileName + "-1.eps", "Time in TX State");
789 gnuplot.SetTerminal("post eps color enhanced");
790 gnuplot.SetLegend("Time (seconds)", "Percent");
791 gnuplot.SetTitle("Percentage time AP1 in TX state vs time");
792 gnuplot.AddDataset(statisticsAp1.GetTxDatafile());
793 gnuplot.GenerateOutput(outfileTx1);
794
795 std::ofstream outfileRx1("rx-" + outputFileName + "-1.plt");
796 gnuplot = Gnuplot("rx-" + outputFileName + "-1.eps", "Time in RX State");
797 gnuplot.SetTerminal("post eps color enhanced");
798 gnuplot.SetLegend("Time (seconds)", "Percent");
799 gnuplot.SetTitle("Percentage time AP1 in RX state vs time");
800 gnuplot.AddDataset(statisticsAp1.GetRxDatafile());
801 gnuplot.GenerateOutput(outfileRx1);
802
803 std::ofstream outfileBusy1("busy-" + outputFileName + "-1.plt");
804 gnuplot = Gnuplot("busy-" + outputFileName + "-1.eps", "Time in Busy State");
805 gnuplot.SetTerminal("post eps color enhanced");
806 gnuplot.SetLegend("Time (seconds)", "Percent");
807 gnuplot.SetTitle("Percentage time AP1 in Busy state vs time");
808 gnuplot.AddDataset(statisticsAp1.GetBusyDatafile());
809 gnuplot.GenerateOutput(outfileBusy1);
810
811 std::ofstream outfileIdle1("idle-" + outputFileName + "-1.plt");
812 gnuplot = Gnuplot("idle-" + outputFileName + "-1.eps", "Time in Idle State");
813 gnuplot.SetTerminal("post eps color enhanced");
814 gnuplot.SetLegend("Time (seconds)", "Percent");
815 gnuplot.SetTitle("Percentage time AP1 in Idle state vs time");
816 gnuplot.AddDataset(statisticsAp1.GetIdleDatafile());
817 gnuplot.GenerateOutput(outfileIdle1);
818
820
821 return 0;
822}
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.
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.
double GetBusyTime() const
Get the Busy time.
void PhyCallback(std::string path, Ptr< const Packet > packet, double powerW)
Callback called by WifiNetDevice/Phy/PhyTxBegin.
a polymophic address class
Definition: address.h:100
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Parse command-line arguments.
Definition: command-line.h:232
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:42
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:116
void Add(double x, double y)
Definition: gnuplot.cc:377
void SetTitle(const std::string &title)
Change line title.
Definition: gnuplot.cc:148
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:370
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:796
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:776
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:764
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:802
void SetTitle(const std::string &title)
Definition: gnuplot.cc:770
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:42
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:46
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
uint32_t GetN() 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:44
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:568
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
static void Run()
Run the simulation.
Definition: simulator.cc:176
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:184
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:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:402
AttributeValue implementation for Time.
Definition: nstime.h:1423
Hold an unsigned integer type.
Definition: uinteger.h:45
helps to create WifiNetDevice objects
Definition: wifi-helper.h:324
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr1() const
Return the address in the Address 1 field.
WifiMacType GetType() const
Return the type (WifiMacType)
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:163
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.
static YansWifiChannelHelper Default()
Create a channel helper in a default working state.
Ptr< YansWifiChannel > Create() 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:44
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:975
#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:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1360
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
@ WIFI_STANDARD_80211a
@ WIFI_PREAMBLE_LONG
ns address
Definition: first.py:40
ns stack
Definition: first.py:37
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:702
@ WIFI_MAC_DATA
ns cmd
Definition: second.py:33
ns wifi
Definition: third.py:88
ns ssid
Definition: third.py:86
ns mobility
Definition: third.py:96
ns wifiStaNodes
Definition: third.py:77
ns phy
Definition: third.py:82
Structure to classify a packet.
Ipv4Address sourceAddress
Source address.
Ipv4Address destinationAddress
Destination address.
WifiPhyState
The state of the PHY layer.
static const uint32_t packetSize
Packet size generated at the AP.
void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
Callback called by WifiNetDevice/RemoteStationManager/x/RateChange.
static const uint32_t packetSize
Packet size generated at the AP.
void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
Callback called by WifiNetDevice/RemoteStationManager/x/PowerChange.
Ptr< PacketSink > sink
Pointer to the packet sink application.
Definition: wifi-tcp.cc:55