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 != 0);
91  NS_ASSERT (dst != 0);
92 
94  NS_ASSERT (c != 0);
95 
96  Ptr<QKDBuffer> buffer = c->GetBufferByDestinationNode ( dst );
97  NS_ASSERT (buffer != 0);
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 == 0) {
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 {
140  QKDControlContainer container;
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 {
170  QKDEncryptorContainer container;
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 == 0) controlAlice = InstallQKDControl(alice);
228 
230  // NODE B
232  Ptr<QKDControl> controlBob = bob->GetObject<QKDControl> ();
233  if(controlBob == 0) 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(void) 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(void) const
Definition: node.cc:109
Instantiate subclasses of ns3::Object.
Ptr< Object > Create(void) 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:88
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
holds a vector of std::pair of Ptr<QKDControl> and interface index.
void Add(const QKDControlContainer &other)
Concatenate the entries in the other container with ours.
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.
void Add(const QKDEncryptorContainer &other)
Concatenate the entries in the other container with ours.
Introspection did not find any typical Config paths.
Definition: qkd-encryptor.h:90
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:67
#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 ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.