A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-error-models-comparison.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 University of Washington
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 * Authors: Sébastien Deronne <sebastien.deronne@gmail.com>
18 * Rohan Patidar <rpatidar@uw.edu>
19 */
20
21// This example is to show difference among Nist, Yans and Table-based error rate models.
22//
23// It outputs plots of the Frame Error Rate versus the Signal-to-noise ratio for
24// Nist, Yans and Table-based error rate models and for MCS 0, 4 and 7 value.
25
26#include "ns3/command-line.h"
27#include "ns3/gnuplot.h"
28#include "ns3/nist-error-rate-model.h"
29#include "ns3/table-based-error-rate-model.h"
30#include "ns3/wifi-tx-vector.h"
31#include "ns3/yans-error-rate-model.h"
32
33#include <cmath>
34#include <fstream>
35
36using namespace ns3;
37
38int
39main(int argc, char* argv[])
40{
41 uint32_t size = 1500 * 8; // bits
42 bool tableErrorModelEnabled = true;
43 bool yansErrorModelEnabled = true;
44 bool nistErrorModelEnabled = true;
45 uint8_t beginMcs = 0;
46 uint8_t endMcs = 7;
47 uint8_t stepMcs = 4;
48 std::string format("Ht");
49
50 CommandLine cmd(__FILE__);
51 cmd.AddValue("size", "The size in bits", size);
52 cmd.AddValue("frameFormat", "The frame format to use: Ht, Vht or He", format);
53 cmd.AddValue("beginMcs", "The first MCS to test", beginMcs);
54 cmd.AddValue("endMcs", "The last MCS to test", endMcs);
55 cmd.AddValue("stepMcs", "The step between two MCSs to test", stepMcs);
56 cmd.AddValue("includeTableErrorModel",
57 "Flag to include/exclude Table-based error model",
58 tableErrorModelEnabled);
59 cmd.AddValue("includeYansErrorModel",
60 "Flag to include/exclude Yans error model",
61 yansErrorModelEnabled);
62 cmd.AddValue("includeNistErrorModel",
63 "Flag to include/exclude Nist error model",
64 nistErrorModelEnabled);
65 cmd.Parse(argc, argv);
66
67 std::ofstream errormodelfile("wifi-error-rate-models.plt");
68 Gnuplot plot = Gnuplot("wifi-error-rate-models.eps");
69
70 Ptr<YansErrorRateModel> yans = CreateObject<YansErrorRateModel>();
71 Ptr<NistErrorRateModel> nist = CreateObject<NistErrorRateModel>();
72 Ptr<TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel>();
73 WifiTxVector txVector;
74 std::vector<std::string> modes;
75
76 std::stringstream mode;
77 mode << format << "Mcs" << +beginMcs;
78 modes.push_back(mode.str());
79 for (uint8_t mcs = (beginMcs + stepMcs); mcs < endMcs; mcs += stepMcs)
80 {
81 mode.str("");
82 mode << format << "Mcs" << +mcs;
83 modes.push_back(mode.str());
84 }
85 mode.str("");
86 mode << format << "Mcs" << +endMcs;
87 modes.push_back(mode.str());
88
89 for (const auto& mode : modes)
90 {
91 std::cout << mode << std::endl;
92 Gnuplot2dDataset yansdataset(mode);
93 Gnuplot2dDataset nistdataset(mode);
94 Gnuplot2dDataset tabledataset(mode);
95 txVector.SetMode(mode);
96
97 WifiMode wifiMode(mode);
98
99 for (double snrDb = -5.0; snrDb <= (endMcs * 5); snrDb += 0.1)
100 {
101 double snr = std::pow(10.0, snrDb / 10.0);
102
103 double ps = yans->GetChunkSuccessRate(wifiMode, txVector, snr, size);
104 if (ps < 0 || ps > 1)
105 {
106 // error
107 exit(1);
108 }
109 yansdataset.Add(snrDb, 1 - ps);
110 ps = nist->GetChunkSuccessRate(wifiMode, txVector, snr, size);
111 if (ps < 0 || ps > 1)
112 {
113 // error
114 exit(1);
115 }
116 nistdataset.Add(snrDb, 1 - ps);
117 ps = table->GetChunkSuccessRate(wifiMode, txVector, snr, size);
118 if (ps < 0 || ps > 1)
119 {
120 // error
121 exit(1);
122 }
123 tabledataset.Add(snrDb, 1 - ps);
124 }
125
126 if (tableErrorModelEnabled)
127 {
128 std::stringstream ss;
129 ss << "Table-" << mode;
130 tabledataset.SetTitle(ss.str());
131 plot.AddDataset(tabledataset);
132 }
133 if (yansErrorModelEnabled)
134 {
135 std::stringstream ss;
136 ss << "Yans-" << mode;
137 yansdataset.SetTitle(ss.str());
138 plot.AddDataset(yansdataset);
139 }
140 if (nistErrorModelEnabled)
141 {
142 std::stringstream ss;
143 ss << "Nist-" << mode;
144 nistdataset.SetTitle(ss.str());
145 plot.AddDataset(nistdataset);
146 }
147 }
148
149 plot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
150 plot.SetLegend("SNR(dB)", "Frame Error Rate");
151
152 std::stringstream plotExtra;
153 plotExtra << "set xrange [-5:" << endMcs * 5 << "]\n\
154set log y\n\
155set yrange [0.0001:1]\n";
156
157 uint8_t lineNumber = 1;
158 for (uint32_t i = 0; i < modes.size(); i++)
159 {
160 if (tableErrorModelEnabled)
161 {
162 plotExtra << "set style line " << +lineNumber++
163 << " linewidth 5 linecolor rgb \"red\" \n";
164 }
165 if (yansErrorModelEnabled)
166 {
167 plotExtra << "set style line " << +lineNumber++
168 << " linewidth 5 linecolor rgb \"green\" \n";
169 }
170 if (nistErrorModelEnabled)
171 {
172 plotExtra << "set style line " << +lineNumber++
173 << " linewidth 5 linecolor rgb \"blue\" \n";
174 }
175 }
176
177 plotExtra << "set style increment user";
178 plot.SetExtra(plotExtra.str());
179
180 plot.GenerateOutput(errormodelfile);
181 errormodelfile.close();
182
183 return 0;
184}
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