A Discrete-Event Network Simulator
API
wifi-dsss-validation.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License version 2 as
4  * published by the Free Software Foundation;
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
16  */
17 
18 // This example is used to validate error rate models for DSSS rates.
19 //
20 // It outputs plots of the Frame Success Rate versus the Signal-to-noise ratio
21 // for the DSSS error rate models and for every DSSS mode.
22 
23 #include "ns3/command-line.h"
24 #include "ns3/gnuplot.h"
25 #include "ns3/nist-error-rate-model.h"
26 #include "ns3/table-based-error-rate-model.h"
27 #include "ns3/wifi-tx-vector.h"
28 #include "ns3/yans-error-rate-model.h"
29 
30 #include <cmath>
31 #include <fstream>
32 
33 using namespace ns3;
34 
35 int
36 main(int argc, char* argv[])
37 {
38  uint32_t FrameSize = 1500; // bytes
39  std::ofstream file("frame-success-rate-dsss.plt");
40 
41  const std::vector<std::string> modes{
42  "DsssRate1Mbps",
43  "DsssRate2Mbps",
44  "DsssRate5_5Mbps",
45  "DsssRate11Mbps",
46  };
47 
48  CommandLine cmd(__FILE__);
49  cmd.AddValue("FrameSize", "The frame size in bytes", FrameSize);
50  cmd.Parse(argc, argv);
51 
52  Gnuplot plot = Gnuplot("frame-success-rate-dsss.eps");
53 
54  Ptr<YansErrorRateModel> yans = CreateObject<YansErrorRateModel>();
55  Ptr<NistErrorRateModel> nist = CreateObject<NistErrorRateModel>();
56  Ptr<TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel>();
57  WifiTxVector txVector;
58 
59  for (uint32_t i = 0; i < modes.size(); i++)
60  {
61  std::cout << modes[i] << std::endl;
62  Gnuplot2dDataset dataset(modes[i]);
63  txVector.SetMode(modes[i]);
64 
65  for (double snr = -10.0; snr <= 20.0; snr += 0.1)
66  {
67  double psYans = yans->GetChunkSuccessRate(WifiMode(modes[i]),
68  txVector,
69  std::pow(10.0, snr / 10.0),
70  FrameSize * 8);
71  if (psYans < 0.0 || psYans > 1.0)
72  {
73  // error
74  exit(1);
75  }
76  double psNist = nist->GetChunkSuccessRate(WifiMode(modes[i]),
77  txVector,
78  std::pow(10.0, snr / 10.0),
79  FrameSize * 8);
80  if (psNist < 0.0 || psNist > 1.0)
81  {
82  std::cout << psNist << std::endl;
83  // error
84  exit(1);
85  }
86  if (psNist != psYans)
87  {
88  exit(1);
89  }
90  double psTable = table->GetChunkSuccessRate(WifiMode(modes[i]),
91  txVector,
92  std::pow(10.0, snr / 10.0),
93  FrameSize * 8);
94  if (psTable < 0.0 || psTable > 1.0)
95  {
96  std::cout << psTable << std::endl;
97  // error
98  exit(1);
99  }
100  if (psTable != psYans)
101  {
102  exit(1);
103  }
104  dataset.Add(snr, psYans);
105  }
106 
107  plot.AddDataset(dataset);
108  }
109 
110  plot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
111  plot.SetLegend("SNR(dB)", "Frame Success Rate");
112  plot.SetExtra("set xrange [-10:20]\n\
113 set yrange [0:1.2]\n\
114 set style line 1 linewidth 5\n\
115 set style line 2 linewidth 5\n\
116 set style line 3 linewidth 5\n\
117 set style line 4 linewidth 5\n\
118 set style line 5 linewidth 5\n\
119 set style line 6 linewidth 5\n\
120 set style line 7 linewidth 5\n\
121 set style line 8 linewidth 5\n\
122 set style increment user");
123  plot.GenerateOutput(file);
124  file.close();
125 
126  return 0;
127 }
Parse command-line arguments.
Definition: command-line.h:232
Class to represent a 2D points plot.
Definition: gnuplot.h:116
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:370
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:796
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:776
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:764
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:802
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:783
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
represent a single transmission mode
Definition: wifi-mode.h:50
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:33