21 #ifndef QKD_SDN_CONTROLLER_H
22 #define QKD_SDN_CONTROLLER_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"
37 #include <unordered_map>
47 #include <cryptopp/base64.h>
260 return std::hash<uint32_t>()(a.
GetIpv4 ().
Get ());
656 uint32_t srcSaeId, uint32_t dstSaeId,
a polymophic address class
The base class for all ns3 applications.
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.
TracedCallback< Ptr< const Packet > > m_txTraceSDNs
static TypeId GetTypeId(void)
Get the type ID.
std::map< Ptr< Socket >, Ptr< Packet > > m_packetQueues
Buffering unsend messages due to connection problems.
void ProcessNewAppResponse(HTTPMessage header, Ptr< Socket > socket)
std::map< std::string, Association004 > m_associations004
uint32_t GetMaxKeyPerRequest()
Get maximum number of keys per request (ETSI QKD 014)
uint32_t GetId()
Get key menager system ID.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced Callback: received packets, source address.
Ipv4Address GetAddress()
Get local address.
void RegisterRequest(std::string ksid)
void ProcessCloseRequest(std::string ksid, HTTPMessage header, Ptr< Socket > socket)
uint32_t m_defaultKeySize
void ProcessGetKey004Request(std::string ksid, HTTPMessage header, Ptr< Socket > socket)
Ptr< Socket > GetSendSocketKMS(Ipv4Address kmsDstAddress)
Obtain send socket.
uint32_t GetTotalRx() const
Get the total amount of bytes received.
void HttpKMSAddQuery(Ipv4Address dstKms, HttpQuery request)
remember HTTP request made to peer KMS
std::map< Ptr< Socket >, Ptr< Socket > > m_socketPairs
the accepted sockets
void HandleRead(Ptr< Socket > socket)
Handle a packet received by the KMS application.
void StopApplication(void)
Stop KMS Application.
uint32_t GetPort()
Get local port.
TracedCallback< const std::string &, const uint32_t &, const uint32_t &, const uint32_t & > m_keyServedETSI004Trace
void ProcessRegisterRequest(HTTPMessage header, std::string ksid, Ptr< Socket > socket)
TracedCallback< Ptr< const Packet >, const Address & > m_rxTraceSDNs
void StartApplication(void)
Start KMS Application.
std::string Base64Decode(std::string input)
Base64 decoder.
void HandlePeerClose(Ptr< Socket > socket)
Handle an connection close.
Ptr< QKDKMSQueueLogic > m_queueLogic
KMS Queue Logic for ETSI 004 QoS handling.
uint32_t m_totalRxKMSs
Total bytes received between KMSs.
void HandlePeerError(Ptr< Socket > socket)
Handle an connection error.
std::string CreateNew004Association(uint32_t srcSaeId, uint32_t dstSaeId, QKDSDNController::QoS inQos, Ipv4Address dstKms, std::string ksid)
Create a new assocation.
uint32_t m_port
Local port to bind to.
Ipv4Address m_local
Local address to bind to.
void DataSendKMSs(Ptr< Socket >, uint32_t)
TracedCallback< const uint32_t & > m_newKeyGeneratedTraceEmir
std::map< uint32_t, EventId > m_scheduledChecks
uint32_t m_totalRx
Total bytes received
void ConnectionFailed(Ptr< Socket > socket)
RequestType HttpQueryMethod(Ipv4Address dstKms)
obtain method_type to map the HTTP response
TracedCallback< const std::string &, const uint32_t &, Ptr< QKDKey > > m_keyServedETSI014Trace
void ConnectionSucceededKMSs(Ptr< Socket > socket)
double m_qkdLinkDefaultUpdateInterval
Default update interval of QKD link status (seconds)
std::multimap< uint32_t, Ptr< Socket > > m_http004App
void SetSocket(std::string type, Ptr< Socket > socket)
Set sink socket.
RequestType
Request types.
@ ETSI_QKD_014_GET_KEY
Integer equivalent = 1.
@ ETSI_QKD_004_OPEN_CONNECT
@ ETSI_QKD_014_GET_KEY_WITH_KEY_IDS
Integer equivalent = 2.
@ ETSI_QKD_014_GET_STATUS
Integer equivalent = 0.
void SetAddress(Ipv4Address address)
Set local address.
EventId m_closeSocketEvent
QKDSDNController::RequestType FetchRequestType(std::string s)
Get request type.
uint32_t m_maliciousBlocking
TracedCallback< const uint32_t & > m_keyServedTraceEmir
void Http004AppQuery(uint32_t saeId, Ptr< Socket > socket)
Ptr< Socket > m_sinkSocket
void PacketReceived(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Assemble byte stream to extract HTTPMessage.
std::string PacketToString(Ptr< Packet > packet)
Convert packet to string.
Ptr< Node > GetNode()
Get node.
void SendToSocketPair(Ptr< Socket > socket, Ptr< Packet > packet)
Send packet to the pair socket.
void CheckSocketsKMS(Ipv4Address dstSaeId)
Prepare send socket to communicate with peer KMS Application.
uint32_t m_maxKeyPerRequest
std::map< Ipv4Address, std::pair< Ptr< Socket >, Ptr< Socket > > > m_socketPairsKMS
the accepted sockets for communication between KMSs
virtual void DoDispose(void)
@toDo
std::string Base64Encode(std::string input)
Base64 encoder.
nlohmann::json CreateKeyContainer(std::vector< Ptr< QKDKey >> keys)
Check the correctness of QKD application request and ability of KMS to fullfil correct request.
virtual ~QKDSDNController()
QKDSDNController destructor.
void Http004AppQueryComplete(uint32_t saeId)
void ConnectionSucceeded(Ptr< Socket > socket)
@toDo:following functions
std::map< Ptr< Socket >, Ptr< Socket > > GetAcceptedSockets(void) const
Get list of all accepted sockets.
void AddNewLink(uint32_t srcSaeId, uint32_t dstSaeId, Ipv4Address kmsDstAddress, Ptr< QKDBuffer > srcBuffer)
Inform KMS about the new QKD connection/link.
std::map< Ipv4Address, std::vector< HttpQuery > > m_httpRequestsQueryKMS
TracedCallback< const Ipv4Address &, Ptr< const Packet > > m_dropTrace
Traced callback: fired when a packet is dropped.
void ConnectionFailedKMSs(Ptr< Socket > socket)
void RegisterSaePair(Ptr< Node > srcNode, Ptr< Node > dstNode, uint32_t srcSaeId, uint32_t dstSaeId, std::string type)
Inform KMS about the SAE connection.
void ProcessAddKeysResponse(HTTPMessage header, Ptr< Socket > socket)
Process FILL response.
void HandleAccept(Ptr< Socket > s, const Address &from)
Handle an incoming connection.
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_bufferKMS
Buffer for received packets (TCP segmentation)
void ProcessRegisterResponse(HTTPMessage header, Ptr< Socket > socket)
TracedCallback< const uint32_t &, const uint32_t & > m_newKeyGeneratedTrace
void SetPort(uint32_t port)
Set local port.
void ReadJsonQos(QKDSDNController::QoS &inQos, nlohmann::json jOpenConnectRequest)
Read the parameters from the JSON OPEN_CONNECT structure!
void DataSend(Ptr< Socket >, uint32_t)
void SendToSocketPairKMS(Ptr< Socket > socket, Ptr< Packet > packet)
Send packet to the pair socket.
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_buffer
Buffer for received packets (TCP segmentation)
void ProcessOpenConnectRequest(HTTPMessage header, Ptr< Socket > socket)
void HttpKMSCompleteQuery(Ipv4Address dstKms)
remove mapped HTTP response from query
std::map< Ipv4Address, uint32_t > m_flagedIPAdr
void ReleaseAssociation(std::string ksid, std::string surplusKeyId, uint32_t syncIndex)
release key stream association
Ptr< Socket > GetSocket(void) const
Get sink socket.
QKDSDNController()
QKDSDNController constructor.
void ProcessRequest(HTTPMessage header, Ptr< Packet > packet, Ptr< Socket > socket)
QKD key manager system application process the request from QKDApp, and complete certain actions to r...
TracedCallback< Ptr< const Packet > > m_txTrace
void ProcessNewAppRequest(HTTPMessage header, Ptr< Socket > socket)
void ProcessAddKeysRequest(HTTPMessage h, Ptr< Socket > socket, std::string ksid)
Process FILL request.
void SetNode(Ptr< Node > n)
Set node.
Ipv4Address GetDestinationKmsAddress(Ptr< Socket > socket)
Ptr< Socket > GetSocketFromHttp004AppQuery(uint32_t saeId)
Forward calls to a chain of Callback.
a unique identifier for an interface.
#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 ()
std::map< uint32_t, ChunkKey > buffer
uint32_t associationDirection
std::vector< std::string > tempBuffer
std::vector< std::string > transform_key_IDs
std::string surplus_key_ID
uint32_t transform_key_size
uint32_t transform_key_number
std::vector< std::string > to_transform_key_IDs