A Discrete-Event Network Simulator
API
ofdm-he-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  * Authors: S├ębastien Deronne <sebastien.deronne@gmail.com>
17  */
18 
19 // This example is used to validate NIST and YANS error rate models for VHT rates.
20 //
21 // It outputs plots of the Frame Success Rate versus the Signal-to-noise ratio for
22 // both NIST and YANS error rate models and for every HE MCS value.
23 
24 #include "ns3/core-module.h"
25 #include "ns3/yans-error-rate-model.h"
26 #include "ns3/nist-error-rate-model.h"
27 #include "ns3/gnuplot.h"
28 
29 #include <fstream>
30 #include <vector>
31 #include <cmath>
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-ax.plt");
39  std::ofstream nistfile ("nist-frame-success-rate-ax.plt");
40  std::vector <std::string> modes;
41 
42  modes.push_back ("HeMcs0");
43  modes.push_back ("HeMcs1");
44  modes.push_back ("HeMcs2");
45  modes.push_back ("HeMcs3");
46  modes.push_back ("HeMcs4");
47  modes.push_back ("HeMcs5");
48  modes.push_back ("HeMcs6");
49  modes.push_back ("HeMcs7");
50  modes.push_back ("HeMcs8");
51  modes.push_back ("HeMcs9");
52  modes.push_back ("HeMcs10");
53  modes.push_back ("HeMcs11");
54 
56  cmd.AddValue ("FrameSize", "The frame size", FrameSize);
57  cmd.Parse (argc, argv);
58 
59  Gnuplot yansplot = Gnuplot ("yans-frame-success-rate-ax.eps");
60  Gnuplot nistplot = Gnuplot ("nist-frame-success-rate-ax.eps");
61 
62  Ptr <YansErrorRateModel> yans = CreateObject<YansErrorRateModel> ();
63  Ptr <NistErrorRateModel> nist = CreateObject<NistErrorRateModel> ();
64  WifiTxVector txVector;
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  txVector.SetMode (modes[i]);
72 
73  for (double snr = -5.0; snr <= 40.0; snr += 0.1)
74  {
75  double ps = yans->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0,snr / 10.0), FrameSize * 8);
76  if (ps < 0 || ps > 1)
77  {
78  //error
79  return 0;
80  }
81  yansdataset.Add (snr, ps);
82  ps = nist->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0,snr / 10.0), FrameSize * 8);
83  if (ps < 0 || ps > 1)
84  {
85  //error
86  return 0;
87  }
88  nistdataset.Add (snr, ps);
89  }
90 
91  yansplot.AddDataset (yansdataset);
92  nistplot.AddDataset (nistdataset);
93  }
94 
95  yansplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
96  yansplot.SetLegend ("SNR(dB)", "Frame Success Rate");
97  yansplot.SetExtra ("set xrange [-5:55]\n\
98 set yrange [0:1]\n\
99 set style line 1 linewidth 5\n\
100 set style line 2 linewidth 5\n\
101 set style line 3 linewidth 5\n\
102 set style line 4 linewidth 5\n\
103 set style line 5 linewidth 5\n\
104 set style line 6 linewidth 5\n\
105 set style line 7 linewidth 5\n\
106 set style line 8 linewidth 5\n\
107 set style line 9 linewidth 5\n\
108 set style line 10 linewidth 5\n\
109 set style line 11 linewidth 5\n\
110 set style increment user" );
111  yansplot.GenerateOutput (yansfile);
112  yansfile.close ();
113 
114  nistplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
115  nistplot.SetLegend ("SNR(dB)", "Frame Success Rate");
116  nistplot.SetExtra ("set xrange [-5:55]\n\
117 set yrange [0:1]\n\
118 set style line 1 linewidth 5\n\
119 set style line 2 linewidth 5\n\
120 set style line 3 linewidth 5\n\
121 set style line 4 linewidth 5\n\
122 set style line 5 linewidth 5\n\
123 set style line 6 linewidth 5\n\
124 set style line 7 linewidth 5\n\
125 set style line 8 linewidth 5\n\
126 set style line 9 linewidth 5\n\
127 set style line 10 linewidth 5\n\
128 set style line 11 linewidth 5\n\
129 set style increment user" );
130 
131  nistplot.GenerateOutput (nistfile);
132  nistfile.close ();
133 }
134 
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Class to represent a 2D points plot.
Definition: gnuplot.h:117
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:756
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
tuple cmd
Definition: second.py:35
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:371
virtual double GetChunkSuccessRate(WifiMode mode, WifiTxVector txVector, double snr, uint32_t nbits) const
A pure virtual method that must be implemented in the subclass.
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:762
Parse command-line arguments.
Definition: command-line.h:205
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:736
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:743
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:498
void Parse(int argc, char *argv[])
Parse the program arguments.
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:724