A Discrete-Event Network Simulator
API
wifi-ofdm-validation.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 The Boeing Company
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Gary Pei <guangyu.pei@boeing.com>
19  */
20 
21 // This example is used to validate Nist, Yans and Table-based error rate models for OFDM rates.
22 //
23 // It outputs plots of the Frame Success Rate versus the Signal-to-noise ratio for
24 // Nist, Yans and Table-based error rate models and for every OFDM mode.
25 
26 #include <fstream>
27 #include <cmath>
28 #include "ns3/gnuplot.h"
29 #include "ns3/command-line.h"
30 #include "ns3/yans-error-rate-model.h"
31 #include "ns3/nist-error-rate-model.h"
32 #include "ns3/table-based-error-rate-model.h"
33 #include "ns3/wifi-tx-vector.h"
34 
35 using namespace ns3;
36 
37 int main (int argc, char *argv[])
38 {
39  uint32_t FrameSize = 1500; //bytes
40  std::ofstream yansfile ("yans-frame-success-rate-ofdm.plt");
41  std::ofstream nistfile ("nist-frame-success-rate-ofdm.plt");
42  std::ofstream tablefile ("table-frame-success-rate-ofdm.plt");
43  std::vector <std::string> modes;
44 
45  modes.push_back ("OfdmRate6Mbps");
46  modes.push_back ("OfdmRate9Mbps");
47  modes.push_back ("OfdmRate12Mbps");
48  modes.push_back ("OfdmRate18Mbps");
49  modes.push_back ("OfdmRate24Mbps");
50  modes.push_back ("OfdmRate36Mbps");
51  modes.push_back ("OfdmRate48Mbps");
52  modes.push_back ("OfdmRate54Mbps");
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-ofdm.eps");
59  Gnuplot nistplot = Gnuplot ("nist-frame-success-rate-ofdm.eps");
60  Gnuplot tableplot = Gnuplot ("table-frame-success-rate-ofdm.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:30]\n\
110 set yrange [0:1.2]\n\
111 set style line 1 linewidth 5\n\
112 set style line 2 linewidth 5\n\
113 set style line 3 linewidth 5\n\
114 set style line 4 linewidth 5\n\
115 set style line 5 linewidth 5\n\
116 set style line 6 linewidth 5\n\
117 set style line 7 linewidth 5\n\
118 set style line 8 linewidth 5\n\
119 set style increment user");
120  yansplot.GenerateOutput (yansfile);
121  yansfile.close ();
122 
123  nistplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
124  nistplot.SetLegend ("SNR(dB)", "Frame Success Rate");
125  nistplot.SetExtra ("set xrange [-5:30]\n\
126 set yrange [0:1.2]\n\
127 set style line 1 linewidth 5\n\
128 set style line 2 linewidth 5\n\
129 set style line 3 linewidth 5\n\
130 set style line 4 linewidth 5\n\
131 set style line 5 linewidth 5\n\
132 set style line 6 linewidth 5\n\
133 set style line 7 linewidth 5\n\
134 set style line 8 linewidth 5\n\
135 set style increment user");
136 
137  nistplot.GenerateOutput (nistfile);
138  nistfile.close ();
139 
140  tableplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
141  tableplot.SetLegend ("SNR(dB)", "Frame Success Rate");
142  tableplot.SetExtra ("set xrange [-5:30]\n\
143 set yrange [0:1.2]\n\
144 set style line 1 linewidth 5\n\
145 set style line 2 linewidth 5\n\
146 set style line 3 linewidth 5\n\
147 set style line 4 linewidth 5\n\
148 set style line 5 linewidth 5\n\
149 set style line 6 linewidth 5\n\
150 set style line 7 linewidth 5\n\
151 set style line 8 linewidth 5\n\
152 set style increment user");
153 
154  tableplot.GenerateOutput (tablefile);
155  tablefile.close ();
156 }
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