A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
qkd-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-graph.h"
12
13namespace ns3 {
14
15NS_LOG_COMPONENT_DEFINE("QKDGraph");
16
18
20{
21 static TypeId tid = TypeId("ns3::QKDGraph")
23 ;
24 return tid;
25}
26
28
30 Ptr<Node> src,
31 Ptr<Node> dst,
33 std::string graphTitle,
34 std::string graphType,
36)
37{
38 NS_LOG_FUNCTION(this << src->GetId() << dst->GetId() << bufferPosition << graphTitle);
39
40 Ptr<Node> node = src;
42 for(uint32_t i = 0; i < src->GetNApplications(); ++i){
43 kms = src->GetApplication(i)->GetObject <QKDKeyManagerSystemApplication>();
44 if(kms) break;
45 }
46
48 //m_buffer = kms->GetQBuffer( dst->GetId() );
49 m_buffer = buff;
50 m_src = src;
51 m_dst = dst;
52
53 m_keymCurrent = m_buffer->GetBitCount();
54 m_keymMin = m_buffer->GetMinKeySizeBit();
55 m_keymMax = m_buffer->GetMaxKeySizeBit();
56 m_maxValueGraph = 100;
57 m_keymThreshold = m_buffer->GetMthr();
59
60 m_plotFileName =(graphTitle.empty()) ? "QKD_keys" : graphTitle;
61 m_plotFileType =(graphType.empty()) ? "png" : graphType;;
62
63 if(graphTitle.empty()){
64 std::ostringstream temp1;
65 temp1 << m_src->GetId() << m_dst->GetId();
66 m_plotFileName = m_plotFileName + "_" + temp1.str();
67 }
68
70
71 m_dataset.SetTitle("Keys (bits)");
73 m_dataset.SetExtra(" ls 1");
75
76 m_datasetThreshold.SetTitle("Threshold");
80
81 m_datasetMinimum.SetTitle("Minimum");
85
86 m_datasetMaximum.SetTitle("Maximum");
90
92 m_datasetWorkingState_0.SetTitle("Status: READY");
93 m_datasetWorkingState_0.SetExtra(" y1=0 lc rgb '#b0fbb4'");
94
96 m_datasetWorkingState_1.SetTitle("Status: WARNING");
97 m_datasetWorkingState_1.SetExtra(" y1=0 lc rgb '#f7ea50'");
98
100 m_datasetWorkingState_2.SetTitle("Status: CHARGING");
101 m_datasetWorkingState_2.SetExtra(" y1=0 lc rgb '#fbc4ca'");
102
104 m_datasetWorkingState_3.SetTitle("Status: EMPTY");
105 m_datasetWorkingState_3.SetExtra(" y1=0 lc rgb '#e6e4e4'");
106
107 m_buffer->CheckState();
108 ProcessMStatusHelpFunction(0.0, m_buffer->GetState());
109
110 std::string outputTerminalCommand;
111
112 if(m_plotFileType=="png") {
113 outputTerminalCommand = "pngcair";
114 } else if(m_plotFileType=="tex") {
115 outputTerminalCommand = "epslatex";
116 } else {
118 }
119
120 m_gnuplot.AppendExtra("set border linewidth 2");
121
122 if(m_plotFileType=="tex") {
124 } else {
125 m_gnuplot.AppendExtra("set terminal " + outputTerminalCommand + " size 1524,768 enhanced font 'Helvetica,18'");
126 }
127
128 m_gnuplot.AppendExtra("set style line 1 linecolor rgb 'red' linetype 1 linewidth 1");
129 m_gnuplot.AppendExtra("set style line 3 linecolor rgb 'black' linetype 1 linewidth 1");
130
131 m_gnuplot.AppendExtra("set style line 4 linecolor rgb \"#8A2BE2\" linetype 1 linewidth 1");
132 m_gnuplot.AppendExtra("set style line 5 linecolor rgb 'blue' linetype 8 linewidth 1");
133 m_gnuplot.AppendExtra("set style line 6 linecolor rgb 'blue' linetype 10 linewidth 1");
134 m_gnuplot.AppendExtra("set style line 7 linecolor rgb 'gray' linetype 0 linewidth 1");
135 m_gnuplot.AppendExtra("set style line 8 linecolor rgb 'gray' linetype 0 linewidth 1 ");
136
137 m_gnuplot.AppendExtra("set grid ytics lt 0 lw 1 lc rgb \"#ccc\"");
138 m_gnuplot.AppendExtra("set grid xtics lt 0 lw 1 lc rgb \"#ccc\"");
139
140 m_gnuplot.AppendExtra("set mxtics 5");
141 m_gnuplot.AppendExtra("set grid mxtics xtics ls 7, ls 8");
142
143 m_gnuplot.AppendExtra("set arrow from graph 1,0 to graph 1.03,0 size screen 0.025,15,60 filled ls 3");
144 m_gnuplot.AppendExtra("set arrow from graph 0,1 to graph 0,1.03 size screen 0.025,15,60 filled ls 3");
145
146 m_gnuplot.AppendExtra("set style fill transparent solid 0.4 noborder");
147 //m_gnuplot.AppendExtra("set logscale y 2");
148
149 if(m_plotFileType=="tex") {
150 m_gnuplot.AppendExtra("set key outside");
151 m_gnuplot.AppendExtra("set key center top");
152 }else{
153 m_gnuplot.AppendExtra("set key outside");
154 m_gnuplot.AppendExtra("set key right bottom");
155 }
156
157 std::string plotTitle;
158
159 if(graphTitle.empty())
160 {
161 plotTitle = "QBuffer on KMS node ";
162 if(m_src && m_dst)
163 {
164 std::ostringstream tempSource;
165 tempSource << m_src->GetId();
166
167 std::ostringstream tempDestination;
169
170 if(m_src->GetId() < m_dst->GetId())
171 plotTitle = plotTitle + tempSource.str() + "\\n QKD link between KMS nodes " + tempSource.str() + " and " + tempDestination.str();
172 else
173 plotTitle = plotTitle + tempSource.str() + "\\n QKD link between KMS nodes " + tempDestination.str() + " and " + tempSource.str();
174 }
175 }else{
177 }
178
180 //m_gnuplot.SetTerminal("png");
181 // Set the labels for each axis.
182 m_gnuplot.SetLegend("Time (seconds)", "Keys (bits)");
183
184}
185
186
187void
189
191
192 std::string tempPlotFileName1 = m_plotFileName;
193 tempPlotFileName1 += "_data.dat";
194 std::ofstream tempPlotFile1(tempPlotFileName1.c_str());
195
196 for(uint i=1;i<=30;i++){
199 }
201
202 m_buffer->CheckState();
204
205 uint32_t m_tempMax = m_maxValueGraph * 1.1; //just to plot arrows on the graph
206 std::ostringstream yrange;
207 yrange << "set yrange[1:" << m_tempMax << "];";
209
218
219 m_plotFileName += ".plt";
220 // Open the plot file.
221 std::ofstream plotFile(m_plotFileName.c_str());
222
223 // Write the plot file.
225
226 // Close the plot file.
227 plotFile.close();
228}
229
230void
232 m_buffer->InitTotalGraph();
233}
234
235
236void
245
246void
253
254void
256
257 NS_LOG_FUNCTION(this << time << newValue << m_src->GetId() << m_dst->GetId() << m_buffer->GetDescription() );
258
259 switch(newValue){
260 case 0:
261 m_datasetWorkingState_0.Add( time, 10000000);
265 break;
266 case 1:
268 m_datasetWorkingState_1.Add( time, 10000000);
270 m_datasetWorkingState_3.Add( time, 0);
271 break;
272 case 2:
275 m_datasetWorkingState_2.Add( time, 10000000);
277 break;
278 case 3:
282 m_datasetWorkingState_3.Add( time, 10000000);
283 break;
284 }
286}
287
288
289void
297
298}
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
uint32_t GetId() const
Definition node.cc:106
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
std::string m_plotFileType
Definition qkd-graph.h:113
Gnuplot2dDataset m_datasetWorkingState_3
Definition qkd-graph.h:123
uint32_t m_keymMax
get some boundaries for the graph
Definition qkd-graph.h:108
std::string m_plotFileName
output filename
Definition qkd-graph.h:112
uint32_t m_maxValueGraph
get some boundaries for the graph
Definition qkd-graph.h:109
Ptr< Node > m_src
source node, info required for graph title
Definition qkd-graph.h:103
~QKDGraph() override
Destructor.
Definition qkd-graph.cc:27
static TypeId GetTypeId()
Get the type ID.
Definition qkd-graph.cc:19
Gnuplot2dDataset m_datasetMaximum
Definition qkd-graph.h:126
Gnuplot m_gnuplot
Gluplot object settings.
Definition qkd-graph.h:117
void ProcessMStatus(uint32_t value)
The status of the QBuffer changed, so plot it on the graph.
Definition qkd-graph.cc:290
void ProcessMStatusHelpFunction(double time, uint32_t newValue)
Help function for detection of status change value.
Definition qkd-graph.cc:255
uint32_t m_keymCurrent
get some boundaries for the graph
Definition qkd-graph.h:107
Gnuplot2dDataset m_datasetThreshold
Definition qkd-graph.h:124
uint32_t m_keymMin
get some boundaries for the graph
Definition qkd-graph.h:106
Gnuplot2dDataset m_datasetWorkingState_0
Definition qkd-graph.h:120
Ptr< QBuffer > m_buffer
QBuffer associated with the QKDGraph.
Definition qkd-graph.h:102
void InitTotalGraph() const
Initialized function for total graph.
Definition qkd-graph.cc:231
uint32_t m_keymThreshold
get some boundaries for the graph
Definition qkd-graph.h:110
Ptr< Node > m_dst
destination node, info required for graph title
Definition qkd-graph.h:104
void PrintGraph()
Print the graph.
Definition qkd-graph.cc:188
uint32_t m_graphStatusEntry
temp variable
Definition qkd-graph.h:115
Gnuplot2dDataset m_datasetWorkingState_1
Definition qkd-graph.h:121
QKDGraph(Ptr< Node > src, Ptr< Node > dst, uint32_t bufferID, std::string graphTitle, std::string graphType, Ptr< QBuffer > buff)
Constructor.
Definition qkd-graph.cc:29
void ProcessMCurrent(uint32_t value)
MCurrent value of the QBuffer changed, so plot it on the graph.
Definition qkd-graph.cc:237
double m_simulationTime
time value, x-axis
Definition qkd-graph.h:114
void ProcessMThrStatus(uint32_t value)
The Mthr value of the QBuffer changed, so plot it on the graph.
Definition qkd-graph.cc:247
Gnuplot2dDataset m_dataset
Definition qkd-graph.h:118
Gnuplot2dDataset m_datasetWorkingState_2
Definition qkd-graph.h:122
Gnuplot2dDataset m_datasetMinimum
Definition qkd-graph.h:125
QKDNetSim implements Key Management System(KMS) as an application that listens on TCP port 80.
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_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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.