examples: Add example to compare wifi error rate models
This commit is contained in:
committed by
Sebastien Deronne
parent
be8a4fe60a
commit
41ceefb0e4
@@ -36,6 +36,7 @@ cpp_examples = [
|
||||
("wifi-ofdm-ht-validation", "True", "True"),
|
||||
("wifi-ofdm-vht-validation", "True", "True"),
|
||||
("wifi-ofdm-he-validation", "True", "True"),
|
||||
("wifi-error-models-comparison", "True", "True"),
|
||||
("wifi-80211n-mimo --simulationTime=0.1 --step=10", "True", "True"),
|
||||
("wifi-ht-network --simulationTime=0.2 --frequency=5 --useRts=0 --minExpectedThroughput=5 --maxExpectedThroughput=135", "True", "True"),
|
||||
("wifi-ht-network --simulationTime=0.2 --frequency=5 --useRts=1 --minExpectedThroughput=5 --maxExpectedThroughput=131", "True", "True"),
|
||||
|
||||
168
examples/wireless/wifi-error-models-comparison.cc
Normal file
168
examples/wireless/wifi-error-models-comparison.cc
Normal file
@@ -0,0 +1,168 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2020 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Authors: Sébastien Deronne <sebastien.deronne@gmail.com>
|
||||
* Rohan Patidar <rpatidar@uw.edu>
|
||||
*/
|
||||
|
||||
// This example is to show difference among Nist, Yans and Table-based error rate models.
|
||||
//
|
||||
// It outputs plots of the Frame Error Rate versus the Signal-to-noise ratio for
|
||||
// Nist, Yans and Table-based error rate models and for MCS 0, 4 and 7 value.
|
||||
|
||||
#include <fstream>
|
||||
#include <cmath>
|
||||
#include "ns3/gnuplot.h"
|
||||
#include "ns3/command-line.h"
|
||||
#include "ns3/yans-error-rate-model.h"
|
||||
#include "ns3/nist-error-rate-model.h"
|
||||
#include "ns3/table-based-error-rate-model.h"
|
||||
#include "ns3/wifi-tx-vector.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
uint32_t size = 1500 * 8; //bits
|
||||
bool tableErrorModelEnabled = true;
|
||||
bool yansErrorModelEnabled = true;
|
||||
bool nistErrorModelEnabled = true;
|
||||
uint8_t beginMcs = 0;
|
||||
uint8_t endMcs = 7;
|
||||
uint8_t stepMcs = 4;
|
||||
std::string format ("Ht");
|
||||
|
||||
CommandLine cmd (__FILE__);
|
||||
cmd.AddValue ("size", "The size in bits", size);
|
||||
cmd.AddValue ("frameFormat", "The frame format to use: Ht, Vht or He", format);
|
||||
cmd.AddValue ("beginMcs", "The first MCS to test", beginMcs);
|
||||
cmd.AddValue ("endMcs", "The last MCS to test", endMcs);
|
||||
cmd.AddValue ("stepMcs", "The step between two MCSs to test", stepMcs);
|
||||
cmd.AddValue ("includeTableErrorModel", "Flag to include/exclude Table-based error model", tableErrorModelEnabled);
|
||||
cmd.AddValue ("includeYansErrorModel", "Flag to include/exclude Yans error model", yansErrorModelEnabled);
|
||||
cmd.AddValue ("includeNistErrorModel", "Flag to include/exclude Nist error model", nistErrorModelEnabled);
|
||||
cmd.Parse (argc, argv);
|
||||
|
||||
std::ofstream errormodelfile ("wifi-error-rate-models.plt");
|
||||
Gnuplot plot = Gnuplot ("wifi-error-rate-models.eps");
|
||||
|
||||
Ptr <YansErrorRateModel> yans = CreateObject<YansErrorRateModel> ();
|
||||
Ptr <NistErrorRateModel> nist = CreateObject<NistErrorRateModel> ();
|
||||
Ptr <TableBasedErrorRateModel> table = CreateObject<TableBasedErrorRateModel> ();
|
||||
WifiTxVector txVector;
|
||||
std::vector <std::string> modes;
|
||||
|
||||
std::stringstream mode;
|
||||
mode << format << "Mcs" << +beginMcs;
|
||||
modes.push_back (mode.str ());
|
||||
for (uint8_t mcs = (beginMcs + stepMcs); mcs < endMcs; mcs += stepMcs)
|
||||
{
|
||||
mode.str ("");
|
||||
mode << format << "Mcs" << +mcs;
|
||||
modes.push_back (mode.str ());
|
||||
}
|
||||
mode.str ("");
|
||||
mode << format << "Mcs" << +endMcs;
|
||||
modes.push_back (mode.str ());
|
||||
|
||||
for (uint32_t i = 0; i < modes.size (); i++)
|
||||
{
|
||||
std::cout << modes[i] << std::endl;
|
||||
Gnuplot2dDataset yansdataset (modes[i]);
|
||||
Gnuplot2dDataset nistdataset (modes[i]);
|
||||
Gnuplot2dDataset tabledataset (modes[i]);
|
||||
txVector.SetMode (modes[i]);
|
||||
|
||||
for (double snr = -5.0; snr <= (endMcs * 5); snr += 0.1)
|
||||
{
|
||||
double ps = yans->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0, snr / 10.0), size);
|
||||
if (ps < 0 || ps > 1)
|
||||
{
|
||||
//error
|
||||
exit (1);
|
||||
}
|
||||
yansdataset.Add (snr, 1 - ps);
|
||||
ps = nist->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0, snr / 10.0), size);
|
||||
if (ps < 0 || ps > 1)
|
||||
{
|
||||
//error
|
||||
exit (1);
|
||||
}
|
||||
nistdataset.Add (snr, 1 - ps);
|
||||
ps = table->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0, snr / 10.0), size);
|
||||
if (ps < 0 || ps > 1)
|
||||
{
|
||||
//error
|
||||
exit (1);
|
||||
}
|
||||
tabledataset.Add (snr, 1 - ps);
|
||||
}
|
||||
|
||||
if (tableErrorModelEnabled)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Table-" << modes[i];
|
||||
tabledataset.SetTitle (ss.str());
|
||||
plot.AddDataset (tabledataset);
|
||||
}
|
||||
if (yansErrorModelEnabled)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Yans-" << modes[i];
|
||||
yansdataset.SetTitle (ss.str ());
|
||||
plot.AddDataset (yansdataset);
|
||||
}
|
||||
if (nistErrorModelEnabled)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Nist-" << modes[i];
|
||||
nistdataset.SetTitle (ss.str ());
|
||||
plot.AddDataset (nistdataset);
|
||||
}
|
||||
}
|
||||
|
||||
plot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
|
||||
plot.SetLegend ("SNR(dB)", "Frame Error Rate");
|
||||
|
||||
std::stringstream plotExtra;
|
||||
plotExtra << "set xrange [-5:" << endMcs * 5 << "]\n\
|
||||
set log y\n\
|
||||
set yrange [0.0001:1]\n";
|
||||
|
||||
uint8_t lineNumber = 1;
|
||||
for (uint32_t i = 0; i < modes.size (); i++)
|
||||
{
|
||||
if (tableErrorModelEnabled)
|
||||
{
|
||||
plotExtra << "set style line " << +lineNumber++ << " linewidth 5 linecolor rgb \"red\" \n";
|
||||
}
|
||||
if (yansErrorModelEnabled)
|
||||
{
|
||||
plotExtra << "set style line " << +lineNumber++ << " linewidth 5 linecolor rgb \"green\" \n";
|
||||
}
|
||||
if (nistErrorModelEnabled)
|
||||
{
|
||||
plotExtra << "set style line " << +lineNumber++ << " linewidth 5 linecolor rgb \"blue\" \n";
|
||||
}
|
||||
}
|
||||
|
||||
plotExtra << "set style increment user";
|
||||
plot.SetExtra (plotExtra.str ());
|
||||
|
||||
plot.GenerateOutput (errormodelfile);
|
||||
errormodelfile.close ();
|
||||
}
|
||||
@@ -121,3 +121,6 @@ def build(bld):
|
||||
|
||||
obj = bld.create_ns3_program('wifi-spatial-reuse', ['wifi', 'applications'])
|
||||
obj.source = 'wifi-spatial-reuse.cc'
|
||||
|
||||
obj = bld.create_ns3_program('wifi-error-models-comparison', ['wifi'])
|
||||
obj.source = 'wifi-error-models-comparison.cc'
|
||||
|
||||
Reference in New Issue
Block a user