24 #include "ns3/application.h"
25 #include "ns3/event-id.h"
27 #include "ns3/traced-callback.h"
28 #include "ns3/address.h"
29 #include "ns3/core-module.h"
30 #include "ns3/applications-module.h"
31 #include "ns3/random-variable-stream.h"
32 #include "ns3/core-module.h"
35 #include "ns3/qkd-encryptor.h"
36 #include <unordered_map>
133 std::string socketType,
153 std::string socketType,
415 void OpenConnect (std::string ksid, uint32_t keyType = 0);
430 void Close (std::string ksid);
483 uint32_t encryptionType,
484 uint32_t authenticationType,
485 uint32_t authenticationTagLengthInBits
672 void Http004KMSQuery (std::string uri, std::string ksid, uint32_t keyType);
743 return std::hash<uint32_t>()(a.
GetIpv4 ().
Get ());
a polymophic address class
The base class for all ns3 applications.
Class for representing data rates.
An identifier for simulation events.
The basic class to represent both HTTP requests and responses.
static bool IsMatchingType(const Address &address)
Ipv4Address GetIpv4() const
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
uint32_t Get() const
Get the host-order 32-bit IP address.
Establish secure communication on application lavel to use the key and test LKSM.
void ProcessDataPacketFromApp(QKDAppHeader header, Ptr< Packet > packet, Ptr< Socket > socket)
Process data packets from the peer QKD application.
void HandlePeerErrorFromKMS(Ptr< Socket > socket)
Handle a connection error from the KMS.
void SetKsidAuthentication(UUID val)
Set authentication key stream identifier.
Ptr< Socket > m_sinkSignalingSocketApp
The receiving socket for the signaling messages.
virtual void StopApplication(void)
Application specific shutdown code.
void HandlePeerCloseFromApp(Ptr< Socket > socket)
Handle a connection close from the peer QKD application.
double m_delay
The time interval between two successive data transmissions (calculated based on the application data...
TracedCallback< Ptr< const Packet > > m_rxSigTrace
A trace for received signaling packets.
void HandleReadFromApp(Ptr< Socket > socket)
Handle a packet received from the peer QKD application.
UUID m_dstSaeId
The peer application identifier.
TracedCallback< Ptr< Packet >, std::string > m_deauthenticationTrace
A trace callback for the authentication check event.
void CancelScheduledAction(uint32_t eventId)
Cancel the scheduled event.
void ConnectionToKMSSucceeded(Ptr< Socket > socket)
Callback function after the connection to the KMS is complete.
std::string GetAppStateString() const
Get the current state of the application in a string notation.
QKDAppState m_appState
The application state.
QKDAppKey GetAuthKey()
Get the authentication key from the queue.
void Http004AppQueryComplete(void)
Remove the request from the vector of HTTP requests made to the peer QKD application.
DataRate m_dataRate
The application data rate.
void ConnectionToKMSFailed(Ptr< Socket > socket)
Callback function after the connection to the KMS has failed.
void HandleAcceptFromKMS(Ptr< Socket > s, const Address &from)
Handle an incoming connection from the KMS.
uint32_t m_useCrypto
Execute actual cryptographic algorithms?
void SendPacket(void)
Send the application packet (includes the generation of a random message and optional encryption or/a...
void OpenConnect(std::string ksid, uint32_t keyType=0)
Request a key stream session (an association) from the local KMS.
uint32_t GetMethodFromHttp004AppQuery(void)
Map the HTTP response from the peer QKD application and obtain the ETSI method type.
void PrepareSinkSocketFromKMS()
Prepare the sink socket to listen from the KMS Application.
void RegisterAckTime(Time oldRtt, Time newRtt)
Register the acknowledgement time.
Address m_localSignaling
The local address for the signaling data transmission.
void SendMaliciousRequestToKMS()
Send a malicious request to the KMS.
static TypeId GetTypeId(void)
Get the type ID.
uint32_t m_keyBufferLengthEncryption
The size of the encryption key queue at the application layer.
void ProcessSignalingPacketFromApp(HTTPMessage &header, Ptr< Socket > socket)
Process a signaling packets from the peer QKD application.
Time m_dosAttackIntensity
The intensity of the DoS attack.
QKDAppState
The QKD application states.
@ ESTABLISHING_ASSOCIATIONS
@ ASSOCIATIONS_ESTABLISHED
@ ESTABLISHING_KEY_QUEUES
void ProcessOpenConnectResponse(HTTPMessage &header)
Process the OPEN_CONNECT response.
void ProcessGetKeyResponse(HTTPMessage &header)
Process the GET_KEY response.
TracedCallback< Ptr< Packet >, std::string > m_authenticationTrace
A trace callback for the authentication event.
UUID m_id
The application identifier.
uint32_t ScheduleAction(Time t, std::string action)
Schedule the action.
uint32_t m_keyBufferLengthAuthentication
The size of the authentication key queue at the application layer.
uint32_t m_packetsSent
The number of sent data packets.
std::map< uint32_t, EventId > m_scheduledEvents
The map of scheduled events.
TracedCallback< Ptr< Packet > > m_encryptionTrace
A trace callback for the encryption event.
Address m_peer
The address of the peer for the data transmission.
void Http004KMSQueryComplete(std::string uri)
Remove the request from the vector of HTTP requests made to the KMS.
void GetKeyFromKMS(std::string ksid, uint32_t index=0)
Get key for the key stream.
ns3::TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
A trace for the application state transitions.
uint32_t GetKeyTypeFromHttp004KMSQuery(std::string uri)
Map the HTTP reponse from the KMS and obtain the key type.
std::string m_socketType
The sockets type.
UUID m_ksid_auth
The authentication key stream identifier.
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_buffer_qkdapp
The buffer for received data packets (fragmentation).
uint32_t m_packetSize
The data packet size.
void DataToKMSSend(Ptr< Socket >, uint32_t)
Callback function to notify that data to KMS has been sent.
TracedCallback< Ptr< const Packet > > m_txSigTrace
A trace for transmitted signaling packets.
void PrepareSinkSocketFromApp()
Prepare the sink socket to listen from the peer QKD Application.
void HandleAcceptSignalingFromApp(Ptr< Socket > s, const Address &from)
Handle a signaling incoming connection from the peer QKD application.
uint32_t m_aesLifetime
The AES key lifetime.
void ClearAssociation(std::string ksid)
Delete all records of key stream session identified with a given KSID.
bool m_primaryQueueEstablished
Is the queue established at the sender application?
void ProcessSendKsidResponse(HTTPMessage &header, std::string ksid)
Process the SEND_KSID response.
virtual ~QKDApp004()
Destructor.
Ptr< UniformRandomVariable > m_random
The uniform random variable.
void HandleReadSignalingFromApp(Ptr< Socket > socket)
Handle a signaling packet received from the peer QKD application.
virtual void StartApplication(void)
EventId m_closeSocketEvent
The closing socket event.
TracedCallback< const uint32_t & > m_obtainedKeyMaterialTrace
A trace callback for the obtained key material.
void ProcessCreateQueuesResponse()
Start establishing key queues at the reciving application once requested by the sender.
std::string GetKsidFromHttp004AppQuery(void)
Map the HTTP response from the peer QKD application and obtain the key stream identifier.
Ptr< Socket > m_sendDataSocketApp
The sending socket for the data.
void HandleAcceptFromApp(Ptr< Socket > s, const Address &from)
Handle an incoming connection from the peer QKD application.
uint32_t GetMethodFromHttp004KMSQuery(std::string uri)
Read the ETSI request method from the URI.
Address m_peerSignaling
The address of the peer for the signaling data transmission.
QKDEncryptor::EncryptionType m_encryptionType
The encryption algorithm.
Ptr< Packet > m_maliciousPacket
The malicious packet.
uint32_t GetEncryptionKeySize()
Get the required key size for the choosen encryption algorithm.
void ConnectionSignalingToAppFailed(Ptr< Socket > socket)
Callback function after the signaling connection to the APP has failed.
Address m_kms
The local KMS address.
EventId m_sendEvent
The data transmission event.
void Close(std::string ksid)
Close the keys stream session (the association).
void HandlePeerErrorSignalingFromApp(Ptr< Socket > socket)
Handle a signaling connection error from the peer QKD application.
Ptr< Socket > m_sinkSocketFromKMS
The receiving socket from the KMS.
void InitializeAssociations()
Initialize the key stream sessions.
uint32_t m_ttl
The time-to-live of the key stream session.
void ProcessPacketsToKMSFromQueue()
Process and send any remaining packets to the KMS.
void CloseSocketToKms()
Close the connecting sockets with the KMS.
uint32_t GetAuthenticationKeySize()
Get the required key size for the choosen authentication algorithm.
std::pair< Association004, Association004 > m_associations
A pair (encryption/authentication) of the establihed key stream session.
bool ConnectionRequestedFromKMS(Ptr< Socket > socket, const Address &address)
Callback function after the connection for response from the KMS has been received.
UUID m_ksid_enc
The encryption key stream identifier.
uint32_t m_dataSent
The amount of the sent data.
void PrepareSendSocketToKMS()
Prepare the send socket to communicate with the KMS Application.
uint64_t GetMaxEncryptionKeyRate()
Get the maximum key rate required for the encryption (QoS settings).
void ProcessCloseResponse(HTTPMessage &header)
Process the CLOSE response.
void PacketReceivedFromKMS(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Check for the tcp segmentation of packets received from the KMS.
std::string GetPacketContent(uint32_t msgLength=0)
Generate a random packet payload (the message).
bool m_replicaQueueEstablished
Is the queue established at the receiver application?
TracedCallback< Ptr< const Packet > > m_rxKmsTrace
A trace for received packets from the KMS.
void Http004KMSQuery(std::string uri, std::string ksid, uint32_t keyType)
Memories the HTTP request made to the local KMS.
void ConnectionSignalingToAppSucceeded(Ptr< Socket > socket)
Callback function after the signaling connection to the APP is complete.
void ConnectionToAppSucceeded(Ptr< Socket > socket)
Callback function after the connection to the APP is complete.
Time m_holdTime
The holding time before closing sockets.
std::map< std::string, std::pair< std::string, uint32_t > > m_httpRequestsKMS
A vector of HTTP requests set to the KMS.
std::vector< std::pair< uint32_t, std::string > > m_httpRequestsApp
A vector of HTTP requests sent to the peer application.
Ptr< Socket > m_sendSocketToKMS
The sending socket to the KMS.
TracedCallback< Ptr< const Packet > > m_txKmsTrace
A trace for transmitted packets to the KMS.
std::multimap< std::string, std::string > m_transitionMatrix
The map of the possible state transitions.
TracedCallback< Ptr< const Packet >, std::string > m_mxTrace
A trace for the missed time slots to send data (due to the lack of keys).
TypeId m_tid
The type identifier.
void SignalingPacketReceivedFromApp(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Check for the tcp segmentation of the signaling packets received from the peer application.
QKDAppState GetAppState() const
Get the current state of the application.
void HandlePeerErrorFromApp(Ptr< Socket > socket)
Handle a connection error from the peer QKD application.
uint64_t GetMaxAuthenticationKeyRate()
Get the maximum key rate required for the authentication (QoS settings).
QKDEncryptor::AuthenticationType m_authenticationType
The authentication algorithm.
void CreateKeyQueuesResponse()
Once the receiving application establishes the queues, it sends a response to the sender application.
Ptr< QKDEncryptor > m_encryptor
The QKD encryptor.
void HandlePeerCloseSignalingFromApp(Ptr< Socket > socket)
Handle a signaling connection close from the peer QKD application.
uint32_t m_priority
The application priority (QoS).
std::string GetKsidFromHttp004KMSQuery(std::string uri)
Map the HTTP response from the KMS and obtain the key stream identifier.
uint32_t m_authenticationTagLengthInBits
The size of the authentication tag in bits (32 by default).
Address m_local
The local address for the data transmission.
void SetEncryptionAndAuthenticationSettings(uint32_t encryptionType, uint32_t authenticationType, uint32_t authenticationTagLengthInBits)
Set the encryption and the authentication algorithms.
void SendKsidResponse(HTTPMessage::HttpStatus httpStatus, std::string msg="")
Send a response on the SEND_KSID request.
uint32_t m_master
Is a master (sender/primary) application?
void CreateKeyQueues()
Create the required key queues to store a set amount of keys from the respective key stream sessions.
void ProcessResponseFromKMS(HTTPMessage &header, Ptr< Packet > packet, Ptr< Socket > socket)
Process a response from the KMS application.
void HandlePeerCloseToKMS(Ptr< Socket > socket)
Handle a connection close to the KMS.
void SwitchAppState(QKDAppState state)
Change the state of the application.
void CheckQueues()
Request new keys from the KMS until the key queues at the application layer are established with a se...
void CheckAssociationsState()
Check if the required key stream sessions are successfuly established.
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_buffer_sig
The buffer for the received signaling packets (fragmentation).
Ptr< Socket > GetSinkSocketFromKMS()
Get the receiving socket from the KMS.
void ConnectionToAppFailed(Ptr< Socket > socket)
Callback function after the connection to the APP has failed.
void CreateKeyStreamAssociations()
void HandlePeerCloseFromKMS(Ptr< Socket > socket)
Handle a connection close from the KMS.
TracedCallback< Ptr< Packet > > m_decryptionTrace
A trace callback for the decryption event.
UUID GetId(void)
Get the application identifier.
uint32_t m_malicious
Is a malicious application?
void AppTransitionTree(void)
Transition through a tree of the application states and trigger actions.
void HandleReadFromKMS(Ptr< Socket > socket)
Handle a packet received by the QKD application from the KMS application.
Ptr< Socket > m_sendSignalingSocketApp
The sending socket for the signaling messages.
std::string PacketToString(Ptr< Packet > packet)
Convert the packet to a string.
DataRate m_minDataRate
The minimum application data rate.
static uint32_t m_applicationCounts
The number of running applications.
QKDAppKey GetEncKey()
Get the encryption key from the queue.
Ptr< Socket > m_sinkDataSocketApp
The receiving socket for the data.
TracedCallback< Ptr< const Packet >, std::string > m_txTrace
void ScheduleTx(void)
Schedule the next time slot to send the data.
Ptr< Socket > GetSendSocketToKMS()
Get the sending socket to the KMS.
uint32_t m_encryptionTypeInt
The encryption algorithm.
TracedCallback< Ptr< const Packet >, std::string > m_rxTrace
A trace for received data packets.
void DataPacketReceivedFromApp(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Check for the tcp segmentation of the signaling packets received from the KMS.
void SendKsidRequest(std::string ksid, uint32_t input)
Inform the peer QKD application of the established key stream session.
void PrepareSendSocketToApp()
Prepare the send socket to communicate with the peer QKD Application.
std::vector< KMSPacket > m_queue_kms
The queue of packets waiting for the transmission to the KMS.
void Http004AppQuery(uint32_t methodType, std::string ksid)
Memories the HTTP request made to the peer QKD application.
void HandlePeerErrorToKMS(Ptr< Socket > socket)
Handle a connection error to the KMS.
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_buffer_kms
The buffer for the received packets from the KMS (fragmentation).
void SetKsidEncryption(UUID val)
Set encryption key stream identifier.
void Setup(std::string socketType, Address src, Address dst, Address kms, UUID dstSaeId, std::string type)
Configure the application.
uint32_t m_authenticationTypeInt
The authentication algorithm.
EncryptionType
Encryption type.
AuthenticationType
Authentication type.
Simulation virtual time values and global simulation resolution.
Forward calls to a chain of Callback.
a unique identifier for an interface.
Universally unique identifier (UUID)
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hashing for the Address class.
size_t operator()(const Address &x) const
operator ()
The key stream session details.
std::map< uint32_t, QKDAppKey > buffer
A cryptographic key at the application layer.
static const uint32_t packetSize
Packet size generated at the AP.