A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
qkd-app-helper.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
11#include "ns3/core-module.h"
12#include "ns3/inet-socket-address.h"
13#include "ns3/packet-socket-address.h"
14#include "ns3/socket.h"
15#include "ns3/string.h"
16#include "ns3/names.h"
17#include "ns3/uinteger.h"
18#include "qkd-app-helper.h"
19#include "ns3/qkd-key-manager-system-application.h"
20#include "ns3/qkd-location-register.h"
21
22NS_LOG_COMPONENT_DEFINE ("QKDAppHelper");
23
24namespace ns3 {
25
27
29{
30 m_factory_qkd_app.SetTypeId ("ns3::QKDApp014");
31
33 m_factory_kms_app.SetTypeId ("ns3::QKDKeyManagerSystemApplication");
34 m_factory_lr_app.SetTypeId ("ns3::QKDLocationRegister");
35 m_factory_postprocessing_app.SetTypeId ("ns3::QKDPostprocessingApplication");
36}
37
42
43void
45{
46 uint16_t port;
47
48 /*************************
49 // MASTER
50 **************************/
51 port = 80;
55 m_factory_kms_app.SetTypeId ("ns3::QKDKeyManagerSystemApplication");
56
57 m_protocol = protocol;
58
59}
60
61
62void
63QKDAppHelper::SetAttribute ( std::string mFactoryName, std::string name, const AttributeValue &value)
64{
65 if(mFactoryName == "kms") {
67 } else if(mFactoryName == "postprocessing") {
69 } else if(mFactoryName == "app") {
71 }
72}
73
74void
76{
77 NS_LOG_FUNCTION(this << "Node ID" << node->GetId() << "Controller ID" << controller->GetNode()->GetId());
79 node->AddApplication (appKMS);
80
82 kms->SetId(UUID::Sequential().string()); //Assign a unique identifier (UUID v1)
83 kms->SetNode(node);
84 kms->SetAddress(kmsAddress);
85 kms->SetPort(port);
86 kms->SetController(controller);
87}
88
89void
91{
92 NS_LOG_FUNCTION(this << "Node ID" << node->GetId() << "Controller ID" << controller->GetNode()->GetId());
94 node->AddApplication (appKMS);
95
97 kms->SetId(UUID::Sequential().string()); //Assign a unique identifier (UUID v1)
98 kms->SetNode(node);
99 kms->SetAddress(kmsAddress);
100 kms->SetPort(port);
101 kms->SetController(controller);
102 kms->SetCenController(cenController);
103}
104
107 Ptr<Node> node1,
108 Ptr<Node> node2,
117)
118{
120 node1,
121 node2,
124 control1,
125 control2,
126 keySize,
127 keyRate,
129 dataRate,
130 "",
131 ""
132 );
133}
134
137 Ptr<Node> node1,
138 Ptr<Node> node2,
147 std::string masterUUID,
148 std::string slaveUUID
149)
150{
151 /**
152 * UDP Protocol is used for sifting (implementation detail)
153 */
154 TypeId m_tid = TypeId::LookupByName ("ns3::TcpSocketFactory");
155 TypeId udp_tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
156
157 /**
158 * Obtain KM addresses from the QKDN Controller!
159 */
160 Ipv4Address km1Address {control1->GetObject<QKDControl> ()->GetLocalKMAddress()};
161 Ipv4Address km2Address {control2->GetObject<QKDControl> ()->GetLocalKMAddress()};
162 NS_LOG_FUNCTION(this << "KM addresses" << km1Address << km2Address);
163
164 /**************
165 // MASTER - Post-Processing running at node A
166 ***************/
172
177
178
180 node1->AddApplication (appMaster);
181
184
185 //POST-processing sockets
186 Ptr<Socket> sckt1 = Socket::CreateSocket (node1, m_tid);
187 Ptr<Socket> sckt2 = Socket::CreateSocket (node1, m_tid);
188 DynamicCast<QKDPostprocessingApplication> (appMaster)->SetSocket ("send", sckt1, true);
189 DynamicCast<QKDPostprocessingApplication> (appMaster)->SetSocket ("sink", sckt2, true);
190 //SIFTING
195
196 /**************
197 // SLAVE - Post-Processing running at node B
198 ***************/
204
209
211 node2->AddApplication (appSlave);
212
215
216 //POST-processing sockets
217 Ptr<Socket> sckt3 = Socket::CreateSocket (node2, m_tid);
218 Ptr<Socket> sckt4 = Socket::CreateSocket (node2, m_tid);
219 DynamicCast<QKDPostprocessingApplication> (appSlave)->SetSocket ("send", sckt3, false);
220 DynamicCast<QKDPostprocessingApplication> (appSlave)->SetSocket ("sink", sckt4, false);
221 //SIFTING
226
227 //Generate UUIDs
228
229 std::string masterModuleId {UUID::Sequential().string()};
230 std::string slaveModuleId {UUID::Sequential().string()};
231
232 if(!masterUUID.empty() && !slaveUUID.empty()){
235 }
236
237 /*std::cout << "\nQKD MODULES INSTALLED\n" << "\tMaster ID:\t" << masterModuleId << "\n\tSlave ID:\t" << slaveModuleId
238 << "\n\tConnecting:\t" << control1->GetObject<QKDControl>()->GetLocalKMNodeId() << "\t<-->\t"
239 << control2->GetObject<QKDControl>()->GetLocalKMNodeId() << "\n\tKey rate:\t" << keyRate;*/
240 //Assign UUIDs
245
246 //Register QKD modules / PP applications at QKDN controller!
247 control1->GetObject<QKDControl> ()->RegisterQKDModulePair (
248 node1, //Local QKD Module Node
249 node2, //Remote QKD Module Node
250 masterModuleId, //Local QKD Module ID
251 slaveModuleId, //Remote QKD Module ID
252 control1->GetObject<QKDControl> ()->GetLocalKMNode(), //Local KM Node
253 control2->GetObject<QKDControl> ()->GetLocalKMNode() //Remote KM Node
254 );
255 control2->GetObject<QKDControl> ()->RegisterQKDModulePair (
256 node2, //Local QKD Module Node
257 node1, //Remote QKD Module Node
258 slaveModuleId, //Local QKD Module ID
259 masterModuleId, //Remote QKD Module ID
260 control2->GetObject<QKDControl> ()->GetLocalKMNode(), //Local KM Node
261 control1->GetObject<QKDControl> ()->GetLocalKMNode() //Remote KM Node
262 );
263
266 apps.Add(appSlave);
267
268 return apps;
269}
270
273 Ptr<Node> node1,
274 Ptr<Node> node2,
279 std::string connectionType,
282 std::string applicationType
283)
284{
286 node1,
287 node2,
290 control1,
291 control2,
294 dataRate,
296 "",
297 ""
298 );
299}
300
301
304(
305 Ptr<Node> node1,
306 Ptr<Node> node2,
311 std::string connectionType,
314 std::string applicationType,
315 std::string masterUUID,
316 std::string slaveUUID
317)
318{
320
321 /**
322 * Obtain KM addresses from the QKDN Controller!
323 */
324 Ipv4Address km1Address {control1->GetObject<QKDControl> ()->GetLocalKMAddress()};
325 Ipv4Address km2Address {control2->GetObject<QKDControl> ()->GetLocalKMAddress()};
326
327 /**
328 * Create unique identifiers
329 */
330 std::string aliceId {UUID::Sequential().string()};
331 std::string bobId {UUID::Sequential().string()};
332 if(!masterUUID.empty() && !slaveUUID.empty()){
335 }
336
337 std::cout << "\n\nCRYPTOGRAPHIC APPLICATION PAIR INSTALLED\n"
338 << "\tMaster ID:\t" << aliceId << "\tLocal KMS node:\t" << control1->GetObject<QKDControl> ()->GetLocalKMNodeId()
339 << "\n\tSlave ID:\t" << bobId << "\tLocal KMS node:\t" << control2->GetObject<QKDControl> ()->GetLocalKMNodeId()
340 << "\n\tData rate:\t" << dataRate << "\tPacket size:\t" << packetSize;
341
342 NS_LOG_FUNCTION(this << "\n\nCRYPTOGRAPHIC APPLICATION PAIR INSTALLED\n"
343 << "\tMaster ID:\t" << aliceId << "\tLocal KMS node:\t" << control1->GetObject<QKDControl> ()->GetLocalKMNodeId()
344 << "\n\tSlave ID:\t" << bobId << "\tLocal KMS node:\t" << control2->GetObject<QKDControl> ()->GetLocalKMNodeId()
345 << "\n\tData rate:\t" << dataRate << "\tPacket size:\t" << packetSize;
346 );
347
348 if(applicationType == "etsi014"){
349
352 appAlice->Setup(
354 aliceId, //This application ID
355 bobId, //Peer application ID
361 "alice"
362 );
363 node1->AddApplication (appAlice);
364
365 appBob->Setup(
367 bobId, //This application ID
368 aliceId, //Peer application ID
372 "bob"
373 );
374 node2->AddApplication (appBob);
375
376 control1->GetObject<QKDControl> ()->RegisterQKDApplicationPair (
377 aliceId,
378 bobId,
379 control2->GetObject<QKDControl> ()->GetLocalKMNode() //KM on which Bob is connected!
380 );
381 control2->GetObject<QKDControl> ()->RegisterQKDApplicationPair (
382 bobId,
383 aliceId,
384 control1->GetObject<QKDControl> ()->GetLocalKMNode() //KM on which Alice is connected!
385 );
386
387
388 apps.Add(appAlice);
389 apps.Add(appBob);
390
391 }else if(applicationType == "etsi004"){
392
395 appAlice->Setup(
397 aliceId, //This application ID
398 bobId, //Peer application ID
404 "alice"
405 );
406 node1->AddApplication (appAlice);
407
408 appBob->Setup(
410 bobId, //This application ID
411 aliceId, //Peer application ID
415 "bob"
416 );
417 node2->AddApplication (appBob);
418
419 control1->GetObject<QKDControl> ()->RegisterQKDApplicationPair (
420 aliceId,
421 bobId,
422 control2->GetObject<QKDControl> ()->GetLocalKMNode() //KM on which Bob is connected!
423 );
424 control2->GetObject<QKDControl> ()->RegisterQKDApplicationPair (
425 bobId,
426 aliceId,
427 control1->GetObject<QKDControl> ()->GetLocalKMNode() //KM on which Alice is connected!
428 );
429
430
431 apps.Add(appAlice);
432 apps.Add(appBob);
433
434 }else
435 std::cout << "ERROR: Unknown application type!";
436
437 return apps;
438}
439
440
441} // namespace ns3
442
a polymophic address class
Definition address.h:90
AttributeValue implementation for Address.
Definition address.h:275
holds a vector of ns3::Application pointers.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
The base class for all ns3 applications.
Definition application.h:51
Hold a value for an Attribute.
Definition attribute.h:59
Class for representing data rates.
Definition data-rate.h:78
AttributeValue implementation for DataRate.
Definition data-rate.h:285
an Inet address class
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny()
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
ApplicationContainer InstallQKDApplication(Ptr< Node > node1, Ptr< Node > node2, Address masterAddress, Address slaveAddress, Ptr< Node > control1, Ptr< Node > control2, std::string connectionType, uint32_t packetSize, DataRate dataRate, std::string applicationType, std::string masterUUID, std::string slaveUUID)
Install a pair of cryptographic applications to consume keys.
ObjectFactory m_factory_postprocessing_app
Object factory.
ObjectFactory m_factory_qkd_app
Object factory.
void InstallKeyManager(Ptr< Node > node, Ipv4Address kmsAddress, uint32_t port, Ptr< QKDControl > controller)
Install key manager.
void SetAttribute(std::string mFactoryName, std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes, not the socket attributes.
void SetSettings(std::string protocol, Ipv4Address master, Ipv4Address slave, uint32_t keyRate)
Install an ns3::QKDAppApplication on each node of the input container configured with all the attribu...
ObjectFactory m_factory_kms_app
Object factory.
std::string m_protocol
ObjectFactory m_factory_lr_app
QKDAppHelper()
Create an QKDAppHelper to make it easier to work with QKD Applications (KMS, Post-processing and othe...
ApplicationContainer InstallPostProcessing(Ptr< Node > node1, Ptr< Node > node2, Address masterAddress, Address slaveAddress, Ptr< Node > control1, Ptr< Node > control2, uint32_t keySize, DataRate keyRate, uint32_t packetSize, DataRate dataRate, std::string masterUUID, std::string slaveUUID)
static uint32_t appCounter
As described in OPENQKD deliverable D6.1(section 5), the QKD control is a network component with the ...
Definition qkd-control.h:64
Ptr< Node > GetLocalKMNode() const
uint32_t GetLocalKMNodeId() const
QKDNetSim implements Key Management System(KMS) as an application that listens on TCP port 80.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition socket.cc:61
a unique identifier for an interface.
Definition type-id.h:49
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition type-id.cc:872
static UUID Sequential()
Generate sequential UUID1(time based version)
Definition uuid.cc:92
std::string string() const
Get string from the current UUID in format "00000000-0000-0000-0000-000000000000".
Definition uuid.cc:74
Hold an unsigned integer type.
Definition uinteger.h:34
uint16_t port
Definition dsdv-manet.cc:33
#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 ",...
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.
static unsigned int value(char c)
static const uint32_t packetSize
Packet size generated at the AP.