A Discrete-Event Network Simulator
API
qkd-total-graph.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 DOTFEESA www.tk.etf.unsa.ba
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: Miralem Mehic <miralem.mehic@ieee.org>
19  */
20 
21 #include "qkd-total-graph.h"
22 
23 namespace ns3 {
24 
25 NS_LOG_COMPONENT_DEFINE ("QKDTotalGraph");
26 
27 NS_OBJECT_ENSURE_REGISTERED (QKDTotalGraph);
28 
30 {
31  static TypeId tid = TypeId ("ns3::QKDTotalGraph")
32  .SetParent<Object> ()
33  ;
34  return tid;
35 }
36 
38 
40  Init("","");
41 }
42 
44  std::string graphName,
45  std::string graphType
46 ){
47  Init(graphName, graphType);
48 }
49 
50 void
52  std::string graphName,
53  std::string graphType
54 )
55 {
56  m_keymCurrent = 0;
57  m_keymThreshold = 0;
58 
59  NS_LOG_FUNCTION (this << graphName);
60 
61  m_plotFileName = (graphName.empty()) ? "QKD Total Graph" : graphName;
62  m_plotFileType = (graphType.empty()) ? "png" : graphType;;
63 
65 
66  m_dataset.SetTitle ("Amount of key material");
68  m_dataset.SetExtra(" ls 1");
69  //m_dataset.Add( 0, m_keymCurrent);
70 
71  m_datasetThreshold.SetTitle ("Threshold");
73  m_datasetThreshold.SetExtra(" ls 4");
74  //m_datasetThreshold.Add( 0, m_keymThreshold);
75 
76  std::string outputTerminalCommand;
77 
78  if (m_plotFileType=="png")
79  outputTerminalCommand = "pngcair";
80  else if (m_plotFileType=="tex")
81  outputTerminalCommand = "epslatex";
82  else
83  outputTerminalCommand = m_plotFileType;
84 
85  m_gnuplot.AppendExtra ("set autoscale y");
86  m_gnuplot.AppendExtra ("set border linewidth 2");
87 
88  if (m_plotFileType=="tex")
89  m_gnuplot.AppendExtra ("set terminal " + outputTerminalCommand);
90  else
91  m_gnuplot.AppendExtra ("set terminal " + outputTerminalCommand + " size 1524,768 enhanced font 'Helvetica,18'");
92 
93  m_gnuplot.AppendExtra ("set style line 1 linecolor rgb 'red' linetype 1 linewidth 1");
94  m_gnuplot.AppendExtra ("set style line 4 linecolor rgb \"#8A2BE2\" linetype 1 linewidth 1");
95 
96  m_gnuplot.AppendExtra ("set style line 7 linecolor rgb 'gray' linetype 0 linewidth 1");
97  m_gnuplot.AppendExtra ("set style line 8 linecolor rgb 'gray' linetype 0 linewidth 1 ");
98 
99  m_gnuplot.AppendExtra ("set grid ytics lt 0 lw 1 lc rgb \"#ccc\"");
100  m_gnuplot.AppendExtra ("set grid xtics lt 0 lw 1 lc rgb \"#ccc\"");
101 
102  m_gnuplot.AppendExtra ("set mxtics 5");
103  m_gnuplot.AppendExtra ("set grid mxtics xtics ls 7, ls 8");
104 
105  m_gnuplot.AppendExtra ("set arrow from graph 1,0 to graph 1.03,0 size screen 0.025,15,60 filled ls 3");
106  m_gnuplot.AppendExtra ("set arrow from graph 0,1 to graph 0,1.03 size screen 0.025,15,60 filled ls 3");
107 
108  m_gnuplot.AppendExtra ("set style fill transparent solid 0.4 noborder");
109  //m_gnuplot.AppendExtra ("set logscale y 2");
110 
111  if (m_plotFileType=="tex") {
112  m_gnuplot.AppendExtra ("set key inside");
113  m_gnuplot.AppendExtra ("set key right top");
114  }else{
115  m_gnuplot.AppendExtra ("set key outside");
116  m_gnuplot.AppendExtra ("set key right bottom");
117  }
118 
119  std::string plotTitle;
120 
121  if(graphName.empty()){
122  plotTitle = "QKD Key Material in Whole Network";
123  }else{
124  plotTitle = graphName;
125  }
126 
127  m_gnuplot.SetTitle (plotTitle);
128  //m_gnuplot.SetTerminal ("png");
129  // Set the labels for each axis.
130  m_gnuplot.SetLegend ("Time (seconds)", "Key material (bits)");
131 
132 }
133 
134 
135 void
137 
139 
140  std::string tempPlotFileName1 = m_plotFileName;
141  tempPlotFileName1 += "_data.dat";
142  std::ofstream tempPlotFile1 (tempPlotFileName1.c_str());
143 
146 
147  m_plotFileName += ".plt";
148  // Open the plot file.
149  std::ofstream plotFile (m_plotFileName.c_str());
150 
151  // Write the plot file.
152  m_gnuplot.GenerateOutput (plotFile, tempPlotFile1, tempPlotFileName1);
153 
154  // Close the plot file.
155  plotFile.close ();
156 }
157 
158 void
159 QKDTotalGraph::ProcessMCurrent(uint32_t newValue, char sign){
160 
161  NS_LOG_FUNCTION (this << newValue << sign);
163 
164  if(sign == '+')
165  m_keymCurrent += newValue;
166  else if(sign == '-')
167  m_keymCurrent -= newValue;
168 
170 }
171 
172 void
173 QKDTotalGraph::ProcessMThr(uint32_t newValue, char sign){
174 
175  NS_LOG_FUNCTION (this << newValue << sign);
177 
178  if(sign == '+')
179  m_keymThreshold += newValue;
180  else if(sign == '-')
181  m_keymThreshold -= newValue;
182 
184 }
185 
186 }
void SetStyle(enum Style style)
Definition: gnuplot.cc:346
void Add(double x, double y)
Definition: gnuplot.cc:363
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
Definition: gnuplot.cc:152
void SetTitle(const std::string &title)
Change line title.
Definition: gnuplot.cc:141
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:760
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:740
void AppendExtra(const std::string &extra)
Definition: gnuplot.cc:753
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:766
void SetTitle(const std::string &title)
Definition: gnuplot.cc:734
void SetOutputFilename(const std::string &outputFilename)
Definition: gnuplot.cc:707
A base class which provides memory management and object aggregation.
Definition: object.h:88
double m_simulationTime
time value, x-axis
Gnuplot2dDataset m_dataset
void PrintGraph()
Print the graph.
std::string m_plotFileName
output filename
virtual ~QKDTotalGraph()
Destructor.
static TypeId GetTypeId(void)
Get the type ID.
void ProcessMThr(uint32_t value, char sign)
Mthr value of the QKDBuffer changed, so plot it on the graph.
uint32_t m_keymCurrent
get some boundaries for the graph
void ProcessMCurrent(uint32_t value, char sign)
MCurrent value of the QKDBuffer changed, so plot it on the graph.
void Init(std::string graphName, std::string graphType)
Initialized function used in constructor.
uint32_t m_keymThreshold
get some boundaries for the graph
Gnuplot2dDataset m_datasetThreshold
QKDTotalGraph()
Constructor.
std::string m_plotFileType
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.