A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
wifi-ofdm-validation.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 The Boeing Company
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Gary Pei <guangyu.pei@boeing.com>
18  */
19 
20 // This example is used to validate Nist, Yans and Table-based error rate models for OFDM rates.
21 //
22 // It outputs plots of the Frame Success Rate versus the Signal-to-noise ratio for
23 // Nist, Yans and Table-based error rate models and for every OFDM mode.
24 
25 #include "ns3/command-line.h"
26 #include "ns3/gnuplot.h"
27 #include "ns3/nist-error-rate-model.h"
28 #include "ns3/table-based-error-rate-model.h"
29 #include "ns3/wifi-tx-vector.h"
30 #include "ns3/yans-error-rate-model.h"
31 
32 #include <cmath>
33 #include <fstream>
34 
35 using namespace ns3;
36 
37 int
38 main(int argc, char* argv[])
39 {
40  uint32_t frameSizeBytes = 1500;
41  std::ofstream yansfile("yans-frame-success-rate-ofdm.plt");
42  std::ofstream nistfile("nist-frame-success-rate-ofdm.plt");
43  std::ofstream tablefile("table-frame-success-rate-ofdm.plt");
44 
45  const std::vector<std::string> modes{
46  "OfdmRate6Mbps",
47  "OfdmRate9Mbps",
48  "OfdmRate12Mbps",
49  "OfdmRate18Mbps",
50  "OfdmRate24Mbps",
51  "OfdmRate36Mbps",
52  "OfdmRate48Mbps",
53  "OfdmRate54Mbps",
54  };
55 
56  CommandLine cmd(__FILE__);
57  cmd.AddValue("FrameSize", "The frame size in bytes", frameSizeBytes);
58  cmd.Parse(argc, argv);
59 
60  Gnuplot yansplot = Gnuplot("yans-frame-success-rate-ofdm.eps");
61  Gnuplot nistplot = Gnuplot("nist-frame-success-rate-ofdm.eps");
62  Gnuplot tableplot = Gnuplot("table-frame-success-rate-ofdm.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  uint32_t frameSizeBits = frameSizeBytes * 8;
70 
71  for (const auto& mode : modes)
72  {
73  std::cout << mode << std::endl;
74  Gnuplot2dDataset yansdataset(mode);
75  Gnuplot2dDataset nistdataset(mode);
76  Gnuplot2dDataset tabledataset(mode);
77  txVector.SetMode(mode);
78 
79  WifiMode wifiMode(mode);
80 
81  for (double snrDb = -5.0; snrDb <= 30.0; snrDb += 0.1)
82  {
83  double snr = std::pow(10.0, snrDb / 10.0);
84 
85  double ps = yans->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
86  if (ps < 0.0 || ps > 1.0)
87  {
88  // error
89  exit(1);
90  }
91  yansdataset.Add(snrDb, ps);
92 
93  ps = nist->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
94  if (ps < 0.0 || ps > 1.0)
95  {
96  // error
97  exit(1);
98  }
99  nistdataset.Add(snrDb, ps);
100 
101  ps = table->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
102  if (ps < 0.0 || ps > 1.0)
103  {
104  // error
105  exit(1);
106  }
107  tabledataset.Add(snrDb, ps);
108  }
109 
110  yansplot.AddDataset(yansdataset);
111  nistplot.AddDataset(nistdataset);
112  tableplot.AddDataset(tabledataset);
113  }
114 
115  yansplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
116  yansplot.SetLegend("SNR(dB)", "Frame Success Rate");
117  yansplot.SetExtra("set xrange [-5:30]\n\
118 set yrange [0:1.2]\n\
119 set style line 1 linewidth 5\n\
120 set style line 2 linewidth 5\n\
121 set style line 3 linewidth 5\n\
122 set style line 4 linewidth 5\n\
123 set style line 5 linewidth 5\n\
124 set style line 6 linewidth 5\n\
125 set style line 7 linewidth 5\n\
126 set style line 8 linewidth 5\n\
127 set style increment user");
128  yansplot.GenerateOutput(yansfile);
129  yansfile.close();
130 
131  nistplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
132  nistplot.SetLegend("SNR(dB)", "Frame Success Rate");
133  nistplot.SetExtra("set xrange [-5:30]\n\
134 set yrange [0:1.2]\n\
135 set style line 1 linewidth 5\n\
136 set style line 2 linewidth 5\n\
137 set style line 3 linewidth 5\n\
138 set style line 4 linewidth 5\n\
139 set style line 5 linewidth 5\n\
140 set style line 6 linewidth 5\n\
141 set style line 7 linewidth 5\n\
142 set style line 8 linewidth 5\n\
143 set style increment user");
144 
145  nistplot.GenerateOutput(nistfile);
146  nistfile.close();
147 
148  tableplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
149  tableplot.SetLegend("SNR(dB)", "Frame Success Rate");
150  tableplot.SetExtra("set xrange [-5:30]\n\
151 set yrange [0:1.2]\n\
152 set style line 1 linewidth 5\n\
153 set style line 2 linewidth 5\n\
154 set style line 3 linewidth 5\n\
155 set style line 4 linewidth 5\n\
156 set style line 5 linewidth 5\n\
157 set style line 6 linewidth 5\n\
158 set style line 7 linewidth 5\n\
159 set style line 8 linewidth 5\n\
160 set style increment user");
161 
162  tableplot.GenerateOutput(tablefile);
163  tablefile.close();
164 
165  return 0;
166 }
Parse command-line arguments.
Definition: command-line.h:232
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:759
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:739
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:727
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:765
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:746
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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.
cmd
Definition: second.py:40