A Discrete-Event Network Simulator
API
wifi-ofdm-ht-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 HT 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 HT MCS value.
23 
24 #include <fstream>
25 #include <cmath>
26 #include "ns3/gnuplot.h"
27 #include "ns3/command-line.h"
28 #include "ns3/yans-error-rate-model.h"
29 #include "ns3/nist-error-rate-model.h"
30 #include "ns3/table-based-error-rate-model.h"
31 #include "ns3/wifi-tx-vector.h"
32 
33 using namespace ns3;
34 
35 int main (int argc, char *argv[])
36 {
37  uint32_t FrameSize = 1500; //bytes
38  std::ofstream yansfile ("yans-frame-success-rate-n.plt");
39  std::ofstream nistfile ("nist-frame-success-rate-n.plt");
40  std::ofstream tablefile ("table-frame-success-rate-n.plt");
41  std::vector <std::string> modes;
42 
43  modes.push_back ("HtMcs0");
44  modes.push_back ("HtMcs1");
45  modes.push_back ("HtMcs2");
46  modes.push_back ("HtMcs3");
47  modes.push_back ("HtMcs4");
48  modes.push_back ("HtMcs5");
49  modes.push_back ("HtMcs6");
50  modes.push_back ("HtMcs7");
51 
52 
53  CommandLine cmd (__FILE__);
54  cmd.AddValue ("FrameSize", "The frame size in bytes", FrameSize);
55  cmd.Parse (argc, argv);
56 
57  Gnuplot yansplot = Gnuplot ("yans-frame-success-rate-n.eps");
58  Gnuplot nistplot = Gnuplot ("nist-frame-success-rate-n.eps");
59  Gnuplot tableplot = Gnuplot ("table-frame-success-rate-n.eps");
60  WifiTxVector txVector;
61 
62  Ptr <YansErrorRateModel> yans = CreateObject<YansErrorRateModel> ();
63  Ptr <NistErrorRateModel> nist = CreateObject<NistErrorRateModel> ();
64  Ptr <TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel> ();
65 
66  for (uint32_t i = 0; i < modes.size (); i++)
67  {
68  std::cout << modes[i] << std::endl;
69  Gnuplot2dDataset yansdataset (modes[i]);
70  Gnuplot2dDataset nistdataset (modes[i]);
71  Gnuplot2dDataset tabledataset (modes[i]);
72  txVector.SetMode (modes[i]);
73 
74  for (double snr = -5.0; snr <= 30.0; snr += 0.1)
75  {
76  double ps = yans->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
77  if (ps < 0.0 || ps > 1.0)
78  {
79  //error
80  exit (1);
81  }
82  yansdataset.Add (snr, ps);
83 
84  ps = nist->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
85  if (ps < 0.0 || ps > 1.0)
86  {
87  //error
88  exit (1);
89  }
90  nistdataset.Add (snr, ps);
91 
92  ps = table->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8);
93  if (ps < 0.0 || ps > 1.0)
94  {
95  //error
96  exit (1);
97  }
98  tabledataset.Add (snr, ps);
99  }
100 
101  yansplot.AddDataset (yansdataset);
102  nistplot.AddDataset (nistdataset);
103  tableplot.AddDataset (tabledataset);
104  }
105 
106  yansplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
107  yansplot.SetLegend ("SNR(dB)", "Frame Success Rate");
108  yansplot.SetExtra ("set xrange [-5:30]\n\
109 set yrange [0:1.2]\n\
110 set style line 1 linewidth 5\n\
111 set style line 2 linewidth 5\n\
112 set style line 3 linewidth 5\n\
113 set style line 4 linewidth 5\n\
114 set style line 5 linewidth 5\n\
115 set style line 6 linewidth 5\n\
116 set style line 7 linewidth 5\n\
117 set style line 8 linewidth 5\n\
118 set style increment user");
119  yansplot.GenerateOutput (yansfile);
120  yansfile.close ();
121 
122  nistplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
123  nistplot.SetLegend ("SNR(dB)", "Frame Success Rate");
124  nistplot.SetExtra ("set xrange [-5:30]\n\
125 set yrange [0:1.2]\n\
126 set style line 1 linewidth 5\n\
127 set style line 2 linewidth 5\n\
128 set style line 3 linewidth 5\n\
129 set style line 4 linewidth 5\n\
130 set style line 5 linewidth 5\n\
131 set style line 6 linewidth 5\n\
132 set style line 7 linewidth 5\n\
133 set style line 8 linewidth 5\n\
134 set style increment user");
135 
136  nistplot.GenerateOutput (nistfile);
137  nistfile.close ();
138 
139  tableplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
140  tableplot.SetLegend ("SNR(dB)", "Frame Success Rate");
141  tableplot.SetExtra ("set xrange [-5:30]\n\
142 set yrange [0:1.2]\n\
143 set style line 1 linewidth 5\n\
144 set style line 2 linewidth 5\n\
145 set style line 3 linewidth 5\n\
146 set style line 4 linewidth 5\n\
147 set style line 5 linewidth 5\n\
148 set style line 6 linewidth 5\n\
149 set style line 7 linewidth 5\n\
150 set style line 8 linewidth 5\n\
151 set style increment user");
152 
153  tableplot.GenerateOutput (tablefile);
154  tablefile.close ();
155 }
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:373
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:760
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:740
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:728
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:766
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:747
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