A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-ofdm-he-validation.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
5 */
6
7// This example is used to validate Nist, Yans and Table-based error rate models for HE rates.
8//
9// It outputs plots of the Frame Success Rate versus the Signal-to-noise ratio for
10// Nist, Yans and Table-based error rate models and for every HE MCS value.
11
12#include "ns3/command-line.h"
13#include "ns3/gnuplot.h"
14#include "ns3/nist-error-rate-model.h"
15#include "ns3/table-based-error-rate-model.h"
16#include "ns3/wifi-tx-vector.h"
17#include "ns3/yans-error-rate-model.h"
18
19#include <cmath>
20#include <fstream>
21
22using namespace ns3;
23
24int
25main(int argc, char* argv[])
26{
27 uint32_t frameSizeBytes = 1500;
28 std::ofstream yansfile("yans-frame-success-rate-ax.plt");
29 std::ofstream nistfile("nist-frame-success-rate-ax.plt");
30 std::ofstream tablefile("table-frame-success-rate-ax.plt");
31
32 const std::vector<std::string> modes{
33 "HeMcs0",
34 "HeMcs1",
35 "HeMcs2",
36 "HeMcs3",
37 "HeMcs4",
38 "HeMcs5",
39 "HeMcs6",
40 "HeMcs7",
41 "HeMcs8",
42 "HeMcs9",
43 "HeMcs10",
44 "HeMcs11",
45 };
46
47 CommandLine cmd(__FILE__);
48 cmd.AddValue("FrameSize", "The frame size", frameSizeBytes);
49 cmd.Parse(argc, argv);
50
51 Gnuplot yansplot = Gnuplot("yans-frame-success-rate-ax.eps");
52 Gnuplot nistplot = Gnuplot("nist-frame-success-rate-ax.eps");
53 Gnuplot tableplot = Gnuplot("table-frame-success-rate-ax.eps");
54
58 WifiTxVector txVector;
59
60 uint32_t frameSizeBits = frameSizeBytes * 8;
61
62 for (const auto& mode : modes)
63 {
64 std::cout << mode << std::endl;
65 Gnuplot2dDataset yansdataset(mode);
66 Gnuplot2dDataset nistdataset(mode);
67 Gnuplot2dDataset tabledataset(mode);
68 txVector.SetMode(mode);
69
70 WifiMode wifiMode(mode);
71
72 for (double snrDb = -5.0; snrDb <= 40.0; snrDb += 0.1)
73 {
74 double snr = std::pow(10.0, snrDb / 10.0);
75
76 double ps = yans->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
77 if (ps < 0.0 || ps > 1.0)
78 {
79 // error
80 exit(1);
81 }
82 yansdataset.Add(snrDb, ps);
83
84 ps = nist->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
85 if (ps < 0.0 || ps > 1.0)
86 {
87 // error
88 exit(1);
89 }
90 nistdataset.Add(snrDb, ps);
91
92 ps = table->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
93 if (ps < 0.0 || ps > 1.0)
94 {
95 // error
96 exit(1);
97 }
98 tabledataset.Add(snrDb, ps);
99 }
100
101 yansplot.AddDataset(yansdataset);
102 nistplot.AddDataset(nistdataset);
103 tableplot.AddDataset(tabledataset);
104 }
105
106 yansplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
107 yansplot.SetLegend("SNR(dB)", "Frame Success Rate");
108 yansplot.SetExtra("set xrange [-5:55]\n\
109set yrange [0:1]\n\
110set style line 1 linewidth 5\n\
111set style line 2 linewidth 5\n\
112set style line 3 linewidth 5\n\
113set style line 4 linewidth 5\n\
114set style line 5 linewidth 5\n\
115set style line 6 linewidth 5\n\
116set style line 7 linewidth 5\n\
117set style line 8 linewidth 5\n\
118set style line 9 linewidth 5\n\
119set style line 10 linewidth 5\n\
120set style line 11 linewidth 5\n\
121set style line 12 linewidth 5\n\
122set style increment user");
123 yansplot.GenerateOutput(yansfile);
124 yansfile.close();
125
126 nistplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
127 nistplot.SetLegend("SNR(dB)", "Frame Success Rate");
128 nistplot.SetExtra("set xrange [-5:55]\n\
129set yrange [0:1]\n\
130set style line 1 linewidth 5\n\
131set style line 2 linewidth 5\n\
132set style line 3 linewidth 5\n\
133set style line 4 linewidth 5\n\
134set style line 5 linewidth 5\n\
135set style line 6 linewidth 5\n\
136set style line 7 linewidth 5\n\
137set style line 8 linewidth 5\n\
138set style line 9 linewidth 5\n\
139set style line 10 linewidth 5\n\
140set style line 11 linewidth 5\n\
141set style line 12 linewidth 5\n\
142set style increment user");
143
144 nistplot.GenerateOutput(nistfile);
145 nistfile.close();
146
147 tableplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
148 tableplot.SetLegend("SNR(dB)", "Frame Success Rate");
149 tableplot.SetExtra("set xrange [-5:55]\n\
150set yrange [0:1]\n\
151set style line 1 linewidth 5\n\
152set style line 2 linewidth 5\n\
153set style line 3 linewidth 5\n\
154set style line 4 linewidth 5\n\
155set style line 5 linewidth 5\n\
156set style line 6 linewidth 5\n\
157set style line 7 linewidth 5\n\
158set style line 8 linewidth 5\n\
159set style line 9 linewidth 5\n\
160set style line 10 linewidth 5\n\
161set style line 11 linewidth 5\n\
162set style line 12 linewidth 5\n\
163set style increment user");
164
165 tableplot.GenerateOutput(tablefile);
166 tablefile.close();
167
168 return 0;
169}
Parse command-line arguments.
Class to represent a 2D points plot.
Definition gnuplot.h:105
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition gnuplot.h:359
void AddDataset(const GnuplotDataset &dataset)
Definition gnuplot.cc:785
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition gnuplot.cc:765
void SetTerminal(const std::string &terminal)
Definition gnuplot.cc:753
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition gnuplot.cc:791
void SetExtra(const std::string &extra)
Definition gnuplot.cc:772
Smart pointer class similar to boost::intrusive_ptr.
represent a single transmission mode
Definition wifi-mode.h:40
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.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Every class exported by the ns3 library is enclosed in the ns3 namespace.