A Discrete-Event Network Simulator
API
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 and YANS error rate models for OFDM rates.
22 //
23 // It outputs plots of the Frame Success Rate versus the Signal-to-noise ratio for
24 // both NIST and YANS error rate models and for every OFDM mode.
25 
26 #include "ns3/core-module.h"
27 #include "ns3/yans-error-rate-model.h"
28 #include "ns3/nist-error-rate-model.h"
29 #include "ns3/gnuplot.h"
30 
31 using namespace ns3;
32 
33 int main (int argc, char *argv[])
34 {
35  uint32_t FrameSize = 1500; //bytes
36  std::ofstream yansfile ("yans-frame-success-rate.plt");
37  std::ofstream nistfile ("nist-frame-success-rate.plt");
38  std::vector <std::string> modes;
39 
40  modes.push_back ("OfdmRate6Mbps");
41  modes.push_back ("OfdmRate9Mbps");
42  modes.push_back ("OfdmRate12Mbps");
43  modes.push_back ("OfdmRate18Mbps");
44  modes.push_back ("OfdmRate24Mbps");
45  modes.push_back ("OfdmRate36Mbps");
46  modes.push_back ("OfdmRate48Mbps");
47  modes.push_back ("OfdmRate54Mbps");
48 
50  cmd.AddValue ("FrameSize", "The frame size in bytes", FrameSize);
51  cmd.Parse (argc, argv);
52 
53  Gnuplot yansplot = Gnuplot ("yans-frame-success-rate.eps");
54  Gnuplot nistplot = Gnuplot ("nist-frame-success-rate.eps");
55 
56  Ptr <YansErrorRateModel> yans = CreateObject<YansErrorRateModel> ();
57  Ptr <NistErrorRateModel> nist = CreateObject<NistErrorRateModel> ();
58  WifiTxVector txVector;
59 
60  for (uint32_t i = 0; i < modes.size (); i++)
61  {
62  std::cout << modes[i] << std::endl;
63  Gnuplot2dDataset yansdataset (modes[i]);
64  Gnuplot2dDataset nistdataset (modes[i]);
65  txVector.SetMode (modes[i]);
66 
67  for (double snr = -5.0; snr <= 30.0; snr += 0.1)
68  {
69  double ps = yans->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0,snr / 10.0), FrameSize * 8);
70  yansdataset.Add (snr, ps);
71  if (ps < 0 || ps > 1)
72  {
73  //error
74  return 0;
75  }
76  ps = nist->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0,snr / 10.0), FrameSize * 8);
77  if (ps < 0 || ps > 1)
78  {
79  //error
80  return 0;
81  }
82  nistdataset.Add (snr, ps);
83  }
84 
85  yansplot.AddDataset (yansdataset);
86  nistplot.AddDataset (nistdataset);
87  }
88 
89  yansplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
90  yansplot.SetLegend ("SNR(dB)", "Frame Success Rate");
91  yansplot.SetExtra ("set xrange [-5:30]\n\
92 set yrange [0:1.2]\n\
93 set style line 1 linewidth 5\n\
94 set style line 2 linewidth 5\n\
95 set style line 3 linewidth 5\n\
96 set style line 4 linewidth 5\n\
97 set style line 5 linewidth 5\n\
98 set style line 6 linewidth 5\n\
99 set style line 7 linewidth 5\n\
100 set style line 8 linewidth 5\n\
101 set style increment user" );
102  yansplot.GenerateOutput (yansfile);
103  yansfile.close ();
104 
105  nistplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
106  nistplot.SetLegend ("SNR(dB)", "Frame Success Rate");
107  nistplot.SetExtra ("set xrange [-5:30]\n\
108 set yrange [0:1.2]\n\
109 set style line 1 linewidth 5\n\
110 set style line 2 linewidth 5\n\
111 set style line 3 linewidth 5\n\
112 set style line 4 linewidth 5\n\
113 set style line 5 linewidth 5\n\
114 set style line 6 linewidth 5\n\
115 set style line 7 linewidth 5\n\
116 set style line 8 linewidth 5\n\
117 set style increment user" );
118 
119  nistplot.GenerateOutput (nistfile);
120  nistfile.close ();
121 }
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