A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
qkd-control.cc
Go to the documentation of this file.
1/*
2 * Copyright(c) 2022 DOTFEESA www.tk.etf.unsa.ba
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 *
7 *
8 * Authors: Emir Dervisevic <emir.dervisevic@etf.unsa.ba>
9 * Miralem Mehic <miralem.mehic@ieee.org>
10 */
11
12#include <cmath>
13#include <algorithm>
14#include <numeric>
15#include "ns3/packet.h"
16#include "ns3/simulator.h"
17#include "ns3/log.h"
18#include "ns3/boolean.h"
19#include "ns3/double.h"
20#include "ns3/uinteger.h"
21
22#include "qkd-control.h"
23
24namespace ns3 {
25
26 NS_LOG_COMPONENT_DEFINE("QKDControl");
27
29
30 TypeId
32 {
33 static TypeId tid = TypeId("ns3::QKDControl")
35 .SetGroupName("QKDControl")
36 .AddConstructor<QKDControl>();
37 return tid;
38 }
39
40 TypeId
42 {
43 return GetTypeId();
44 }
45
51
55
56 void
61
62 void
68
71
72 NS_LOG_FUNCTION(this << src->GetId() << dst->GetId() );
73
75 for(uint32_t i = 0; i < src->GetNApplications(); ++i){
76 kms = src->GetApplication(i)->GetObject <QKDKeyManagerSystemApplication>();
77 if(kms) break;
78 }
79
80 Ptr<QBuffer> buffer = kms->GetQBuffer( dst->GetId() );
81 NS_ASSERT(buffer);
82
83 return buffer;
84 }
85
88 return m_node;
89 }
90
91 void
93 m_node = node;
94 }
95
96 void
98 {
99 NS_LOG_FUNCTION(this);
100 SetNode(n);
101 m_routingTable = CreateObject<QKDLocationRegister>(GetNode()); //Initialize Routing Table
102 m_routingTable->SetNode( GetNode() );
103 m_routingTable->SetAddress( GetLocalKMAddress() );
104 }
105
108 {
109 NS_LOG_FUNCTION(this);
111 for(uint32_t i = 0; i < n->GetNApplications(); ++i){
112 lkm = n->GetApplication(i)->GetObject <QKDKeyManagerSystemApplication>();
113 if(lkm) break;
114 }
115 //NS_ASSERT(lkm);
116
117 return lkm;
118 }
119
124
127 return GetNode();
128 }
129
132 return GetLocalKMNode()->GetId();
133 }
134
135 std::string
139
140 std::vector<uint32_t>
142 {
143 std::vector<uint32_t> output;
144 for(auto el : m_remote_km_nodes)
145 output.push_back(el->GetId());
146
147 return output;
148 }
149
150 void
154 std::string idLocal,
155 std::string idRemote,
158 )
159 {
160 NS_LOG_FUNCTION(this);
161 //Assign QKD module in m_qkd_modules(currently is not necessary to record all entries)
164 localQKDModule.remoteNode = moduleRemote;
166 localQKDModule.remoteId = idRemote;
167 localQKDModule.kmNode = kmLocal;
168 localQKDModule.remoteKmNode = kmRemote;
169 m_qkd_modules.push_back(localQKDModule);
170 //m_conn_qkdn_controllers.push_back(GetKeyManagerSystemApplication(kmRemote)->GetController()); //Add connecting QKDNController
171
172 //Check if we have the same connecting KM in m_remote_km_nodes. If not, add this one!
173 bool registered {false};
174 for(auto kmNodes : m_remote_km_nodes)
175 if(kmRemote->GetId() == kmNodes->GetId()){
176 registered = true;
177 break;
178 }
179
180 //Tell local KM to establish QKD buffer for this connection!
181 //If QKD buffer exists KM will do nothing, exept remember a pair modulId and matching modulId
182 if(!registered){
183 m_remote_km_nodes.push_back(kmRemote);
184 NS_LOG_FUNCTION(this << "New remote KM added");
185 //Instruct Key Manager to establish QBuffer for this connection with kmRemote!
187 kmRemote->GetId(),
188 GetQBufferConf( kmRemote->GetId() )
189 );
190 GetKeyManagerSystemApplication( GetLocalKMNode() )->SetPeerKmAddress(
191 kmRemote->GetId(),
193 );
194 }
195
196 //Each QKD buffer should have corresponding moduleIds so KM knows where to put keys
197 GetKeyManagerSystemApplication( GetLocalKMNode() )->RegisterQKDModule(
198 kmRemote->GetId(),
199 idLocal
200 );
201
202 GetKeyManagerSystemApplication( GetLocalKMNode() )->EstablishKMLinkSockets(
204 );
205 GetKeyManagerSystemApplication( kmRemote )->EstablishKMLinkSockets(
207 );
208 }
209
210 void
212 std::string localAppId,
213 std::string remoteAppId,
214 Ptr<Node> remoteKmNode
215 )
216 {
218 m_local_qkdapps.push_back(localAppId);
219 m_remote_qkdapps.insert(std::make_pair(remoteAppId, remoteKmNode->GetId()));
220 m_qkdapp_pairs.insert(std::make_pair(remoteAppId, localAppId));
221
222 /*for(auto remoteKm : m_remote_km_nodes) {
223 if(remoteKm->GetId() == remoteKmNode->GetId()) { //This is direct connection to remoteApp!
224 QKDLocationRegisterEntry newEntry(
225 localAppId,
226 remoteAppId,
227 remoteKmNode->GetId(),//nextHop KM node ID
228 GetKeyManagerSystemApplication(remoteKmNode)->GetAddress(), //nextHop KM address
229 1, // Dirrect p2p connection(number of hops)
230 remoteKmNode->GetId(), //Destination KM node ID
231 GetKeyManagerSystemApplication(remoteKmNode)->GetAddress(), //Destination KM address
232 GetKeyManagerSystemApplication(remoteKmNode)->GetId()
233 );
234 m_routingTable->AddEntry(newEntry);
235 break;
236 }
237 }*/
238 }
239
240 std::string
242 {
243 NS_LOG_FUNCTION(this << peerAppId);
244 std::string appId;
245 auto it = m_qkdapp_pairs.find(peerAppId);
246 if(it != m_qkdapp_pairs.end())
247 appId = it->second;
248 else
249 NS_LOG_ERROR(this << "Peer application ID not registered!");
250 return appId;
251 }
252
253 void
260 )
261 {
262 NS_LOG_FUNCTION(this << "\tMmin:" << Mmin << "\tMthr:" << Mthr << "\tMmax:" << Mmax << "\tMcurr:" << Mcurr);
265 }
266
269 {
270 NS_LOG_FUNCTION(this);
271
272 auto it = m_qbuffers_conf.find(remoteId);
273 if(it == m_qbuffers_conf.end()){
274 NS_LOG_LOGIC(this << "\tDefault configuration selected");
275 return m_qbuffer_config;
276 }else{
277 NS_LOG_LOGIC(this << "\tCustom buffer configuration selected");
278 return it->second;
279 }
280 }
281
282 void
289 )
290 {
291 NS_LOG_FUNCTION(this << "\tMmin:" << Mmin << "\tMthr:" << Mthr << "\tMmax:" << Mmax << "\tMcurr:" << Mcurr);
294 }
295
298 {
299 NS_LOG_FUNCTION(this << remoteId);
301 sBuffer->Init(
302 remoteId,
303 m_rsbuffer_config->GetMmin(),
304 m_rsbuffer_config->GetMthr(),
305 m_rsbuffer_config->GetMmax(),
306 m_rsbuffer_config->GetBitCount(),
307 m_rsbuffer_config->GetKeySize()
308 );
309 //@toDo QKDNController holds a pointer to S-Buffer and monitors it to control thr, max values!
310 return sBuffer;
311 }
312
315 {
316 NS_LOG_FUNCTION(this << "remoteAppId:" << remoteAppId);
318 auto it = m_remote_qkdapps.find(remoteAppId);
319 if(it!=m_remote_qkdapps.end()){
320 routeInfo = GetRoute(it->second);
321 }else{
322 NS_LOG_ERROR(this << "\t Remote SAE not known to QKDN controller!" <<remoteAppId);
323 }
324 return routeInfo;
325 }
326
329 {
330 NS_LOG_FUNCTION(this << "remoteKmId:" << remoteKmId);
332 if(!m_routingTable->Lookup(remoteKmId, routeInfo))
333 NS_LOG_ERROR(this << "\t Route to remoteKME " << remoteKmId << " not found!");
334 return routeInfo;
335 }
336
337 void
339 {
340 //m_routingTable = null;
341 }
342
343 void
349
350
351} // namespace ns3
Ipv4 addresses are stored in host order in this class.
uint32_t GetId() const
Definition node.cc:106
A base class which provides memory management and object aggregation.
Definition object.h:78
virtual void DoInitialize()
Initialize() implementation.
Definition object.cc:440
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
As described in OPENQKD deliverable D6.1(section 5), the QKD control is a network component with the ...
Definition qkd-control.h:64
void AssignKeyManager(Ptr< Node > n)
Assign key manager.
Ptr< Node > m_node
Ptr< QBuffer > GetQBufferConf(uint32_t remoteId)
void AddRouteEntry(QKDLocationRegisterEntry entry)
Ipv4Address GetLocalKMAddress() const
void DoInitialize() override
@briefInitialization function
void RegisterQKDModulePair(Ptr< Node > moduleLocal, Ptr< Node > moduleRemote, std::string idLocal, std::string idRemote, Ptr< Node > kmLocal, Ptr< Node > kmRemote)
Register QKD Module / PP application pair.
TypeId GetInstanceTypeId() const override
Get the type ID for the instance.
std::vector< uint32_t > GetRemoteKmNodeIds() const
~QKDControl() override
Destructor.
static TypeId GetTypeId()
Get the type ID.
Ptr< QBuffer > m_rsbuffer_config
void ClearRoutingTable()
Ptr< QBuffer > m_qbuffer_config
Default QKD buffer configuration.
std::vector< std::string > m_local_qkdapps
Vector of all the apps(IDs) connecting to local KM node.
Ptr< QBuffer > GetBufferByDestinationNode(Ptr< Node >, Ptr< Node >)
Return QKDQBuffer for plotting.
std::string GetApplicationId(std::string peerAppId)
Get local application ID based on the remote application ID.
std::vector< Ptr< Node > > m_remote_km_nodes
Remote Key Manager Node(s)(direct QKD connection!)
Ptr< QKDLocationRegister > m_routingTable
Routing Table.
std::map< uint32_t, Ptr< QBuffer > > m_qbuffers_conf
Dedicaded QKD buffer configuration.
Ptr< Node > GetLocalKMNode() const
std::map< std::string, uint32_t > m_remote_qkdapps
All remote apps(IDs) and their KM nodes(must keep nodes to get remote KM address in QKD network)
Ptr< Node > GetNode() const
std::vector< QKDModule > m_qkd_modules
Registered QKD modules.
QKDLocationRegisterEntry GetRoute(std::string remoteAppId)
void SetNode(Ptr< Node >)
Ptr< QKDKeyManagerSystemApplication > GetKeyManagerSystemApplication(Ptr< Node > n) const
Get Key Manager System Application from node.
QKDControl()
Constructor.
void DoDispose() override
The dispose method.
void RegisterQKDApplicationPair(std::string localAppId, std::string remoteAppId, Ptr< Node > remoteKmNode)
register a pair of QKD applications
void ConfigureQBuffers(uint32_t Mmin, uint32_t Mthr, uint32_t Mmax, uint32_t Mcurr, uint32_t defaultKeySize)
Configure all buffers(default conf).
uint32_t GetLocalKMNodeId() const
std::string GetLocalKMId() const
Ptr< SBuffer > CreateRSBuffer(uint32_t remoteId)
std::map< std::string, std::string > m_qkdapp_pairs
QKDapp pair(remoteApp, localApp)
void ConfigureRSBuffers(uint32_t Mmin, uint32_t Mthr, uint32_t Mmax, uint32_t Mcurr, uint32_t defaultKeySize)
QKDNetSim implements Key Management System(KMS) as an application that listens on TCP port 80.
Introspection did not find any typical Config paths.
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#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:35
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.
Describes QKD modules at site.
Definition qkd-control.h:71