A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-ofdm-ht-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 HT 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 HT 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 FrameSize = 1500; // bytes
39 std::ofstream yansfile("yans-frame-success-rate-n.plt");
40 std::ofstream nistfile("nist-frame-success-rate-n.plt");
41 std::ofstream tablefile("table-frame-success-rate-n.plt");
42
43 const std::vector<std::string> modes{
44 "HtMcs0",
45 "HtMcs1",
46 "HtMcs2",
47 "HtMcs3",
48 "HtMcs4",
49 "HtMcs5",
50 "HtMcs6",
51 "HtMcs7",
52 };
53
54 CommandLine cmd(__FILE__);
55 cmd.AddValue("FrameSize", "The frame size in bytes", FrameSize);
56 cmd.Parse(argc, argv);
57
58 Gnuplot yansplot = Gnuplot("yans-frame-success-rate-n.eps");
59 Gnuplot nistplot = Gnuplot("nist-frame-success-rate-n.eps");
60 Gnuplot tableplot = Gnuplot("table-frame-success-rate-n.eps");
61 WifiTxVector txVector;
62
63 Ptr<YansErrorRateModel> yans = CreateObject<YansErrorRateModel>();
64 Ptr<NistErrorRateModel> nist = CreateObject<NistErrorRateModel>();
65 Ptr<TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel>();
66
67 for (uint32_t i = 0; i < modes.size(); i++)
68 {
69 std::cout << modes[i] << std::endl;
70 Gnuplot2dDataset yansdataset(modes[i]);
71 Gnuplot2dDataset nistdataset(modes[i]);
72 Gnuplot2dDataset tabledataset(modes[i]);
73 txVector.SetMode(modes[i]);
74
75 for (double snr = -5.0; snr <= 30.0; snr += 0.1)
76 {
77 double ps = yans->GetChunkSuccessRate(WifiMode(modes[i]),
78 txVector,
79 std::pow(10.0, snr / 10.0),
80 FrameSize * 8);
81 if (ps < 0.0 || ps > 1.0)
82 {
83 // error
84 exit(1);
85 }
86 yansdataset.Add(snr, ps);
87
88 ps = nist->GetChunkSuccessRate(WifiMode(modes[i]),
89 txVector,
90 std::pow(10.0, snr / 10.0),
91 FrameSize * 8);
92 if (ps < 0.0 || ps > 1.0)
93 {
94 // error
95 exit(1);
96 }
97 nistdataset.Add(snr, ps);
98
99 ps = table->GetChunkSuccessRate(WifiMode(modes[i]),
100 txVector,
101 std::pow(10.0, snr / 10.0),
102 FrameSize * 8);
103 if (ps < 0.0 || ps > 1.0)
104 {
105 // error
106 exit(1);
107 }
108 tabledataset.Add(snr, ps);
109 }
110
111 yansplot.AddDataset(yansdataset);
112 nistplot.AddDataset(nistdataset);
113 tableplot.AddDataset(tabledataset);
114 }
115
116 yansplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
117 yansplot.SetLegend("SNR(dB)", "Frame Success Rate");
118 yansplot.SetExtra("set xrange [-5:30]\n\
119set yrange [0:1.2]\n\
120set style line 1 linewidth 5\n\
121set style line 2 linewidth 5\n\
122set style line 3 linewidth 5\n\
123set style line 4 linewidth 5\n\
124set style line 5 linewidth 5\n\
125set style line 6 linewidth 5\n\
126set style line 7 linewidth 5\n\
127set style line 8 linewidth 5\n\
128set style increment user");
129 yansplot.GenerateOutput(yansfile);
130 yansfile.close();
131
132 nistplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
133 nistplot.SetLegend("SNR(dB)", "Frame Success Rate");
134 nistplot.SetExtra("set xrange [-5:30]\n\
135set yrange [0:1.2]\n\
136set style line 1 linewidth 5\n\
137set style line 2 linewidth 5\n\
138set style line 3 linewidth 5\n\
139set style line 4 linewidth 5\n\
140set style line 5 linewidth 5\n\
141set style line 6 linewidth 5\n\
142set style line 7 linewidth 5\n\
143set style line 8 linewidth 5\n\
144set style increment user");
145
146 nistplot.GenerateOutput(nistfile);
147 nistfile.close();
148
149 tableplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
150 tableplot.SetLegend("SNR(dB)", "Frame Success Rate");
151 tableplot.SetExtra("set xrange [-5:30]\n\
152set yrange [0:1.2]\n\
153set style line 1 linewidth 5\n\
154set style line 2 linewidth 5\n\
155set style line 3 linewidth 5\n\
156set style line 4 linewidth 5\n\
157set style line 5 linewidth 5\n\
158set style line 6 linewidth 5\n\
159set style line 7 linewidth 5\n\
160set style line 8 linewidth 5\n\
161set style increment user");
162
163 tableplot.GenerateOutput(tablefile);
164 tablefile.close();
165
166 return 0;
167}
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns cmd
Definition: second.py:33