A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-ofdm-eht-validation.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 DERONNE SOFTWARE ENGINEERING
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: Sébastien Deronne <sebastien.deronne@gmail.com>
18 */
19
20// This example is used to validate NIST and YANS error rate models for EHT rates.
21//
22// It outputs plots of the Frame Success Rate versus the Signal-to-noise ratio for
23// Nist, Yans and Table-based error rate models and for every HT MCS value.
24
25#include "ns3/command-line.h"
26#include "ns3/gnuplot.h"
27#include "ns3/nist-error-rate-model.h"
28#include "ns3/table-based-error-rate-model.h"
29#include "ns3/wifi-tx-vector.h"
30#include "ns3/yans-error-rate-model.h"
31
32#include <cmath>
33#include <fstream>
34
35using namespace ns3;
36
37int
38main(int argc, char* argv[])
39{
40 uint32_t FrameSize = 1500; // bytes
41 std::ofstream yansfile("yans-frame-success-rate-be.plt");
42 std::ofstream nistfile("nist-frame-success-rate-be.plt");
43 std::ofstream tablefile("table-frame-success-rate-be.plt");
44
45 const std::vector<std::string> modes{
46 "EhtMcs0",
47 "EhtMcs1",
48 "EhtMcs2",
49 "EhtMcs3",
50 "EhtMcs4",
51 "EhtMcs5",
52 "EhtMcs6",
53 "EhtMcs7",
54 "EhtMcs8",
55 "EhtMcs9",
56 "EhtMcs10",
57 "EhtMcs11",
58 "EhtMcs12",
59 "EhtMcs13",
60 };
61
62 CommandLine cmd(__FILE__);
63 cmd.AddValue("FrameSize", "The frame size", FrameSize);
64 cmd.Parse(argc, argv);
65
66 Gnuplot yansplot = Gnuplot("yans-frame-success-rate-be.eps");
67 Gnuplot nistplot = Gnuplot("nist-frame-success-rate-be.eps");
68 Gnuplot tableplot = Gnuplot("table-frame-success-rate-be.eps");
69
70 Ptr<YansErrorRateModel> yans = CreateObject<YansErrorRateModel>();
71 Ptr<NistErrorRateModel> nist = CreateObject<NistErrorRateModel>();
72 Ptr<TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel>();
73 WifiTxVector txVector;
74
75 for (uint32_t i = 0; i < modes.size(); i++)
76 {
77 std::cout << modes[i] << std::endl;
78 Gnuplot2dDataset yansdataset(modes[i]);
79 Gnuplot2dDataset nistdataset(modes[i]);
80 Gnuplot2dDataset tabledataset(modes[i]);
81 txVector.SetMode(modes[i]);
82
83 for (double snr = -5.0; snr <= 55.0; snr += 0.1)
84 {
85 double ps = yans->GetChunkSuccessRate(WifiMode(modes[i]),
86 txVector,
87 std::pow(10.0, snr / 10.0),
88 FrameSize * 8);
89 if (ps < 0.0 || ps > 1.0)
90 {
91 // error
92 exit(1);
93 }
94 yansdataset.Add(snr, ps);
95
96 ps = nist->GetChunkSuccessRate(WifiMode(modes[i]),
97 txVector,
98 std::pow(10.0, snr / 10.0),
99 FrameSize * 8);
100 if (ps < 0.0 || ps > 1.0)
101 {
102 // error
103 exit(1);
104 }
105 nistdataset.Add(snr, ps);
106
107 ps = table->GetChunkSuccessRate(WifiMode(modes[i]),
108 txVector,
109 std::pow(10.0, snr / 10.0),
110 FrameSize * 8);
111 if (ps < 0.0 || ps > 1.0)
112 {
113 // error
114 exit(1);
115 }
116 tabledataset.Add(snr, ps);
117 }
118
119 yansplot.AddDataset(yansdataset);
120 nistplot.AddDataset(nistdataset);
121 tableplot.AddDataset(tabledataset);
122 }
123
124 std::stringstream plotExtra;
125 plotExtra << "set xrange [-5:55]\n\
126set yrange [0:1]\n";
127
128 const std::vector<std::string> colors{
129 "green",
130 "blue",
131 "red",
132 "black",
133 "orange",
134 "purple",
135 "yellow",
136 "pink",
137 "grey",
138 "magenta",
139 "brown",
140 "turquoise",
141 "olive",
142 "beige",
143 };
144
145 NS_ASSERT_MSG(colors.size() == modes.size(), "Colors and modes vectors have different sizes");
146
147 for (std::size_t i = 0; i < modes.size(); i++)
148 {
149 plotExtra << "set style line " << (i + 1) << " linewidth 5 linecolor rgb \"" << colors[i]
150 << "\" \n";
151 }
152 plotExtra << "set style increment user";
153
154 yansplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
155 yansplot.SetLegend("SNR(dB)", "Frame Success Rate");
156 yansplot.SetExtra(plotExtra.str());
157 yansplot.GenerateOutput(yansfile);
158 yansfile.close();
159
160 nistplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
161 nistplot.SetLegend("SNR(dB)", "Frame Success Rate");
162 nistplot.SetExtra(plotExtra.str());
163 nistplot.GenerateOutput(nistfile);
164 nistfile.close();
165
166 tableplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
167 tableplot.SetLegend("SNR(dB)", "Frame Success Rate");
168 tableplot.SetExtra(plotExtra.str());
169 tableplot.GenerateOutput(tablefile);
170 tablefile.close();
171
172 return 0;
173}
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:78
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.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns cmd
Definition: second.py:33