A Discrete-Event Network Simulator
API
qkd-postprocessing-application.h
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 #ifndef QKD_POSTPROCESSING_APPLICATION_H
22 #define QKD_POSTPROCESSING_APPLICATION_H
23 
24 #include "ns3/application.h"
25 #include "ns3/address.h"
26 #include "ns3/event-id.h"
27 #include "ns3/nstime.h"
28 #include "ns3/ptr.h"
29 #include "ns3/log.h"
30 #include "ns3/data-rate.h"
31 #include "ns3/traced-callback.h"
32 #include "ns3/event-id.h"
33 #include "ns3/ptr.h"
34 #include "ns3/ipv4-address.h"
35 #include "ns3/random-variable-stream.h"
36 #include "ns3/qkd-key-manager-system-application.h"
37 #include "ns3/socket-factory.h"
38 #include "ns3/tcp-socket-factory.h"
39 #include "ns3/udp-socket-factory.h"
40 #include "ns3/ipv4-l3-protocol.h"
41 #include "ns3/uuid.h"
42 #include "ns3/http.h"
43 
44 namespace ns3 {
45 
46 class Address;
47 class Socket;
48 class Packet;
49 
73 {
74 public:
79  static TypeId GetTypeId (void);
80 
85 
90 
95  Ptr<Socket> GetSendSocket (void) const;
96 
101  Ptr<Socket> GetSinkSocket (void) const;
102 
108  void PrepareOutput (std::string value, std::string action);
109 
116  void SetSocket (std::string type, Ptr<Socket> socket, bool isMaster);
117 
123  void SetSiftingSocket (std::string type, Ptr<Socket> socket);
124 
129  uint32_t GetTotalRx () const;
130 
136 
141  std::list<Ptr<Socket> > GetAcceptedSockets (void) const;
142 
147  Time GetLastAckTime ();
148 
153  Ptr<Node> GetSrc();
154 
159  void SetSrc(Ptr<Node>);
160 
165  Ptr<Node> GetDst();
166 
171  void SetDst(Ptr<Node>);
172 
173 protected:
174 
175  virtual void DoDispose (void);
176 
177 private:
178 
183  void ProcessIncomingPacket(Ptr<Packet> packet);
184 
188  void StartApplication (void);
189 
193  void StopApplication (void);
194 
199  void SendPacket (Ptr<Packet> packet);
200 
205  void SendPacketToKMS (Ptr<QKDKey> packet);
206 
210  void SendSiftingPacket (void);
211 
216  void HandleRead (Ptr<Socket> socket);
217 
222  void HandleReadKMS (Ptr<Socket> socket);
223 
228  void HandleReadSifting (Ptr<Socket> socket);
229 
235  void HandleAccept (Ptr<Socket> socket, const Address& from);
241  void HandleAcceptKMS (Ptr<Socket> socket, const Address& from);
247  void HandleAcceptSifting (Ptr<Socket> socket, const Address& from);
252  void HandlePeerClose (Ptr<Socket> socket);
257  void HandlePeerCloseKMS (Ptr<Socket> socket);
262  void HandlePeerError (Ptr<Socket> socket);
267  void HandlePeerErrorKMS (Ptr<Socket> socket);
268 
273  void ConnectionSucceeded (Ptr<Socket> socket);
274 
279  void ConnectionFailed (Ptr<Socket> socket);
280 
285  void ConnectionSucceededKMS (Ptr<Socket> socket);
286 
291  void ConnectionFailedKMS (Ptr<Socket> socket);
292 
298 
304 
308  void SendData ();
309 
313  void ResetCounter ();
314 
318  void ScheduleNextReset();
319 
323  void GenerateRandomKeyId();
324 
327 
343 
346 
350 
351  uint32_t m_keySizeInBits;
352  bool m_connected;
353  bool m_master;
354  uint32_t m_packetNumber; // Total number of packets received so far
355  uint32_t m_totalRx;
356  Time m_lastAck; // Time of last ACK received
357 
358  std::list<Ptr<Socket> > m_sinkSocketList;
360 
363  uint32_t m_pktSize;
366 
367  std::string m_appId;
368 
369  std::string m_lastUUID;
370 
374 
377 
380  uint64_t m_keyId;
381 
382 private:
383 
384  void DataSend (Ptr<Socket> s, uint32_t); // for socket's SetSendCallback
385  void DataSendKMS (Ptr<Socket> s, uint32_t); // for socket's SetSendCallback
386  void RegisterAckTime (Time oldRtt, Time newRtt);
387 
393  std::string GenerateRandomString(const int len);
394 
396 };
397 
398 } // namespace ns3
399 
400 #endif /* QKD_POSTPROCESSING_APPLICATION_H */
401 
a polymophic address class
Definition: address.h:101
The base class for all ns3 applications.
Definition: application.h:62
Class for representing data rates.
Definition: data-rate.h:89
An identifier for simulation events.
Definition: event-id.h:55
Ptr< Socket > m_sinkSocketKMS
Associated socket.
void HandleRead(Ptr< Socket > socket)
Handle a packet received from the peer application.
void SendPacketToKMS(Ptr< QKDKey > packet)
Send the packet to the local KMS.
void HandleAccept(Ptr< Socket > socket, const Address &from)
Handle an incoming connection from the application.
std::list< Ptr< Socket > > m_sinkSocketList
the accepted sockets
void PrepareOutput(std::string value, std::string action)
Prepare the output data.
void ConnectionFailedSifting(Ptr< Socket > socket)
Callback function after the sifting connection has failed.
void StartApplication(void)
Start the post-processing application.
void HandlePeerCloseKMS(Ptr< Socket > socket)
Handle a connection close from the KMS.
std::string m_lastUUID
The latest UUID of the key.
Ptr< Socket > GetSinkSocket(void) const
Get the sink socket.
Ptr< Socket > GetListeningSocket(void) const
Get the listening socket.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTraceKMS
Ptr< Node > GetSrc()
Get the source node.
uint64_t m_keyId
ID counter of generated keys.
void HandleAcceptKMS(Ptr< Socket > socket, const Address &from)
Handle an incoming connection from the KMS.
Ptr< Node > GetDst()
Get the destination node.
std::list< Ptr< Socket > > GetAcceptedSockets(void) const
Get the list of the accepted sockets.
Address m_peer_sifting
Peer address for sifting.
std::string GenerateRandomString(const int len)
Generate a random string with a given length.
uint32_t m_maxPackets_sifting
Limitation for the number of sifting packets.
void SetSiftingSocket(std::string type, Ptr< Socket > socket)
Set the sifting socket.
void HandlePeerError(Ptr< Socket > socket)
Handle a connection error from the peer application.
Ptr< Socket > m_sendSocket_sifting
Sockets used for SIFTING.
Time GetLastAckTime()
Get the timestamp of the last acknowledgement.
DataRate m_dataRate
Rate that data is generatedm_pktSize.
void ConnectionFailed(Ptr< Socket > socket)
Callback function after the connection to the peer application has failed.
Ptr< Socket > m_sinkSocket_sifting
Associated socket for sifting.
void SetSocket(std::string type, Ptr< Socket > socket, bool isMaster)
Set the socket.
void HandleReadKMS(Ptr< Socket > socket)
Handle a packet received from the KMS.
TracedCallback< Ptr< const Packet > > m_txTrace
static TypeId GetTypeId(void)
Get the type ID.
void HandleReadSifting(Ptr< Socket > socket)
Handle a sifting packet received from the application.
void SendData()
Schedule time slot to send data.
void GenerateRandomKeyId()
Generate a random seed that will be used to generate key values.
void SendPacket(Ptr< Packet > packet)
Send the packet to the socket.
Address m_local_sifting
Local address for sifting to bind to.
void SendSiftingPacket(void)
Send the sifting packet to the socket.
void RegisterAckTime(Time oldRtt, Time newRtt)
Callback for ack messages.
void ConnectionSucceededSifting(Ptr< Socket > socket)
Callback function after the sifting connection is complete.
Address m_local
Local address to bind to.
void ConnectionSucceededKMS(Ptr< Socket > socket)
Callback function after the connection to the KMS is complete.
std::string m_appId
Random string marking the app 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 a reset of the post-processing round.
Ptr< UniformRandomVariable > m_random
The uniform random variable.
Ptr< Socket > m_sendSocket
IMITATE post-processing traffic (CASCADE, PRIVACY AMPLIFICATION and etc.
void ConnectionSucceeded(Ptr< Socket > socket)
Callback function after the connection to the peer application is complete.
void ProcessIncomingPacket(Ptr< Packet > packet)
Process data received.
Ptr< Socket > m_sendSocketKMS
Sockets to talk with LKMS.
Ptr< Socket > m_sinkSocket
Associated socket.
uint32_t GetTotalRx() const
Get the total amount of data received (in bytes).
void ResetCounter()
Reset the counter after completing the post-processing round.
void SetSrc(Ptr< Node >)
Set the source node.
TracedCallback< Ptr< const Packet > > m_txTraceKMS
void ConnectionFailedKMS(Ptr< Socket > socket)
Callback function after the connection to the KMS has failed.
uint32_t m_keySizeInBits
KeyRate of the QKDlink.
virtual void DoDispose(void)
Destructor implementation.
void HandlePeerErrorKMS(Ptr< Socket > socket)
Handle a connection error from the KMS.
uint32_t m_packetNumber_sifting
How many sifting packets have been sent.
void StopApplication(void)
Stop the post-processing application.
void HandleAcceptSifting(Ptr< Socket > socket, const Address &from)
Handle an incoming connection for the sifting.
Ptr< Socket > GetSendSocket(void) const
Get the send socket.
void HandlePeerClose(Ptr< Socket > socket)
Handle a connection close from the peer application.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.