A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
qkd-postprocessing-application.h
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#ifndef QKD_POSTPROCESSING_APPLICATION_H
12#define QKD_POSTPROCESSING_APPLICATION_H
13
14#include "ns3/application.h"
15#include "ns3/address.h"
16#include "ns3/event-id.h"
17#include "ns3/nstime.h"
18#include "ns3/ptr.h"
19#include "ns3/log.h"
20#include "ns3/data-rate.h"
21#include "ns3/traced-callback.h"
22#include "ns3/event-id.h"
23#include "ns3/ptr.h"
24#include "ns3/ipv4-address.h"
25#include "ns3/random-variable-stream.h"
27#include "ns3/qkd-encryptor.h"
28#include "ns3/socket-factory.h"
29#include "ns3/tcp-socket-factory.h"
30#include "ns3/udp-socket-factory.h"
31#include "ns3/ipv4-l3-protocol.h"
32#include "ns3/uuid.h"
33#include "http.h"
34
35namespace ns3 {
36
37class Address;
38class Socket;
39class Packet;
40
41/**
42 * @ingroup applications
43 * @defgroup qkd QKDPostprocessingApplication
44 *
45 * QKDPostprocessingApplication is a class used to
46 * generate QKD key in key establishment process.
47 *
48*/
49
50/**
51 * @ingroup qkd
52 *
53 * @brief QKDPostprocessingApplication is a class used to
54 * generate QKD key in key establishment process. *
55 *
56 * QKD protocols are used to securely generate new key material.
57 * Although there are different types of QKD protocols, each of them
58 * requires raw material processing through post-processing applications
59 * implementing the following steps: the extraction of the raw key(sifting),
60 * error rate estimation, key reconciliation, privacy amplification and
61 * authentication. However, since the QKDNetSim focus is primarily QKD
62 * network organization, management and network traffic, one uses QKD
63 * post-processing application to imitate the network activity of a QKD
64 * protocol. The goal was to build an application that credibly imitates
65 * the traffic from the existing post-processing applications to reduce
66 * the simulation time and computational resources.
67 * Such implementation of QKD post-processing allows analyzing the influence
68 * of various parameters on the state of the network, such as: the impact of
69 * key generation rate, the impact of traffic volume of the reconciled
70 * protocol on network capacity and others.
71 */
73{
74public:
75 /**
76 * @brief Get the type ID.
77 * @return the object TypeId
78 */
79 static TypeId GetTypeId();
80
82
84
85 /**
86 * @return pointer to associated socket
87 */
89
90 /**
91 * @brief set the sink socket
92 */
94
95 /**
96 * @param socket pointer to socket to be set
97 */
98 void SetSocket(std::string type, Ptr<Socket> socket, bool isMaster);
99
100 /**
101 * @param socket pointer to socket to be set
102 */
103 void SetSiftingSocket(std::string type, Ptr<Socket> socket);
104
105 /**
106 * @return the total bytes received in this sink app
107 */
108 uint32_t GetTotalRx() const;
109
110 /**
111 * @return pointer to listening socket
112 */
114
115 /**
116 * @return list of pointers to accepted sockets
117 */
118 std::list<Ptr<Socket> > GetAcceptedSockets() const;
119
121
122 /**
123 * @brief pointer to associated source node
124 * @return Ptr<Node> pointer to associated source node
125 */
127
128 /**
129 * @return Set the source node
130 * @param <Ptr> sourceNode
131 */
132 void SetSrc(Ptr<Node>);
133
134 /**
135 * @brief pointer to associated destination node
136 * @return Ptr<Node> pointer to associated destination node
137 */
139
140 /**
141 * @return Set the destination node
142 * @param <Ptr> destinationNode
143 */
144 void SetDst(Ptr<Node>);
145
146 /**
147 * @brief Set QKD module ID
148 * @param id UUID ID
149 */
150 void SetId(UUID id){
151 m_module_id = id.string();
152 }
153
154 /**
155 * @brief Set QKD module ID
156 * @param id string ID
157 */
158 void SetId(std::string id){
159 m_module_id = id;
160 }
161
162 /**
163 * @brief Get QKD module ID
164 * @return string QKD module ID
165 */
166 std::string GetId(){
167 return m_module_id;
168 }
169
170 /**
171 * @brief Set matching QKD module ID
172 * @param id UUID ID
173 */
174 void SetPeerId(UUID id){
175 m_matching_module_id = id.string();
176 }
177
178 /**
179 * @brief Set matching QKD module ID
180 * @param id string ID
181 */
182 void SetPeerId(std::string id){
184 }
185
186 /**
187 * @brief Get matching QKD module ID
188 * @return string QKD module ID
189 */
190 std::string GetPeerId(){
192 }
193
194protected:
195
196 void DoDispose() override;
197
198private:
199
200
201 /**
202 * @brief Hashing for the Address class
203 */
205 {
206 /**
207 * @brief operator()
208 * @param x the address of which calculate the hash
209 * @return the hash of x
210 *
211 * Should this method go in address.h?
212 *
213 * It calculates the hash taking the uint32_t hash value of the ipv4 address.
214 * It works only for InetSocketAddresses(Ipv4 version)
215 */
216 size_t operator()(const Address &x) const
217 {
220 return std::hash<uint32_t>()(a.GetIpv4().Get());
221 }
222 };
223
224 /**
225 * @brief Process data received
226 * @param Packet to be processed
227 */
229
230 // inherited from Application base class.
231 void StartApplication() override; //!< Called at time specified by Start
232
233 void StopApplication() override; //!< Called at time specified by Stop
234
235 /**
236 * @brief Send packet to the socket
237 * @param Packet to be sent
238 */
239 void SendPacket(Ptr<Packet> packet);
240
241 /**
242 * @brief Help function to prepare output values
243 * @param string value
244 * @param string action
245 */
246 void PrepareOutput(std::string value, std::string action);
247
248 /**
249 * @brief Store generated key at KMS
250 * @param keyId unique key identifier
251 * @param keyValue generated key in byte format
252 */
253 void StoreKey(std::string keyId, std::string keyValue);
254
255 /**
256 * @brief Send SIFTING packet to the socket
257 * @param Packet to be sent
258 */
259 void SendSiftingPacket();
260
261 /**
262 * @brief Handle a packet received by the application
263 * @param socket the receiving socket
264 */
265 void HandleRead(Ptr<Socket> socket);
266
267 /**
268 * @brief Handle a packet received by the application
269 * @param socket the receiving socket
270 */
271 void HandleReadQiskit(Ptr<Socket> socket);
272
273 /**
274 * @brief Handle a packet received by the application from KMS
275 * @param socket the receiving socket
276 */
277 void HandleReadKMS(Ptr<Socket> socket);
278
279 /**
280 * @brief Handle a packet received by the application
281 * @param socket the receiving socket
282 */
283 void HandleReadSifting(Ptr<Socket> socket);
284
285 /**
286 * @brief Handle an incoming connection
287 * @param socket the incoming connection socket
288 * @param from the address the connection is from
289 */
290 void HandleAccept(Ptr<Socket> socket, const Address& from);
291
292 /**
293 * @brief Handle an incoming connection
294 * @param socket the incoming connection socket
295 * @param from the address the connection is from
296 */
297 void HandleAcceptQiskit(Ptr<Socket> socket, const Address& from);
298
299 /**
300 * @brief Handle an incoming connection from KMS
301 * @param socket the incoming connection socket
302 * @param from the address the connection is from
303 */
304 void HandleAcceptKMS(Ptr<Socket> socket, const Address& from);
305
306 /**
307 * @brief Handle an incoming connection
308 * @param socket the incoming connection socket
309 * @param from the address the connection is from
310 */
311 void HandleAcceptSifting(Ptr<Socket> socket, const Address& from);
312
313 /**
314 * @brief Handle an connection close
315 * @param socket the connected socket
316 */
317 void HandlePeerClose(Ptr<Socket> socket);
318
319 /**
320 * @brief Handle an connection close
321 * @param socket the connected socket
322 */
324
325 /**
326 * @brief Handle an connection close
327 * @param socket the connected socket
328 */
329 void HandlePeerCloseKMS(Ptr<Socket> socket);
330
331 /**
332 * @brief Handle an connection error KMS
333 * @param socket the connected socket
334 */
335 void HandlePeerError(Ptr<Socket> socket);
336
337 /**
338 * @brief Handle an connection error KMS
339 * @param socket the connected socket
340 */
342
343 /**
344 * @brief Handle an connection error KMS
345 * @param socket the connected socket
346 */
347 void HandlePeerErrorKMS(Ptr<Socket> socket);
348
349 void ConnectionSucceeded(Ptr<Socket> socket);
350 void ConnectionFailed(Ptr<Socket> socket);
351
353 void ConnectionFailedKMS(Ptr<Socket> socket);
354
357
358 /**
359 * @brief Schedule data to be sent
360 */
361 void SendData();
362
363 /**
364 * @brief After completing post-processing round, reset counters
365 */
366 void ResetCounter();
367
368 /**
369 * @brief Schedule reset of post-processing round
370 */
371 void ScheduleNextReset();
372
373 /**
374 * @brief Generate Random Seed Used to Generate Key Values
375 */
376 void GenerateRandomKeyId();
377
378 /**
379 * @brief Obtain IPv4 address in string type
380 * @param m_address input Address type
381 * @return string IPv4 address as string
382 */
383 std::string GetStringAddress(Address m_address);
384
386
388
391
392 /**
393 * IMITATE post-processing traffic(CASCADE, PRIVACY AMPLIFICATION and etc. )
394 */
395 Ptr<Socket> m_sendSocket; //!< Associated socket
396 Ptr<Socket> m_sinkSocket; //!< Associated socket
397 /**
398 * Sockets used for SIFTING
399 */
400 Ptr<Socket> m_sendSocket_sifting; //!< Associated socket for sifting
401 Ptr<Socket> m_sinkSocket_sifting; //!< Associated socket for sifting
402 /**
403 * Sockets to talk with LKMS
404 */
405 Ptr<Socket> m_sendSocketKMS; //!< Associated socket
406 Ptr<Socket> m_sinkSocketKMS; //!< Associated socket
407
408 Ptr<Socket> m_sinkSocketQiskit; //!< Associated socket
409
410 Address m_peer; //!< Peer address
411 Address m_local; //!< Local address to bind to
412
413 Address m_peer_sifting; //!< Peer address for sifting
414 Address m_local_sifting; //!< Local address for sifting to bind to
416
417 uint32_t m_keySize; //!< KeyRate of the QKDlink
418 bool m_connected; //!< Connection Status
419 bool m_master; //!< Alice(1) or Bob(0)
420 uint32_t m_packetNumber; // Total number of packets received so far
421 uint32_t m_totalRx; //!< Total bytes received
422 Time m_lastAck; // Time of last ACK received
423
424 std::list<Ptr<Socket> > m_sinkSocketList; //!< the accepted sockets
425 EventId m_sendEvent; //!< Event id of pending "send packet" event
426
427 DataRate m_dataRate; //!< Rate that data is generatedm_pktSize
428 DataRate m_keyRate; //!< QKD Key rate
429 uint32_t m_pktSize; //!< Size of packets
432
433 std::string m_module_id; //!< Unique UUID of QKD module
434 std::string m_matching_module_id; //!< Unique UUID of matching QKD module
435
436 std::string m_lastUUID; //!< The latest UUID of the key
437 std::unordered_map<Address, Ptr<Packet>, AddressHash> m_buffer; //!< Buffer for received packets(TCP segmentation)
438
439 /// Traced Callback: received packets, source address.
442
445
446 uint32_t m_packetNumber_sifting; //!< How many sifting packets have been sent
447 uint32_t m_maxPackets_sifting; //!< Limitation for the number of sifting packets
448 uint64_t m_randomSeed; //!< Random seed used when generating key values
449
450private:
451
453 void PacketReceived(const Ptr<Packet> &p, const Address &from, Ptr<Socket> socket);
454
455 void DataSend(Ptr<Socket> s, uint32_t); // for socket's SetSendCallback
456 void DataSendKMS(Ptr<Socket> s, uint32_t); // for socket's SetSendCallback
457 void RegisterAckTime(Time oldRtt, Time newRtt); //!< Callback for ack messages
458 std::string GenerateRandomString(const int len); //!< Internal help function
459
461
463};
464
465} // namespace ns3
466
467#endif /* QKD_POSTPROCESSING_APPLICATION_H */
468
a polymophic address class
Definition address.h:90
The base class for all ns3 applications.
Definition application.h:51
Class for representing data rates.
Definition data-rate.h:78
An identifier for simulation events.
Definition event-id.h:45
The basic class to represent both HTTP requests and responses.
Definition http.h:77
an Inet address class
static bool IsMatchingType(const Address &address)
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
QKDPostprocessingApplication is a class used to generate QKD key in key establishment process.
Ptr< Socket > m_sinkSocketKMS
Associated socket.
void HandleRead(Ptr< Socket > socket)
Handle a packet received by the application.
std::list< Ptr< Socket > > GetAcceptedSockets() const
void HandleAccept(Ptr< Socket > socket, const Address &from)
Handle an incoming connection.
std::string m_matching_module_id
Unique UUID of matching QKD module.
void HandlePeerCloseQiskit(Ptr< Socket > socket)
Handle an connection close.
std::list< Ptr< Socket > > m_sinkSocketList
the accepted sockets
void StartApplication() override
Called at time specified by Start.
void PrepareOutput(std::string value, std::string action)
Help function to prepare output values.
void ConnectionFailedSifting(Ptr< Socket > socket)
void StoreKey(std::string keyId, std::string keyValue)
Store generated key at KMS.
void SetId(std::string id)
Set QKD module ID.
void HandlePeerCloseKMS(Ptr< Socket > socket)
Handle an connection close.
std::string m_lastUUID
The latest UUID of the key.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTraceKMS
Ptr< Node > GetSrc()
pointer to associated source node
void HandleReadQiskit(Ptr< Socket > socket)
Handle a packet received by the application.
void HandleAcceptKMS(Ptr< Socket > socket, const Address &from)
Handle an incoming connection from KMS.
Ptr< Socket > GetSinkSocket() const
set the sink socket
Ptr< Node > GetDst()
pointer to associated destination node
void StopApplication() override
Called at time specified by Stop.
Address m_peer_sifting
Peer address for sifting.
std::string GenerateRandomString(const int len)
Internal help function.
uint32_t m_maxPackets_sifting
Limitation for the number of sifting packets.
void SetSiftingSocket(std::string type, Ptr< Socket > socket)
uint64_t m_randomSeed
Random seed used when generating key values.
void HandlePeerError(Ptr< Socket > socket)
Handle an connection error KMS.
Ptr< Socket > m_sendSocket_sifting
Sockets used for SIFTING.
Ptr< Socket > GetListeningSocket() const
DataRate m_dataRate
Rate that data is generatedm_pktSize.
Ptr< Socket > m_sinkSocket_sifting
Associated socket for sifting.
void SetSocket(std::string type, Ptr< Socket > socket, bool isMaster)
void DoDispose() override
Destructor implementation.
void HandleReadKMS(Ptr< Socket > socket)
Handle a packet received by the application from KMS.
TracedCallback< Ptr< const Packet > > m_txTrace
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_buffer
Buffer for received packets(TCP segmentation)
std::string m_module_id
Unique UUID of QKD module.
std::string GetStringAddress(Address m_address)
Obtain IPv4 address in string type.
void HandleReadSifting(Ptr< Socket > socket)
Handle a packet received by the application.
void SendSiftingPacket()
Send SIFTING packet to the socket.
void HandleAcceptQiskit(Ptr< Socket > socket, const Address &from)
Handle an incoming connection.
void GenerateRandomKeyId()
Generate Random Seed Used to Generate Key Values.
void ProcessQiskitRequest(HTTPMessage headerIn, Ptr< Packet > packet, Ptr< Socket > socket)
void SendPacket(Ptr< Packet > packet)
Send packet to the socket.
Address m_local_sifting
Local address for sifting to bind to.
std::string GetPeerId()
Get matching QKD module ID.
void RegisterAckTime(Time oldRtt, Time newRtt)
Callback for ack messages.
void SetPeerId(std::string id)
Set matching QKD module ID.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced Callback: received packets, source address.
EventId m_sendEvent
Event id of pending "send packet" event.
void ScheduleNextReset()
Schedule reset of post-processing round.
void HandlePeerErrorQiskit(Ptr< Socket > socket)
Handle an connection error KMS.
Ptr< Socket > m_sendSocket
IMITATE post-processing traffic(CASCADE, PRIVACY AMPLIFICATION and etc.
void ProcessIncomingPacket(Ptr< Packet > packet)
Process data received.
Ptr< Socket > m_sendSocketKMS
Sockets to talk with LKMS.
void ResetCounter()
After completing post-processing round, reset counters.
void SetPeerId(UUID id)
Set matching QKD module ID.
TracedCallback< Ptr< const Packet > > m_txTraceKMS
Ptr< Socket > m_sinkSocketQiskit
Associated socket.
void PacketReceived(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
void HandlePeerErrorKMS(Ptr< Socket > socket)
Handle an connection error KMS.
uint32_t m_packetNumber_sifting
How many sifting packets have been sent.
void HandleAcceptSifting(Ptr< Socket > socket, const Address &from)
Handle an incoming connection.
void HandlePeerClose(Ptr< Socket > socket)
Handle an connection close.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:49
Universally unique identifier(UUID)
Definition uuid.h:35
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition abort.h:65
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)