A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-ofdm-eht-validation.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 DERONNE SOFTWARE ENGINEERING
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
7 */
8
9// This example is used to validate NIST and YANS error rate models for EHT rates.
10//
11// It outputs plots of the Frame Success Rate versus the Signal-to-noise ratio for
12// Nist, Yans and Table-based error rate models and for every HT MCS value.
13
14#include "ns3/command-line.h"
15#include "ns3/gnuplot.h"
16#include "ns3/nist-error-rate-model.h"
17#include "ns3/table-based-error-rate-model.h"
18#include "ns3/wifi-tx-vector.h"
19#include "ns3/yans-error-rate-model.h"
20
21#include <cmath>
22#include <fstream>
23
24using namespace ns3;
25
26int
27main(int argc, char* argv[])
28{
29 uint32_t frameSizeBytes = 1500;
30 std::ofstream yansfile("yans-frame-success-rate-be.plt");
31 std::ofstream nistfile("nist-frame-success-rate-be.plt");
32 std::ofstream tablefile("table-frame-success-rate-be.plt");
33
34 const std::vector<std::string> modes{
35 "EhtMcs0",
36 "EhtMcs1",
37 "EhtMcs2",
38 "EhtMcs3",
39 "EhtMcs4",
40 "EhtMcs5",
41 "EhtMcs6",
42 "EhtMcs7",
43 "EhtMcs8",
44 "EhtMcs9",
45 "EhtMcs10",
46 "EhtMcs11",
47 "EhtMcs12",
48 "EhtMcs13",
49 };
50
51 CommandLine cmd(__FILE__);
52 cmd.AddValue("FrameSize", "The frame size", frameSizeBytes);
53 cmd.Parse(argc, argv);
54
55 Gnuplot yansplot = Gnuplot("yans-frame-success-rate-be.eps");
56 Gnuplot nistplot = Gnuplot("nist-frame-success-rate-be.eps");
57 Gnuplot tableplot = Gnuplot("table-frame-success-rate-be.eps");
58
62 WifiTxVector txVector;
63
64 uint32_t frameSizeBits = frameSizeBytes * 8;
65
66 for (const auto& mode : modes)
67 {
68 std::cout << mode << std::endl;
69 Gnuplot2dDataset yansdataset(mode);
70 Gnuplot2dDataset nistdataset(mode);
71 Gnuplot2dDataset tabledataset(mode);
72 txVector.SetMode(mode);
73
74 WifiMode wifiMode(mode);
75
76 for (double snrDb = -5.0; snrDb <= 55.0; snrDb += 0.1)
77 {
78 double snr = std::pow(10.0, snrDb / 10.0);
79
80 double ps = yans->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
81 if (ps < 0.0 || ps > 1.0)
82 {
83 // error
84 exit(1);
85 }
86 yansdataset.Add(snrDb, ps);
87
88 ps = nist->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
89 if (ps < 0.0 || ps > 1.0)
90 {
91 // error
92 exit(1);
93 }
94 nistdataset.Add(snrDb, ps);
95
96 ps = table->GetChunkSuccessRate(wifiMode, txVector, snr, frameSizeBits);
97 if (ps < 0.0 || ps > 1.0)
98 {
99 // error
100 exit(1);
101 }
102 tabledataset.Add(snrDb, ps);
103 }
104
105 yansplot.AddDataset(yansdataset);
106 nistplot.AddDataset(nistdataset);
107 tableplot.AddDataset(tabledataset);
108 }
109
110 std::stringstream plotExtra;
111 plotExtra << "set xrange [-5:55]\n\
112set yrange [0:1]\n";
113
114 const std::vector<std::string> colors{
115 "green",
116 "blue",
117 "red",
118 "black",
119 "orange",
120 "purple",
121 "yellow",
122 "pink",
123 "grey",
124 "magenta",
125 "brown",
126 "turquoise",
127 "olive",
128 "beige",
129 };
130
131 NS_ASSERT_MSG(colors.size() == modes.size(), "Colors and modes vectors have different sizes");
132
133 for (std::size_t i = 0; i < modes.size(); i++)
134 {
135 plotExtra << "set style line " << (i + 1) << " linewidth 5 linecolor rgb \"" << colors[i]
136 << "\" \n";
137 }
138 plotExtra << "set style increment user";
139
140 yansplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
141 yansplot.SetLegend("SNR(dB)", "Frame Success Rate");
142 yansplot.SetExtra(plotExtra.str());
143 yansplot.GenerateOutput(yansfile);
144 yansfile.close();
145
146 nistplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
147 nistplot.SetLegend("SNR(dB)", "Frame Success Rate");
148 nistplot.SetExtra(plotExtra.str());
149 nistplot.GenerateOutput(nistfile);
150 nistfile.close();
151
152 tableplot.SetTerminal("postscript eps color enh \"Times-BoldItalic\"");
153 tableplot.SetLegend("SNR(dB)", "Frame Success Rate");
154 tableplot.SetExtra(plotExtra.str());
155 tableplot.GenerateOutput(tablefile);
156 tablefile.close();
157
158 return 0;
159}
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.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
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.