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-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 frameSizeBytes = 1500;
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", frameSizeBytes);
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  uint32_t frameSizeBits = frameSizeBytes * 8;
60 
61  for (const auto& mode : modes)
62  {
63  std::cout << mode << std::endl;
64  Gnuplot2dDataset dataset(mode);
65  txVector.SetMode(mode);
66 
67  WifiMode wifiMode(mode);
68 
69  for (double snrDb = -10.0; snrDb <= 20.0; snrDb += 0.1)
70  {
71  double snr = std::pow(10.0, snrDb / 10.0);
72 
73  double psYans = yans->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
74  if (psYans < 0.0 || psYans > 1.0)
75  {
76  // error
77  exit(1);
78  }
79  double psNist = nist->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
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, txVector, snr, frameSizeBits);
91  if (psTable < 0.0 || psTable > 1.0)
92  {
93  std::cout << psTable << std::endl;
94  // error
95  exit(1);
96  }
97  if (psTable != psYans)
98  {
99  exit(1);
100  }
101  dataset.Add(snrDb, psYans);
102  }
103 
104  plot.AddDataset(dataset);
105  }
106 
107  plot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
108  plot.SetLegend("SNR(dB)", "Frame Success Rate");
109  plot.SetExtra("set xrange [-10:20]\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  plot.GenerateOutput(file);
121  file.close();
122 
123  return 0;
124 }
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