A Discrete-Event Network Simulator
API
wifi-ofdm-vht-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 VHT 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 VHT MCS value (MCS 9 is not
22 // included since it is forbidden for 20 MHz channels).
23 
24 #include "ns3/command-line.h"
25 #include "ns3/gnuplot.h"
26 #include "ns3/nist-error-rate-model.h"
27 #include "ns3/table-based-error-rate-model.h"
28 #include "ns3/wifi-tx-vector.h"
29 #include "ns3/yans-error-rate-model.h"
30 
31 #include <cmath>
32 #include <fstream>
33 
34 using namespace ns3;
35 
36 int
37 main(int argc, char* argv[])
38 {
39  uint32_t FrameSize = 1500; // bytes
40  std::ofstream yansfile("yans-frame-success-rate-ac.plt");
41  std::ofstream nistfile("nist-frame-success-rate-ac.plt");
42  std::ofstream tablefile("table-frame-success-rate-ac.plt");
43 
44  const std::vector<std::string> modes{
45  "VhtMcs0",
46  "VhtMcs1",
47  "VhtMcs2",
48  "VhtMcs3",
49  "VhtMcs4",
50  "VhtMcs5",
51  "VhtMcs6",
52  "VhtMcs7",
53  "VhtMcs8",
54  };
55 
56  CommandLine cmd(__FILE__);
57  cmd.AddValue("FrameSize", "The frame size in bytes", FrameSize);
58  cmd.Parse(argc, argv);
59 
60  Gnuplot yansplot = Gnuplot("yans-frame-success-rate-ac.eps");
61  Gnuplot nistplot = Gnuplot("nist-frame-success-rate-ac.eps");
62  Gnuplot tableplot = Gnuplot("table-frame-success-rate-ac.eps");
63 
64  Ptr<YansErrorRateModel> yans = CreateObject<YansErrorRateModel>();
65  Ptr<NistErrorRateModel> nist = CreateObject<NistErrorRateModel>();
66  Ptr<TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel>();
67  WifiTxVector txVector;
68 
69  for (uint32_t i = 0; i < modes.size(); i++)
70  {
71  std::cout << modes[i] << std::endl;
72  Gnuplot2dDataset yansdataset(modes[i]);
73  Gnuplot2dDataset nistdataset(modes[i]);
74  Gnuplot2dDataset tabledataset(modes[i]);
75  txVector.SetMode(modes[i]);
76 
77  for (double snr = -5.0; snr <= 30.0; snr += 0.1)
78  {
79  double ps = yans->GetChunkSuccessRate(WifiMode(modes[i]),
80  txVector,
81  std::pow(10.0, snr / 10.0),
82  FrameSize * 8);
83  if (ps < 0.0 || ps > 1.0)
84  {
85  // error
86  exit(1);
87  }
88  yansdataset.Add(snr, ps);
89 
90  ps = nist->GetChunkSuccessRate(WifiMode(modes[i]),
91  txVector,
92  std::pow(10.0, snr / 10.0),
93  FrameSize * 8);
94  if (ps < 0.0 || ps > 1.0)
95  {
96  // error
97  exit(1);
98  }
99  nistdataset.Add(snr, ps);
100 
101  ps = table->GetChunkSuccessRate(WifiMode(modes[i]),
102  txVector,
103  std::pow(10.0, snr / 10.0),
104  FrameSize * 8);
105  if (ps < 0.0 || ps > 1.0)
106  {
107  // error
108  exit(1);
109  }
110  tabledataset.Add(snr, ps);
111  }
112 
113  yansplot.AddDataset(yansdataset);
114  nistplot.AddDataset(nistdataset);
115  tableplot.AddDataset(tabledataset);
116  }
117 
118  yansplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
119  yansplot.SetLegend("SNR(dB)", "Frame Success Rate");
120  yansplot.SetExtra("set xrange [-5:55]\n\
121 set yrange [0:1]\n\
122 set style line 1 linewidth 5\n\
123 set style line 2 linewidth 5\n\
124 set style line 3 linewidth 5\n\
125 set style line 4 linewidth 5\n\
126 set style line 5 linewidth 5\n\
127 set style line 6 linewidth 5\n\
128 set style line 7 linewidth 5\n\
129 set style line 8 linewidth 5\n\
130 set style line 9 linewidth 5\n\
131 set style increment user");
132  yansplot.GenerateOutput(yansfile);
133  yansfile.close();
134 
135  nistplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
136  nistplot.SetLegend("SNR(dB)", "Frame Success Rate");
137  nistplot.SetExtra("set xrange [-5:55]\n\
138 set yrange [0:1]\n\
139 set style line 1 linewidth 5\n\
140 set style line 2 linewidth 5\n\
141 set style line 3 linewidth 5\n\
142 set style line 4 linewidth 5\n\
143 set style line 5 linewidth 5\n\
144 set style line 6 linewidth 5\n\
145 set style line 7 linewidth 5\n\
146 set style line 8 linewidth 5\n\
147 set style line 9 linewidth 5\n\
148 set style increment user");
149 
150  nistplot.GenerateOutput(nistfile);
151  nistfile.close();
152 
153  tableplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
154  tableplot.SetLegend("SNR(dB)", "Frame Success Rate");
155  tableplot.SetExtra("set xrange [-5:55]\n\
156 set yrange [0:1]\n\
157 set style line 1 linewidth 5\n\
158 set style line 2 linewidth 5\n\
159 set style line 3 linewidth 5\n\
160 set style line 4 linewidth 5\n\
161 set style line 5 linewidth 5\n\
162 set style line 6 linewidth 5\n\
163 set style line 7 linewidth 5\n\
164 set style line 8 linewidth 5\n\
165 set style line 9 linewidth 5\n\
166 set style increment user");
167 
168  tableplot.GenerateOutput(tablefile);
169  tablefile.close();
170 
171  return 0;
172 }
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