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-dsss-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 error rate models for DSSS rates.
8
//
9
// It outputs plots of the Frame Success Rate versus the Signal-to-noise ratio
10
// for the DSSS error rate models and for every DSSS mode.
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
file
(
"frame-success-rate-dsss.plt"
);
29
30
const
std::vector<std::string>
modes
{
31
"DsssRate1Mbps"
,
32
"DsssRate2Mbps"
,
33
"DsssRate5_5Mbps"
,
34
"DsssRate11Mbps"
,
35
};
36
37
CommandLine
cmd
(
__FILE__
);
38
cmd
.AddValue(
"FrameSize"
,
"The frame size in bytes"
,
frameSizeBytes
);
39
cmd
.Parse(
argc
,
argv
);
40
41
Gnuplot
plot
=
Gnuplot
(
"frame-success-rate-dsss.eps"
);
42
43
Ptr<YansErrorRateModel>
yans
=
CreateObject<YansErrorRateModel>
();
44
Ptr<NistErrorRateModel>
nist
=
CreateObject<NistErrorRateModel>
();
45
Ptr<TableBasedErrorRateModel>
table =
CreateObject<TableBasedErrorRateModel>
();
46
WifiTxVector
txVector;
47
48
uint32_t
frameSizeBits
=
frameSizeBytes
* 8;
49
50
for
(
const
auto
& mode :
modes
)
51
{
52
std::cout << mode << std::endl;
53
Gnuplot2dDataset
dataset
(mode);
54
txVector.
SetMode
(mode);
55
56
WifiMode
wifiMode
(mode);
57
58
for
(
double
snrDb
= -10.0;
snrDb
<= 20.0;
snrDb
+= 0.1)
59
{
60
double
snr = std::pow(10.0,
snrDb
/ 10.0);
61
62
double
psYans
=
yans
->GetChunkSuccessRate(
wifiMode
, txVector, snr,
frameSizeBits
);
63
if
(
psYans < 0.0 || psYans >
1.0)
64
{
65
// error
66
exit
(1);
67
}
68
double
psNist
=
nist
->GetChunkSuccessRate(
wifiMode
, txVector, snr,
frameSizeBits
);
69
if
(
psNist < 0.0 || psNist >
1.0)
70
{
71
std::cout <<
psNist
<< std::endl;
72
// error
73
exit
(1);
74
}
75
if
(
psNist
!=
psYans
)
76
{
77
exit
(1);
78
}
79
double
psTable
= table->GetChunkSuccessRate(
wifiMode
, txVector, snr,
frameSizeBits
);
80
if
(
psTable < 0.0 || psTable >
1.0)
81
{
82
std::cout <<
psTable
<< std::endl;
83
// error
84
exit
(1);
85
}
86
if
(
psTable
!=
psYans
)
87
{
88
exit
(1);
89
}
90
dataset
.Add(
snrDb
,
psYans
);
91
}
92
93
plot
.AddDataset(
dataset
);
94
}
95
96
plot
.SetTerminal(
"postscript eps color enh \"Times-BoldItalic\""
);
97
plot
.SetLegend(
"SNR(dB)"
,
"Frame Success Rate"
);
98
plot
.SetExtra(
"set xrange [-10:20]\n\
99
set yrange [0:1.2]\n\
100
set style line 1 linewidth 5\n\
101
set style line 2 linewidth 5\n\
102
set style line 3 linewidth 5\n\
103
set style line 4 linewidth 5\n\
104
set style line 5 linewidth 5\n\
105
set style line 6 linewidth 5\n\
106
set style line 7 linewidth 5\n\
107
set style line 8 linewidth 5\n\
108
set style increment user"
);
109
plot
.GenerateOutput(file);
110
file
.close();
111
112
return
0;
113
}
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
create-module.file
file
Definition
create-module.py:673
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
cmd
Definition
second.py:29
examples
wireless
wifi-dsss-validation.cc
Generated on Mon Dec 15 2025 15:21:48 for ns-3 by
1.9.8