sat-link-results-plot.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Magister Solutions
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Budiarto Herman <budiarto.herman@magister.fi>
19  *
20  */
21 
22 #include "ns3/core-module.h"
23 #include "ns3/gnuplot.h"
24 #include "ns3/satellite-env-variables.h"
25 #include "ns3/satellite-look-up-table.h"
26 #include "ns3/singleton.h"
27 
28 #include <fstream>
29 #include <stdint.h>
30 
38 NS_LOG_COMPONENT_DEFINE("SatLinkResultsPlot");
39 
40 namespace ns3
41 {
42 
62 class SatLinkResultsPlot : public SimpleRefCount<SatLinkResultsPlot>
63 {
64  public:
68  void Run();
69 
70  private:
71  void RunDvbRcs2Qpsk();
72  void RunDvbRcs2Psk8();
73  void RunDvbRcs2Qam16();
74  void RunDvbS2Qpsk();
75  void RunDvbS2Psk8();
76  void RunDvbS2Apsk16();
77  void RunDvbS2Apsk32();
78 
79  Gnuplot2dDataset GetGnuplotDataset(Ptr<SatLookUpTable> table, std::string title);
80  Gnuplot GetGnuplot(std::string outputName, std::string title);
81 
83  double m_minSinrDb;
84  double m_maxSinrDb;
85  std::string m_inputPath;
86 
87 }; // end of class SatLinkResultsPlot
88 
90 {
91  m_resolutionDb = 0.01;
92  m_minSinrDb = 0.0;
93  m_maxSinrDb = 20.0;
94  m_inputPath =
95  Singleton<SatEnvVariables>::Get()->GetDataPath() + "/additional-input/linkresults/";
96 }
97 
98 void
100 {
101  RunDvbRcs2Qpsk();
102  RunDvbRcs2Psk8();
103  RunDvbRcs2Qam16();
104  RunDvbS2Qpsk();
105  RunDvbS2Psk8();
106  RunDvbS2Apsk16();
107  RunDvbS2Apsk32();
108 }
109 
110 void
112 {
113  Ptr<SatLookUpTable> table1 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat2.txt");
114  Ptr<SatLookUpTable> table2 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat3.txt");
115  Ptr<SatLookUpTable> table3 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat4.txt");
116  Ptr<SatLookUpTable> table4 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat5.txt");
117  Ptr<SatLookUpTable> table5 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat6.txt");
118  Ptr<SatLookUpTable> table6 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat7.txt");
119  Ptr<SatLookUpTable> table7 =
120  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat13.txt");
121  Ptr<SatLookUpTable> table8 =
122  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat14.txt");
123  Ptr<SatLookUpTable> table9 =
124  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat15.txt");
125  Ptr<SatLookUpTable> table10 =
126  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat16.txt");
127  Ptr<SatLookUpTable> table11 =
128  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat17.txt");
129 
130  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "Waveform 2: 112 bits, QPSK 1/3");
131  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "Waveform 3: 304 bits, QPSK 1/3");
132  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "Waveform 4: 472 bits, QPSK 1/2");
133  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "Waveform 5: 680 bits, QPSK 2/3");
134  Gnuplot2dDataset dataset5 = GetGnuplotDataset(table5, "Waveform 6: 768 bits, QPSK 3/4");
135  Gnuplot2dDataset dataset6 = GetGnuplotDataset(table6, "Waveform 7: 864 bits, QPSK 5/6");
136  Gnuplot2dDataset dataset7 = GetGnuplotDataset(table7, "Waveform 13: 984 bits, QPSK 1/3");
137  Gnuplot2dDataset dataset8 = GetGnuplotDataset(table8, "Waveform 14: 1504 bits, QPSK 1/2");
138  Gnuplot2dDataset dataset9 = GetGnuplotDataset(table9, "Waveform 15: 2112 bits, QPSK 2/3");
139  Gnuplot2dDataset dataset10 = GetGnuplotDataset(table10, "Waveform 16: 2384 bits, QPSK 3/4");
140  Gnuplot2dDataset dataset11 = GetGnuplotDataset(table11, "Waveform 17: 2664 bits, QPSK 5/6");
141 
142  Gnuplot plot = GetGnuplot("rcs2_qpsk", "Link Results for DVB-RCS2 with QPSK");
143  plot.AddDataset(dataset1);
144  plot.AddDataset(dataset2);
145  plot.AddDataset(dataset3);
146  plot.AddDataset(dataset4);
147  plot.AddDataset(dataset5);
148  plot.AddDataset(dataset6);
149  plot.AddDataset(dataset7);
150  plot.AddDataset(dataset8);
151  plot.AddDataset(dataset9);
152  plot.AddDataset(dataset10);
153  plot.AddDataset(dataset11);
154 
155  std::string plotFileName = "rcs2_qpsk.plt";
156  std::ofstream plotFile(plotFileName.c_str());
157  plot.GenerateOutput(plotFile);
158  plotFile.close();
159 
160  std::cout << "Output file written: " << plotFileName << std::endl;
161 
162 } // end of void SatLinkResultsPlot::RunDvbRcs2Qpsk ()
163 
164 void
166 {
167  Ptr<SatLookUpTable> table1 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat8.txt");
168  Ptr<SatLookUpTable> table2 = CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat9.txt");
169  Ptr<SatLookUpTable> table3 =
170  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat10.txt");
171  Ptr<SatLookUpTable> table4 =
172  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat18.txt");
173  Ptr<SatLookUpTable> table5 =
174  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat19.txt");
175  Ptr<SatLookUpTable> table6 =
176  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat20.txt");
177 
178  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "Waveform 8: 920 bits, 8PSK 2/3");
179  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "Waveform 9: 1040 bits, 8PSK 3/4");
180  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "Waveform 10: 1152 bits, 8PSK 5/6");
181  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "Waveform 18: 2840 bits, 8PSK 2/3");
182  Gnuplot2dDataset dataset5 = GetGnuplotDataset(table5, "Waveform 19: 3200 bits, 8PSK 3/4");
183  Gnuplot2dDataset dataset6 = GetGnuplotDataset(table6, "Waveform 20: 3552 bits, 8PSK 5/6");
184 
185  Gnuplot plot = GetGnuplot("rcs2_8psk", "Link Results for DVB-RCS2 with 8PSK");
186  plot.AddDataset(dataset1);
187  plot.AddDataset(dataset2);
188  plot.AddDataset(dataset3);
189  plot.AddDataset(dataset4);
190  plot.AddDataset(dataset5);
191  plot.AddDataset(dataset6);
192 
193  std::string plotFileName = "rcs2_8psk.plt";
194  std::ofstream plotFile(plotFileName.c_str());
195  plot.GenerateOutput(plotFile);
196  plotFile.close();
197 
198  std::cout << "Output file written: " << plotFileName << std::endl;
199 
200 } // end of void SatLinkResultsPlot::RunDvbRcs2Psk8 ()
201 
202 void
204 {
205  Ptr<SatLookUpTable> table1 =
206  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat11.txt");
207  Ptr<SatLookUpTable> table2 =
208  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat12.txt");
209  Ptr<SatLookUpTable> table3 =
210  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat21.txt");
211  Ptr<SatLookUpTable> table4 =
212  CreateObject<SatLookUpTable>(m_inputPath + "rcs2_waveformat22.txt");
213 
214  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "Waveform 11: 1400 bits, 16QAM 3/4");
215  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "Waveform 12: 1552 bits, 16QAM 5/6");
216  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "Waveform 21: 4312 bits, 16QAM 3/4");
217  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "Waveform 22: 4792 bits, 16QAM 5/6");
218 
219  Gnuplot plot = GetGnuplot("rcs2_16qam", "Link Results for DVB-RCS2 with 16QAM");
220  plot.AddDataset(dataset1);
221  plot.AddDataset(dataset2);
222  plot.AddDataset(dataset3);
223  plot.AddDataset(dataset4);
224 
225  std::string plotFileName = "rcs2_16qam.plt";
226  std::ofstream plotFile(plotFileName.c_str());
227  plot.GenerateOutput(plotFile);
228  plotFile.close();
229 
230  std::cout << "Output file written: " << plotFileName << std::endl;
231 
232 } // end of void SatLinkResultsPlot::RunDvbRcs2Qam16 ()
233 
234 void
236 {
237  Ptr<SatLookUpTable> table1 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_1_to_2.txt");
238  Ptr<SatLookUpTable> table2 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_2_to_3.txt");
239  Ptr<SatLookUpTable> table3 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_3_to_4.txt");
240  Ptr<SatLookUpTable> table4 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_3_to_5.txt");
241  Ptr<SatLookUpTable> table5 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_4_to_5.txt");
242  Ptr<SatLookUpTable> table6 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_5_to_6.txt");
243  Ptr<SatLookUpTable> table7 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_8_to_9.txt");
244  Ptr<SatLookUpTable> table8 = CreateObject<SatLookUpTable>(m_inputPath + "s2_qpsk_9_to_10.txt");
245 
246  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "QPSK 1/2");
247  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "QPSK 2/3");
248  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "QPSK 3/4");
249  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "QPSK 3/5");
250  Gnuplot2dDataset dataset5 = GetGnuplotDataset(table5, "QPSK 4/5");
251  Gnuplot2dDataset dataset6 = GetGnuplotDataset(table6, "QPSK 5/6");
252  Gnuplot2dDataset dataset7 = GetGnuplotDataset(table7, "QPSK 8/9");
253  Gnuplot2dDataset dataset8 = GetGnuplotDataset(table8, "QPSK 9/10");
254 
255  Gnuplot plot = GetGnuplot("s2_qpsk", "Link Results for DVB-S2 with QPSK");
256  plot.AddDataset(dataset1);
257  plot.AddDataset(dataset2);
258  plot.AddDataset(dataset3);
259  plot.AddDataset(dataset4);
260  plot.AddDataset(dataset5);
261  plot.AddDataset(dataset6);
262  plot.AddDataset(dataset7);
263  plot.AddDataset(dataset8);
264 
265  std::string plotFileName = "s2_qpsk.plt";
266  std::ofstream plotFile(plotFileName.c_str());
267  plot.GenerateOutput(plotFile);
268  plotFile.close();
269 
270  std::cout << "Output file written: " << plotFileName << std::endl;
271 
272 } // end of void SatLinkResultsPlot::RunDvbS2Qpsk ()
273 
274 void
276 {
277  Ptr<SatLookUpTable> table1 = CreateObject<SatLookUpTable>(m_inputPath + "s2_8psk_2_to_3.txt");
278  Ptr<SatLookUpTable> table2 = CreateObject<SatLookUpTable>(m_inputPath + "s2_8psk_3_to_4.txt");
279  Ptr<SatLookUpTable> table3 = CreateObject<SatLookUpTable>(m_inputPath + "s2_8psk_3_to_5.txt");
280  Ptr<SatLookUpTable> table4 = CreateObject<SatLookUpTable>(m_inputPath + "s2_8psk_5_to_6.txt");
281  Ptr<SatLookUpTable> table5 = CreateObject<SatLookUpTable>(m_inputPath + "s2_8psk_8_to_9.txt");
282  Ptr<SatLookUpTable> table6 = CreateObject<SatLookUpTable>(m_inputPath + "s2_8psk_9_to_10.txt");
283 
284  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "8PSK 2/3");
285  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "8PSK 3/4");
286  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "8PSK 3/5");
287  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "8PSK 5/6");
288  Gnuplot2dDataset dataset5 = GetGnuplotDataset(table5, "8PSK 8/9");
289  Gnuplot2dDataset dataset6 = GetGnuplotDataset(table6, "8PSK 9/10");
290 
291  Gnuplot plot = GetGnuplot("s2_8psk", "Link Results for DVB-S2 with 8PSK");
292  plot.AddDataset(dataset1);
293  plot.AddDataset(dataset2);
294  plot.AddDataset(dataset3);
295  plot.AddDataset(dataset4);
296  plot.AddDataset(dataset5);
297  plot.AddDataset(dataset6);
298 
299  std::string plotFileName = "s2_8psk.plt";
300  std::ofstream plotFile(plotFileName.c_str());
301  plot.GenerateOutput(plotFile);
302  plotFile.close();
303 
304  std::cout << "Output file written: " << plotFileName << std::endl;
305 
306 } // end of void SatLinkResultsPlot::RunDvbS2Psk8 ()
307 
308 void
310 {
311  Ptr<SatLookUpTable> table1 = CreateObject<SatLookUpTable>(m_inputPath + "s2_16apsk_2_to_3.txt");
312  Ptr<SatLookUpTable> table2 = CreateObject<SatLookUpTable>(m_inputPath + "s2_16apsk_3_to_4.txt");
313  Ptr<SatLookUpTable> table3 = CreateObject<SatLookUpTable>(m_inputPath + "s2_16apsk_4_to_5.txt");
314  Ptr<SatLookUpTable> table4 = CreateObject<SatLookUpTable>(m_inputPath + "s2_16apsk_5_to_6.txt");
315  Ptr<SatLookUpTable> table5 = CreateObject<SatLookUpTable>(m_inputPath + "s2_16apsk_8_to_9.txt");
316  Ptr<SatLookUpTable> table6 =
317  CreateObject<SatLookUpTable>(m_inputPath + "s2_16apsk_9_to_10.txt");
318 
319  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "16APSK 2/3");
320  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "16APSK 3/4");
321  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "16APSK 4/5");
322  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "16APSK 5/6");
323  Gnuplot2dDataset dataset5 = GetGnuplotDataset(table5, "16APSK 8/9");
324  Gnuplot2dDataset dataset6 = GetGnuplotDataset(table6, "16APSK 9/10");
325 
326  Gnuplot plot = GetGnuplot("s2_16apsk", "Link Results for DVB-S2 with 16APSK");
327  plot.AddDataset(dataset1);
328  plot.AddDataset(dataset2);
329  plot.AddDataset(dataset3);
330  plot.AddDataset(dataset4);
331  plot.AddDataset(dataset5);
332  plot.AddDataset(dataset6);
333 
334  std::string plotFileName = "s2_16apsk.plt";
335  std::ofstream plotFile(plotFileName.c_str());
336  plot.GenerateOutput(plotFile);
337  plotFile.close();
338 
339  std::cout << "Output file written: " << plotFileName << std::endl;
340 
341 } // end of void SatLinkResultsPlot::RunDvbS2Apsk16 ()
342 
343 void
345 {
346  Ptr<SatLookUpTable> table1 = CreateObject<SatLookUpTable>(m_inputPath + "s2_32apsk_3_to_4.txt");
347  Ptr<SatLookUpTable> table2 = CreateObject<SatLookUpTable>(m_inputPath + "s2_32apsk_4_to_5.txt");
348  Ptr<SatLookUpTable> table3 = CreateObject<SatLookUpTable>(m_inputPath + "s2_32apsk_5_to_6.txt");
349  Ptr<SatLookUpTable> table4 = CreateObject<SatLookUpTable>(m_inputPath + "s2_32apsk_8_to_9.txt");
350 
351  Gnuplot2dDataset dataset1 = GetGnuplotDataset(table1, "32APSK 3/4");
352  Gnuplot2dDataset dataset2 = GetGnuplotDataset(table2, "32APSK 4/5");
353  Gnuplot2dDataset dataset3 = GetGnuplotDataset(table3, "32APSK 5/6");
354  Gnuplot2dDataset dataset4 = GetGnuplotDataset(table4, "32APSK 8/9");
355 
356  Gnuplot plot = GetGnuplot("s2_32apsk", "Link Results for DVB-S2 with 32APSK");
357  plot.AddDataset(dataset1);
358  plot.AddDataset(dataset2);
359  plot.AddDataset(dataset3);
360  plot.AddDataset(dataset4);
361 
362  std::string plotFileName = "s2_32apsk.plt";
363  std::ofstream plotFile(plotFileName.c_str());
364  plot.GenerateOutput(plotFile);
365  plotFile.close();
366 
367  std::cout << "Output file written: " << plotFileName << std::endl;
368 
369 } // end of void SatLinkResultsPlot::RunDvbS2Apsk32 ()
370 
371 Gnuplot2dDataset
372 SatLinkResultsPlot::GetGnuplotDataset(Ptr<SatLookUpTable> table, std::string title)
373 {
374  Gnuplot2dDataset ret;
375  ret.SetTitle(title);
376  ret.SetStyle(Gnuplot2dDataset::LINES);
377 
378  bool writeFlag = false;
379  double bler;
380 
381  for (double sinr = m_minSinrDb; sinr < m_maxSinrDb; sinr += m_resolutionDb)
382  {
383  bler = table->GetBler(sinr);
384 
385  if (!writeFlag)
386  {
387  if (bler < 1)
388  {
389  // first time error rate is not 100%
390  writeFlag = true; // start writing the plot
391  ret.Add(sinr - m_resolutionDb, 1.0); // also add the previous point
392  ret.Add(sinr, bler);
393  }
394  }
395  else
396  {
397  if (bler < 1e-10)
398  {
399  // close enough to 0% error rate
400  writeFlag = false; // stop writing the plot
401  sinr = m_maxSinrDb; // exit for
402  }
403  else
404  {
405  ret.Add(sinr, bler);
406  }
407  }
408 
409  } // end of for (sinr = m_minSinrDb; sinr < m_maxSinrDb; sinr += m_resolutionDb)
410 
411  return ret;
412 
413 } // end of GetGnuplotDataset
414 
415 Gnuplot
416 SatLinkResultsPlot::GetGnuplot(std::string outputName, std::string title)
417 {
418  Gnuplot ret(outputName + ".png");
419  ret.SetTitle(title);
420  ret.SetTerminal("png");
421  ret.SetLegend("SINR (in dB)", "BLER");
422  ret.AppendExtra("set key bottom left");
423  ret.AppendExtra("set logscale y 10");
424  ret.AppendExtra("set ytics 10");
425  ret.AppendExtra("set mxtics 5");
426  ret.AppendExtra("set grid xtics mxtics ytics");
427  // TODO probably better if the X axis and its labels are on top and maybe emphasize major grid
428  // lines more than minor ones
429  return ret;
430 }
431 
432 } // end of namespace ns3
433 
434 int
435 main(int argc, char* argv[])
436 {
437  ns3::Ptr<ns3::SatLinkResultsPlot> stub;
438  stub = ns3::Create<ns3::SatLinkResultsPlot>();
439  stub->Run();
440 
441  return 0;
442 }
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.