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>
163 std::string socketType,
184 std::string socketType,
506 uint32_t encryptionType,
507 uint32_t authenticationType,
508 uint32_t authenticationTagLengthInBits
663 return std::hash<uint32_t>()(a.
GetIpv4 ().
Get ());
692 std::vector<std::string> keyIds,
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.
uint32_t m_master
Is a master (sender/primary) application?
void HandleAcceptFromKMS(Ptr< Socket > s, const Address &from)
Handle an incoming connection from the KMS.
void GetKeyWithKeyIDs()
Requests keys with given identifiers from the KMS (ETSI QKD 014 - Get key with key IDs method).
void PrepareSendSocketToKMS()
Prepare the send socket to communicate with the KMS Application.
uint32_t GetKeyType(void)
Map the HTTP response and obtain the key type.
void SwitchAppState(QKDApp014State state)
Change the state of the application.
void HandleReadFromKMS(Ptr< Socket > socket)
Handle a packet received from the KMS application.
Ptr< QKDEncryptor > m_encryptor
The QKD encryptor.
void ConnectionSignalingToAppSucceeded(Ptr< Socket > socket)
Callback function after the signaling connection to the APP is complete.
TracedCallback< const uint32_t & > m_obtainedKeyMaterialTrace
A trace callback for the obtained key material.
std::string CreateKeyIdField(std::string keyId)
Adjust the encryption key identifier for the QKDApp header.
void HandlePeerCloseSignalingFromApp(Ptr< Socket > socket)
Handle a signaling connection close from the peer QKD application.
TracedCallback< Ptr< const Packet >, std::string > m_txTrace
A trace for transmitted data packets.
void ConnectionSignalingToAppFailed(Ptr< Socket > socket)
Callback function after the signaling connection to the APP has failed.
void AddAuthKeyInKeyStore(QKDApp014::QKDApp014Key &key)
Add a new key to the authentication key store.
void ProcessStatusResponse(HTTPMessage &header, nlohmann::json jstatusResponse)
Process the status response from the KMS.
QKDApp014State
The application states.
std::string GetPacketContent(uint32_t msgLength=0)
Generate a random packet (message) of a given size.
void HandlePeerErrorFromKMS(Ptr< Socket > socket)
Handle a connection error from the KMS.
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_buffer_kms
The buffer for the received packets from the KMS (fragmentation).
QKDApp014State GetAppState() const
Get the current state of the application.
TypeId m_tid
The type identifier.
UUID m_ksid_auth
The authentication key stream identifier.
static TypeId GetTypeId(void)
Get the type ID.
void GetKeysFromKMS(uint32_t keyType)
Request keys from the KMS (ETSI QKD 014 - Get key method).
Time m_waitInsufficient
The amount of time spent waiting before issuing a new GET_KEY request when the previous one resulted ...
void SendPacket(void)
Send the application packet (includes the generation of a random message and optional encryption or/a...
void ConnectionToKMSSucceeded(Ptr< Socket > socket)
Callback function after the connection to the KMS is complete.
void ProcessDataPacketFromApp(QKDAppHeader header, Ptr< Packet > packet, Ptr< Socket > socket)
Process the data packets from the peer QKD application.
std::vector< std::vector< std::string > > m_httpRequestsApp
A vector of HTTP requests sent to the peer application.
std::map< uint32_t, EventId > m_scheduledEvents
The map of scheduled events.
void MemoriesRequestKMS(uint32_t methodType, uint32_t keyType=0)
Memories the HTTP request made to the local KMS.
TracedCallback< Ptr< const Packet >, std::string > m_mxTrace
A trace for the missed time slots to send data packets.
UUID m_dstSaeId
The peer application identifier.
uint32_t ScheduleAction(Time t, std::string action)
Schedule the action.
DataRate m_dataRate
The application data rate.
UUID m_ksid_enc
The encryption key stream identifier.
void AddEncKeyInKeyStore(QKDApp014::QKDApp014Key &key)
Add a new key to the encryption key store.
void PacketReceivedFromKMS(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Check for the TCP segmentation of the packets received from the KMS.
uint32_t GetETSIMethod(void)
Map the HTTP response and obtrain the request method.
void HandleAcceptSignalingFromApp(Ptr< Socket > s, const Address &from)
Handle a signaling incoming connection from the peer QKD application.
uint32_t GetAuthenticationKeySize()
Get required key size for the choosen authentication algorithm.
TracedCallback< Ptr< const Packet > > m_txKmsTrace
A trace for transmitted packets to the KMS.
void HandlePeerCloseFromKMS(Ptr< Socket > socket)
Handle a connection close from the KMS.
QKDApp014State m_appState
The application state.
uint32_t GetEncryptionKeySize()
Get required key size for the choosen encryption algorithm.
void MemoriesRequestApp(std::vector< std::string > keyIds)
Memories the HTTP request made to the peer QKD application.
Ptr< Socket > m_sendSocketToKMS
The sending socket to the KMS.
void ProcessResponseFromKMS(HTTPMessage &header, Ptr< Packet > packet, Ptr< Socket > socket)
Process the response from the KMS application.
uint32_t m_encryptionTypeInt
The encryption algorithm.
void ProcessGetKeyResponse(HTTPMessage &header, nlohmann::json jGetKeyResponse)
Process the GET_KEY response from the KMS.
void HandleAcceptFromApp(Ptr< Socket > s, const Address &from)
Handle an incoming connection from the peer QKD application.
void ConnectionToAppFailed(Ptr< Socket > socket)
Callback function after the connection to the APP has failed.
std::string GetAppStateString() const
Get the current state of the application in the string format.
Address m_kms
The local KMS address.
uint32_t m_authenticationTagLengthInBits
The size of the authentication tag in bits (32 by default).
TracedCallback< Ptr< const Packet > > m_rxSigTrace
A trace for received signaling packets.
void ExchangeInfoMessages(std::string ksid, std::vector< std::string > keyIds, HTTPMessage::HttpStatus statusCode=HTTPMessage::Ok)
Exchange key identifiers between sending and receiving application.
ns3::TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
The posible application state transitions.
TracedCallback< Ptr< Packet >, std::string > m_authenticationTrace
A trace callback for the authentication event.
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 QKD application.
uint32_t m_numberOfKeysKMS
The number of keys to fetch per request.
std::string ReadKeyIdField(std::string keyId)
Rebuild the key identifier for the QKDApp header.
bool ConnectionRequestedFromKMS(Ptr< Socket > socket, const Address &address)
Callback function after the connection response from the KMS has been received.
void RequestProcessedKMS(void)
Remove the request from the HTTP requests store (once the response from the KMS has been processed).
virtual void StartApplication(void)
void CheckAppBufferState()
Check the state of the application key buffer.
std::string m_socketType
The sockets type.
QKDApp014KeyBuffer m_appKeyBuffer
The application key buffer.
UUID GetId(void)
Get the application identifier.
Address m_localSignaling
The local address for the signaling data transmission.
TracedCallback< Ptr< Packet > > m_encryptionTrace
A trace callback for the encryption event.
std::vector< std::pair< uint32_t, uint32_t > > m_httpRequestsKMS
A vector of HTTP requests set to the KMS.
EventId m_sendEvent
The data transmission event.
void PrintAppBufferStatusInformation()
Print the status information on the application key buffer.
uint32_t m_authenticationTypeInt
The authentication algorithm.
void ProcessGetKeyWithKeyIDsResponse(HTTPMessage &header, nlohmann::json jGetKeyWithKeyIDsResponse)
Process the Get Key with Key IDs response from the KMS.
void InitializeAppKeyBuffer()
Initialize the application key buffer.
uint32_t m_packetSize
The data packet size.
void HandleReadFromApp(Ptr< Socket > socket)
Handle a packet received from the peer QKD application.
TracedCallback< Ptr< const Packet > > m_txSigTrace
A trace for transmitted signaling packets.
Ptr< Socket > m_sendDataSocketApp
The sending socket for the data.
TracedCallback< Ptr< const Packet > > m_rxKmsTrace
A trace for received packets from the KMS.
virtual void StopApplication(void)
Application specific shutdown code.
void HandlePeerErrorFromApp(Ptr< Socket > socket)
Handle a connection error from the peer QKD application.
void ConnectionToAppSucceeded(Ptr< Socket > socket)
Callback function after the connection to the APP is complete.
void ProcessSignalingPacketFromApp(HTTPMessage &header, Ptr< Packet > packet, Ptr< Socket > socket)
Process the signaling packets received from the peer QKD application.
uint32_t m_packetsSent
The number of sent data packets.
uint64_t m_aesLifetime
The AES key lifetime.
void DataPacketReceivedFromApp(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Check for the TCP segmentation of the data packets received from the peer QKD application.
void DataToKMSSend(Ptr< Socket >, uint32_t)
Callback function to notify that data to KMS has been sent.
void ConnectionToKMSFailed(Ptr< Socket > socket)
Callback function after the connection to the KMS has failed.
Ptr< Socket > m_sinkDataSocketApp
The receiving socket for the data.
TracedCallback< Ptr< const Packet >, std::string > m_rxTrace
A trace for received data packets.
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_buffer_QKDApp014
The buffer for received data packets (fragmentation).
void SetEncryptionAndAuthenticationSettings(uint32_t encryptionType, uint32_t authenticationType, uint32_t authenticationTagLengthInBits)
Set the encryption and the authentication algorithms.
void CancelScheduledAction(uint32_t eventId)
Cancel the scheduled event/action.
Ptr< Socket > m_sinkSocketFromKMS
The receiving socket from the KMS.
QKDApp014::QKDApp014Key GetKeyFromAppKeyBuffer(uint32_t keyType)
Get the key from the application key buffer.
void RemoveKeysFromTemporaryKeyStore(std::vector< std::string > keyIds)
Remove keys from the temporary key store.
Address m_local
The local address for the data transmission.
void HandlePeerErrorSignalingFromApp(Ptr< Socket > socket)
Handle a signaling connection error from the peer QKD application.
static uint32_t m_applicationCounts
The number of running applications.
nlohmann::json m_keyIDs
The latest received key identifiers from the sender application.
bool m_internalAppWait
The indicator for the longer wait (used after the GetKey error!).
void AppTransitionTree(void)
Transition through a tree of the application states and trigger actions.
void CheckAppState()
Check the conditions to change the application state.
uint32_t m_useCrypto
Execute actual cryptographic algorithms?
std::multimap< std::string, std::string > m_transitionMatrix
The map of the possible state transitions.
void RequestProcessedApp(void)
Remove request from the HTTP requests store (once the response from the peer application has been pro...
virtual ~QKDApp014()
Destructor.
Ptr< UniformRandomVariable > m_random
The uniform random variable.
TracedCallback< Ptr< Packet >, std::string > m_deauthenticationTrace
A trace callback for the authentication check event.
void PrintTemporaryKeyStoreContent()
Print the content of the temporary key store.
void PrepareSendSocketToApp()
Prepare the send socket to communicate with the peer QKD Application.
void SetKsidAuthentication(UUID val)
Set the authentication identifier.
void Setup(std::string socketType, Address src, Address dst, Address kms, UUID dstSaeId, std::string type)
Configure the application.
UUID m_id
The application identifier.
void HandleReadSignalingFromApp(Ptr< Socket > socket)
Handle a signaling packet received from the peer QKD application.
void GetStatusFromKMS(uint32_t keyType)
Request status information from the KMS (ETSI QKD 014 - Get status method).
Time m_waitTransform
The amount of time spent waiting before issuing a new GET_KEY request when the previous one resulted ...
TracedCallback< Ptr< Packet > > m_decryptionTrace
A trace callback for the decryption event.
Ptr< Socket > m_sendSignalingSocketApp
The sending socket for the signaling messages.
void ScheduleTx(void)
Schedule the time slot to send the data packets.
Address m_peer
The address of the peer for the data transmission.
QKDEncryptor::AuthenticationType m_authenticationType
The authentication algorithm.
Address m_peerSignaling
The address of the peer for the signaling data transmission.
void HandlePeerCloseFromApp(Ptr< Socket > socket)
Handle a connection close from the peer QKD application.
uint32_t m_dataSent
The amount of the sent data.
void AddKeyInInboundKeyStore(QKDApp014::QKDApp014Key &key)
Add a new key to the inbound key store.
Ptr< Socket > m_sinkSignalingSocketApp
The receiving socket for the signaling messages.
void PrepareSinkSocketFromApp()
Prepare the sink socket to listen from the peer QKD Application.
QKDEncryptor::EncryptionType m_encryptionType
The encryption algorithm.
void SetKsidEncryption(UUID val)
Set the encryption identifier.
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_buffer_sig
The buffer for the received signaling packets (fragmentation).
void PrepareSinkSocketFromKMS()
Prepare the sink socket to listen from the KMS Application.
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.
basic_json<> json
default JSON class
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 buffer at the application layer.
std::map< std::string, QKDApp014Key > outboundEncKeyStore
std::map< std::string, QKDApp014Key > outboundAuthKeyStore
std::map< std::string, QKDApp014Key > inboundKeyStore
std::map< std::string, QKDApp014Key > temporaryKeyStoreMaster
The cryptographic key at the application layer.
static const uint32_t packetSize
Packet size generated at the AP.