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