A Discrete-Event Network Simulator
API
qkd-key-manager-system-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: Emir Dervisevic <emir.dervisevic@etf.unsa.ba>
19  * Miralem Mehic <miralem.mehic@ieee.org>
20  */
21 #ifndef QKD_KEY_MANAGER_SYSTEM_APPLICATION_H
22 #define QKD_KEY_MANAGER_SYSTEM_APPLICATION_H
23 
24 #include "ns3/address.h"
25 #include "ns3/application.h"
26 #include "ns3/event-id.h"
27 #include "ns3/ptr.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"
37 #include "ns3/http.h"
38 #include "ns3/json.h"
39 #include <unordered_map>
40 #include "ns3/uuid.h"
41 
42 #include <iostream>
43 #include <sstream>
44 #include <unistd.h>
45 #include <sstream>
46 #include <string>
47 #include <regex>
48 #include <cryptopp/base64.h>
49 
50 
51 namespace ns3 {
52 
53 class Address;
54 class Socket;
55 
79 {
80 public:
81 
86  {
87 
88  NONE = 50,
95  NEW_APP = 6,
96  REGISTER = 7,
97  FILL = 8,
98  STORE_PP_KEYS = 9, //Store postprocessing keys
99  TRANSFORM_KEYS = 10, //Transform (merge, split) QKD keys
101  };
102 
107  static TypeId GetTypeId (void);
108 
113 
118 
123  Ptr<Socket> GetSocket (void) const;
124 
125  //void PrepareOutput (std::string key, uint32_t value); @toDo ? not used
126 
132  void SetSocket (std::string type, Ptr<Socket> socket);
133 
138  uint32_t GetTotalRx () const;
139 
144  std::map<Ptr<Socket>, Ptr<Socket> > GetAcceptedSockets (void) const;
145 
146 
151  uint32_t GetMaxKeyPerRequest();
152 
161  std::string AddNewLink(
162  uint32_t srcSaeId,
163  uint32_t dstSaeId,
164  Ipv4Address kmsDstAddress,
165  Ptr<QKDBuffer> srcBuffer
166  );
167 
177  std::string AddNewLink(
178  uint32_t srcSaeId,
179  uint32_t dstSaeId,
180  Ipv4Address kmsDstAddress,
181  Ptr<QKDBuffer> srcBuffer,
182  std::string keyAssociationId
183  );
184 
199  UUID keyAssociationId,
200  UUID applicationEntryId,
201  UUID srcSaeId,
202  UUID dstSaeId,
203  std::string type,
204  Ipv4Address dstKmsAddress,
205  uint32_t priority,
206  double expirationTime
207  );
208 
221  UUID srcSaeId,
222  UUID dstSaeId,
223  std::string type,
224  Ipv4Address dstKmsAddress,
225  uint32_t priority,
226  double expirationTime
227  );
228 
233  void SetNode(Ptr<Node> n);
234 
239  Ptr<Node> GetNode();
240 
245  uint32_t GetId();
246 
253  bool AddNewKey(Ptr<QKDKey> key, uint32_t srcNodeId, uint32_t dstNodeId);
254 
260  m_local = address;
261  }
262 
268  return m_local;
269  }
270 
275  void SetPort(uint32_t port) {
276  m_port = port;
277  };
278 
283  uint32_t GetPort() {
284  return m_port;
285  }
286 
290  void ConnectToSDNController();
291 
297  m_sdnControllerAddress = sdnAddress;
298  m_sdnSupportEnabled = true;
299  }
300 
306  void SendQKDLinkStatusToSDN(UUID linkId, double updatePeriod);
307 
313 
314 protected:
315 
316  virtual void DoDispose (void);
317 
318 private:
319 
320  static uint32_t nKMS;
321 
324 
331 
338 
345  QKDKeyAssociationLinkEntry GetKeyAssociationByNodeIds(uint32_t srcNodeId, uint32_t dstNodeId);
346 
353 
361  std::string srcSaeId,
362  std::string dstSaeId,
364  );
365 
372 
376  struct AddressHash
377  {
388  size_t operator() (const Address &x) const
389  {
392  return std::hash<uint32_t>()(a.GetIpv4 ().Get ());
393  }
394  };
395 
396  // inherited from Application base class.
400  void StartApplication (void);
401 
405  void StopApplication (void);
406 
412  void SendToSocketPair (Ptr<Socket> socket, Ptr<Packet> packet);
413 
419  void SendToSocketPairKMS (Ptr<Socket> socket, Ptr<Packet> packet);
420 
425  void HandleRead (Ptr<Socket> socket);
426 
431  void HandleReadKMSs (Ptr<Socket> socket);
432 
437  void HandleReadSDN (Ptr<Socket> socket);
438 
444  void HandleAccept (Ptr<Socket> s, const Address& from);
445 
450  void HandlePeerClose (Ptr<Socket> socket);
451 
456  void HandlePeerError (Ptr<Socket> socket);
457 
463  void HandleAcceptKMSs (Ptr<Socket> s, const Address& from);
464 
470  void HandleAcceptSDN (Ptr<Socket> s, const Address& from);
471 
476  void HandlePeerCloseKMSs (Ptr<Socket> socket);
477 
482  void HandlePeerCloseSDN (Ptr<Socket> socket);
483 
488  void HandlePeerErrorKMSs (Ptr<Socket> socket);
489 
494  void HandlePeerErrorSDN (Ptr<Socket> socket);
495 
502  void PacketReceived (const Ptr<Packet> &p, const Address &from, Ptr<Socket> socket);
503 
510  void PacketReceivedKMSs (const Ptr<Packet> &p, const Address &from, Ptr<Socket> socket);
511 
518  void PacketReceivedSDN (const Ptr<Packet> &p, const Address &from, Ptr<Socket> socket);
519 
520 
527  void ProcessRequest(HTTPMessage header, Ptr<Packet> packet, Ptr<Socket> socket);
528 
535  void ProcessPacketKMSs(HTTPMessage header, Ptr<Packet> packet, Ptr<Socket> socket);
536 
543  void ProcessResponseSDN (HTTPMessage header, Ptr<Packet> packet, Ptr<Socket> socket);
544 
551  void ProcessRequestSDN (HTTPMessage header, Ptr<Packet> packet, Ptr<Socket> socket);
552 
558  void ProcessRequestKMS (HTTPMessage header, Ptr<Socket> socket);
559 
566  void ProcessResponseKMS (HTTPMessage header, Ptr<Packet> packet, Ptr<Socket> socket);
567 
574  void ProcessPPRequest (HTTPMessage header, Ptr<Packet> packet, Ptr<Socket> socket);
575 
576  /*
577  * \brief Process the OPEN_CONNECT request - ETSI QKD GS 004.
578  * \param header The received HTTP message.
579  * \param socket The receiving socket.
580  */
581  void ProcessOpenConnectRequest(HTTPMessage header, Ptr<Socket> socket);
582 
583  /*
584  * \brief Process the GET_KEY request - ETSI QKD GS 004.
585  * \param ksid The key stream identifier.
586  * \param header The received HTTP message.
587  * \param socket The receiving socket.
588  */
589  void ProcessGetKey004Request(std::string ksid, HTTPMessage header, Ptr<Socket> socket);
590 
591  /*
592  * \brief Process the CLOSE request - ETSI QKD GS 004.
593  * \param ksid The key stream identifier.
594  * \param header The received HTTP message.
595  * \param socket The receiving socket.
596  */
597  void ProcessCloseRequest(std::string ksid, HTTPMessage header, Ptr<Socket> socket);
598 
599  /*
600  * \brief Process the NEW_APP request.
601  * \param header The received HTTP message.
602  * \param socket The receiving socket.
603  *
604  * The KMS process the NEW_APP request received from the peer KMS. This request
605  * notifies the KMS about a new key stream session.
606  */
607  void ProcessNewAppRequest(HTTPMessage header, Ptr<Socket> socket);
608 
617  void ProcessNewAppResponse (HTTPMessage header, Ptr<Socket> socket);
618 
626  void RegisterRequest (std::string ksid);
627 
636  void ProcessRegisterRequest (HTTPMessage header, std::string ksid, Ptr<Socket> socket);
637 
645  void ProcessRegisterResponse(HTTPMessage header, Ptr<Socket> socket);
646 
650  void PrepareSinkSocket ();
651 
662  void ProcessAddKeysRequest (HTTPMessage h, Ptr<Socket> socket, std::string ksid);
663 
672  void ProcessAddKeysResponse (HTTPMessage header, Ptr<Socket> socket);
673 
684  void TransformKeys (uint32_t keySize, uint32_t keyNumber, UUID slave_SAE_ID);
685 
695  void ProcessTransformRequest(HTTPMessage header, Ptr<Socket> socket);
696 
704  void ProcessTransformResponse(HTTPMessage header, Ptr<Socket> socket);
705 
716  void ProcessKMSCloseRequest (HTTPMessage header, Ptr<Socket> socket, std::string ksid);
717 
723  void ProcessKMSCloseResponse(HTTPMessage header, Ptr<Socket> socket);
724 
731  void ReleaseAssociation (std::string ksid, std::string surplusKeyId, uint32_t syncIndex);
732 
740 
746  nlohmann::json CreateKeyContainer (std::vector<Ptr<QKDKey>> keys);
747 
753  std::string Base64Encode(std::string input);
754 
760  std::string Base64Decode(std::string input);
761 
767  std::vector<std::string> ProcessUriParams(std::string s);
768 
773 
774 private:
775 
779  struct QoS
780  {
781  uint32_t chunkSize; //Key_chunk_size
782  uint32_t maxRate; //Max_bps
783  uint32_t minRate; //Min_bps
784  uint32_t jitter; //Jitter
785  uint32_t priority; //Priority
786  uint32_t timeout; //Timeout
787  uint32_t TTL; //Time to Live
788  //metadata mimetype is left out
789  };
790 
794  struct ChunkKey
795  {
796  uint32_t index;
797  uint32_t chunkSize;
798  bool ready;
799  std::string key; //key of key_chunk_size
800  //std::vector<std::pair<std::string, std::pair<uint32_t, uint32_t> > > keyIds; //"QKDKey"s that form ChunkKey
801  //keyId start end
802  };
803 
807  struct HttpQuery
808  {
809  RequestType method_type; //For every query!
810 
811  //Specific to TRANSFORM
814  std::vector<std::string> transform_key_IDs;
815  std::vector<std::string> to_transform_key_IDs;
816  std::string surplus_key_ID;
817  UUID sae_id; //Needed to specify buffer to fetch the key from
818 
819  //Specific to ETSI 004 (NEW_APP)
822  std::string ksid;
823 
824  //Specific to ETSI 004 (KMS CLOSE)
825  uint32_t sync_index;
826 
827  };
828 
832  struct Association004 //Holds information of the association and dedicated key store
833  {
835  UUID srcSaeId; //Source application that requested the KSID
836  UUID dstSaeId; //Destination application
837  uint32_t associationDirection; //0-Outbound, 1-Inbound - Important while monitoring the associations!
838  QoS qos; //Quality of service
839  Ipv4Address dstKmsNode; //Address of the destination KMS. Important!
840  bool peerRegistered; //KMS must know the state of connection for association on peer KMS!
841  std::map<uint32_t, ChunkKey> buffer; //index & key ; index is KeyId for key of the association
842  uint32_t lastIndex;
843  std::vector<std::string> tempBuffer; //Buffer for keys in negotiation. It holds only KeyIds, while keys are in QKDBuffer!
844  };
845 
846  std::map<std::string, Association004> m_associations004;
851  uint32_t m_port;
852  uint32_t m_totalRx;
853  uint32_t m_totalRxKMSs;
855  uint32_t m_kms_id;
856  uint32_t m_kms_key_id;
859 
860  std::map<uint32_t, EventId > m_scheduledChecks;
861  std::map<Ipv4Address, uint32_t> m_flagedIPAdr;
863 
871 
874 
876 
879 
881  const std::string &,
882  const std::string &,
883  const uint32_t&,
884  const uint32_t&,
885  const uint32_t&,
886  const uint32_t&,
887  const uint32_t&
889 
891  uint32_t m_minKeySize;
892  uint32_t m_maxKeySize;
893  uint32_t m_defaultKeySize;
894 
895  std::unordered_map<uint64_t, Ptr<Packet>, AddressHash> m_buffer;
896  std::unordered_map<Address, Ptr<Packet>, AddressHash> m_bufferKMS;
897 
898  // In the case of TCP, each socket accept returns a new socket, so the
899  // listening socket is stored separately from the accepted sockets
900  std::map<Ptr<Socket>, Ptr<Socket> > m_socketPairs;
901 
902  std::map<Ipv4Address, std::pair<Ptr<Socket>, Ptr<Socket> > > m_socketPairsKMS;
903 
904  Ptr<Node> m_node; //<! The node on which the KMS is installed.
905  std::map<Ptr<Socket>, Ptr<Packet> > m_packetQueues;
906  std::map<Ptr<Socket>, Ptr<Packet> > m_packetQueuesToSDN;
907 
909 
910  std::map<std::string, uint32_t> m_sessionList;
912 
919  void CheckSessionList(std::string ksid);
920 
921 
924  uint32_t m_default_ttl;
925 
927 
932  void ConnectionSucceeded (Ptr<Socket> socket);
933 
938  void ConnectionFailed (Ptr<Socket> socket);
939 
945  void DataSend (Ptr<Socket>, uint32_t); // for socket's SetSendCallback
946 
951  void ConnectionSucceededKMSs (Ptr<Socket> socket);
952 
957  void ConnectionFailedKMSs (Ptr<Socket> socket);
958 
964  void DataSendKMSs (Ptr<Socket>, uint32_t); // for socket's SetSendCallback
965 
971 
976  void ConnectionToSDNFailed (Ptr<Socket> socket);
977 
983  void DataToSDNSend (Ptr<Socket>, uint32_t); // for socket's SetSendCallback
984 
990  bool CheckDoSAttack(HTTPMessage headerIn, Ptr<Socket> socket);
991 
992  std::map<Ipv4Address, std::vector<HttpQuery> > m_httpRequestsQueryKMS;
993  std::multimap<UUID, Ptr<Socket> > m_http004App;
994 
1000  void HttpKMSAddQuery(Ipv4Address dstKms, HttpQuery request);
1001 
1006  void HttpKMSCompleteQuery(Ipv4Address dstKms);
1007 
1014 
1020  void Http004AppQuery (UUID saeId, Ptr<Socket> socket);
1021 
1026  void Http004AppQueryComplete (UUID saeId);
1027 
1034 
1041 
1046  void CheckSocketsKMS (Ipv4Address dstSaeId);
1047 
1053  Ptr<Socket> GetSendSocketKMS (Ipv4Address kmsDstAddress);
1054 
1060  std::string PacketToString (Ptr<Packet> packet);
1061 
1067  void ReadJsonQos (
1069  nlohmann::json jOpenConnectRequest );
1070 
1085  std::string srcSaeId,
1086  std::string dstSaeId,
1088  Ipv4Address dstKms,
1089  std::string &ksid,
1090  std::string appConnectionId
1091  );
1092 
1102  bool ProcessQoSRequest(
1103  QKDApplicationEntry &appConnection,
1104  QKDKeyAssociationLinkEntry &keyAssociation,
1107  std::string ksid
1108  );
1109 
1114  void NewAppRequest (std::string ksid);
1115 
1120  std::string GenerateKsid ();
1121 
1126 
1131  void CheckAssociation (std::string ksid);
1132 
1140  uint32_t ScheduleCheckAssociation(Time t, std::string action, std::string ksid);
1141 
1148  void NegotiateKeysForAssociation (std::string ksid, uint32_t keyAmount = 1024, uint32_t priority = 0);
1149 
1155  void AddKeyToAssociationDedicatedStore (std::string ksid, Ptr<QKDKey> key);
1156 
1161  std::string GenerateKeyId();
1162 
1163 
1164 };
1165 
1166 } // namespace ns3
1167 
1168 #endif /* QKD_APPLICATION_H */
1169 
a polymophic address class
Definition: address.h:91
The base class for all ns3 applications.
Definition: application.h:61
Class for representing data rates.
Definition: data-rate.h:89
An identifier for simulation events.
Definition: event-id.h:54
The basic class to represent both HTTP requests and responses.
Definition: http.h:78
an Inet address class
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.
Definition: ipv4-address.h:41
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).
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.
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.
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.
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.
void ProcessCloseRequest(std::string ksid, HTTPMessage header, Ptr< Socket > socket)
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.
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.
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.
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.
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.
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.
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)
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.
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.
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.
std::string Base64Decode(std::string input)
Base64 decoder.
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.
Definition: nstime.h:103
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Universally unique identifier (UUID)
Definition: uuid.h:35
uint16_t port
Definition: dsdv-manet.cc:45
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:77
address
Definition: first.py:44
basic_json<> json
default JSON class
Definition: json.h:3000
Every class exported by the ns3 library is enclosed in the ns3 namespace.
list x
Random number samples.
The key within the key stream session buffer.