21 #ifndef QKD_KEY_MANAGER_SYSTEM_APPLICATION_H
22 #define QKD_KEY_MANAGER_SYSTEM_APPLICATION_H
24 #include "ns3/address.h"
25 #include "ns3/application.h"
26 #include "ns3/event-id.h"
28 #include "ns3/data-rate.h"
29 #include "ns3/traced-callback.h"
30 #include "ns3/random-variable-stream.h"
31 #include "ns3/qkd-buffer.h"
32 #include "ns3/qkd-connection-register.h"
33 #include "ns3/qkd-key-association-link-entry.h"
34 #include "ns3/qkd-application-entry.h"
35 #include "ns3/qkd-kms-queue-logic.h"
36 #include "ns3/random-variable-stream.h"
39 #include <unordered_map>
48 #include <cryptopp/base64.h>
182 std::string keyAssociationId
199 UUID keyAssociationId,
200 UUID applicationEntryId,
206 double expirationTime
226 double expirationTime
361 std::string srcSaeId,
362 std::string dstSaeId,
392 return std::hash<uint32_t>()(a.
GetIpv4 ().
Get ());
731 void ReleaseAssociation (std::string ksid, std::string surplusKeyId, uint32_t syncIndex);
1085 std::string srcSaeId,
1086 std::string dstSaeId,
1090 std::string appConnectionId
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.
Ipv4Address GetIpv4(void) const
static bool IsMatchingType(const Address &address)
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Ipv4 addresses are stored in host order in this class.
uint32_t Get(void) const
Get the host-order 32-bit IP address.
Introspection did not find any typical Config paths.
ConnectionType
The connection types.
Introspection did not find any typical Config paths.
Address m_sdnControllerAddress
The SDN controller address.
void ProcessRegisterResponse(HTTPMessage header, Ptr< Socket > socket)
Process the REGISTER response.
uint32_t GetMaxKeyPerRequest()
Get maximum number of keys that can be supplied via a single response (ETSI QKD 014).
uint32_t m_port
Local port to bind to.
QKDApplicationEntry GetApplicationConnectionDetails(std::string saeId)
Get the application connection details.
TracedCallback< const std::string &, Ptr< QKDKey > > m_keyServedETSI014Trace
A trace for the consumed keys by the ETSI 014 clients.
void HandlePeerCloseKMSs(Ptr< Socket > socket)
Handle a connection close from the KMS.
void DataSend(Ptr< Socket >, uint32_t)
Callback function for the data sent.
Ptr< QKDKMSQueueLogic > m_queueLogic
The KMS Queue Logic for the ETSI 004 QoS handling.
void SendToSocketPairKMS(Ptr< Socket > socket, Ptr< Packet > packet)
Send the packet to the pair socket.
RequestType
Request methods.
@ ETSI_QKD_014_GET_KEY
Integer equivalent = 1.
@ ETSI_QKD_014_GET_KEY_WITH_KEY_IDS
Integer equivalent = 2.
@ ETSI_QKD_004_OPEN_CONNECT
@ ETSI_QKD_014_GET_STATUS
Integer equivalent = 0.
void HandleAccept(Ptr< Socket > s, const Address &from)
Handle an incoming connection from the application.
std::map< std::string, Association004 > m_associations004
The list of active key stream sessions.
Ptr< Socket > GetSendSocketKMS(Ipv4Address kmsDstAddress)
Obtain the send socket.
uint32_t m_default_ttl
The default value of TTL.
void DataToSDNSend(Ptr< Socket >, uint32_t)
Callback function for the data sent to the SDN controller.
uint32_t GetTotalRx() const
Get the total amount of received bytes.
void HttpKMSAddQuery(Ipv4Address dstKms, HttpQuery request)
Remember the HTTP request made to the peer KMS.
uint32_t ScheduleCheckAssociation(Time t, std::string action, std::string ksid)
Schedule the next event in the attempt to fill the key stream session buffer.
void ProcessRegisterRequest(HTTPMessage header, std::string ksid, Ptr< Socket > socket)
Process the REGISTER request.
QKDKeyAssociationLinkEntry GetKeyAssociationByNodeIds(uint32_t srcNodeId, uint32_t dstNodeId)
Get the key association link details.
std::multimap< UUID, Ptr< Socket > > m_http004App
The list of HTTP requests (without response) set to the application.
Ipv4Address GetDestinationKmsAddress(Ptr< Socket > socket)
Get the destiantion KMS IP address based on the connected socket.
void Http004AppQuery(UUID saeId, Ptr< Socket > socket)
Remember the HTTP request received from the application.
nlohmann::json Check014GetKeyRequest(nlohmann::json request, QKDKeyAssociationLinkEntry conn)
Validate the request and probe if the KMS can meet the request requirements.
std::string PacketToString(Ptr< Packet > packet)
Convert the packet to a string.
void HandleAcceptKMSs(Ptr< Socket > s, const Address &from)
Handle an incoming connection from the KMS.
void CreateNew004Association(std::string srcSaeId, std::string dstSaeId, QKDKeyManagerSystemApplication::QoS &inQos, Ipv4Address dstKms, std::string &ksid, std::string appConnectionId)
Create a new key stream session.
std::map< Ipv4Address, std::pair< Ptr< Socket >, Ptr< Socket > > > m_socketPairsKMS
The accepted sockets for the communication between KMSs.
void HandleAcceptSDN(Ptr< Socket > s, const Address &from)
Handle an incoming connection from the SDN.
uint32_t m_totalRx
Total bytes received.
void PurgeExpiredAssociations()
Purge (delete) the expired ETSI 004 key stream sessions based on the QoS - TTL value.
void ProcessPacketKMSs(HTTPMessage header, Ptr< Packet > packet, Ptr< Socket > socket)
Process incoming request at the KM link.
std::string Base64Encode(std::string input)
Base64 encoder.
void ConnectionSucceeded(Ptr< Socket > socket)
Callback function after the connection to the APP is complete.
std::string GenerateKeyId()
Generate unique key identifier.
void ProcessRequestKMS(HTTPMessage header, Ptr< Socket > socket)
Process request from the peer KMS.
std::map< Ptr< Socket >, Ptr< Packet > > m_packetQueues
Buffering unsend messages due to the connection problems.
void TransformKeys(uint32_t keySize, uint32_t keyNumber, UUID slave_SAE_ID)
Transform a number of keys to a given size.
void NewAppRequest(std::string ksid)
Make a NEW_APP request to the peer KMS.
void HttpKMSCompleteQuery(Ipv4Address dstKms)
Remove the HTTP request from the list.
void ProcessPPRequest(HTTPMessage header, Ptr< Packet > packet, Ptr< Socket > socket)
Process request from the QKD post-processing application.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
A trace for the received packets from the applications.
void ProcessResponseKMS(HTTPMessage header, Ptr< Packet > packet, Ptr< Socket > socket)
Process response from the peer KMS.
void SetSocket(std::string type, Ptr< Socket > socket)
Set the sink socket.
void SendQKDLinkStatusToSDN(UUID linkId, double updatePeriod)
Send the QKD link statistics to the SDN controller.
std::string AddNewLink(uint32_t srcSaeId, uint32_t dstSaeId, Ipv4Address kmsDstAddress, Ptr< QKDBuffer > srcBuffer)
Register a new QKD link, or a pair of post-processing applications.
TracedCallback< const std::string &, const uint32_t &, const uint32_t & > m_keyServedETSI004Trace
A trace for the consumed keys by the ETSI 004 clients.
static uint32_t nKMS
The number of created KMSs.
void RegisterRequest(std::string ksid)
Send the REGISTER request.
QKDKeyManagerSystemApplication::RequestType FetchRequestType(std::string s)
Read the request method from the request URI.
void ProcessAddKeysRequest(HTTPMessage h, Ptr< Socket > socket, std::string ksid)
Process the FILL request.
uint32_t m_sdnSupportEnabled
The support for the SDN.
uint32_t m_kms_id
The KMS identifier.
TypeId m_tid
The object type identifier.
void ProcessCloseRequest(std::string ksid, HTTPMessage header, Ptr< Socket > socket)
static TypeId GetTypeId(void)
Get the type ID.
void NegotiateKeysForAssociation(std::string ksid, uint32_t keyAmount=1024, uint32_t priority=0)
Add new keys to the key stream session buffer.
void DataSendKMSs(Ptr< Socket >, uint32_t)
Callback function for the data sent to the peer KMS.
void CheckSessionList(std::string ksid)
Check whether a new OPEN_CONNECT was received before the previously established session expired.
Ipv4Address GetAddress()
Get the local IP address.
void HandleReadKMSs(Ptr< Socket > socket)
Handle a packet received from the KMS.
void HandlePeerError(Ptr< Socket > socket)
Handle a connection error from the application.
void HandlePeerErrorSDN(Ptr< Socket > socket)
Handle a connection error from the SDN.
void SetNode(Ptr< Node > n)
Set the node.
double m_qos_maxrate_threshold
The maximal rate threshold.
void ProcessResponseSDN(HTTPMessage header, Ptr< Packet > packet, Ptr< Socket > socket)
Process response from the SDN controller.
TracedCallback< const Ipv4Address &, Ptr< const Packet > > m_dropTrace
A trace for the dropped packets.
void HandlePeerClose(Ptr< Socket > socket)
Handle an connection close from the application.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTraceKMSs
A trace for the received packets from the peer KMS.
nlohmann::json CreateKeyContainer(std::vector< Ptr< QKDKey >> keys)
Create the key container data structure.
QKDApplicationEntry GetApplicationConnectionDetailsBySaeIDsAndType(std::string srcSaeId, std::string dstSaeId, QKDApplicationEntry::ConnectionType type)
Get the application connection details.
TracedCallback< Ptr< const Packet > > m_txTraceSDN
A trace for the sent packets to the SDN controller.
void PrepareSinkSocket()
Prepare the sink socket.
uint32_t m_maliciousBlocking
Should KMS detect and block malicious requests?
std::map< Ptr< Socket >, Ptr< Socket > > m_socketPairs
The accepted sockets.
void PacketReceivedKMSs(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Assemble a byte stream from the peer KMS to extract the HTTP message.
void ProcessTransformRequest(HTTPMessage header, Ptr< Socket > socket)
Process the transform request.
TracedCallback< const uint32_t & > m_newKeyGeneratedTraceEmir
A trace for the generated keys.
void ProcessGetKey004Request(std::string ksid, HTTPMessage header, Ptr< Socket > socket)
Ptr< Socket > GetSocketFromHttp004AppQuery(UUID saeId)
Lookup the HTTP request and obtain connected socket.
std::unordered_map< uint64_t, Ptr< Packet >, AddressHash > m_buffer
The buffer for the received packets from the applications (TCP segmentation).
void ProcessOpenConnectRequest(HTTPMessage header, Ptr< Socket > socket)
std::map< Ptr< Socket >, Ptr< Socket > > GetAcceptedSockets(void) const
Get the list of all the accepted sockets.
void ProcessNewAppResponse(HTTPMessage header, Ptr< Socket > socket)
Process the NEW_APP response.
Ptr< Node > GetNode()
Get the node.
void MonitorAssociations()
\breif Monitor the state of the existing key stream sessions.
void SetAddress(Ipv4Address address)
Set the local IP address.
bool CheckDoSAttack(HTTPMessage headerIn, Ptr< Socket > socket)
Check for the DoS attack.
void CheckAssociation(std::string ksid)
Check the state of a single key stream session.
Ptr< Socket > m_sinkSocketFromSDN
The sink socket from the SND controller.
void ProcessKMSCloseRequest(HTTPMessage header, Ptr< Socket > socket, std::string ksid)
Process the close request from the peer KMS.
RequestType HttpQueryMethod(Ipv4Address dstKms)
Map the HTTP response and obtain the request method.
std::map< Ipv4Address, uint32_t > m_flagedIPAdr
A list of flaged IP addresses.
uint32_t m_maxKeyPerRequest
The maximal number of keys per request application can ask for.
QKDKeyAssociationLinkEntry GetKeyAssociationById(UUID keyAssociationId)
Get the key association link details.
void ProcessKMSCloseResponse(HTTPMessage header, Ptr< Socket > socket)
Process close response from the peer KMS.
void SaveKeyAssociation(QKDKeyAssociationLinkEntry &rt)
Add the key association.
void ConnectionToSDNSucceeded(Ptr< Socket > socket)
Callback function after the connection to the SDN controller is complete.
void AddKeyToAssociationDedicatedStore(std::string ksid, Ptr< QKDKey > key)
Add the key to the key stream session buffer.
bool connectedToSDN
Is conncted to the SDN controller?
void HandlePeerErrorKMSs(Ptr< Socket > socket)
Handle a connection error from the KMS.
DataRate m_minKeyRate
The minimal key rate.
std::map< Ptr< Socket >, Ptr< Packet > > m_packetQueuesToSDN
Buffering unsend messages due to the connection problems.
uint32_t m_defaultKeySize
The default key size KMS will deliver if the size was not defined in the request.
std::vector< std::string > ProcessUriParams(std::string s)
Read the URI parameters in a vector.
void ConnectionToSDNFailed(Ptr< Socket > socket)
Callback function after the connection to the SDN controller has failed.
void ProcessRequestSDN(HTTPMessage header, Ptr< Packet > packet, Ptr< Socket > socket)
Process request from the SDN controller.
void SendToSocketPair(Ptr< Socket > socket, Ptr< Packet > packet)
Send the packet to the pair socket.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTraceSDN
A trace for the received packets from the SDN controller.
uint32_t m_maxKeySize
The maximal size of the key application can request.
Ptr< Socket > m_sinkSocket
The sink socket.
uint32_t m_totalRxKMSs
Total bytes sent between KMSs.
void PacketReceivedSDN(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Assemble a byte stream from the SDN to extract the HTTP message.
void ProcessTransformResponse(HTTPMessage header, Ptr< Socket > socket)
Process the transform response.
void HandleReadSDN(Ptr< Socket > socket)
Handle a packet received from the SDN.
void HandleRead(Ptr< Socket > socket)
Handle a packet received from the application.
DataRate m_maxKeyRate
The maximal key rate.
QKDKeyAssociationLinkEntry GetKeyAssociationLinkDetailsByApplicationId(std::string appId)
Get the key association link details.
void SetPort(uint32_t port)
Set the local port.
void ReadJsonQos(QKDKeyManagerSystemApplication::QoS &inQos, nlohmann::json jOpenConnectRequest)
Read the QoS parameters from the JSON OPEN_CONNECT structure.
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_bufferKMS
The buffer for the received packets from the peer KMS (TCP segmentation).
QKDApplicationEntry RegisterApplicationEntry(UUID keyAssociationId, UUID applicationEntryId, UUID srcSaeId, UUID dstSaeId, std::string type, Ipv4Address dstKmsAddress, uint32_t priority, double expirationTime)
Register a new pair of QKD applications.
void StartApplication(void)
Start the KMS Application.
bool ProcessQoSRequest(QKDApplicationEntry &appConnection, QKDKeyAssociationLinkEntry &keyAssociation, QKDKeyManagerSystemApplication::QoS &inQos, QKDKeyManagerSystemApplication::QoS &outQos, std::string ksid)
Process the QoS requirements.
TracedCallback< const std::string &, const std::string &, const uint32_t &, const uint32_t &, const uint32_t &, const uint32_t &, const uint32_t & > m_providedQoS
A trace for the admitted QoS.
void ProcessNewAppRequest(HTTPMessage header, Ptr< Socket > socket)
virtual ~QKDKeyManagerSystemApplication()
Destructor.
bool AddNewKey(Ptr< QKDKey > key, uint32_t srcNodeId, uint32_t dstNodeId)
Add new keys to the QKD buffer.
std::string GenerateKsid()
Generate a new key stream session identifier (ksid).
std::map< std::string, uint32_t > m_sessionList
A list of sessions.
std::map< Ipv4Address, std::vector< HttpQuery > > m_httpRequestsQueryKMS
The list of HTTP request (without response) sent to the peer KMS.
uint32_t m_minKeySize
The minimal size of the key application can request.
void PacketReceived(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Assemble a byte stream from the application to extract the HTTP message.
void StopApplication(void)
Stop the KMS Application.
TracedCallback< Ptr< const Packet > > m_txTraceKMSs
A trace for the sent packets to the peer KMS.
virtual void DoDispose(void)
Destructor implementation.
void ReleaseAssociation(std::string ksid, std::string surplusKeyId, uint32_t syncIndex)
Release the key stream session.
void HandlePeerCloseSDN(Ptr< Socket > socket)
Handle a connection close from the SDN.
void ConnectionFailedKMSs(Ptr< Socket > socket)
Callback function after the connection to the peer KMS has failed.
void ConnectionFailed(Ptr< Socket > socket)
Callback function after the connection to the APP has failed.
EventId m_closeSocketEvent
The close socket event.
void ProcessRequest(HTTPMessage header, Ptr< Packet > packet, Ptr< Socket > socket)
Process incoming requests from the service layer, i.e., QKD applications.
std::map< uint32_t, EventId > m_scheduledChecks
The scheduled events.
TracedCallback< const uint32_t & > m_keyServedTraceEmir
A trace for the consumed keys.
TracedCallback< Ptr< const Packet > > m_txTrace
A trace for the sent packets to the applications.
void ConnectToSDNController()
Connect to the SDN controller.
Ptr< Socket > GetSocket(void) const
Get the sink socket.
Ptr< Socket > m_sendSocketToSDN
The send socket to the SDN controller.
Ptr< UniformRandomVariable > m_random
The uniform random variable.
void SetSDNControllerAddress(Address sdnAddress)
Set the SDN controller address.
void ConnectionSucceededKMSs(Ptr< Socket > socket)
Callback function after the connection to the peer KMS is complete.
uint32_t GetId()
Get the KMS identifier.
void ProcessAddKeysResponse(HTTPMessage header, Ptr< Socket > socket)
Process the FILL response.
void CheckSocketsKMS(Ipv4Address dstSaeId)
Prepare the send socket to communicate with the peer KMS.
uint32_t m_kms_key_id
The counter value to assure generation of the unique key identifiers.
QKDKeyManagerSystemApplication()
Constructor.
std::string Base64Decode(std::string input)
Base64 decoder.
uint32_t GetPort()
Get the local port.
TracedCallback< const uint32_t &, const uint32_t & > m_newKeyGeneratedTrace
A trace for the generated keys.
Ipv4Address m_local
Local address to bind to.
void Http004AppQueryComplete(UUID saeId)
Remove the HTTP request from the list.
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.
list x
Random number samples.
Hashing for the Address class.
size_t operator()(const Address &x) const
operator ()
The key stream session details.
std::map< uint32_t, ChunkKey > buffer
std::vector< std::string > tempBuffer
uint32_t associationDirection
The key within the key stream session buffer.
The HTTP request details.
std::vector< std::string > transform_key_IDs
uint32_t transform_key_number
uint32_t transform_key_size
std::string surplus_key_ID
std::vector< std::string > to_transform_key_IDs
The Quality of service indicators.