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) 2015 LIPTEL.ieee.org
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::QKDManager/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::QKDManager/BufferList/0/CurrentChange
118  int nodeId=0;
119  int bufferPosition=0;
120  std::sscanf(context.c_str(), "/NodeList/%d/$ns3::QKDManager/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::QKDManager/BufferList/0/ThresholdChange
129  int nodeId=0;
130  int bufferPosition=0;
131  std::sscanf(context.c_str(), "/NodeList/%d/$ns3::QKDManager/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
166 QKDGraphManager::AddBuffer(uint32_t nodeID, uint32_t bufferPosition, std::string graphName, std::string graphType)
167 {
168  NS_LOG_FUNCTION (this << nodeID << bufferPosition << graphName);
169 
170  if(m_graphs.size() <= nodeID)
171  m_graphs.resize(nodeID+1);
172 
173  if(m_graphs.size() == 0)
174  m_graphs[nodeID] = std::vector<QKDGraph *> ();
175 
176  if(m_graphs[nodeID].size() <= bufferPosition)
177  m_graphs[nodeID].resize(bufferPosition+1);
178 
179  //only svg,png and tex graph file are allowd for now
180  std::string graphTypeFilter = (graphType=="svg" || graphType=="png" || graphType=="tex") ? graphType : "png";
181  m_graphs[nodeID][bufferPosition] = new QKDGraph (nodeID, bufferPosition, graphName, graphTypeFilter);
182 
183  std::ostringstream currentPath;
184  currentPath << "/NodeList/" << nodeID << "/$ns3::QKDManager/BufferList/" << bufferPosition << "/CurrentChange";
185 
186  std::string query(currentPath.str());
188  NS_LOG_FUNCTION (this << query);
189 
190  std::ostringstream statusPath;
191  statusPath << "/NodeList/" << nodeID << "/$ns3::QKDManager/BufferList/" << bufferPosition << "/StatusChange";
192  std::string query2(statusPath.str());
194  NS_LOG_FUNCTION (this << query2);
195 
196  std::ostringstream MthrPath;
197  MthrPath << "/NodeList/" << nodeID << "/$ns3::QKDManager/BufferList/" << bufferPosition << "/ThresholdChange";
198  std::string query3 (MthrPath.str());
200  NS_LOG_FUNCTION (this << query3);
201 
202  //FOR QKD TOTAL GRAPH
203 
204  std::ostringstream currentPathIncrease;
205  currentPathIncrease << "/NodeList/" << nodeID << "/$ns3::QKDManager/BufferList/" << bufferPosition << "/CurrentIncrease";
206  std::string query4(currentPathIncrease.str());
208  NS_LOG_FUNCTION (this << query4);
209 
210  std::ostringstream currentPathDecrease;
211  currentPathDecrease << "/NodeList/" << nodeID << "/$ns3::QKDManager/BufferList/" << bufferPosition << "/CurrentDecrease";
212  std::string query5(currentPathDecrease.str());
214  NS_LOG_FUNCTION (this << query5);
215 
216  std::ostringstream currentPathMthrIncrease;
217  currentPathMthrIncrease << "/NodeList/" << nodeID << "/$ns3::QKDManager/BufferList/" << bufferPosition << "/ThresholdIncrease";
218  std::string query6(currentPathMthrIncrease.str());
220  NS_LOG_FUNCTION (this << query6);
221 
222  std::ostringstream currentPathMthrDecrease;
223  currentPathMthrDecrease << "/NodeList/" << nodeID << "/$ns3::QKDManager/BufferList/" << bufferPosition << "/ThresholdDecrease";
224  std::string query7(currentPathMthrDecrease.str());
226  NS_LOG_FUNCTION (this << query7);
227 
228  m_graphs[nodeID][bufferPosition]->InitTotalGraph();
229 }
230 }
231 
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.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#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
static void ProcessCurrentDecrease(std::string context, uint32_t value)
Mcur value decreased, so plot it on the graph.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
static void ProcessCurrentChange(std::string context, uint32_t value)
Mcur value changed, so plot it on the graph.
static void ProcessThresholdIncrease(std::string context, uint32_t value)
Mthr value increased, so plot it on the graph.
static void ProcessCurrentIncrease(std::string context, uint32_t value)
Mcur value increase, so plot it on the graph.
void PrintGraphs()
Print graphs.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
static bool instanceFlag
check whether object exists
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:843
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.
static void ProcessThresholdDecrease(std::string context, uint32_t value)
Mthr value decreased, so plot it on the graph.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::vector< std::vector< QKDGraph * > > m_graphs
void AddBuffer(uint32_t nodeID, uint32_t bufferID, std::string graphName, std::string graphType)
Connect new QKDBuffer to QKDTotalGraph.
Ptr< QKDTotalGraph > GetTotalGraph()
Return Ptr to QKDTotalGraph.
Introspection did not find any typical Config paths.
Definition: qkd-graph.h:47
static void ProcessStatusChange(std::string context, uint32_t value)
Status changed, so plot it on the graph.
static QKDGraphManager * getInstance()
Signelton getInstance function.
static void ProcessThresholdChange(std::string context, uint32_t value)
Mthr value changed, so plot it on the graph.
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 TypeId GetTypeId(void)
Get the type ID.
A base class which provides memory management and object aggregation.
Definition: object.h:87
a unique identifier for an interface.
Definition: type-id.h:58
virtual ~QKDGraphManager()
Destructor.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
static QKDGraphManager * single
Introspection did not find any typical Config paths.