A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
wifi-error-models-comparison.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 University of Washington
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Authors: Sébastien Deronne <sebastien.deronne@gmail.com>
7
* Rohan Patidar <rpatidar@uw.edu>
8
*/
9
10
// This example is to show difference among Nist, Yans and Table-based error rate models.
11
//
12
// It outputs plots of the Frame Error Rate versus the Signal-to-noise ratio for
13
// Nist, Yans and Table-based error rate models and for MCS 0, 4 and 7 value.
14
15
#include "ns3/command-line.h"
16
#include "ns3/gnuplot.h"
17
#include "ns3/nist-error-rate-model.h"
18
#include "ns3/table-based-error-rate-model.h"
19
#include "ns3/wifi-tx-vector.h"
20
#include "ns3/yans-error-rate-model.h"
21
22
#include <cmath>
23
#include <fstream>
24
25
using namespace
ns3
;
26
27
int
28
main(
int
argc
,
char
*
argv
[])
29
{
30
uint32_t
size = 1500 * 8;
// bits
31
bool
tableErrorModelEnabled
=
true
;
32
bool
yansErrorModelEnabled
=
true
;
33
bool
nistErrorModelEnabled
=
true
;
34
uint8_t
beginMcs
= 0;
35
uint8_t
endMcs
= 7;
36
uint8_t
stepMcs
= 4;
37
std::string
format
(
"Ht"
);
38
39
CommandLine
cmd
(
__FILE__
);
40
cmd
.AddValue(
"size"
,
"The size in bits"
, size);
41
cmd
.AddValue(
"frameFormat"
,
"The frame format to use: Ht, Vht or He"
,
format
);
42
cmd
.AddValue(
"beginMcs"
,
"The first MCS to test"
,
beginMcs
);
43
cmd
.AddValue(
"endMcs"
,
"The last MCS to test"
,
endMcs
);
44
cmd
.AddValue(
"stepMcs"
,
"The step between two MCSs to test"
,
stepMcs
);
45
cmd
.AddValue(
"includeTableErrorModel"
,
46
"Flag to include/exclude Table-based error model"
,
47
tableErrorModelEnabled
);
48
cmd
.AddValue(
"includeYansErrorModel"
,
49
"Flag to include/exclude Yans error model"
,
50
yansErrorModelEnabled
);
51
cmd
.AddValue(
"includeNistErrorModel"
,
52
"Flag to include/exclude Nist error model"
,
53
nistErrorModelEnabled
);
54
cmd
.Parse(
argc
,
argv
);
55
56
std::ofstream
errormodelfile
(
"wifi-error-rate-models.plt"
);
57
Gnuplot
plot
=
Gnuplot
(
"wifi-error-rate-models.eps"
);
58
59
Ptr<YansErrorRateModel>
yans
=
CreateObject<YansErrorRateModel>
();
60
Ptr<NistErrorRateModel>
nist
=
CreateObject<NistErrorRateModel>
();
61
Ptr<TableBasedErrorRateModel>
table =
CreateObject<TableBasedErrorRateModel>
();
62
WifiTxVector
txVector;
63
std::vector<std::string>
modes
;
64
65
std::stringstream mode;
66
mode <<
format
<<
"Mcs"
<< +
beginMcs
;
67
modes
.push_back(mode.str());
68
for
(uint8_t mcs = (
beginMcs
+
stepMcs
); mcs <
endMcs
; mcs +=
stepMcs
)
69
{
70
mode.str(
""
);
71
mode <<
format
<<
"Mcs"
<< +mcs;
72
modes
.push_back(mode.str());
73
}
74
mode.str(
""
);
75
mode <<
format
<<
"Mcs"
<< +
endMcs
;
76
modes
.push_back(mode.str());
77
78
for
(
const
auto
& mode :
modes
)
79
{
80
std::cout << mode << std::endl;
81
Gnuplot2dDataset
yansdataset
(mode);
82
Gnuplot2dDataset
nistdataset
(mode);
83
Gnuplot2dDataset
tabledataset
(mode);
84
txVector.
SetMode
(mode);
85
86
WifiMode
wifiMode
(mode);
87
88
for
(
double
snrDb
= -5.0;
snrDb
<= (
endMcs
* 5);
snrDb
+= 0.1)
89
{
90
double
snr = std::pow(10.0,
snrDb
/ 10.0);
91
92
double
ps
=
yans
->GetChunkSuccessRate(
wifiMode
, txVector, snr, size);
93
if
(
ps < 0 || ps >
1)
94
{
95
// error
96
exit
(1);
97
}
98
yansdataset
.Add(
snrDb
, 1 -
ps
);
99
ps
=
nist
->GetChunkSuccessRate(
wifiMode
, txVector, snr, size);
100
if
(
ps < 0 || ps >
1)
101
{
102
// error
103
exit
(1);
104
}
105
nistdataset
.Add(
snrDb
, 1 -
ps
);
106
ps
= table->GetChunkSuccessRate(
wifiMode
, txVector, snr, size);
107
if
(
ps < 0 || ps >
1)
108
{
109
// error
110
exit
(1);
111
}
112
tabledataset
.Add(
snrDb
, 1 -
ps
);
113
}
114
115
if
(
tableErrorModelEnabled
)
116
{
117
std::stringstream
ss
;
118
ss
<<
"Table-"
<< mode;
119
tabledataset
.SetTitle(
ss
.str());
120
plot
.AddDataset(
tabledataset
);
121
}
122
if
(
yansErrorModelEnabled
)
123
{
124
std::stringstream
ss
;
125
ss
<<
"Yans-"
<< mode;
126
yansdataset
.SetTitle(
ss
.str());
127
plot
.AddDataset(
yansdataset
);
128
}
129
if
(
nistErrorModelEnabled
)
130
{
131
std::stringstream
ss
;
132
ss
<<
"Nist-"
<< mode;
133
nistdataset
.SetTitle(
ss
.str());
134
plot
.AddDataset(
nistdataset
);
135
}
136
}
137
138
plot
.SetTerminal(
"postscript eps color enh \"Times-BoldItalic\""
);
139
plot
.SetLegend(
"SNR(dB)"
,
"Frame Error Rate"
);
140
141
std::stringstream
plotExtra
;
142
plotExtra
<<
"set xrange [-5:"
<<
endMcs
* 5 <<
"]\n\
143
set log y\n\
144
set yrange [0.0001:1]\n"
;
145
146
uint8_t
lineNumber
= 1;
147
for
(
uint32_t
i
= 0;
i
<
modes
.size();
i
++)
148
{
149
if
(
tableErrorModelEnabled
)
150
{
151
plotExtra
<<
"set style line "
<< +
lineNumber
++
152
<<
" linewidth 5 linecolor rgb \"red\" \n"
;
153
}
154
if
(
yansErrorModelEnabled
)
155
{
156
plotExtra
<<
"set style line "
<< +
lineNumber
++
157
<<
" linewidth 5 linecolor rgb \"green\" \n"
;
158
}
159
if
(
nistErrorModelEnabled
)
160
{
161
plotExtra
<<
"set style line "
<< +
lineNumber
++
162
<<
" linewidth 5 linecolor rgb \"blue\" \n"
;
163
}
164
}
165
166
plotExtra
<<
"set style increment user"
;
167
plot
.SetExtra(
plotExtra
.str());
168
169
plot
.GenerateOutput(
errormodelfile
);
170
errormodelfile
.close();
171
172
return
0;
173
}
ns3::CommandLine
Parse command-line arguments.
Definition
command-line.h:221
ns3::Gnuplot2dDataset
Class to represent a 2D points plot.
Definition
gnuplot.h:105
ns3::Gnuplot
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition
gnuplot.h:360
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::WifiMode
represent a single transmission mode
Definition
wifi-mode.h:40
ns3::WifiTxVector
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Definition
wifi-tx-vector.h:101
ns3::WifiTxVector::SetMode
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
Definition
wifi-tx-vector.cc:274
uint32_t
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
cmd
Definition
second.py:29
examples
wireless
wifi-error-models-comparison.cc
Generated on Mon Dec 15 2025 15:21:48 for ns-3 by
1.9.8