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-ofdm-ht-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 HT 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 HT 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
22
using namespace
ns3
;
23
24
int
25
main(
int
argc
,
char
*
argv
[])
26
{
27
uint32_t
frameSizeBytes
= 1500;
28
std::ofstream
yansfile
(
"yans-frame-success-rate-n.plt"
);
29
std::ofstream
nistfile
(
"nist-frame-success-rate-n.plt"
);
30
std::ofstream
tablefile
(
"table-frame-success-rate-n.plt"
);
31
32
const
std::vector<std::string>
modes
{
33
"HtMcs0"
,
34
"HtMcs1"
,
35
"HtMcs2"
,
36
"HtMcs3"
,
37
"HtMcs4"
,
38
"HtMcs5"
,
39
"HtMcs6"
,
40
"HtMcs7"
,
41
};
42
43
CommandLine
cmd
(
__FILE__
);
44
cmd
.AddValue(
"FrameSize"
,
"The frame size in bytes"
,
frameSizeBytes
);
45
cmd
.Parse(
argc
,
argv
);
46
47
Gnuplot
yansplot
=
Gnuplot
(
"yans-frame-success-rate-n.eps"
);
48
Gnuplot
nistplot
=
Gnuplot
(
"nist-frame-success-rate-n.eps"
);
49
Gnuplot
tableplot
=
Gnuplot
(
"table-frame-success-rate-n.eps"
);
50
WifiTxVector
txVector;
51
52
Ptr<YansErrorRateModel>
yans
=
CreateObject<YansErrorRateModel>
();
53
Ptr<NistErrorRateModel>
nist
=
CreateObject<NistErrorRateModel>
();
54
Ptr<TableBasedErrorRateModel>
table =
CreateObject<TableBasedErrorRateModel>
();
55
56
uint32_t
frameSizeBits
=
frameSizeBytes
* 8;
57
58
for
(
const
auto
& mode :
modes
)
59
{
60
std::cout << mode << std::endl;
61
Gnuplot2dDataset
yansdataset
(mode);
62
Gnuplot2dDataset
nistdataset
(mode);
63
Gnuplot2dDataset
tabledataset
(mode);
64
txVector.
SetMode
(mode);
65
66
WifiMode
wifiMode
(mode);
67
68
for
(
double
snrDb
= -5.0;
snrDb
<= 30.0;
snrDb
+= 0.1)
69
{
70
double
snr = std::pow(10.0,
snrDb
/ 10.0);
71
72
double
ps
=
yans
->GetChunkSuccessRate(
wifiMode
, txVector, snr,
frameSizeBits
);
73
if
(
ps < 0.0 || ps >
1.0)
74
{
75
// error
76
exit
(1);
77
}
78
yansdataset
.Add(
snrDb
,
ps
);
79
80
ps
=
nist
->GetChunkSuccessRate(
wifiMode
, txVector, snr,
frameSizeBits
);
81
if
(
ps < 0.0 || ps >
1.0)
82
{
83
// error
84
exit
(1);
85
}
86
nistdataset
.Add(
snrDb
,
ps
);
87
88
ps
= table->GetChunkSuccessRate(
wifiMode
, txVector, snr,
frameSizeBits
);
89
if
(
ps < 0.0 || ps >
1.0)
90
{
91
// error
92
exit
(1);
93
}
94
tabledataset
.Add(
snrDb
,
ps
);
95
}
96
97
yansplot
.AddDataset(
yansdataset
);
98
nistplot
.AddDataset(
nistdataset
);
99
tableplot
.AddDataset(
tabledataset
);
100
}
101
102
yansplot
.SetTerminal(
"postscript eps color enh \"Times-BoldItalic\""
);
103
yansplot
.SetLegend(
"SNR(dB)"
,
"Frame Success Rate"
);
104
yansplot
.SetExtra(
"set xrange [-5:30]\n\
105
set yrange [0:1.2]\n\
106
set style line 1 linewidth 5\n\
107
set style line 2 linewidth 5\n\
108
set style line 3 linewidth 5\n\
109
set style line 4 linewidth 5\n\
110
set style line 5 linewidth 5\n\
111
set style line 6 linewidth 5\n\
112
set style line 7 linewidth 5\n\
113
set style line 8 linewidth 5\n\
114
set style increment user"
);
115
yansplot
.GenerateOutput(
yansfile
);
116
yansfile
.close();
117
118
nistplot
.SetTerminal(
"postscript eps color enh \"Times-BoldItalic\""
);
119
nistplot
.SetLegend(
"SNR(dB)"
,
"Frame Success Rate"
);
120
nistplot
.SetExtra(
"set xrange [-5:30]\n\
121
set yrange [0:1.2]\n\
122
set style line 1 linewidth 5\n\
123
set style line 2 linewidth 5\n\
124
set style line 3 linewidth 5\n\
125
set style line 4 linewidth 5\n\
126
set style line 5 linewidth 5\n\
127
set style line 6 linewidth 5\n\
128
set style line 7 linewidth 5\n\
129
set style line 8 linewidth 5\n\
130
set style increment user"
);
131
132
nistplot
.GenerateOutput(
nistfile
);
133
nistfile
.close();
134
135
tableplot
.SetTerminal(
"postscript eps color enh \"Times-BoldItalic\""
);
136
tableplot
.SetLegend(
"SNR(dB)"
,
"Frame Success Rate"
);
137
tableplot
.SetExtra(
"set xrange [-5:30]\n\
138
set yrange [0:1.2]\n\
139
set style line 1 linewidth 5\n\
140
set style line 2 linewidth 5\n\
141
set style line 3 linewidth 5\n\
142
set style line 4 linewidth 5\n\
143
set style line 5 linewidth 5\n\
144
set style line 6 linewidth 5\n\
145
set style line 7 linewidth 5\n\
146
set style line 8 linewidth 5\n\
147
set style increment user"
);
148
149
tableplot
.GenerateOutput(
tablefile
);
150
tablefile
.close();
151
152
return
0;
153
}
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-ofdm-ht-validation.cc
Generated on Mon Dec 15 2025 15:21:48 for ns-3 by
1.9.8