A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
qkd-total-graph.cc
Go to the documentation of this file.
1/*
2 * Copyright(c) 2020 DOTFEESA www.tk.etf.unsa.ba
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 *
7 *
8 * Author: Miralem Mehic <miralem.mehic@ieee.org>
9 */
10
11#include "qkd-total-graph.h"
12
13namespace ns3 {
14
15NS_LOG_COMPONENT_DEFINE("QKDTotalGraph");
16
17NS_OBJECT_ENSURE_REGISTERED(QKDTotalGraph);
18
20{
21 static TypeId tid = TypeId("ns3::QKDTotalGraph")
23 ;
24 return tid;
25}
26
28
32
34 std::string graphName,
35 std::string graphType
36){
38}
39
40void
42 std::string graphName,
43 std::string graphType
44)
45{
46 m_keymCurrent = 0;
48 m_keymMax = 100;
49
51
52 m_plotFileName =(graphName.empty()) ? "QKD Total Graph" : graphName;
53 m_plotFileType =(graphType.empty()) ? "png" : graphType;;
54
56
57 m_dataset.SetTitle("Keys (bits)");
59 m_dataset.SetExtra(" ls 1");
60 //m_dataset.Add( 0, m_keymCurrent);
61
62 std::string outputTerminalCommand;
63
64 if(m_plotFileType=="png")
65 outputTerminalCommand = "pngcair";
66 else if(m_plotFileType=="tex")
67 outputTerminalCommand = "epslatex";
68 else
70
71 m_gnuplot.AppendExtra("set autoscale y");
72 m_gnuplot.AppendExtra("set border linewidth 2");
73
74 if(m_plotFileType=="tex")
76 else
77 m_gnuplot.AppendExtra("set terminal " + outputTerminalCommand + " size 1524,768 enhanced font 'Helvetica,18'");
78
79 m_gnuplot.AppendExtra("set style line 1 linecolor rgb 'red' linetype 1 linewidth 1");
80 m_gnuplot.AppendExtra("set style line 4 linecolor rgb \"#8A2BE2\" linetype 1 linewidth 1");
81
82 m_gnuplot.AppendExtra("set style line 7 linecolor rgb 'gray' linetype 0 linewidth 1");
83 m_gnuplot.AppendExtra("set style line 8 linecolor rgb 'gray' linetype 0 linewidth 1 ");
84
85 m_gnuplot.AppendExtra("set grid ytics lt 0 lw 1 lc rgb \"#ccc\"");
86 m_gnuplot.AppendExtra("set grid xtics lt 0 lw 1 lc rgb \"#ccc\"");
87
88 m_gnuplot.AppendExtra("set mxtics 5");
89 m_gnuplot.AppendExtra("set grid mxtics xtics ls 7, ls 8");
90
91 m_gnuplot.AppendExtra("set arrow from graph 1,0 to graph 1.03,0 size screen 0.025,15,60 filled ls 3");
92 m_gnuplot.AppendExtra("set arrow from graph 0,1 to graph 0,1.03 size screen 0.025,15,60 filled ls 3");
93
94 m_gnuplot.AppendExtra("set style fill transparent solid 0.4 noborder");
95 //m_gnuplot.AppendExtra("set logscale y 2");
96
97 if(m_plotFileType=="tex") {
98 m_gnuplot.AppendExtra("set key inside");
99 m_gnuplot.AppendExtra("set key right top");
100 }else{
101 m_gnuplot.AppendExtra("set key outside");
102 m_gnuplot.AppendExtra("set key right bottom");
103 }
104
105 std::string plotTitle;
106
107 if(graphName.empty()){
108 plotTitle = "QKD Keys in the Whole Network";
109 }else{
111 }
112
114 //m_gnuplot.SetTerminal("png");
115 // Set the labels for each axis.
116 m_gnuplot.SetLegend("Time(seconds)", "Keys (bits)");
117
118}
119
120
121void
123
125
126 std::string tempPlotFileName1 = m_plotFileName;
127 tempPlotFileName1 += "_data.dat";
128 std::ofstream tempPlotFile1(tempPlotFileName1.c_str());
129
130 uint32_t m_tempMax = m_keymMax * 1.1; //just to plot arrows on the graph
131 std::ostringstream yrange;
132 yrange << "set yrange[1:" << m_tempMax << "];";
135
136 m_plotFileName += ".plt";
137 // Open the plot file.
138 std::ofstream plotFile(m_plotFileName.c_str());
139
140 // Write the plot file.
142
143 // Close the plot file.
144 plotFile.close();
145}
146
147void
161
162
163}
void SetStyle(Style style)
Definition gnuplot.cc:351
void Add(double x, double y)
Definition gnuplot.cc:369
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
Definition gnuplot.cc:149
void SetTitle(const std::string &title)
Change line title.
Definition gnuplot.cc:137
void AddDataset(const GnuplotDataset &dataset)
Definition gnuplot.cc:788
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition gnuplot.cc:768
void AppendExtra(const std::string &extra)
Definition gnuplot.cc:781
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition gnuplot.cc:794
void SetTitle(const std::string &title)
Definition gnuplot.cc:762
void SetOutputFilename(const std::string &outputFilename)
Definition gnuplot.cc:729
A base class which provides memory management and object aggregation.
Definition object.h:78
double m_simulationTime
time value, x-axis
~QKDTotalGraph() override
Destructor.
Gnuplot2dDataset m_dataset
void PrintGraph()
Print the graph.
std::string m_plotFileName
output filename
static TypeId GetTypeId()
Get the type ID.
uint32_t m_keymCurrent
get some boundaries for the graph
void ProcessMCurrent(uint32_t value, char sign)
MCurrent value of the QBuffer 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
uint32_t m_keymMax
get some boundaries for the graph
QKDTotalGraph()
Constructor.
std::string m_plotFileType
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.