A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-ofdm-he-validation.cc
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation;
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 *
15 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
16 */
17
18// This example is used to validate Nist, Yans and Table-based error rate models for HE rates.
19//
20// It outputs plots of the Frame Success Rate versus the Signal-to-noise ratio for
21// Nist, Yans and Table-based error rate models and for every HE MCS value.
22
23#include "ns3/command-line.h"
24#include "ns3/gnuplot.h"
25#include "ns3/nist-error-rate-model.h"
26#include "ns3/table-based-error-rate-model.h"
27#include "ns3/wifi-tx-vector.h"
28#include "ns3/yans-error-rate-model.h"
29
30#include <cmath>
31#include <fstream>
32
33using namespace ns3;
34
35int
36main(int argc, char* argv[])
37{
38 uint32_t frameSizeBytes = 1500;
39 std::ofstream yansfile("yans-frame-success-rate-ax.plt");
40 std::ofstream nistfile("nist-frame-success-rate-ax.plt");
41 std::ofstream tablefile("table-frame-success-rate-ax.plt");
42
43 const std::vector<std::string> modes{
44 "HeMcs0",
45 "HeMcs1",
46 "HeMcs2",
47 "HeMcs3",
48 "HeMcs4",
49 "HeMcs5",
50 "HeMcs6",
51 "HeMcs7",
52 "HeMcs8",
53 "HeMcs9",
54 "HeMcs10",
55 "HeMcs11",
56 };
57
58 CommandLine cmd(__FILE__);
59 cmd.AddValue("FrameSize", "The frame size", frameSizeBytes);
60 cmd.Parse(argc, argv);
61
62 Gnuplot yansplot = Gnuplot("yans-frame-success-rate-ax.eps");
63 Gnuplot nistplot = Gnuplot("nist-frame-success-rate-ax.eps");
64 Gnuplot tableplot = Gnuplot("table-frame-success-rate-ax.eps");
65
66 Ptr<YansErrorRateModel> yans = CreateObject<YansErrorRateModel>();
67 Ptr<NistErrorRateModel> nist = CreateObject<NistErrorRateModel>();
68 Ptr<TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel>();
69 WifiTxVector txVector;
70
71 uint32_t frameSizeBits = frameSizeBytes * 8;
72
73 for (const auto& mode : modes)
74 {
75 std::cout << mode << std::endl;
76 Gnuplot2dDataset yansdataset(mode);
77 Gnuplot2dDataset nistdataset(mode);
78 Gnuplot2dDataset tabledataset(mode);
79 txVector.SetMode(mode);
80
81 WifiMode wifiMode(mode);
82
83 for (double snrDb = -5.0; snrDb <= 40.0; snrDb += 0.1)
84 {
85 double snr = std::pow(10.0, snrDb / 10.0);
86
87 double ps = yans->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
88 if (ps < 0.0 || ps > 1.0)
89 {
90 // error
91 exit(1);
92 }
93 yansdataset.Add(snrDb, ps);
94
95 ps = nist->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
96 if (ps < 0.0 || ps > 1.0)
97 {
98 // error
99 exit(1);
100 }
101 nistdataset.Add(snrDb, ps);
102
103 ps = table->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
104 if (ps < 0.0 || ps > 1.0)
105 {
106 // error
107 exit(1);
108 }
109 tabledataset.Add(snrDb, ps);
110 }
111
112 yansplot.AddDataset(yansdataset);
113 nistplot.AddDataset(nistdataset);
114 tableplot.AddDataset(tabledataset);
115 }
116
117 yansplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
118 yansplot.SetLegend("SNR(dB)", "Frame Success Rate");
119 yansplot.SetExtra("set xrange [-5:55]\n\
120set yrange [0:1]\n\
121set style line 1 linewidth 5\n\
122set style line 2 linewidth 5\n\
123set style line 3 linewidth 5\n\
124set style line 4 linewidth 5\n\
125set style line 5 linewidth 5\n\
126set style line 6 linewidth 5\n\
127set style line 7 linewidth 5\n\
128set style line 8 linewidth 5\n\
129set style line 9 linewidth 5\n\
130set style line 10 linewidth 5\n\
131set style line 11 linewidth 5\n\
132set style line 12 linewidth 5\n\
133set style increment user");
134 yansplot.GenerateOutput(yansfile);
135 yansfile.close();
136
137 nistplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
138 nistplot.SetLegend("SNR(dB)", "Frame Success Rate");
139 nistplot.SetExtra("set xrange [-5:55]\n\
140set yrange [0:1]\n\
141set style line 1 linewidth 5\n\
142set style line 2 linewidth 5\n\
143set style line 3 linewidth 5\n\
144set style line 4 linewidth 5\n\
145set style line 5 linewidth 5\n\
146set style line 6 linewidth 5\n\
147set style line 7 linewidth 5\n\
148set style line 8 linewidth 5\n\
149set style line 9 linewidth 5\n\
150set style line 10 linewidth 5\n\
151set style line 11 linewidth 5\n\
152set style line 12 linewidth 5\n\
153set style increment user");
154
155 nistplot.GenerateOutput(nistfile);
156 nistfile.close();
157
158 tableplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
159 tableplot.SetLegend("SNR(dB)", "Frame Success Rate");
160 tableplot.SetExtra("set xrange [-5:55]\n\
161set yrange [0:1]\n\
162set style line 1 linewidth 5\n\
163set style line 2 linewidth 5\n\
164set style line 3 linewidth 5\n\
165set style line 4 linewidth 5\n\
166set style line 5 linewidth 5\n\
167set style line 6 linewidth 5\n\
168set style line 7 linewidth 5\n\
169set style line 8 linewidth 5\n\
170set style line 9 linewidth 5\n\
171set style line 10 linewidth 5\n\
172set style line 11 linewidth 5\n\
173set style line 12 linewidth 5\n\
174set style increment user");
175
176 tableplot.GenerateOutput(tablefile);
177 tablefile.close();
178
179 return 0;
180}
Parse command-line arguments.
Definition: command-line.h:232
Class to represent a 2D points plot.
Definition: gnuplot.h:116
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 SetExtra(const std::string &extra)
Definition: gnuplot.cc:783
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
represent a single transmission mode
Definition: wifi-mode.h:51
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns cmd
Definition: second.py:40