A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-ofdm-vht-validation.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
5 */
6
7// This example is used to validate Nist, Yans and Table-based error rate models for VHT rates.
8//
9// It outputs plots of the Frame Success Rate versus the Signal-to-noise ratio for
10// Nist, Yans and Table-based error rate models and for every VHT MCS value (MCS 9 is not
11// included since it is forbidden for 20 MHz channels).
12
13#include "ns3/command-line.h"
14#include "ns3/gnuplot.h"
15#include "ns3/nist-error-rate-model.h"
16#include "ns3/table-based-error-rate-model.h"
17#include "ns3/wifi-tx-vector.h"
18#include "ns3/yans-error-rate-model.h"
19
20#include <cmath>
21#include <fstream>
22
23using namespace ns3;
24
25int
26main(int argc, char* argv[])
27{
28 uint32_t frameSizeBytes = 1500;
29 std::ofstream yansfile("yans-frame-success-rate-ac.plt");
30 std::ofstream nistfile("nist-frame-success-rate-ac.plt");
31 std::ofstream tablefile("table-frame-success-rate-ac.plt");
32
33 const std::vector<std::string> modes{
34 "VhtMcs0",
35 "VhtMcs1",
36 "VhtMcs2",
37 "VhtMcs3",
38 "VhtMcs4",
39 "VhtMcs5",
40 "VhtMcs6",
41 "VhtMcs7",
42 "VhtMcs8",
43 };
44
45 CommandLine cmd(__FILE__);
46 cmd.AddValue("FrameSize", "The frame size in bytes", frameSizeBytes);
47 cmd.Parse(argc, argv);
48
49 Gnuplot yansplot = Gnuplot("yans-frame-success-rate-ac.eps");
50 Gnuplot nistplot = Gnuplot("nist-frame-success-rate-ac.eps");
51 Gnuplot tableplot = Gnuplot("table-frame-success-rate-ac.eps");
52
56 WifiTxVector txVector;
57
58 uint32_t frameSizeBits = frameSizeBytes * 8;
59
60 for (const auto& mode : modes)
61 {
62 std::cout << mode << std::endl;
63 Gnuplot2dDataset yansdataset(mode);
64 Gnuplot2dDataset nistdataset(mode);
65 Gnuplot2dDataset tabledataset(mode);
66 txVector.SetMode(mode);
67
68 WifiMode wifiMode(mode);
69
70 for (double snrDb = -5.0; snrDb <= 30.0; snrDb += 0.1)
71 {
72 double snr = std::pow(10.0, snrDb / 10.0);
73
74 double ps = yans->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
75 if (ps < 0.0 || ps > 1.0)
76 {
77 // error
78 exit(1);
79 }
80 yansdataset.Add(snrDb, ps);
81
82 ps = nist->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
83 if (ps < 0.0 || ps > 1.0)
84 {
85 // error
86 exit(1);
87 }
88 nistdataset.Add(snrDb, ps);
89
90 ps = table->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
91 if (ps < 0.0 || ps > 1.0)
92 {
93 // error
94 exit(1);
95 }
96 tabledataset.Add(snrDb, ps);
97 }
98
99 yansplot.AddDataset(yansdataset);
100 nistplot.AddDataset(nistdataset);
101 tableplot.AddDataset(tabledataset);
102 }
103
104 yansplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
105 yansplot.SetLegend("SNR(dB)", "Frame Success Rate");
106 yansplot.SetExtra("set xrange [-5:55]\n\
107set yrange [0:1]\n\
108set style line 1 linewidth 5\n\
109set style line 2 linewidth 5\n\
110set style line 3 linewidth 5\n\
111set style line 4 linewidth 5\n\
112set style line 5 linewidth 5\n\
113set style line 6 linewidth 5\n\
114set style line 7 linewidth 5\n\
115set style line 8 linewidth 5\n\
116set style line 9 linewidth 5\n\
117set style increment user");
118 yansplot.GenerateOutput(yansfile);
119 yansfile.close();
120
121 nistplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
122 nistplot.SetLegend("SNR(dB)", "Frame Success Rate");
123 nistplot.SetExtra("set xrange [-5:55]\n\
124set yrange [0:1]\n\
125set style line 1 linewidth 5\n\
126set style line 2 linewidth 5\n\
127set style line 3 linewidth 5\n\
128set style line 4 linewidth 5\n\
129set style line 5 linewidth 5\n\
130set style line 6 linewidth 5\n\
131set style line 7 linewidth 5\n\
132set style line 8 linewidth 5\n\
133set style line 9 linewidth 5\n\
134set style increment user");
135
136 nistplot.GenerateOutput(nistfile);
137 nistfile.close();
138
139 tableplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
140 tableplot.SetLegend("SNR(dB)", "Frame Success Rate");
141 tableplot.SetExtra("set xrange [-5:55]\n\
142set yrange [0:1]\n\
143set style line 1 linewidth 5\n\
144set style line 2 linewidth 5\n\
145set style line 3 linewidth 5\n\
146set style line 4 linewidth 5\n\
147set style line 5 linewidth 5\n\
148set style line 6 linewidth 5\n\
149set style line 7 linewidth 5\n\
150set style line 8 linewidth 5\n\
151set style line 9 linewidth 5\n\
152set style increment user");
153
154 tableplot.GenerateOutput(tablefile);
155 tablefile.close();
156
157 return 0;
158}
Parse command-line arguments.
Class to represent a 2D points plot.
Definition gnuplot.h:105
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 SetExtra(const std::string &extra)
Definition gnuplot.cc:772
Smart pointer class similar to boost::intrusive_ptr.
represent a single transmission mode
Definition wifi-mode.h:40
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Every class exported by the ns3 library is enclosed in the ns3 namespace.