A Discrete-Event Network Simulator
API
qkd-app-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/core-module.h"
22 #include "ns3/inet-socket-address.h"
23 #include "ns3/packet-socket-address.h"
24 #include "ns3/socket.h"
25 #include "ns3/string.h"
26 #include "ns3/names.h"
27 #include "ns3/uinteger.h"
28 #include "ns3/qkd-app-helper.h"
29 #include "ns3/qkd-key-manager-system-application.h"
30 #include "ns3/qkd-sdn-controller.h"
31 #include "ns3/qkd-connection-register.h"
32 
33 namespace ns3 {
34 
35 uint32_t QKDAppHelper::appCounter = 0;
36 
38 {
39  m_factory_qkd_app.SetTypeId ("ns3::QKDApp014");
40 
41  Address sinkAddress (InetSocketAddress (Ipv4Address::GetAny (), 80));
42  m_factory_kms_app.SetTypeId ("ns3::QKDKeyManagerSystemApplication");
43  m_factory_lr_app.SetTypeId ("ns3::QKDConnectionRegister");
44  m_factory_postprocessing_app.SetTypeId ("ns3::QKDPostprocessingApplication");
45  m_factory_sdn_app.SetTypeId ("ns3::QKDSDNController");
46 }
47 
48 QKDAppHelper::QKDAppHelper (std::string protocol, Ipv4Address master, Ipv4Address slave, uint32_t keyRate)
49 {
50  SetSettings(protocol, master, slave, keyRate);
51 }
52 
53 void
54 QKDAppHelper::SetSettings ( std::string protocol, Ipv4Address master, Ipv4Address slave, uint32_t keyRate)
55 {
56  uint16_t port;
57 
58  /*************************
59  // MASTER
60  **************************/
61  port = 80;
63  Address masterAppRemoteAddress (InetSocketAddress (master, port));
64  Address slaveAppRemoteAddress (InetSocketAddress (slave, port));
65  m_factory_kms_app.SetTypeId ("ns3::QKDKeyManagerSystemApplication");
66 
67  m_protocol = protocol;
68 
69 }
70 
71 
72 void
73 QKDAppHelper::SetAttribute ( std::string mFactoryName, std::string name, const AttributeValue &value)
74 {
75  if(mFactoryName == "kms") {
76  m_factory_kms_app.Set (name, value);
77  } else if(mFactoryName == "postprocessing") {
78  m_factory_postprocessing_app.Set (name, value);
79  } else if(mFactoryName == "app") {
80  m_factory_qkd_app.Set (name, value);
81  }
82 }
83 
86 {
89  node->AddApplication (app);
90  apps.Add(app);
91  return apps;
92 }
93 
96 {
97  return InstallKMS(node, kmsAddress, 80);
98 }
99 
101 QKDAppHelper::InstallKMS (Ptr<Node> node, Ipv4Address kmsAddress, uint32_t port) const
102 {
104  node->AddApplication (appKMS);
105 
107  kms->SetNode(node);
108  kms->SetAddress(kmsAddress);
109  kms->SetPort(port);
110 
112  if(!lr)
113  {
115  node->AggregateObject (lra);
116  }
117  return kms;
118 }
119 
120 void
122 {
123  InstallSDN(node, sdnAddress, 3060);
124 }
125 void
126 QKDAppHelper::InstallSDN (Ptr<Node> node, Ipv4Address sdnAddress, uint32_t port) const
127 {
129  node->AddApplication (appSDN);
130 
132  sdn->SetNode(node);
133  sdn->SetAddress(sdnAddress);
134  sdn->SetPort(port);
135 
137  if(!lr)
138  {
140  node->AggregateObject (lra);
141  }
142 }
143 
144 void
146 
148  //if(kms != 0)
149  //kms->ConnectToSDNController(sdnAddress, port);
150 }
151 
152 
153 
156  Ptr<Node> node1,
157  Ptr<Node> node2,
158  Address masterAddress,
159  Address slaveAddress,
160  Address masterKMSAddress,
161  Address slaveKMSAddress,
162  uint32_t keySizeInBits,
163  DataRate keyRate,
164  uint32_t packetSize,
165  DataRate dataRate
166 )
167 {
171  TypeId m_tid = TypeId::LookupByName ("ns3::TcpSocketFactory");
172  TypeId udp_tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
173 
174  /**************
175  //MASTER
176  ***************/
177  m_factory_postprocessing_app.Set ("Local", AddressValue (masterAddress));
178  m_factory_postprocessing_app.Set ("Local_Sifting", AddressValue (masterAddress));
179  m_factory_postprocessing_app.Set ("Local_KMS", AddressValue (masterKMSAddress));
180  m_factory_postprocessing_app.Set ("Remote", AddressValue (slaveAddress));
181  m_factory_postprocessing_app.Set ("Remote_Sifting", AddressValue (slaveAddress));
182  m_factory_postprocessing_app.Set ("KeySizeInBits", UintegerValue (keySizeInBits));
183  m_factory_postprocessing_app.Set ("KeyRate", DataRateValue (keyRate));
185  m_factory_postprocessing_app.Set ("DataRate", DataRateValue (dataRate));
186 
188  appMaster->SetAttribute ("Local", AddressValue (masterAddress));
189  appMaster->SetAttribute ("Local_Sifting", AddressValue (masterAddress));
190  appMaster->SetAttribute ("Local_KMS", AddressValue (masterKMSAddress));
191  appMaster->SetAttribute ("Remote", AddressValue (slaveAddress));
192  appMaster->SetAttribute ("Remote_Sifting", AddressValue (slaveAddress));
193  appMaster->SetAttribute ("KeySizeInBits", UintegerValue (keySizeInBits));
194  appMaster->SetAttribute ("KeyRate", DataRateValue (keyRate));
195  appMaster->SetAttribute ("PacketSize", UintegerValue (packetSize));
196  appMaster->SetAttribute ("DataRate", DataRateValue (dataRate));
197 
198 
199  node1->AddApplication (appMaster);
200 
201  DynamicCast<QKDPostprocessingApplication> (appMaster)->SetSrc (node1);
202  DynamicCast<QKDPostprocessingApplication> (appMaster)->SetDst (node2);
203 
204  //POST-processing sockets
205  Ptr<Socket> sckt1 = Socket::CreateSocket (node1, m_tid);
206  Ptr<Socket> sckt2 = Socket::CreateSocket (node1, m_tid);
207  DynamicCast<QKDPostprocessingApplication> (appMaster)->SetSocket ("send", sckt1, true);
208  DynamicCast<QKDPostprocessingApplication> (appMaster)->SetSocket ("sink", sckt2, true);
209  //SIFTING
210  Ptr<Socket> sckt1_sifting = Socket::CreateSocket (node1, udp_tid);
211  Ptr<Socket> sckt2_sifting = Socket::CreateSocket (node1, udp_tid);
212  DynamicCast<QKDPostprocessingApplication> (appMaster)->SetSiftingSocket ("send", sckt1_sifting);
213  DynamicCast<QKDPostprocessingApplication> (appMaster)->SetSiftingSocket ("sink", sckt2_sifting);
214 
215  /**************
216  //SLAVE
217  ***************/
218  m_factory_postprocessing_app.Set ("Local", AddressValue (slaveAddress));
219  m_factory_postprocessing_app.Set ("Local_Sifting", AddressValue (slaveAddress));
220  m_factory_postprocessing_app.Set ("Local_KMS", AddressValue (slaveKMSAddress));
221  m_factory_postprocessing_app.Set ("Remote", AddressValue (masterAddress));
222  m_factory_postprocessing_app.Set ("Remote_Sifting", AddressValue (masterAddress));
223  m_factory_postprocessing_app.Set ("KeySizeInBits", UintegerValue (keySizeInBits));
224  m_factory_postprocessing_app.Set ("KeyRate", DataRateValue (keyRate));
226  m_factory_postprocessing_app.Set ("DataRate", DataRateValue (dataRate));
227 
229  appSlave->SetAttribute("Local", AddressValue (slaveAddress));
230  appSlave->SetAttribute("Local_Sifting", AddressValue (slaveAddress));
231  appSlave->SetAttribute("Local_KMS", AddressValue (slaveKMSAddress));
232  appSlave->SetAttribute("Remote", AddressValue (masterAddress));
233  appSlave->SetAttribute("Remote_Sifting", AddressValue (masterAddress));
234  appSlave->SetAttribute("KeySizeInBits", UintegerValue (keySizeInBits));
235  appSlave->SetAttribute("KeyRate", DataRateValue (keyRate));
236  appSlave->SetAttribute("PacketSize", UintegerValue (packetSize));
237  appSlave->SetAttribute("DataRate", DataRateValue (dataRate));
238  node2->AddApplication (appSlave);
239 
240  DynamicCast<QKDPostprocessingApplication> (appSlave)->SetSrc (node2);
241  DynamicCast<QKDPostprocessingApplication> (appSlave)->SetDst (node1);
242 
243  //POST-processing sockets
244  Ptr<Socket> sckt3 = Socket::CreateSocket (node2, m_tid);
245  Ptr<Socket> sckt4 = Socket::CreateSocket (node2, m_tid);
246  DynamicCast<QKDPostprocessingApplication> (appSlave)->SetSocket ("send", sckt3, false);
247  DynamicCast<QKDPostprocessingApplication> (appSlave)->SetSocket ("sink", sckt4, false);
248  //SIFTING
249  Ptr<Socket> sckt3_sifting = Socket::CreateSocket (node2, udp_tid);
250  Ptr<Socket> sckt4_sifting = Socket::CreateSocket (node2, udp_tid);
251  DynamicCast<QKDPostprocessingApplication> (appSlave)->SetSiftingSocket ("send", sckt3_sifting);
252  DynamicCast<QKDPostprocessingApplication> (appSlave)->SetSiftingSocket ("sink", sckt4_sifting);
253 
255  apps.Add(appMaster);
256  apps.Add(appSlave);
257 
258  return apps;
259 }
260 
261 } // namespace ns3
262 
a polymophic address class
Definition: address.h:101
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:62
Hold a value for an Attribute.
Definition: attribute.h:70
Class for representing data rates.
Definition: data-rate.h:89
an Inet address class
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
static Ipv4Address GetAny()
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:169
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:204
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.
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
void ConnectKMSToSDN(Ptr< Node > kmsNode, Ipv4Address sdnAddress, uint32_t port)
ObjectFactory m_factory_postprocessing_app
Object factory.
ObjectFactory m_factory_qkd_app
Object factory.
ApplicationContainer InstallPostProcessing(Ptr< Node > node1, Ptr< Node > node2, Address masterAddress, Address slaveAddress, Address masterKMSAddress, Address slaveKMSAddress, uint32_t keySizeInBits, DataRate keyRate, uint32_t packetSize, DataRate dataRate)
Install an ns3::QKDPostprocessingApplication on the node configured with all the attributes set with ...
void InstallSDN(Ptr< Node > node, Ipv4Address sdnAddress) const
Install an ns3::QKDKeyManagmentSystem on the node configured with all the attributes set with SetAttr...
void SetAttribute(std::string mFactoryName, std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes, not the socket attributes.
ApplicationContainer InstallQKDApp(Ptr< Node > node) const
Install an ns3::QKDApp on the node configured with all the attributes set with SetAttribute.
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_sdn_app
Object factory.
Ptr< QKDKeyManagerSystemApplication > InstallKMS(Ptr< Node > node, Ipv4Address kmsAddress) const
Install an ns3::QKDKeyManagmentSystem on the node configured with all the attributes set with SetAttr...
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...
static uint32_t appCounter
QKDConnectionRegister is a class used to keep details about distant QKD links and applications.
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:72
a unique identifier for an interface.
Definition: type-id.h:59
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:835
Hold an unsigned integer type.
Definition: uinteger.h:45
uint16_t port
Definition: dsdv-manet.cc:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const uint32_t packetSize
Packet size generated at the AP.