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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Matias Richart <mrichart@fing.edu.uy>
7 */
8
9/**
10 * This example program is designed to illustrate the behavior of three
11 * power/rate-adaptive WiFi rate controls; namely, ns3::ParfWifiManager,
12 * ns3::AparfWifiManager and ns3::RrpaaWifiManager.
13 *
14 * This simulation consist of 4 nodes, two APs and two STAs.
15 * The APs generates UDP traffic with a CBR of 54 Mbps to the STAs.
16 * The APa use any power and rate control mechanism, and the STAs use only
17 * Minstrel rate control.
18 * The STAs can be configured to be at any distance from the APs.
19 *
20 * The objective is to test power and rate control in the links with
21 * interference from the other link.
22 *
23 * The output consists of:
24 * - A plot of average throughput vs. time.
25 * - A plot of average transmit power vs. time.
26 * - Plots for the percentage of time the APs are in each MAC state (IDLE, TX, RX, BUSY)
27 * - If enabled, the changes of power and rate to standard output.
28 * - If enabled, the average throughput, delay, jitter and tx opportunity for the total simulation
29 * time.
30 *
31 * Example usage:
32 * \code{.sh}
33 * ./ns3 run "wifi-power-adaptation-interference --manager=ns3::AparfWifiManager
34 * --outputFileName=aparf" \endcode
35 *
36 * Another example (changing STAs position):
37 * \code{.sh}
38 * ./ns3 run "wifi-power-adaptation-interference --manager=ns3::AparfWifiManager
39 * --outputFileName=aparf --STA1_x=5 --STA2_x=205" \endcode
40 *
41 * To enable the log of rate and power changes:
42 * \code{.sh}
43 * export NS_LOG=PowerAdaptationInterference=level_info
44 * \endcode
45 */
46
47#include "ns3/command-line.h"
48#include "ns3/config.h"
49#include "ns3/double.h"
50#include "ns3/flow-monitor-helper.h"
51#include "ns3/gnuplot.h"
52#include "ns3/internet-stack-helper.h"
53#include "ns3/ipv4-address-helper.h"
54#include "ns3/ipv4-flow-classifier.h"
55#include "ns3/log.h"
56#include "ns3/mobility-helper.h"
57#include "ns3/on-off-helper.h"
58#include "ns3/packet-sink-helper.h"
59#include "ns3/ssid.h"
60#include "ns3/uinteger.h"
61#include "ns3/wifi-mac-header.h"
62#include "ns3/wifi-mac.h"
63#include "ns3/wifi-net-device.h"
64#include "ns3/yans-wifi-channel.h"
65#include "ns3/yans-wifi-helper.h"
66
67using namespace ns3;
69NS_LOG_COMPONENT_DEFINE("PowerAdaptationInterference");
70
71/// Packet size generated at the AP.
72static const uint32_t packetSize = 1420;
73
74/**
75 * \brief Class to collect node statistics.
76 */
78{
79 public:
80 /**
81 * \brief Constructor.
82 *
83 * \param aps Access points
84 * \param stas WiFi Stations.
85 */
87
88 /**
89 * \brief Collects the statistics at a given time.
90 *
91 * \param time Time at which the statistics are collected.
92 */
93 void CheckStatistics(double time);
94
95 /**
96 * \brief Callback called by WifiNetDevice/Phy/PhyTxBegin.
97 *
98 * \param path The trace path.
99 * \param packet The sent packet.
100 * \param powerW The Tx power.
101 */
102 void PhyCallback(std::string path, Ptr<const Packet> packet, double powerW);
103 /**
104 * \brief Callback called by PacketSink/Rx.
105 *
106 * \param path The trace path.
107 * \param packet The received packet.
108 * \param from The sender address.
109 */
110 void RxCallback(std::string path, Ptr<const Packet> packet, const Address& from);
111 /**
112 * \brief Callback called by WifiNetDevice/RemoteStationManager/x/PowerChange.
113 *
114 * \param path The trace path.
115 * \param oldPower Old Tx power.
116 * \param newPower Actual Tx power.
117 * \param dest Destination of the transmission.
118 */
119 void PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest);
120 /**
121 * \brief Callback called by WifiNetDevice/RemoteStationManager/x/RateChange.
122 *
123 * \param path The trace path.
124 * \param oldRate Old rate.
125 * \param newRate Actual rate.
126 * \param dest Destination of the transmission.
127 */
128 void RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest);
129 /**
130 * \brief Callback called by YansWifiPhy/State/State.
131 *
132 * \param path The trace path.
133 * \param init Time when the state started.
134 * \param duration Amount of time we've been in (or will be in) the state.
135 * \param state The state.
136 */
137 void StateCallback(std::string path, Time init, Time duration, WifiPhyState state);
138
139 /**
140 * \brief Get the Throughput output data
141 *
142 * \return the Throughput output data.
143 */
145 /**
146 * \brief Get the Power output data.
147 *
148 * \return the Power output data.
149 */
151 /**
152 * \brief Get the IDLE state output data.
153 *
154 * \return the IDLE state output data.
155 */
157 /**
158 * \brief Get the BUSY state output data.
159 *
160 * \return the BUSY state output data.
161 */
163 /**
164 * \brief Get the TX state output data.
165 *
166 * \return the TX state output data.
167 */
169 /**
170 * \brief Get the RX state output data.
171 *
172 * \return the RX state output data.
173 */
175
176 /**
177 * \brief Get the Busy time.
178 *
179 * \return the busy time.
180 */
181 double GetBusyTime() const;
182
183 private:
184 /// Time, DataRate pair vector.
185 typedef std::vector<std::pair<Time, DataRate>> TxTime;
186 /**
187 * \brief Setup the WifiPhy object.
188 *
189 * \param phy The WifiPhy to setup.
190 */
191 void SetupPhy(Ptr<WifiPhy> phy);
192 /**
193 * \brief Get the time at which a given datarate has been recorded.
195 * \param rate The datarate to search.
196 * \return the time.
197 */
199
200 std::map<Mac48Address, dBm_u> m_currentPower; //!< Current Tx power for each sender.
201 std::map<Mac48Address, DataRate> m_currentRate; //!< Current Tx rate for each sender.
202 uint32_t m_bytesTotal; //!< Number of received bytes.
203 double m_totalEnergy; //!< Energy used.
204 double m_totalTime; //!< Time spent.
205 double busyTime; //!< BUSY time.
206 double idleTime; //!< IDLE time.
207 double txTime; //!< TX time.
208 double rxTime; //!< RX time.
209 double m_totalBusyTime; //!< Total time in BUSY state.
210 double m_totalIdleTime; //!< Total time in IDLE state.
211 double m_totalTxTime; //!< Total time in TX state.
212 double m_totalRxTime; //!< Total time in RX state.
213 TxTime m_timeTable; //!< Time, DataRate table.
214 Gnuplot2dDataset m_output; //!< Throughput output data.
215 Gnuplot2dDataset m_output_power; //!< Power output data.
216 Gnuplot2dDataset m_output_idle; //!< IDLE output data.
217 Gnuplot2dDataset m_output_busy; //!< BUSY output data.
218 Gnuplot2dDataset m_output_rx; //!< RX output data.
219 Gnuplot2dDataset m_output_tx; //!< TX output data.
220};
221
223{
224 Ptr<NetDevice> device = aps.Get(0);
226 Ptr<WifiPhy> phy = wifiDevice->GetPhy();
227 SetupPhy(phy);
228 DataRate dataRate = DataRate(phy->GetDefaultMode().GetDataRate(phy->GetChannelWidth()));
229 const auto power = phy->GetTxPowerEnd();
230 for (uint32_t j = 0; j < stas.GetN(); j++)
231 {
232 Ptr<NetDevice> staDevice = stas.Get(j);
233 Ptr<WifiNetDevice> wifiStaDevice = DynamicCast<WifiNetDevice>(staDevice);
234 Mac48Address addr = wifiStaDevice->GetMac()->GetAddress();
235 m_currentPower[addr] = power;
236 m_currentRate[addr] = dataRate;
237 }
238 m_currentRate[Mac48Address("ff:ff:ff:ff:ff:ff")] = dataRate;
239 m_totalEnergy = 0;
240 m_totalTime = 0;
241 busyTime = 0;
242 idleTime = 0;
243 txTime = 0;
244 rxTime = 0;
245 m_totalBusyTime = 0;
246 m_totalIdleTime = 0;
247 m_totalTxTime = 0;
248 m_totalRxTime = 0;
249 m_bytesTotal = 0;
250 m_output.SetTitle("Throughput Mbits/s");
251 m_output_idle.SetTitle("Idle Time");
252 m_output_busy.SetTitle("Busy Time");
253 m_output_rx.SetTitle("RX Time");
254 m_output_tx.SetTitle("TX Time");
255}
256
257void
259{
260 for (const auto& mode : phy->GetModeList())
261 {
262 WifiTxVector txVector;
263 txVector.SetMode(mode);
265 txVector.SetChannelWidth(phy->GetChannelWidth());
266 DataRate dataRate(mode.GetDataRate(phy->GetChannelWidth()));
267 Time time = phy->CalculateTxDuration(packetSize, txVector, phy->GetPhyBand());
268 NS_LOG_DEBUG(mode.GetUniqueName() << " " << time.GetSeconds() << " " << dataRate);
269 m_timeTable.emplace_back(time, dataRate);
270 }
271}
272
273Time
275{
276 for (auto i = m_timeTable.begin(); i != m_timeTable.end(); i++)
277 {
278 if (rate == i->second)
279 {
280 return i->first;
281 }
282 }
283 NS_ASSERT(false);
284 return Seconds(0);
285}
286
287void
288NodeStatistics::PhyCallback(std::string path, Ptr<const Packet> packet, double powerW)
289{
290 WifiMacHeader head;
291 packet->PeekHeader(head);
292 Mac48Address dest = head.GetAddr1();
293
294 if (head.GetType() == WIFI_MAC_DATA)
295 {
296 m_totalEnergy += pow(10.0, m_currentPower[dest] / 10.0) *
299 }
300}
301
302void
303NodeStatistics::PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
304{
305 m_currentPower[dest] = newPower;
306}
307
308void
309NodeStatistics::RateCallback(std::string path,
310 DataRate oldRate,
311 DataRate newRate,
312 Mac48Address dest)
313{
314 m_currentRate[dest] = newRate;
315}
316
317void
318NodeStatistics::StateCallback(std::string path, Time init, Time duration, WifiPhyState state)
319{
320 if (state == WifiPhyState::CCA_BUSY)
321 {
322 busyTime += duration.GetSeconds();
323 m_totalBusyTime += duration.GetSeconds();
324 }
325 else if (state == WifiPhyState::IDLE)
326 {
327 idleTime += duration.GetSeconds();
328 m_totalIdleTime += duration.GetSeconds();
329 }
330 else if (state == WifiPhyState::TX)
331 {
332 txTime += duration.GetSeconds();
333 m_totalTxTime += duration.GetSeconds();
334 }
335 else if (state == WifiPhyState::RX)
336 {
337 rxTime += duration.GetSeconds();
338 m_totalRxTime += duration.GetSeconds();
339 }
340}
341
342void
343NodeStatistics::RxCallback(std::string path, Ptr<const Packet> packet, const Address& from)
344{
345 m_bytesTotal += packet->GetSize();
346}
347
348void
350{
351 double mbs = ((m_bytesTotal * 8.0) / (1000000 * time));
352 m_bytesTotal = 0;
353 double atp = m_totalEnergy / time;
354 m_totalEnergy = 0;
355 m_totalTime = 0;
356 m_output_power.Add((Simulator::Now()).GetSeconds(), atp);
357 m_output.Add((Simulator::Now()).GetSeconds(), mbs);
358
359 m_output_idle.Add((Simulator::Now()).GetSeconds(), idleTime * 100);
360 m_output_busy.Add((Simulator::Now()).GetSeconds(), busyTime * 100);
361 m_output_tx.Add((Simulator::Now()).GetSeconds(), txTime * 100);
362 m_output_rx.Add((Simulator::Now()).GetSeconds(), rxTime * 100);
363 busyTime = 0;
364 idleTime = 0;
365 txTime = 0;
366 rxTime = 0;
367
369}
370
373{
374 return m_output;
375}
376
379{
381}
382
385{
387}
388
391{
393}
394
397{
399}
400
403{
405}
406
407double
409{
411}
412
413/**
414 * Callback called by WifiNetDevice/RemoteStationManager/x/PowerChange.
415 *
416 * \param path The trace path.
417 * \param oldPower Old Tx power.
418 * \param newPower Actual Tx power.
419 * \param dest Destination of the transmission.
420 */
421void
422PowerCallback(std::string path, double oldPower, double newPower, Mac48Address dest)
423{
424 NS_LOG_INFO((Simulator::Now()).GetSeconds()
425 << " " << dest << " Old power=" << oldPower << " New power=" << newPower);
426}
427
428/**
429 * \brief Callback called by WifiNetDevice/RemoteStationManager/x/RateChange.
430 *
431 * \param path The trace path.
432 * \param oldRate Old rate.
433 * \param newRate Actual rate.
434 * \param dest Destination of the transmission.
435 */
436void
437RateCallback(std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest)
438{
439 NS_LOG_INFO((Simulator::Now()).GetSeconds()
440 << " " << dest << " Old rate=" << oldRate << " New rate=" << newRate);
441}
442
443int
444main(int argc, char* argv[])
445{
446 // LogComponentEnable("ConstantRateWifiManager", LOG_LEVEL_FUNCTION);
447
448 dBm_u maxPower{17};
449 dBm_u minPower{0};
450 uint32_t powerLevels{18};
451
452 uint32_t rtsThreshold{2346};
453 std::string manager{"ns3::ParfWifiManager"};
454 std::string outputFileName{"parf"};
455 int ap1_x{0};
456 int ap1_y{0};
457 int sta1_x{10};
458 int sta1_y{0};
459 int ap2_x{200};
460 int ap2_y{0};
461 int sta2_x{180};
462 int sta2_y{0};
463 Time simuTime{"100s"};
464
465 CommandLine cmd(__FILE__);
466 cmd.AddValue("manager", "PRC Manager", manager);
467 cmd.AddValue("rtsThreshold", "RTS threshold", rtsThreshold);
468 cmd.AddValue("outputFileName", "Output filename", outputFileName);
469 cmd.AddValue("simuTime", "Total simulation time (sec)", simuTime);
470 cmd.AddValue("maxPower", "Maximum available transmission level (dbm).", maxPower);
471 cmd.AddValue("minPower", "Minimum available transmission level (dbm).", minPower);
472 cmd.AddValue("powerLevels",
473 "Number of transmission power levels available between "
474 "TxPowerStart and TxPowerEnd included.",
475 powerLevels);
476 cmd.AddValue("AP1_x", "Position of AP1 in x coordinate", ap1_x);
477 cmd.AddValue("AP1_y", "Position of AP1 in y coordinate", ap1_y);
478 cmd.AddValue("STA1_x", "Position of STA1 in x coordinate", sta1_x);
479 cmd.AddValue("STA1_y", "Position of STA1 in y coordinate", sta1_y);
480 cmd.AddValue("AP2_x", "Position of AP2 in x coordinate", ap2_x);
481 cmd.AddValue("AP2_y", "Position of AP2 in y coordinate", ap2_y);
482 cmd.AddValue("STA2_x", "Position of STA2 in x coordinate", sta2_x);
483 cmd.AddValue("STA2_y", "Position of STA2 in y coordinate", sta2_y);
484 cmd.Parse(argc, argv);
485
486 // Define the APs
487 NodeContainer wifiApNodes;
488 wifiApNodes.Create(2);
489
490 // Define the STAs
492 wifiStaNodes.Create(2);
493
495 wifi.SetStandard(WIFI_STANDARD_80211a);
496 WifiMacHelper wifiMac;
497 YansWifiPhyHelper wifiPhy;
499
500 wifiPhy.SetChannel(wifiChannel.Create());
501
502 NetDeviceContainer wifiApDevices;
503 NetDeviceContainer wifiStaDevices;
504 NetDeviceContainer wifiDevices;
505
506 // Configure the STA nodes
507 wifi.SetRemoteStationManager("ns3::AarfWifiManager",
508 "RtsCtsThreshold",
509 UintegerValue(rtsThreshold));
510 wifiPhy.Set("TxPowerStart", DoubleValue(maxPower));
511 wifiPhy.Set("TxPowerEnd", DoubleValue(maxPower));
512
513 Ssid ssid = Ssid("AP0");
514 wifiMac.SetType("ns3::StaWifiMac",
515 "Ssid",
516 SsidValue(ssid),
517 "MaxMissedBeacons",
518 UintegerValue(1000));
519 wifiStaDevices.Add(wifi.Install(wifiPhy, wifiMac, wifiStaNodes.Get(0)));
520
521 ssid = Ssid("AP1");
522 wifiMac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
523 wifiStaDevices.Add(wifi.Install(wifiPhy, wifiMac, wifiStaNodes.Get(1)));
524
525 // Configure the AP nodes
526 wifi.SetRemoteStationManager(manager,
527 "DefaultTxPowerLevel",
528 UintegerValue(powerLevels - 1),
529 "RtsCtsThreshold",
530 UintegerValue(rtsThreshold));
531 wifiPhy.Set("TxPowerStart", DoubleValue(minPower));
532 wifiPhy.Set("TxPowerEnd", DoubleValue(maxPower));
533 wifiPhy.Set("TxPowerLevels", UintegerValue(powerLevels));
534
535 ssid = Ssid("AP0");
536 wifiMac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
537 wifiApDevices.Add(wifi.Install(wifiPhy, wifiMac, wifiApNodes.Get(0)));
538
539 ssid = Ssid("AP1");
540 wifiMac.SetType("ns3::ApWifiMac",
541 "Ssid",
542 SsidValue(ssid),
543 "BeaconInterval",
544 TimeValue(MicroSeconds(103424))); // for avoiding collisions);
545 wifiApDevices.Add(wifi.Install(wifiPhy, wifiMac, wifiApNodes.Get(1)));
546
547 wifiDevices.Add(wifiStaDevices);
548 wifiDevices.Add(wifiApDevices);
549
550 // Configure the mobility.
553 positionAlloc->Add(Vector(ap1_x, ap1_y, 0.0));
554 positionAlloc->Add(Vector(sta1_x, sta1_y, 0.0));
555 positionAlloc->Add(Vector(ap2_x, ap2_y, 0.0));
556 positionAlloc->Add(Vector(sta2_x, sta2_y, 0.0));
557 mobility.SetPositionAllocator(positionAlloc);
558 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
559 mobility.Install(wifiApNodes.Get(0));
560 mobility.Install(wifiStaNodes.Get(0));
561 mobility.Install(wifiApNodes.Get(1));
562 mobility.Install(wifiStaNodes.Get(1));
563
564 // Configure the IP stack
566 stack.Install(wifiApNodes);
567 stack.Install(wifiStaNodes);
569 address.SetBase("10.1.1.0", "255.255.255.0");
570 Ipv4InterfaceContainer i = address.Assign(wifiDevices);
571 Ipv4Address sinkAddress = i.GetAddress(0);
572 Ipv4Address sinkAddress1 = i.GetAddress(1);
573 uint16_t port = 9;
574
575 // Configure the CBR generator
576 PacketSinkHelper sink("ns3::UdpSocketFactory", InetSocketAddress(sinkAddress, port));
577 ApplicationContainer apps_sink = sink.Install(wifiStaNodes.Get(0));
578
579 OnOffHelper onoff("ns3::UdpSocketFactory", InetSocketAddress(sinkAddress, port));
580 onoff.SetConstantRate(DataRate("54Mb/s"), packetSize);
581 onoff.SetAttribute("StartTime", TimeValue(Seconds(0.0)));
582 onoff.SetAttribute("StopTime", TimeValue(Seconds(100.0)));
583 ApplicationContainer apps_source = onoff.Install(wifiApNodes.Get(0));
584
585 PacketSinkHelper sink1("ns3::UdpSocketFactory", InetSocketAddress(sinkAddress1, port));
586 apps_sink.Add(sink1.Install(wifiStaNodes.Get(1)));
587
588 OnOffHelper onoff1("ns3::UdpSocketFactory", InetSocketAddress(sinkAddress1, port));
589 onoff1.SetConstantRate(DataRate("54Mb/s"), packetSize);
590 onoff1.SetAttribute("StartTime", TimeValue(Seconds(0.0)));
591 onoff1.SetAttribute("StopTime", TimeValue(Seconds(100.0)));
592 apps_source.Add(onoff1.Install(wifiApNodes.Get(1)));
593
594 apps_sink.Start(Seconds(0.5));
595 apps_sink.Stop(simuTime);
596
597 //------------------------------------------------------------
598 //-- Setup stats and data collection
599 //--------------------------------------------
600
601 // Statistics counters
602 NodeStatistics statisticsAp0 = NodeStatistics(wifiApDevices, wifiStaDevices);
603 NodeStatistics statisticsAp1 = NodeStatistics(wifiApDevices, wifiStaDevices);
604
605 // Register packet receptions to calculate throughput
606 Config::Connect("/NodeList/2/ApplicationList/*/$ns3::PacketSink/Rx",
607 MakeCallback(&NodeStatistics::RxCallback, &statisticsAp0));
608 Config::Connect("/NodeList/3/ApplicationList/*/$ns3::PacketSink/Rx",
609 MakeCallback(&NodeStatistics::RxCallback, &statisticsAp1));
610
611 // Register power and rate changes to calculate the Average Transmit Power
612 Config::Connect("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
613 manager + "/PowerChange",
615 Config::Connect("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
616 manager + "/RateChange",
618 Config::Connect("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
619 manager + "/PowerChange",
621 Config::Connect("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
622 manager + "/RateChange",
624
625 Config::Connect("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
626 MakeCallback(&NodeStatistics::PhyCallback, &statisticsAp0));
627 Config::Connect("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin",
628 MakeCallback(&NodeStatistics::PhyCallback, &statisticsAp1));
629
630 // Register States
632 "/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
635 "/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/State/State",
637
638 statisticsAp0.CheckStatistics(1);
639 statisticsAp1.CheckStatistics(1);
640
641 // Callbacks to print every change of power and rate
642 Config::Connect("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
643 manager + "/PowerChange",
645 Config::Connect("/NodeList/[0-1]/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$" +
646 manager + "/RateChange",
648
649 // Calculate Throughput using Flowmonitor
650
651 FlowMonitorHelper flowmon;
652 Ptr<FlowMonitor> monitor = flowmon.InstallAll();
653
654 Simulator::Stop(simuTime);
656
658 std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
659 for (auto i = stats.begin(); i != stats.end(); ++i)
660 {
661 Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(i->first);
662 if (t.sourceAddress == "10.1.1.3" && t.destinationAddress == "10.1.1.1")
663 {
664 NS_LOG_INFO("Flow " << i->first << " (" << t.sourceAddress << " -> "
665 << t.destinationAddress << ")\n");
666 NS_LOG_INFO(" Tx Bytes: " << i->second.txBytes << "\n");
667 NS_LOG_INFO(" Rx Bytes: " << i->second.rxBytes << "\n");
668 NS_LOG_UNCOND(" Throughput to 10.1.1.1: "
669 << i->second.rxBytes * 8.0 /
670 (i->second.timeLastRxPacket.GetSeconds() -
671 i->second.timeFirstTxPacket.GetSeconds()) /
672 1024 / 1024
673 << " Mbps\n");
674 NS_LOG_INFO(" Mean delay: " << i->second.delaySum.GetSeconds() / i->second.rxPackets
675 << "\n");
676 NS_LOG_INFO(" Mean jitter: "
677 << i->second.jitterSum.GetSeconds() / (i->second.rxPackets - 1) << "\n");
678 NS_LOG_INFO(" Tx Opp: " << 1 - (statisticsAp0.GetBusyTime() / simuTime.GetSeconds()));
679 }
680 if (t.sourceAddress == "10.1.1.4" && t.destinationAddress == "10.1.1.2")
681 {
682 NS_LOG_INFO("Flow " << i->first << " (" << t.sourceAddress << " -> "
683 << t.destinationAddress << ")\n");
684 NS_LOG_INFO(" Tx Bytes: " << i->second.txBytes << "\n");
685 NS_LOG_INFO(" Rx Bytes: " << i->second.rxBytes << "\n");
686 NS_LOG_UNCOND(" Throughput to 10.1.1.2: "
687 << i->second.rxBytes * 8.0 /
688 (i->second.timeLastRxPacket.GetSeconds() -
689 i->second.timeFirstTxPacket.GetSeconds()) /
690 1024 / 1024
691 << " Mbps\n");
692 NS_LOG_INFO(" Mean delay: " << i->second.delaySum.GetSeconds() / i->second.rxPackets
693 << "\n");
694 NS_LOG_INFO(" Mean jitter: "
695 << i->second.jitterSum.GetSeconds() / (i->second.rxPackets - 1) << "\n");
696 NS_LOG_INFO(" Tx Opp: " << 1 - (statisticsAp1.GetBusyTime() / simuTime.GetSeconds()));
697 }
698 }
699
700 // Plots for AP0
701 std::ofstream outfileTh0("throughput-" + outputFileName + "-0.plt");
702 Gnuplot gnuplot = Gnuplot("throughput-" + outputFileName + "-0.eps", "Throughput");
703 gnuplot.SetTerminal("post eps color enhanced");
704 gnuplot.SetLegend("Time (seconds)", "Throughput (Mb/s)");
705 gnuplot.SetTitle("Throughput (AP0 to STA) vs time");
706 gnuplot.AddDataset(statisticsAp0.GetDatafile());
707 gnuplot.GenerateOutput(outfileTh0);
708
709 if (manager == "ns3::ParfWifiManager" || manager == "ns3::AparfWifiManager" ||
710 manager == "ns3::RrpaaWifiManager")
711 {
712 std::ofstream outfilePower0("power-" + outputFileName + "-0.plt");
713 gnuplot = Gnuplot("power-" + outputFileName + "-0.eps", "Average Transmit Power");
714 gnuplot.SetTerminal("post eps color enhanced");
715 gnuplot.SetLegend("Time (seconds)", "Power (mW)");
716 gnuplot.SetTitle("Average transmit power (AP0 to STA) vs time");
717 gnuplot.AddDataset(statisticsAp0.GetPowerDatafile());
718 gnuplot.GenerateOutput(outfilePower0);
719 }
720
721 std::ofstream outfileTx0("tx-" + outputFileName + "-0.plt");
722 gnuplot = Gnuplot("tx-" + outputFileName + "-0.eps", "Time in TX State");
723 gnuplot.SetTerminal("post eps color enhanced");
724 gnuplot.SetLegend("Time (seconds)", "Percent");
725 gnuplot.SetTitle("Percentage time AP0 in TX state vs time");
726 gnuplot.AddDataset(statisticsAp0.GetTxDatafile());
727 gnuplot.GenerateOutput(outfileTx0);
728
729 std::ofstream outfileRx0("rx-" + outputFileName + "-0.plt");
730 gnuplot = Gnuplot("rx-" + outputFileName + "-0.eps", "Time in RX State");
731 gnuplot.SetTerminal("post eps color enhanced");
732 gnuplot.SetLegend("Time (seconds)", "Percent");
733 gnuplot.SetTitle("Percentage time AP0 in RX state vs time");
734 gnuplot.AddDataset(statisticsAp0.GetRxDatafile());
735 gnuplot.GenerateOutput(outfileRx0);
736
737 std::ofstream outfileBusy0("busy-" + outputFileName + "-0.plt");
738 gnuplot = Gnuplot("busy-" + outputFileName + "-0.eps", "Time in Busy State");
739 gnuplot.SetTerminal("post eps color enhanced");
740 gnuplot.SetLegend("Time (seconds)", "Percent");
741 gnuplot.SetTitle("Percentage time AP0 in Busy state vs time");
742 gnuplot.AddDataset(statisticsAp0.GetBusyDatafile());
743 gnuplot.GenerateOutput(outfileBusy0);
744
745 std::ofstream outfileIdle0("idle-" + outputFileName + "-0.plt");
746 gnuplot = Gnuplot("idle-" + outputFileName + "-0.eps", "Time in Idle State");
747 gnuplot.SetTerminal("post eps color enhanced");
748 gnuplot.SetLegend("Time (seconds)", "Percent");
749 gnuplot.SetTitle("Percentage time AP0 in Idle state vs time");
750 gnuplot.AddDataset(statisticsAp0.GetIdleDatafile());
751 gnuplot.GenerateOutput(outfileIdle0);
752
753 // Plots for AP1
754 std::ofstream outfileTh1("throughput-" + outputFileName + "-1.plt");
755 gnuplot = Gnuplot("throughput-" + outputFileName + "-1.eps", "Throughput");
756 gnuplot.SetTerminal("post eps color enhanced");
757 gnuplot.SetLegend("Time (seconds)", "Throughput (Mb/s)");
758 gnuplot.SetTitle("Throughput (AP1 to STA) vs time");
759 gnuplot.AddDataset(statisticsAp1.GetDatafile());
760 gnuplot.GenerateOutput(outfileTh1);
761
762 if (manager == "ns3::ParfWifiManager" || manager == "ns3::AparfWifiManager" ||
763 manager == "ns3::RrpaaWifiManager")
764 {
765 std::ofstream outfilePower1("power-" + outputFileName + "-1.plt");
766 gnuplot = Gnuplot("power-" + outputFileName + "-1.eps", "Average Transmit Power");
767 gnuplot.SetTerminal("post eps color enhanced");
768 gnuplot.SetLegend("Time (seconds)", "Power (mW)");
769 gnuplot.SetTitle("Average transmit power (AP1 to STA) vs time");
770 gnuplot.AddDataset(statisticsAp1.GetPowerDatafile());
771 gnuplot.GenerateOutput(outfilePower1);
772 }
773
774 std::ofstream outfileTx1("tx-" + outputFileName + "-1.plt");
775 gnuplot = Gnuplot("tx-" + outputFileName + "-1.eps", "Time in TX State");
776 gnuplot.SetTerminal("post eps color enhanced");
777 gnuplot.SetLegend("Time (seconds)", "Percent");
778 gnuplot.SetTitle("Percentage time AP1 in TX state vs time");
779 gnuplot.AddDataset(statisticsAp1.GetTxDatafile());
780 gnuplot.GenerateOutput(outfileTx1);
781
782 std::ofstream outfileRx1("rx-" + outputFileName + "-1.plt");
783 gnuplot = Gnuplot("rx-" + outputFileName + "-1.eps", "Time in RX State");
784 gnuplot.SetTerminal("post eps color enhanced");
785 gnuplot.SetLegend("Time (seconds)", "Percent");
786 gnuplot.SetTitle("Percentage time AP1 in RX state vs time");
787 gnuplot.AddDataset(statisticsAp1.GetRxDatafile());
788 gnuplot.GenerateOutput(outfileRx1);
789
790 std::ofstream outfileBusy1("busy-" + outputFileName + "-1.plt");
791 gnuplot = Gnuplot("busy-" + outputFileName + "-1.eps", "Time in Busy State");
792 gnuplot.SetTerminal("post eps color enhanced");
793 gnuplot.SetLegend("Time (seconds)", "Percent");
794 gnuplot.SetTitle("Percentage time AP1 in Busy state vs time");
795 gnuplot.AddDataset(statisticsAp1.GetBusyDatafile());
796 gnuplot.GenerateOutput(outfileBusy1);
797
798 std::ofstream outfileIdle1("idle-" + outputFileName + "-1.plt");
799 gnuplot = Gnuplot("idle-" + outputFileName + "-1.eps", "Time in Idle State");
800 gnuplot.SetTerminal("post eps color enhanced");
801 gnuplot.SetLegend("Time (seconds)", "Percent");
802 gnuplot.SetTitle("Percentage time AP1 in Idle state vs time");
803 gnuplot.AddDataset(statisticsAp1.GetIdleDatafile());
804 gnuplot.GenerateOutput(outfileIdle1);
805
807
808 return 0;
809}
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 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.
std::map< Mac48Address, dBm_u > m_currentPower
Current Tx power 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:90
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.
Class for representing data rates.
Definition data-rate.h:78
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
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:105
void Add(double x, double y)
Definition gnuplot.cc:366
void SetTitle(const std::string &title)
Change line title.
Definition gnuplot.cc:137
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition gnuplot.h:359
void AddDataset(const GnuplotDataset &dataset)
Definition gnuplot.cc:785
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition gnuplot.cc:765
void SetTerminal(const std::string &terminal)
Definition gnuplot.cc:753
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition gnuplot.cc:791
void SetTitle(const std::string &title)
Definition gnuplot.cc:759
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.
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
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.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
The IEEE 802.11 SSID Information Element.
Definition ssid.h:25
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
Hold an unsigned integer type.
Definition uinteger.h:34
helps to create WifiNetDevice objects
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr1() const
Return the address in the Address 1 field.
virtual 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)
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetChannelWidth(MHz_u channelWidth)
Sets the selected channelWidth.
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:33
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
void Connect(std::string path, const CallbackBase &cb)
Definition config.cc:967
#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:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1332
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
@ WIFI_STANDARD_80211a
@ WIFI_PREAMBLE_LONG
address
Definition first.py:36
stack
Definition first.py:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiPhyState
The state of the PHY layer.
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:684
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
@ WIFI_MAC_DATA
ssid
Definition third.py:82
wifi
Definition third.py:84
mobility
Definition third.py:92
wifiStaNodes
Definition third.py:73
phy
Definition third.py:78
Structure to classify a packet.
Ipv4Address sourceAddress
Source address.
Ipv4Address destinationAddress
Destination address.
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:44