A Discrete-Event Network Simulator
API
qkd-graph-manager.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  * QKDGraphManager is a singleton class!
21  */
22 
23 #include "ns3/qkd-graph-manager.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("QKDGraphManager");
28 
29 NS_OBJECT_ENSURE_REGISTERED (QKDGraphManager);
30 
32 {
33  static TypeId tid = TypeId ("ns3::QKDGraphManager")
34  .SetParent<Object> ()
35  ;
36  return tid;
37 }
38 
43 {
44  if(!instanceFlag){
45  m_totalGraph = CreateObject<QKDTotalGraph> ("QKD Total Graph", "png");
46  single = new QKDGraphManager();
47  instanceFlag = true;
48  }
49  return single;
50 }
51 
53  instanceFlag = false;
54  delete single;
55 
56 }
57 
60  return m_totalGraph;
61 }
62 
63 void
65 
66  NS_LOG_FUNCTION (this);
67  m_totalGraph->PrintGraph();
68  for (std::vector<std::vector<QKDGraph *> >::iterator i = m_graphs.begin();i != m_graphs.end(); ++i)
69  {
70  for (std::vector<QKDGraph *>::iterator j = i->begin(); j != i->end(); ++j)
71  {
72  if((*j)!=0)
73  {
74  (*j)->PrintGraph();
75  delete *j;
76  }
77  }
78  }
79 }
80 
81 
82 void
83 QKDGraphManager::SendCurrentChangeValueToGraph(const uint32_t& nodeID,const uint32_t& bufferPosition,const uint32_t& value){
84 
85  NS_LOG_FUNCTION (this << nodeID << bufferPosition << value);
86  m_graphs[nodeID][bufferPosition]->ProcessMCurrent(value);
87 }
88 
89 void
90 QKDGraphManager::SendStatusValueToGraph(const uint32_t& nodeID, const uint32_t& bufferPosition,const uint32_t& value){
91 
92  NS_LOG_FUNCTION (this << nodeID << bufferPosition << value);
93  m_graphs[nodeID][bufferPosition]->ProcessMStatus(value);
94 }
95 
96 void
97 QKDGraphManager::SendThresholdValueToGraph(const uint32_t& nodeID, const uint32_t& bufferPosition, const uint32_t& value){
98 
99  NS_LOG_FUNCTION (this << nodeID << bufferPosition << value);
100  m_graphs[nodeID][bufferPosition]->ProcessMThrStatus(value);
101 }
102 
103 void
104 QKDGraphManager::ProcessCurrentChange(std::string context, uint32_t value)
105 {
106  //std::cout << Simulator::Now() << "\t" << context << value << "\t\n" ;
107  int nodeId=0;
108  int bufferPosition=0;
109  std::sscanf(context.c_str(), "/NodeList/%d/$ns3::QKDControl/BufferList/%d/*", &nodeId, &bufferPosition);
110 
111  QKDGraphManager::single->SendCurrentChangeValueToGraph (nodeId, bufferPosition, value);
112 }
113 
114 void
115 QKDGraphManager::ProcessStatusChange(std::string context, uint32_t value)
116 {
117  //NodeList/0/$ns3::QKDControl/BufferList/0/CurrentChange
118  int nodeId=0;
119  int bufferPosition=0;
120  std::sscanf(context.c_str(), "/NodeList/%d/$ns3::QKDControl/BufferList/%d/*", &nodeId, &bufferPosition);
121 
122  QKDGraphManager::single->SendStatusValueToGraph (nodeId, bufferPosition, value);
123 }
124 
125 void
126 QKDGraphManager::ProcessThresholdChange(std::string context, uint32_t value)
127 {
128  //NodeList/0/$ns3::QKDControl/BufferList/0/ThresholdChange
129  int nodeId=0;
130  int bufferPosition=0;
131  std::sscanf(context.c_str(), "/NodeList/%d/$ns3::QKDControl/BufferList/%d/*", &nodeId, &bufferPosition);
132 
133  QKDGraphManager::single->SendThresholdValueToGraph (nodeId, bufferPosition, value);
134 }
135 
136 
137 // FOR QKD TOTAL GRAPH
138 void
139 QKDGraphManager::ProcessCurrentIncrease(std::string context, uint32_t value)
140 {
141  m_totalGraph->ProcessMCurrent(value, '+');
142 }
143 
144 // FOR QKD TOTAL GRAPH
145 void
146 QKDGraphManager::ProcessCurrentDecrease(std::string context, uint32_t value)
147 {
148  m_totalGraph->ProcessMCurrent(value, '-');
149 }
150 
151 // FOR QKD TOTAL GRAPH
152 void
153 QKDGraphManager::ProcessThresholdIncrease(std::string context, uint32_t value)
154 {
155  m_totalGraph->ProcessMThr(value, '+');
156 }
157 
158 // FOR QKD TOTAL GRAPH
159 void
160 QKDGraphManager::ProcessThresholdDecrease(std::string context, uint32_t value)
161 {
162  m_totalGraph->ProcessMThr(value, '-');
163 }
164 
165 void
167  Ptr<QKDControl> c,
168  Ptr<Node> src,
169  Ptr<Node> dst,
170  uint32_t bufferPosition,
171  std::string graphName,
172  std::string graphType
173 ) {
174  NS_LOG_FUNCTION (this << src->GetId() << bufferPosition << graphName);
175 
176  uint32_t nodeID = c->GetNode()->GetId();
177  uint32_t nodeMax = nodeID;
178  if(nodeMax < src->GetId()){
179  nodeMax = src->GetId();
180  }
181  if(nodeMax < dst->GetId()){
182  nodeMax = dst->GetId();
183  }
184 
185  if(m_graphs.size() <= nodeMax){
186  m_graphs.resize( nodeMax + 1 );
187  }
188 
189  if(m_graphs.size() == 0){
190  m_graphs[nodeID] = std::vector<QKDGraph *> ();
191  }
192 
193  if(m_graphs[nodeID].size() <= bufferPosition){
194  m_graphs[nodeID].resize(bufferPosition+1);
195  }
196 
197  //only svg,png and tex graph file are allowd for now
198  std::string graphTypeFilter = (graphType=="svg" || graphType=="png" || graphType=="tex") ? graphType : "png";
199  m_graphs[nodeID][bufferPosition] = new QKDGraph (c, src, dst, bufferPosition, graphName, graphTypeFilter);
200 
201  std::ostringstream currentPath;
202  currentPath << "/NodeList/" << nodeID << "/$ns3::QKDControl/BufferList/" << bufferPosition << "/CurrentChange";
203 
204  std::string query(currentPath.str());
206  NS_LOG_FUNCTION (this << query);
207 
208  std::ostringstream statusPath;
209  statusPath << "/NodeList/" << nodeID << "/$ns3::QKDControl/BufferList/" << bufferPosition << "/StatusChange";
210  std::string query2(statusPath.str());
212  NS_LOG_FUNCTION (this << query2);
213 
214  std::ostringstream MthrPath;
215  MthrPath << "/NodeList/" << nodeID << "/$ns3::QKDControl/BufferList/" << bufferPosition << "/ThresholdChange";
216  std::string query3 (MthrPath.str());
218  NS_LOG_FUNCTION (this << query3);
219 
220  //FOR QKD TOTAL GRAPH
221 
222  std::ostringstream currentPathIncrease;
223  currentPathIncrease << "/NodeList/" << nodeID << "/$ns3::QKDControl/BufferList/" << bufferPosition << "/CurrentIncrease";
224  std::string query4(currentPathIncrease.str());
226  NS_LOG_FUNCTION (this << query4);
227 
228  std::ostringstream currentPathDecrease;
229  currentPathDecrease << "/NodeList/" << nodeID << "/$ns3::QKDControl/BufferList/" << bufferPosition << "/CurrentDecrease";
230  std::string query5(currentPathDecrease.str());
232  NS_LOG_FUNCTION (this << query5);
233 
234  std::ostringstream currentPathMthrIncrease;
235  currentPathMthrIncrease << "/NodeList/" << nodeID << "/$ns3::QKDControl/BufferList/" << bufferPosition << "/ThresholdIncrease";
236  std::string query6(currentPathMthrIncrease.str());
238  NS_LOG_FUNCTION (this << query6);
239 
240  std::ostringstream currentPathMthrDecrease;
241  currentPathMthrDecrease << "/NodeList/" << nodeID << "/$ns3::QKDControl/BufferList/" << bufferPosition << "/ThresholdDecrease";
242  std::string query7(currentPathMthrDecrease.str());
244  NS_LOG_FUNCTION (this << query7);
245 
246  m_graphs[nodeID][bufferPosition]->InitTotalGraph();
247 }
248 }
249 
uint32_t GetId(void) const
Definition: node.cc:109
A base class which provides memory management and object aggregation.
Definition: object.h:88
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
QKD graphs are implemented to allow straightforward access to QKD buffers' state and convenient monit...
Definition: qkd-graph.h:47
QKDGraphManager.
static void ProcessThresholdIncrease(std::string context, uint32_t value)
Mthr value increased, so plot it on the graph.
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.
static void ProcessThresholdDecrease(std::string context, uint32_t value)
Mthr value decreased, so plot it on the graph.
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.
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 AddQKDBuffer(Ptr< QKDControl > c, Ptr< Node > src, Ptr< Node > dst, uint32_t bufferID, std::string graphName, std::string graphType)
Connect new QKDBuffer to QKDTotalGraph.
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
virtual ~QKDGraphManager()
Destructor.
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.
std::vector< std::vector< QKDGraph * > > m_graphs
static TypeId GetTypeId(void)
Get the type ID.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
#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.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648