diff --git a/examples/wireless/CMakeLists.txt b/examples/wireless/CMakeLists.txt index 7f5004910..cad81d69f 100644 --- a/examples/wireless/CMakeLists.txt +++ b/examples/wireless/CMakeLists.txt @@ -285,3 +285,10 @@ build_example( ${libbridge} ${libapplications} ) + +build_example( + NAME wifi-ofdm-eht-validation + SOURCE_FILES wifi-ofdm-eht-validation.cc + LIBRARIES_TO_LINK ${libwifi} +) + diff --git a/examples/wireless/wifi-ofdm-eht-validation.cc b/examples/wireless/wifi-ofdm-eht-validation.cc new file mode 100644 index 000000000..c7def4b33 --- /dev/null +++ b/examples/wireless/wifi-ofdm-eht-validation.cc @@ -0,0 +1,141 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2021 DERONNE SOFTWARE ENGINEERING + * + * 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 + * + * Author: Sébastien Deronne + */ + +// This example is used to validate NIST and YANS error rate models for EHT rates. +// +// It outputs plots of the Frame Success Rate versus the Signal-to-noise ratio for +// Nist, Yans and Table-based error rate models and for every HT MCS value. + +#include +#include +#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 FrameSize = 1500; //bytes + std::ofstream yansfile ("yans-frame-success-rate-be.plt"); + std::ofstream nistfile ("nist-frame-success-rate-be.plt"); + std::ofstream tablefile ("table-frame-success-rate-be.plt"); + std::vector modes; + + modes.push_back ("EhtMcs0"); + modes.push_back ("EhtMcs1"); + modes.push_back ("EhtMcs2"); + modes.push_back ("EhtMcs3"); + modes.push_back ("EhtMcs4"); + modes.push_back ("EhtMcs5"); + modes.push_back ("EhtMcs6"); + modes.push_back ("EhtMcs7"); + modes.push_back ("EhtMcs8"); + modes.push_back ("EhtMcs9"); + modes.push_back ("EhtMcs10"); + modes.push_back ("EhtMcs11"); + modes.push_back ("EhtMcs12"); + modes.push_back ("EhtMcs13"); + + CommandLine cmd (__FILE__); + cmd.AddValue ("FrameSize", "The frame size", FrameSize); + cmd.Parse (argc, argv); + + Gnuplot yansplot = Gnuplot ("yans-frame-success-rate-be.eps"); + Gnuplot nistplot = Gnuplot ("nist-frame-success-rate-be.eps"); + Gnuplot tableplot = Gnuplot ("table-frame-success-rate-be.eps"); + + Ptr yans = CreateObject (); + Ptr nist = CreateObject (); + Ptr table = CreateObject (); + WifiTxVector txVector; + + 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 <= 55.0; snr += 0.1) + { + double ps = yans->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8); + if (ps < 0.0 || ps > 1.0) + { + //error + exit (1); + } + yansdataset.Add (snr, ps); + + ps = nist->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0,snr / 10.0), FrameSize * 8); + if (ps < 0.0 || ps > 1.0) + { + //error + exit (1); + } + nistdataset.Add (snr, ps); + + ps = table->GetChunkSuccessRate (WifiMode (modes[i]), txVector, std::pow (10.0, snr / 10.0), FrameSize * 8); + if (ps < 0.0 || ps > 1.0) + { + //error + exit (1); + } + tabledataset.Add (snr, ps); + } + + yansplot.AddDataset (yansdataset); + nistplot.AddDataset (nistdataset); + tableplot.AddDataset (tabledataset); + } + + std::stringstream plotExtra; + plotExtra << "set xrange [-5:55]\n\ +set yrange [0:1]\n"; + uint8_t lineNumber = 1; + const std::string colors[14] = {"green", "blue", "red", "black", "orange", "purple", "yellow", "pink", "grey", "magenta", "brown", "turquoise", "olive", "beige"}; + for (uint32_t i = 0; i < modes.size (); i++) + { + plotExtra << "set style line " << +lineNumber++ << " linewidth 5 linecolor rgb \"" << colors[i] << "\" \n"; + } + plotExtra << "set style increment user"; + + yansplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\""); + yansplot.SetLegend ("SNR(dB)", "Frame Success Rate"); + yansplot.SetExtra (plotExtra.str ()); + yansplot.GenerateOutput (yansfile); + yansfile.close (); + + nistplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\""); + nistplot.SetLegend ("SNR(dB)", "Frame Success Rate"); + nistplot.SetExtra (plotExtra.str ()); + nistplot.GenerateOutput (nistfile); + nistfile.close (); + + tableplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\""); + tableplot.SetLegend ("SNR(dB)", "Frame Success Rate"); + tableplot.SetExtra (plotExtra.str ()); + tableplot.GenerateOutput (tablefile); + tablefile.close (); +}