A Discrete-Event Network Simulator
API
qkd-link-helper.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 
21 #include "ns3/abort.h"
22 #include "ns3/log.h"
23 #include "ns3/simulator.h"
24 #include "ns3/queue.h"
25 #include "ns3/config.h"
26 #include "ns3/packet.h"
27 #include "ns3/object.h"
28 #include "ns3/names.h"
29 
30 #include "ns3/internet-module.h"
31 #include "ns3/random-variable-stream.h"
32 #include "ns3/trace-helper.h"
33 #include "ns3/traffic-control-module.h"
34 
35 #include "qkd-link-helper.h"
36 
37 namespace ns3 {
38 
39 NS_LOG_COMPONENT_DEFINE ("QKDLinkHelper");
40 
42 {
43  m_useRealStorages = false;
44  m_qkdbufferFactory.SetTypeId ("ns3::QKDBuffer");
45 }
46 
52 void
54  Ptr<Node> src,
55  Ptr<Node> dst
56 ) {
57  AddGraph(src, dst, "", "png");
58 }
59 
66 void
68  Ptr<Node> src,
69  Ptr<Node> dst,
70  std::string graphName
71 ){
72  AddGraph(src, dst, graphName, "png");
73 }
82 void
84  Ptr<Node> src,
85  Ptr<Node> dst,
86  std::string graphName,
87  std::string graphType
88 ) {
89 
90  NS_ASSERT (src);
91  NS_ASSERT (dst);
92 
94  NS_ASSERT (c);
95 
96  Ptr<QKDBuffer> buffer = c->GetBufferByDestinationNode ( dst );
97  NS_ASSERT (buffer);
98 
99  NS_LOG_FUNCTION(this << buffer << buffer->FetchState() << c->GetNQKDBuffers() << buffer->GetIndex() );
100 
102  QKDGraphManager->AddQKDBuffer(c, src, dst, buffer->GetIndex(), graphName, graphType);
103 }
104 
108 void
110 {
113 }
114 
121 {
122  Ptr<QKDControl> control = n->GetObject<QKDControl> ();
123  if(!control) {
124  ObjectFactory factory;
125  factory.SetTypeId ("ns3::QKDControl");
126  control = factory.Create <QKDControl> ();
127  control->SetNode(n);
128  n->AggregateObject (control);
129  }
130  return control;
131 }
132 
139 {
141  for(uint16_t i=0; i < n.GetN(); i++)
142  {
143  Ptr<QKDControl> control = InstallQKDControl( n.Get(i) );
144  container.Add( control, i );
145  }
146  return container;
147 }
148 
155 {
156  ObjectFactory factory;
157  factory.SetTypeId ("ns3::QKDEncryptor");
158  Ptr<QKDEncryptor> ecrypto = factory.Create <QKDEncryptor> ();
159  n->AggregateObject (ecrypto);
160  return ecrypto;
161 }
162 
169 {
171  for(uint16_t i=0; i < n.GetN(); i++)
172  {
173  Ptr<QKDEncryptor> ecrypto = InstallQKDEncryptor( n.Get(i) );
174  container.Add( ecrypto, i );
175  }
176  return container;
177 }
178 
184 void
186 {
187  ObjectFactory factory;
188  factory.SetTypeId (typeId);
189  Ptr<Object> protocol = factory.Create <Object> ();
190  node->AggregateObject (protocol);
191 }
192 
208 std::string
210  Ptr<QKDControl> centralControler, //not currently used
211  Ptr<Node> alice,
212  Ptr<Node> bob,
213  Ptr<Node> aliceKMS,
214  Ptr<Node> bobKMS,
215  uint32_t Mmin, //Buffer details
216  uint32_t Mthr, //Buffer details
217  uint32_t Mmax, //Buffer details
218  uint32_t Mcurrent //Buffer details
219 )
220 {
221  NS_LOG_FUNCTION( this << alice->GetId() << bob->GetId() );
222 
224  // NODE A
226  Ptr<QKDControl> controlAlice = alice->GetObject<QKDControl> ();
227  if(!controlAlice) controlAlice = InstallQKDControl(alice);
228 
230  // NODE B
232  Ptr<QKDControl> controlBob = bob->GetObject<QKDControl> ();
233  if(!controlBob) controlBob = InstallQKDControl(bob);
234 
235  struct QKDControl::QKDLink linkDetails = controlAlice->AddNewLink (
236  alice,
237  bob,
238  aliceKMS,
239  bobKMS,
240  Mmin,
241  Mthr,
242  Mmax,
243  Mcurrent,
244  true,
246  );
247 
248  controlBob->AddLinkRecord(linkDetails);
249  return linkDetails.keyAssociationId;
250 
251 }
252 
253 } // namespace ns3
keep track of a set of node pointers.
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t GetId() const
Definition: node.cc:117
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
A base class which provides memory management and object aggregation.
Definition: object.h:89
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:259
holds a vector of std::pair of Ptr<QKDControl> and interface index.
QKD control is a network component with the knowledge of the network status.
Definition: qkd-control.h:73
holds a vector of std::pair of Ptr<QKDEncryptor> and interface index.
QKDGraphManager.
static QKDGraphManager * getInstance()
Signelton getInstance function.
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 PrintGraphs()
Print graphs.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.