A Discrete-Event Network Simulator
API
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 
33 using namespace ns3;
34 
35 int
36 main(int argc, char* argv[])
37 {
38  uint32_t FrameSize = 1500; // bytes
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", FrameSize);
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  for (uint32_t i = 0; i < modes.size(); i++)
72  {
73  std::cout << modes[i] << std::endl;
74  Gnuplot2dDataset yansdataset(modes[i]);
75  Gnuplot2dDataset nistdataset(modes[i]);
76  Gnuplot2dDataset tabledataset(modes[i]);
77  txVector.SetMode(modes[i]);
78 
79  for (double snr = -5.0; snr <= 40.0; snr += 0.1)
80  {
81  double ps = yans->GetChunkSuccessRate(WifiMode(modes[i]),
82  txVector,
83  std::pow(10.0, snr / 10.0),
84  FrameSize * 8);
85  if (ps < 0.0 || ps > 1.0)
86  {
87  // error
88  exit(1);
89  }
90  yansdataset.Add(snr, ps);
91 
92  ps = nist->GetChunkSuccessRate(WifiMode(modes[i]),
93  txVector,
94  std::pow(10.0, snr / 10.0),
95  FrameSize * 8);
96  if (ps < 0.0 || ps > 1.0)
97  {
98  // error
99  exit(1);
100  }
101  nistdataset.Add(snr, ps);
102 
103  ps = table->GetChunkSuccessRate(WifiMode(modes[i]),
104  txVector,
105  std::pow(10.0, snr / 10.0),
106  FrameSize * 8);
107  if (ps < 0.0 || ps > 1.0)
108  {
109  // error
110  exit(1);
111  }
112  tabledataset.Add(snr, ps);
113  }
114 
115  yansplot.AddDataset(yansdataset);
116  nistplot.AddDataset(nistdataset);
117  tableplot.AddDataset(tabledataset);
118  }
119 
120  yansplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
121  yansplot.SetLegend("SNR(dB)", "Frame Success Rate");
122  yansplot.SetExtra("set xrange [-5:55]\n\
123 set yrange [0:1]\n\
124 set style line 1 linewidth 5\n\
125 set style line 2 linewidth 5\n\
126 set style line 3 linewidth 5\n\
127 set style line 4 linewidth 5\n\
128 set style line 5 linewidth 5\n\
129 set style line 6 linewidth 5\n\
130 set style line 7 linewidth 5\n\
131 set style line 8 linewidth 5\n\
132 set style line 9 linewidth 5\n\
133 set style line 10 linewidth 5\n\
134 set style line 11 linewidth 5\n\
135 set style line 12 linewidth 5\n\
136 set style increment user");
137  yansplot.GenerateOutput(yansfile);
138  yansfile.close();
139 
140  nistplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
141  nistplot.SetLegend("SNR(dB)", "Frame Success Rate");
142  nistplot.SetExtra("set xrange [-5:55]\n\
143 set yrange [0:1]\n\
144 set style line 1 linewidth 5\n\
145 set style line 2 linewidth 5\n\
146 set style line 3 linewidth 5\n\
147 set style line 4 linewidth 5\n\
148 set style line 5 linewidth 5\n\
149 set style line 6 linewidth 5\n\
150 set style line 7 linewidth 5\n\
151 set style line 8 linewidth 5\n\
152 set style line 9 linewidth 5\n\
153 set style line 10 linewidth 5\n\
154 set style line 11 linewidth 5\n\
155 set style line 12 linewidth 5\n\
156 set style increment user");
157 
158  nistplot.GenerateOutput(nistfile);
159  nistfile.close();
160 
161  tableplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
162  tableplot.SetLegend("SNR(dB)", "Frame Success Rate");
163  tableplot.SetExtra("set xrange [-5:55]\n\
164 set yrange [0:1]\n\
165 set style line 1 linewidth 5\n\
166 set style line 2 linewidth 5\n\
167 set style line 3 linewidth 5\n\
168 set style line 4 linewidth 5\n\
169 set style line 5 linewidth 5\n\
170 set style line 6 linewidth 5\n\
171 set style line 7 linewidth 5\n\
172 set style line 8 linewidth 5\n\
173 set style line 9 linewidth 5\n\
174 set style line 10 linewidth 5\n\
175 set style line 11 linewidth 5\n\
176 set style line 12 linewidth 5\n\
177 set style increment user");
178 
179  tableplot.GenerateOutput(tablefile);
180  tablefile.close();
181 
182  return 0;
183 }
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:50
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.
cmd
Definition: second.py:33