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