A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
qkd-graph-manager.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 * QKDGraphManager is a singleton class!
11 */
12
13#include "qkd-graph-manager.h"
14
15namespace ns3 {
16
17NS_LOG_COMPONENT_DEFINE("QKDGraphManager");
18
19NS_OBJECT_ENSURE_REGISTERED(QKDGraphManager);
20
22{
23 static TypeId tid = TypeId("ns3::QKDGraphManager")
25 ;
26 return tid;
27}
28
33{
34 if(!instanceFlag){
35 m_totalGraph = CreateObject<QKDTotalGraph>("QKD Total Graph", "png");
36 single = new QKDGraphManager();
37 instanceFlag = true;
38 }
39 return single;
40}
41
43 instanceFlag = false;
44 delete single;
45
46}
47
52
53void
55
56 NS_LOG_FUNCTION(this);
57 m_totalGraph->PrintGraph();
58 for(size_t i = 0; i < m_graphs.size(); ++i)
59 {
60 for(size_t j = 0; j < m_graphs[i].size(); ++j)
61 {
63 graph->PrintGraph();
64 }
65 }
66}
67
68
69void
75
76void
82
83void
89
90void
92{
93 //NS_LOG_FUNCTION(context << value);
94 //std::cout << Simulator::Now() << "\t" << context << value << "\t\n" ;
95
96 ///NodeList/8/ApplicationList/0/$ns3::QKDKeyManagerSystemApplication/BufferList/1/CurrentChange
97 int nodeId=0;
98 int applicationId=0;
99 int bufferPosition=0;
100 std::sscanf(context.c_str(), "/NodeList/%d/ApplicationList/%d/$ns3::QKDKeyManagerSystemApplication/BufferList/%d/*", &nodeId, &applicationId, &bufferPosition);
101
103}
104
105void
107{
108 //NS_LOG_FUNCTION(context << value);
109 //NodeList/0/ApplicationList/%d/$ns3::QKDKeyManagerSystemApplication/BufferList/0/CurrentChange
110 int nodeId=0;
111 int applicationId=0;
112 int bufferPosition=0;
113 std::sscanf(context.c_str(), "/NodeList/%d/ApplicationList/%d/$ns3::QKDKeyManagerSystemApplication/BufferList/%d/*", &nodeId, &applicationId, &bufferPosition);
114
116}
117
118void
120{
121 //NodeList/0/ApplicationList/%d/$ns3::QKDKeyManagerSystemApplication/BufferList/0/ThresholdChange
122 int nodeId=0;
123 int applicationId=0;
124 int bufferPosition=0;
125 std::sscanf(context.c_str(), "/NodeList/%d/ApplicationList/%d/$ns3::QKDKeyManagerSystemApplication/BufferList/%d/*", &nodeId, &applicationId, &bufferPosition);
126
128}
129
130
131// FOR QKD TOTAL GRAPH
132void
134{
135 m_totalGraph->ProcessMCurrent(value, '+');
136}
137
138// FOR QKD TOTAL GRAPH
139void
141{
142 m_totalGraph->ProcessMCurrent(value, '-');
143}
144
145
146void
152 std::string graphName = "",
153 std::string graphType = "",
154 Ptr<QBuffer> buff = nullptr
155) {
157
158 uint32_t nodeMax = srcKMSNode->GetId();
160 if(srcKMSNode->GetId() < dstKMSNode->GetId())
161 nodeMax = dstKMSNode->GetId();
162
163 if(m_graphs.size() <= static_cast<size_t>(nodeMax))
164 m_graphs.resize(nodeMax + 1); // Resize based on nodeID directly, not nodeMax
165
166 if(m_graphs[nodeID].size() <= static_cast<size_t>(bufferPosition))
167 m_graphs[nodeID].resize(bufferPosition + 1);
168
169 if(m_graphs[nodeID].size() <= bufferPosition)
170 m_graphs[nodeID].resize(bufferPosition+1);
171
172 NS_LOG_FUNCTION(this << m_graphs.size() << m_graphs[nodeID].size() << bufferPosition);
173
174 std::string graphTypeFilter =(graphType=="svg" || graphType=="png" || graphType=="tex") ? graphType : "png";
177
178 std::ostringstream currentPath;
179 currentPath << "/NodeList/" << nodeID << "/ApplicationList/" << srcKMSApplicationIndex << "/$ns3::QKDKeyManagerSystemApplication/BufferList/" << bufferPosition << "/CurrentChange";
180 std::string query(currentPath.str());
181
183 NS_LOG_FUNCTION(this << query);
184
185 std::ostringstream statusPath;
186 statusPath << "/NodeList/" << nodeID << "/ApplicationList/" << srcKMSApplicationIndex << "/$ns3::QKDKeyManagerSystemApplication/BufferList/" << bufferPosition << "/StatusChange";
187 std::string query2(statusPath.str());
189 NS_LOG_FUNCTION(this << query2);
190
191 std::ostringstream MthrPath;
192 MthrPath << "/NodeList/" << nodeID << "/ApplicationList/" << srcKMSApplicationIndex << "/$ns3::QKDKeyManagerSystemApplication/BufferList/" << bufferPosition << "/ThresholdChange";
193 std::string query3(MthrPath.str());
195 NS_LOG_FUNCTION(this << query3);
196
197 //FOR QKD TOTAL GRAPH
198 std::ostringstream currentPathIncrease;
199 currentPathIncrease << "/NodeList/" << nodeID << "/ApplicationList/" << srcKMSApplicationIndex << "/$ns3::QKDKeyManagerSystemApplication/BufferList/" << bufferPosition << "/CurrentIncrease";
200 std::string query4(currentPathIncrease.str());
202 NS_LOG_FUNCTION(this << query4);
203
204 std::ostringstream currentPathDecrease;
205 currentPathDecrease << "/NodeList/" << nodeID << "/ApplicationList/" << srcKMSApplicationIndex << "/$ns3::QKDKeyManagerSystemApplication/BufferList/" << bufferPosition << "/CurrentDecrease";
206 std::string query5(currentPathDecrease.str());
208 NS_LOG_FUNCTION(this << query5);
209
210 m_graphs[nodeID][bufferPosition]->InitTotalGraph();
211}
212}
213
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
static void ProcessCurrentChange(std::string context, uint32_t value)
Mcur value changed, so plot it on the graph.
static QKDGraphManager * single
static QKDGraphManager * getInstance()
Signelton getInstance function.
~QKDGraphManager() override
Destructor.
Ptr< QKDTotalGraph > GetTotalGraph()
Return Ptr to QKDTotalGraph.
void SendCurrentChangeValueToGraph(const uint32_t &nodeID, const uint32_t &bufferID, const uint32_t &value)
Temp function, forward value form trace source to the graph in the list.
std::vector< std::vector< Ptr< QKDGraph > > > m_graphs
static Ptr< QKDTotalGraph > m_totalGraph
Ptr to QKDTotalGraph.
void SendStatusValueToGraph(const uint32_t &nodeID, const uint32_t &bufferID, const uint32_t &value)
Temp function, forward value form trace source to the graph in the list.
void SendThresholdValueToGraph(const uint32_t &nodeID, const uint32_t &bufferID, const uint32_t &value)
Temp function, forward value form trace source to the graph in the list.
static void ProcessCurrentDecrease(std::string context, uint32_t value)
Mcur value decreased, so plot it on the graph.
static void ProcessCurrentIncrease(std::string context, uint32_t value)
Mcur value increase, so plot it on the graph.
static bool instanceFlag
check whether object exists
static void ProcessThresholdChange(std::string context, uint32_t value)
Mthr value changed, so plot it on the graph.
static void ProcessStatusChange(std::string context, uint32_t value)
Status changed, so plot it on the graph.
void PrintGraphs()
Print graphs.
static TypeId GetTypeId()
Get the type ID.
void CreateGraphForBuffer(Ptr< Node > srcKMSNode, Ptr< Node > dstKMSNode, uint32_t bufferID, uint32_t srcKMSApplicationIndex, std::string graphName, std::string graphType, Ptr< QBuffer > buff)
Connect new QBuffer/Sbuffer to QKDTotalGraph.
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
void Connect(std::string path, const CallbackBase &cb)
Definition config.cc:967
#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.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:684
static unsigned int value(char c)