A Discrete-Event Network Simulator
API
wifi-ofdm-vht-validation.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 as
5 * published by the Free Software Foundation;
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
17 */
18
19// This example is used to validate Nist, Yans and Table-based error rate models for VHT rates.
20//
21// It outputs plots of the Frame Success Rate versus the Signal-to-noise ratio for
22// Nist, Yans and Table-based error rate models and for every VHT MCS value (MCS 9 is not
23// included since it is forbidden for 20 MHz channels).
24
25#include <fstream>
26#include <cmath>
27#include "ns3/gnuplot.h"
28#include "ns3/command-line.h"
29#include "ns3/yans-error-rate-model.h"
30#include "ns3/nist-error-rate-model.h"
31#include "ns3/table-based-error-rate-model.h"
32#include "ns3/wifi-tx-vector.h"
33
34using namespace ns3;
35
36int main (int argc, char *argv[])
37{
38 uint32_t FrameSize = 1500; //bytes
39 std::ofstream yansfile ("yans-frame-success-rate-ac.plt");
40 std::ofstream nistfile ("nist-frame-success-rate-ac.plt");
41 std::ofstream tablefile ("table-frame-success-rate-ac.plt");
42 std::vector <std::string> modes;
43
44 modes.push_back ("VhtMcs0");
45 modes.push_back ("VhtMcs1");
46 modes.push_back ("VhtMcs2");
47 modes.push_back ("VhtMcs3");
48 modes.push_back ("VhtMcs4");
49 modes.push_back ("VhtMcs5");
50 modes.push_back ("VhtMcs6");
51 modes.push_back ("VhtMcs7");
52 modes.push_back ("VhtMcs8");
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-ac.eps");
59 Gnuplot nistplot = Gnuplot ("nist-frame-success-rate-ac.eps");
60 Gnuplot tableplot = Gnuplot ("table-frame-success-rate-ac.eps");
61
62 Ptr <YansErrorRateModel> yans = CreateObject<YansErrorRateModel> ();
63 Ptr <NistErrorRateModel> nist = CreateObject<NistErrorRateModel> ();
64 Ptr <TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel> ();
65 WifiTxVector txVector;
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]), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
78 if (ps < 0.0 || ps > 1.0)
79 {
80 //error
81 exit (1);
82 }
83 yansdataset.Add (snr, ps);
84
85 ps = nist->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
86 if (ps < 0.0 || ps > 1.0)
87 {
88 //error
89 exit (1);
90 }
91 nistdataset.Add (snr, ps);
92
93 ps = table->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
94 if (ps < 0.0 || ps > 1.0)
95 {
96 //error
97 exit (1);
98 }
99 tabledataset.Add (snr, ps);
100 }
101
102 yansplot.AddDataset (yansdataset);
103 nistplot.AddDataset (nistdataset);
104 tableplot.AddDataset (tabledataset);
105 }
106
107 yansplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
108 yansplot.SetLegend ("SNR(dB)", "Frame Success Rate");
109 yansplot.SetExtra ("set xrange [-5:55]\n\
110set yrange [0:1]\n\
111set style line 1 linewidth 5\n\
112set style line 2 linewidth 5\n\
113set style line 3 linewidth 5\n\
114set style line 4 linewidth 5\n\
115set style line 5 linewidth 5\n\
116set style line 6 linewidth 5\n\
117set style line 7 linewidth 5\n\
118set style line 8 linewidth 5\n\
119set style line 9 linewidth 5\n\
120set style increment user");
121 yansplot.GenerateOutput (yansfile);
122 yansfile.close ();
123
124 nistplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
125 nistplot.SetLegend ("SNR(dB)", "Frame Success Rate");
126 nistplot.SetExtra ("set xrange [-5:55]\n\
127set yrange [0:1]\n\
128set style line 1 linewidth 5\n\
129set style line 2 linewidth 5\n\
130set style line 3 linewidth 5\n\
131set style line 4 linewidth 5\n\
132set style line 5 linewidth 5\n\
133set style line 6 linewidth 5\n\
134set style line 7 linewidth 5\n\
135set style line 8 linewidth 5\n\
136set style line 9 linewidth 5\n\
137set style increment user");
138
139 nistplot.GenerateOutput (nistfile);
140 nistfile.close ();
141
142 tableplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
143 tableplot.SetLegend ("SNR(dB)", "Frame Success Rate");
144 tableplot.SetExtra ("set xrange [-5:55]\n\
145set yrange [0:1]\n\
146set style line 1 linewidth 5\n\
147set style line 2 linewidth 5\n\
148set style line 3 linewidth 5\n\
149set style line 4 linewidth 5\n\
150set style line 5 linewidth 5\n\
151set style line 6 linewidth 5\n\
152set style line 7 linewidth 5\n\
153set style line 8 linewidth 5\n\
154set style line 9 linewidth 5\n\
155set style increment user");
156
157 tableplot.GenerateOutput (tablefile);
158 tablefile.close ();
159}
Parse command-line arguments.
Definition: command-line.h:229
Class to represent a 2D points plot.
Definition: gnuplot.h:118
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:372
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:758
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:738
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:726
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:764
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:745
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
represent a single transmission mode
Definition: wifi-mode.h:48
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:35