author | Tom Henderson <tomh@tomh.org> |
Wed, 16 Nov 2011 22:01:06 -0800 | |
changeset 10712 | b953606d11fa |
child 10720 | 4e4a0de88982 |
permissions | -rw-r--r-- |
10712
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
2 |
/* |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
3 |
* Copyright (c) 2011 The Boeing Company |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
4 |
* |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
8 |
* |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
13 |
* |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
17 |
* |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
18 |
* Author: Gary Pei <guangyu.pei@boeing.com> |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
19 |
*/ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
20 |
#include "ns3/packet.h" |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
21 |
#include "ns3/uinteger.h" |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
22 |
#include "ns3/simulator.h" |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
23 |
#include "ns3/nstime.h" |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
24 |
#include "ns3/log.h" |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
25 |
#include "ns3/abort.h" |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
26 |
#include "ns3/command-line.h" |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
27 |
#include "ns3/gnuplot.h" |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
28 |
#include "ns3/lr-wpan-error-model.h" |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
29 |
|
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
30 |
#include <fstream> |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
31 |
#include <iostream> |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
32 |
#include <string> |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
33 |
#include <vector> |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
34 |
|
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
35 |
using namespace ns3; |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
36 |
using namespace std; |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
37 |
|
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
38 |
NS_LOG_COMPONENT_DEFINE ("LrWpanErrorModelPlot"); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
39 |
|
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
40 |
// |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
41 |
// Plot 802.15.4 BER curve (compare against Figure E.2 of IEEE-802.15.4-2006) |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
42 |
// |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
43 |
int main (int argc, char *argv[]) |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
44 |
{ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
45 |
std::ofstream berfile ("802.15.4-ber.plt"); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
46 |
Ptr<LrWpanErrorModel> lrWpanError = CreateObject<LrWpanErrorModel> (); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
47 |
|
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
48 |
double increment = 0.1; |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
49 |
double minSnr = -10; //dB |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
50 |
double maxSnr = 5; |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
51 |
|
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
52 |
Gnuplot berplot = Gnuplot ("802.15.4-ber.eps"); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
53 |
Gnuplot2dDataset berdataset ("802.15.4"); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
54 |
|
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
55 |
for (double snr = minSnr; snr <= maxSnr; snr += increment) |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
56 |
{ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
57 |
double ber = 1.0 - lrWpanError->GetChunkSuccessRate (pow (10.0,snr / 10.0), 1); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
58 |
NS_LOG_DEBUG (snr << "(dB) " << ber << " (BER)"); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
59 |
berdataset.Add (snr, ber); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
60 |
} |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
61 |
|
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
62 |
berplot.AddDataset (berdataset); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
63 |
|
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
64 |
berplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\""); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
65 |
berplot.SetLegend ("SNR (dB)", "Bit Error Rate (BER)"); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
66 |
berplot.SetExtra ("set xrange [-10:15]\n\ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
67 |
set yrange [1e-9:1]\n\ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
68 |
set log y\n\ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
69 |
set grid\n\ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
70 |
set style line 1 linewidth 5\n\ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
71 |
set style line 2 linewidth 5\n\ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
72 |
set style line 3 linewidth 5\n\ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
73 |
set style line 4 linewidth 5\n\ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
74 |
set style line 5 linewidth 5\n\ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
75 |
set style line 6 linewidth 5\n\ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
76 |
set style line 7 linewidth 5\n\ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
77 |
set style line 8 linewidth 5\n\ |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
78 |
set style increment user"); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
79 |
berplot.GenerateOutput (berfile); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
80 |
berfile.close (); |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
81 |
|
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
82 |
return 0; |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
83 |
} |
b953606d11fa
roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
84 |