A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
qkd-key-manager-system-application.h
Go to the documentation of this file.
1/*
2 * Copyright(c) 2020 DOTFEESA www.tk.etf.unsa.ba
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 *
7 *
8 * Author: Emir Dervisevic <emir.dervisevic@etf.unsa.ba>
9 * Miralem Mehic <miralem.mehic@ieee.org>
10 */
11#ifndef QKD_KEY_MANAGER_SYSTEM_APPLICATION_H
12#define QKD_KEY_MANAGER_SYSTEM_APPLICATION_H
13
14#include "ns3/address.h"
15#include "ns3/application.h"
16#include "ns3/event-id.h"
17#include "ns3/ptr.h"
18#include "ns3/data-rate.h"
19#include "ns3/traced-callback.h"
20#include "ns3/random-variable-stream.h"
21#include "ns3/inet-socket-address.h"
22#include "ns3/qkd-graph.h"
23#include "ns3/q-buffer.h"
24#include "ns3/s-buffer.h"
25#include "ns3/qkd-control.h"
26#include "ns3/qkd-encryptor.h"
27//#include "ns3/qcen-control.h"
28#include "ns3/qkd-location-register.h"
29#include "ns3/qkd-location-register-entry.h"
30#include "ns3/qkd-graph-manager.h"
31#include "qkd-kms-queue-logic.h"
32#include "http.h"
33#include "json.h"
34#include <unordered_map>
35#include "ns3/uuid.h"
36
37#include <iostream>
38#include <sstream>
39#include <unistd.h>
40#include <sstream>
41#include <string>
42#include <regex>
43
44
45namespace ns3 {
46
47class Address;
48class Socket;
49class QKDLocationRegisterEntry;
50class QKDControl;
51class QCenController;
52
53/**
54 * @ingroup applications
55 * @defgroup qkd QKDKeyManagerSystemApplication
56 *
57 * QKDKeyManagerSystemApplication is a class used to
58 * serve requests for cryptographic keys from user's applications.
59 */
60
61/**
62 * @ingroup qkd
63 *
64 * @brief QKDNetSim implements Key Management System(KMS) as an
65 * application that listens on TCP port 80.
66 *
67 * The KMS can be installed
68 * on any node but the QKD post-processing application expects the
69 * existence of a local KMS application on the same nodes where the
70 * post-processing application is implemented. The local KMS is
71 * contacted to add the keys to the QKD buffer and is contacted
72 * during the operation of the QKD application to retrieve the keys
73 * from the QKD buffer as described in the following section.
74 * Communication between KMS systems installed on different nodes
75 * is under construction and will be based on the ETSI QKD 004 standard.
76 * The KMS application tracks REST-full design serving status and
77 * key retrieval requests from QKD applications.
78 * The KMS follows HTTP 1.1 specification including Request-URI
79 * for mapping of request-response values. More details available at
80 * https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
81 */
83{
84public:
85
86 /**
87 * @brief Request types
88 */
90 {
91 EMPTY = -1,
92 ETSI_QKD_014_GET_STATUS = 0, ///< Integer equivalent = 0.
93 ETSI_QKD_014_GET_KEY = 1, ///< Integer equivalent = 1.
94 ETSI_QKD_014_GET_KEY_WITH_KEY_IDS = 2, ///< Integer equivalent = 2.
100 FILL = 8,
101 STORE_KEY = 9, //Store postprocessing keys
102 TRANSFORM_KEYS = 10, //Transform(merge, split) QKD keys
104 RELAY_KEYS = 12
105 };
106
107 /**
108 * @brief Get the type ID
109 * @return the object TypeId
110 */
111 static TypeId GetTypeId();
112
113 /**
114 * @brief QKDKeyManagerSystemApplication constructor
115 */
117
118 /**
119 * @brief QKDKeyManagerSystemApplication destructor
120 */
122
123 /**
124 * @brief Get sink socket
125 * @return pointer to the sink socket
126 */
127 Ptr<Socket> GetSocket() const;
128
129 //void PrepareOutput(std::string key, uint32_t value); @toDo ? not used
130
131 /**
132 * @brief Set sink socket
133 * @param type socket type
134 * @param socket pointer to socket to be set
135 */
136 void SetSocket(std::string type, Ptr<Socket> socket);
137
138 /**
139 * @brief Get the total amount of bytes received
140 * @return the total bytes received in this sink app
141 */
142 uint32_t GetTotalRx() const;
143
144
145 /**
146 * @brief Get maximum number of keys per request(ETSI QKD 014)
147 * @return uint32_t maximum number of keys per request
148 */
150
151 /**
152 * @brief Set node
153 * @param n node to be set
154 */
156 m_node = n;
157 }
158
159 /**
160 * @brief Get node
161 * @return pointer to node
162 */
164 return m_node;
165 }
166
167 /**
168 * @brief Set key manager ID
169 * @param id UUID ID
170 */
171 void SetId(UUID id){
172 m_km_id = id.string();
173 }
174
175 /**
176 * @brief Set key manager ID
177 * @param id string ID
178 */
179 void SetId(std::string id){
180 m_km_id = id;
181 }
182
183 /**
184 * @brief Get key menager ID
185 * @return string key manager ID
186 */
187 std::string GetId(){
188 return m_km_id;
189 }
190
191 /**
192 * @brief Set local address
193 * @param Ipv4Address address
194 */
195 void SetAddress(Ipv4Address address) {
196 m_local = address;
197 }
198
199 /**
200 * @brief Get local address
201 * @return return local address
202 */
204 return m_local;
205 }
206
207 /**
208 * @brief Get address as string
209 * @param address address
210 * @return string address
211 */
212 std::string GetAddressString(Ipv4Address address);
213
214 /**
215 * @brief Set local port
216 * @param uint32_t port
217 */
219 m_port = port;
220 }
221
222 /**
223 * @brief Get local port
224 * @return return local port
225 */
227 {
228 return m_port;
229 }
230
231 /**
232 * @brief Assign QKDN controller
233 * @param controller pointer on QKDN controller
234 */
235 void SetController(Ptr<QKDControl> controller);
236
237 void SetCenController(Ptr<QCenController> controller);
238
239 /**
240 * @brief Get QKDN controller object
241 * @return QKDN controller
242 */
244
246
247 /**
248 * @brief Check the QKD link state to given destination.
249 * @param dstKmNodeId The destination KM node identifier.
250 *
251 * @note Is used for centralized routing, to enable re-routing.
252 */
254
255 /**
256 * @brief Create Q buffer shared with remote key manager node
257 * @param dstId remote key manager node ID
258 * @param bufferConf QKD buffer configuration
259 */
260 void CreateQBuffer(
263 );
264
265 /**
266 * @brief Set peer KM node address
267 * @param dstKmNodeId peer KM node ID
268 * @param dstKmAddress peer KM address
269 *
270 * It is called from qkd-control to register peer KM address.
271 */
273
274 /**
275 * @brief Get q-buffer established with remote key manager
276 * @param remoteKmNodeId remote key manager node ID
277 * @return Ptr on q-buffer
278 */
279 Ptr<QBuffer> GetQBuffer(uint32_t remoteKmNodeId, std::string type = "ns3::QBuffer");
280
281 /**
282 * @brief Registers a QKD module in key manager
283 * @param dstId remote key manager node ID
284 * @param moduleId local QKD module ID
285 */
286 void RegisterQKDModule(uint32_t dstId, std::string moduleId);
287
288 /**
289 * @brief Create sink socket to listen requests exchanged between KMSs
290 * @param remoteKmAddress Ipv4 address of remote key manager
291 */
293
294 /**
295 * @brief Get all QBuffers created on the KMS. Function used for plotting QKD Graphs
296 */
297 std::vector<Ptr<QBuffer> > GetQBuffersVector(){
298 return m_qbuffersVector;
299 }
300
301protected:
302
303 void DoDispose() override;
304
305private:
306
307 static uint32_t nKMS; //!< number of created KMSs - static value
308
309 /**
310 * @brief Get request type
311 * @param s string from HTTP URI
312 * @return request type
313 */
315
316 /**
317 * @brief Hashing for the Address class
318 */
320 {
321 /**
322 * @brief operator()
323 * @param x the address of which calculate the hash
324 * @return the hash of x
325 *
326 * Should this method go in address.h?
327 *
328 * It calculates the hash taking the uint32_t hash value of the ipv4 address.
329 * It works only for InetSocketAddresses(Ipv4 version)
330 */
331 size_t operator()(const Address &x) const
332 {
335 return std::hash<uint32_t>()(a.GetIpv4().Get());
336 }
337 };
338
339 // inherited from Application base class.
340 /**
341 * @brief Start KMS Application
342 */
343 void StartApplication() override; // Called at time specified by Start
344
345 /**
346 * @brief Stop KMS Application
347 */
348 void StopApplication() override; // Called at time specified by Stop
349
350 /**
351 * @brief Send packet to the pair socket
352 * @param socket receiving socket
353 * @param packet packet to send
354 */
355 void SendToSocketPair(Ptr<Socket> socket, Ptr<Packet> packet);
356
357 /**
358 * @brief Send packet to the pair socket
359 * @param socket receiving socket
360 * @param packet packet to send
361 */
362 void SendToSocketPairKMS(Ptr<Socket> socket, Ptr<Packet> packet);
363
364 /**
365 * @brief Handle a packet received by the KMS application
366 * @param socket the receiving socket
367 */
368 void HandleRead(Ptr<Socket> socket);
369
370 /**
371 * @brief Handle a packet received by the KMS from KMS
372 * @param socket the receiving socket
373 */
374 void HandleReadKMSs(Ptr<Socket> socket);
375
376 /**
377 * @brief Handle an incoming connection
378 * @param s the incoming connection socket
379 * @param from the address the connection is from
380 */
381 void HandleAccept(Ptr<Socket> s, const Address& from);
382
383 /**
384 * @brief Handle an connection close
385 * @param socket the connected socket
386 */
387 void HandlePeerClose(Ptr<Socket> socket);
388
389 /**
390 * @brief Handle an connection error
391 * @param socket the connected socket
392 */
393 void HandlePeerError(Ptr<Socket> socket);
394
395 /**
396 * @brief Handle an incoming connection
397 * @param s the incoming connection socket
398 * @param from the address the connection is from
399 */
400 void HandleAcceptKMSs(Ptr<Socket> s, const Address& from);
401
402 /**
403 * @brief Handle an connection close
404 * @param socket the connected socket
405 */
406 void HandlePeerCloseKMSs(Ptr<Socket> socket);
407
408 /**
409 * @brief Handle an connection error
410 * @param socket the connected socket
411 */
412 void HandlePeerErrorKMSs(Ptr<Socket> socket);
413 /**
414 * @brief Assemble byte stream to extract HTTPMessage
415 * @param p received packet
416 * @param from from address
417 *
418 * The method assembles a received byte stream and extracts HTTPMessage
419 * instances from the stream to export in a trace source.
420 */
421 void PacketReceived(const Ptr<Packet> &p, const Address &from, Ptr<Socket> socket);
422
423 /**
424 * @brief Assemble byte stream to extract HTTPMessage
425 * @param p received packet
426 * @param from from address
427 *
428 * The method assembles a received byte stream and extracts HTTPMessage
429 * instances from the stream to export in a trace source.
430 */
431 void PacketReceivedKMSs(const Ptr<Packet> &p, const Address &from, Ptr<Socket> socket);
432
433 /**
434 * @brief QKD key manager system application process the request
435 * from QKDApp, and complete certain actions
436 * to respond on received request.
437 * @param header received HTTP header
438 * @param packet received packet
439 * @param socket the receiving socket
440 *
441 * Data structure of key managment respond
442 * is described in ETSI014 document.
443 */
444 void ProcessRequest(HTTPMessage header, Ptr<Packet> packet, Ptr<Socket> socket);
445
446 /**
447 * @brief QKD key manager system application process the request
448 * peer KMS, and complete certain actions
449 * to respond on received request.
450 * @param header received HTTP header
451 * @param packet received packet
452 * @param socket the receiving socket
453 *
454 * Data structure of key managment respond
455 * is described in ETSI004 document.
456 */
457 void ProcessPacketKMSs(HTTPMessage header, Ptr<Packet> packet, Ptr<Socket> socket);
458
459 void ProcessRequestKMS(HTTPMessage header, Ptr<Socket> socket);
460
461 void ProcessResponseKMS(HTTPMessage header, Ptr<Packet> packet, Ptr<Socket> socket);
462
464
465 /**
466 * @brief Start key relay function
467 * @param dstKmNodeId destination KM node
468 * @param amount amount of key material
469 */
471
472 /**
473 * @brief Process key relay request
474 * @param header http request
475 * @param socket receiving socket
476 */
478
479 /**
480 * @brief Process key relay response
481 * @param headerIn http response
482 */
484
485 /*
486 * @brief Process OPEN_CONNECT request - ETSI QKD GS 004
487 * @param header received request
488 * @param socket receiving socket
489 */
491
492 /*
493 * @brief Process GET_KEY request - ETSI QKD GS 004
494 * @param ksid Unique identifier of the association
495 * @param header received request
496 * @param socket receiving socket
497 */
498 void ProcessGetKey004Request(std::string ksid, HTTPMessage header, Ptr<Socket> socket);
499
500 /*
501 * @brief Process CLOSE request - ETSI QKD GS 004
502 * @param ksid Unique identifier of the association
503 * @param header received request
504 * @param socket receiving socket
505 */
506 void ProcessCloseRequest(std::string ksid, HTTPMessage header, Ptr<Socket> socket);
507
508 /*
509 * @brief Process NEW_APP request
510 * @param header received request
511 * @param socket receiving socket
512 */
513 void ProcessNewAppRequest(HTTPMessage header, Ptr<Socket> socket);
514
515 void ProcessNewAppResponse(HTTPMessage header, Ptr<Socket> socket);
516
517 void RegisterRequest(std::string ksid);
518
519 void ProcessRegisterRequest(HTTPMessage header, std::string ksid, Ptr<Socket> socket);
520
522
523 void PrepareSinkSocket();
524
526
528
529 /**
530 * @brief process transform request
531 * @param header receiving http header
532 * @param socket receiving socket
533 */
535
536 /**
537 * @brief process transform response
538 * @param header receiving http header
539 * @param socket receiving socket
540 */
542
543 /**
544 * @brief process close request from peer KMS
545 * @param header receiving http header
546 * @param socket receiving socket
547 * @param ksid unique key stream identifier
548 *
549 * When QKDApp initiate etsi004 close request, its local KMS should release quantum keys
550 * currently assign to the key stream association. To do so, KMS should sync with peer KMS.
551 * This function perform necessery processing on the peer KMS to do sync.
552 */
553 void ProcessKMSCloseRequest(HTTPMessage header, Ptr<Socket> socket, std::string ksid);
554
555 /**
556 * @brief process close response from peer KMS
557 * @param header receiving http header
558 * @param socket receiving socket
559 */
561
562 /**
563 * @brief release key stream association
564 * @param ksid unique key stream identifier
565 * @param surplusKeyId unique key identifier for surplus key material in dedicated association buffer
566 * @param syncIndex unique key index in dedicated association buffer for synchronisation
567 */
568 void ReleaseAssociation(std::string ksid, std::string surplusKeyId, uint32_t syncIndex);
569
570 /**
571 * @brief Validate request and probe ability to fullfil valid request
572 * @param number number of requested keys
573 * @param size requested keys size
574 * @param buffer associated buffer
575 * @return json error structure
576 *
577 * Funtion returns an empty json if the request is valid and can be fullfiled.
578 */
579 nlohmann::json Check014GetKeyRequest(uint32_t number, uint32_t size, Ptr<SBuffer> buffer);
580
581 /**
582 * @brief Create key container data structure described in ETSI014 document.
583 * @param keys vector of pointers on the QKD key
584 * @return json data structure for key container
585 */
586 nlohmann::json CreateKeyContainer(std::vector<Ptr<QKDKey>> keys);
587
588private:
589
590 struct QoS
591 {
592 uint32_t chunkSize; //Key_chunk_size
593 uint32_t maxRate; //Max_bps
594 uint32_t minRate; //Min_bps
595 uint32_t jitter; //Jitter
596 uint32_t priority; //Priority
597 uint32_t timeout; //Timeout
598 uint32_t TTL; //Time to Live
599 //metadata mimetype is left out
600 };
601
602 struct ChunkKey
603 {
606 bool ready;
607 std::string key; //key of key_chunk_size
608 //std::vector<std::pair<std::string, std::pair<uint32_t, uint32_t> > > keyIds; //"QKDKey"s that form ChunkKey
609 //keyId start end
610 };
611
613 {
614 RequestType method_type; //For every query!
615
616 //RELAY_KEYS
617 std::string req_id;
620 std::string request_uri;
622
623 //Specific to new FILL method
625 std::vector<std::string> keyIds;
626 std::string sBuffer;
627
628 //Specific to TRANSFORM / SKEY_CREATE(new)
629 //uint32_t transform_key_size;
630 //uint32_t transform_key_number;
631 //std::vector<std::string> transform_key_IDs;
632 //std::vector<std::string> to_transform_key_IDs;
633 std::string surplus_key_ID;
634 std::string sae_id; //Needed to specify buffer to fetch the key from
635
636 //Specific to ETSI 004(NEW_APP)
637 std::string source_sae;
638 std::string destination_sae;
639 std::string ksid;
640
641 //Specific to ETSI 004(KMS CLOSE)
643
644 };
645
646 struct Association004 //Holds information of the association and dedicated key store
647 {
648 std::string srcSaeId; //Source application that requested the KSID
649 std::string dstSaeId; //Destination application
650 uint32_t srcNodeId; //Source KM node ID
651 uint32_t dstNodeId; //Destination KM node ID
652 Ipv4Address dstKmsAddr; //Address of the destination KMS. Important!
653 QoS qos; //Quality of service
654 bool peerRegistered; //KMS must know the state of connection for association on peer KMS!
655 Ptr<SBuffer> stre_buffer; //A pointer on a SBUFFER
656 };
657
658 /**
659 * @brief Help function to create relay SBuffers
660 * @param srcNodeId source KM node ID
661 * @param dstNodeId peer KM node ID
662 * @param descrition buffer description used for QKDGraph
663 *
664 * It is called to create new SBuffers for relay on demand.
665 */
666 Ptr<SBuffer> CreateRelaySBuffer(uint32_t srcNodeId, uint32_t dstNodeId, std::string description);
667
668 std::map<std::string, Association004> m_associations004; //Associations map
669
670 Ptr<Socket> m_sinkSocket; // Associated socket
671
672 Ipv4Address m_local; //!< Local address to bind to
673
674 uint32_t m_port; //!< Local port to bind to
675
676 uint32_t m_totalRx; //!< Total bytes received
677
678 uint32_t m_totalRxKMSs; //!< Total bytes received between KMSs
679
681
682 std::string m_km_id; //Unique identifier assigned to Key Manager
683
684 Ptr<QCenController> m_cen_controller; //!< Asigned Q centralized controler for routing!
685
686 Ptr<QKDControl> m_controller; //!< Asigned QKDN controller
687
688 std::map<uint32_t, uint32_t> m_link_states; //!<Notified link states!
689
690 std::map<uint32_t, Ptr<QBuffer> > m_qbuffers; //!< Q-buffers for every QKD connection
691
692 std::map<uint32_t, Ptr<SBuffer> > m_keys_enc; //!< LOCAL S-buffers for the outbound point-to-point usage
693
694 std::map<uint32_t, Ptr<SBuffer> > m_keys_dec; //!< LOCAL S-buffers for the inbound point-to-poit usage
695
696 std::map<std::string, uint32_t> m_qkdmodules; //!< QKD modules and KM node ID they connect to
697
699
700 uint32_t m_kms_key_id; //key counter to generate unique keyIDs on KMS
701
703
704 std::map<std::string, EventId > m_scheduledChecks;
705
706 /// Traced Callback: received packets, source address.
711
714 TracedCallback<const uint32_t&, const uint32_t&, const uint32_t&> m_keyConsumedLink; //Total amount of key material consumed for direct p2p usage!
716 TracedCallback<const uint32_t&, const uint32_t&, const uint32_t&> m_keyWasteRelay; //Amount of wasted key material(traced on source node, and failed relay node only)
717
718 uint32_t m_maxKeyPerRequest; //Maximal number of keys per request QKDApp can ask for
719 uint32_t m_minKeySize; //Minimal size of key QKDApp can request from KMS
720 uint32_t m_maxKeySize; //Maximal size of key QKDApp can request from KMS
721
722
723 uint32_t m_maxSBufferSizeInBits; //Maximal size of LOCAL SBuffer in bits
724 uint32_t m_minSBufferSizeInBits; //Minimal size of LOCAL SBuffer in bits
725 uint32_t m_thrSBufferSizeInBits; //Threshold value of LOCAL SBuffer in bits
726
727 std::unordered_map<Address, Ptr<Packet>, AddressHash> m_buffer; //!< Buffer for received packets(TCP segmentation)
728 std::unordered_map<Address, Ptr<Packet>, AddressHash> m_bufferKMS; //!< Buffer for received packets(TCP segmentation)
729
730 std::map<Ipv4Address, std::pair<Ptr<Socket>, Ptr<Socket> > > m_socketPairsKMS; //!< we do not know which KMS is going to initialize new TCP connection to peer KMS. Therefore, we have two sockets(sink and send) per node.
731
732 Ptr<Node> m_node; //<! node on which KMS is installed
733 std::map<Ptr<Socket>, Ptr<Packet> > m_packetQueues; //!< Buffering unsend messages due to connection problems
734
735 Ptr<QKDKMSQueueLogic> m_queueLogic; //!< KMS Queue Logic for ETSI 004 QoS handling
736
737 std::vector<Ptr<QBuffer> > m_qbuffersVector; //!< The list of QBuffers is necessary for plotting
738
739 /**
740 @toDo:following functions
741 */
742 void ConnectionSucceeded(Ptr<Socket> socket);
743 void ConnectionFailed(Ptr<Socket> socket);
744 void DataSend(Ptr<Socket>, uint32_t); // for socket's SetSendCallback
745
748 void DataSendKMSs(Ptr<Socket>, uint32_t); // for socket's SetSendCallback
749
750
751 /**
752 * HTTP handling
753 *
754 * Each application can open only one connection with its local KMS(current socket).
755 * Each KMS can have only one connection with arbitrary KMS(current socket).
756 */
757
758 std::map<Ipv4Address, std::vector<HttpQuery> > m_httpRequestsQueryKMS;
759 //std::map<Ipv4Address, std::unordered_map<std::string, HttpQuery> > m_httpProxyRequests;
760 std::unordered_map<std::string, HttpQuery> m_httpProxyRequests;
761 std::multimap<std::string, Ptr<Socket> > m_http004App; //SAE_ID, receiving socket
762
763 /**
764 * @brief remember HTTP request made to peer KMS
765 * @param dstKms destination kms IP address
766 * @param request request parameters
767 */
769
770 /**
771 * @brief remove mapped HTTP response from query
772 * @param dstKms destination kms IP address
773 */
775
776 /**
777 * @brief obtain method_type to map the HTTP response
778 * @param dstKms destination KMS IP address
779 * @return RequestType method function
780 */
782
783 void Http004AppQuery(std::string saeId, Ptr<Socket> socket);
784
785 void Http004AppQueryComplete(std::string saeId);
786
788
789
790 /**
791 * @brief Save query
792 * @param query http query
793 */
795
796 /**
797 * @brief Get saved query
798 * @param reqId request identifier
799 * @return HttpQuery query
800 */
801 HttpQuery GetProxyQuery(std::string reqId);
802
803 /**
804 * @brief Remove proxy query when processed
805 * @param reqId request identifier
806 */
807 void RemoveProxyQuery(std::string reqId);
808
809
811
812 /**
813 * @brief Prepare send socket to communicate with peer KMS Application
814 * @param uint32_t destination SAE ID
815 */
816 void CheckSocketsKMS(Ipv4Address dstSaeId);
817
818 /**
819 * @brief Obtain send socket
820 * @param kmsDstAddress Address of the destination KMS
821 * @return Socket send socket
822 */
824
825 /**
826 * @brief Convert packet to string
827 * @param packet the packet
828 * @return string packet
829 */
830 std::string PacketToString(Ptr<Packet> packet);
831
832 /**
833 * @brief Read the parameters from the JSON OPEN_CONNECT structure!
834 * @param &dstSaeId destination secure application entity
835 * @param &srcSaeId source secure application entity
836 * @param &inQos requested QoS
837 * @param &ksid Unique identifier of the association
838 * @param jOpenConncetRequest JSON structure of the OPEN_CONNECT call
839 */
840 void ReadJsonQos(
842 nlohmann::json jOpenConnectRequest );
843
844 /**
845 * @brief Read parameters from URI
846 * @param s string URI
847 * @return vector of uri parameters
848 */
849 std::vector<std::string> ReadUri(std::string s);
850
851 /**
852 * @brief Create a new assocation
853 * @param srcSaeId source secure application entity
854 * @param dstSaeId destination secure application entity
855 * @param inQos Quality of Service
856 * @param ksid Unique identifier of the association
857 * @return string Unique identifier of the association
858 *
859 * Input ksid can be empty if it is not predefined. In that case
860 * new ksid is generated for this new association and return from
861 * the function.
862 */
863 std::string CreateKeyStreamSession(
864 std::string srcSaeId, std::string dstSaeId,
866 std::string ksid );
867
868 /**
869 * @brief Make NEW_APP request to peer KMS
870 * @param ksid Unique identifier of the association
871 */
872 void NewAppRequest(std::string ksid);
873
874 /**
875 * @brief Check the state of a single assocation
876 * @param ksid Unique identifier of the association
877 */
878 void CheckEtsi004Association(std::string ksid);
879
880 /**
881 * @brief schedule next event in an attempt to fill association buffer
882 * @param t time shift
883 * @param action name of the action
884 * @param ksid unique identifier of the association
885 * @return uint32_t schedule event ID
886 */
887 void ScheduleCheckEtsi004Association(Time t, std::string action, std::string ksid);
888
889 void ScheduleReleaseAssociation(Time t, std::string action, std::string ksid, std::string surplusKeyId, uint32_t syncIndex);
890
891 /**
892 * @brief Add key to dedicated key store corresponding to association identified with KSID
893 * @param ksid Unique identifier of the association
894 * @param key The QKD key being added to the store
895 */
897
898 /**
899 * @brief Generate UUID
900 * @return string UUID
901 */
902 std::string GenerateUUID();
903
904 /**
905 * @brief Generate random string with given length
906 * @param len string length
907 * @return string random string
908 */
909 std::string GenerateRandomString(const int len, const uint32_t seed = 0);
910
911 /**
912 * @brief Start s-buffers control -- monitoring
913 * @param dstKmNodeId remote KM node ID
914 */
916
917 /**
918 * @brief Fill s-buffer
919 * @param dstKmNodeId remote KM node ID
920 * @param direction s-buffer type
921 * @param amount key amount
922 */
923 void Fill(uint32_t dstKmNodeId, std::string direction, uint32_t amount);
924
925 /**
926 * @brief check s-buffer levels
927 * @param dstKmNodeId remote KM node ID
928 */
930
931 Ptr<SBuffer> GetSBuffer(uint32_t dstKmNodeId, std::string type);
932
934
935 std::map<uint32_t, Ipv4Address> m_peerAddressTable; //!<IP address of peer KM nodes
936
938
939};
940
941} // namespace ns3
942
943#endif /* QKD_APPLICATION_H */
944
a polymophic address class
Definition address.h:90
The base class for all ns3 applications.
Definition application.h:51
An identifier for simulation events.
Definition event-id.h:45
The basic class to represent both HTTP requests and responses.
Definition http.h:77
an Inet address class
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.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
QKDNetSim implements Key Management System(KMS) as an application that listens on TCP port 80.
void ProcessRegisterResponse(HTTPMessage header, Ptr< Socket > socket)
uint32_t GetMaxKeyPerRequest()
Get maximum number of keys per request(ETSI QKD 014)
void HandlePeerCloseKMSs(Ptr< Socket > socket)
Handle an connection close.
void ProcessFillRequest(HTTPMessage headerIn, std::string resource, Ptr< Socket > socket)
void ProcessFillResponse(HTTPMessage headerIn, Ipv4Address from)
Ptr< QKDKMSQueueLogic > m_queueLogic
KMS Queue Logic for ETSI 004 QoS handling.
void SendToSocketPairKMS(Ptr< Socket > socket, Ptr< Packet > packet)
Send packet to the pair socket.
void HandleAccept(Ptr< Socket > s, const Address &from)
Handle an incoming connection.
void StopApplication() override
Stop KMS Application.
nlohmann::json Check014GetKeyRequest(uint32_t number, uint32_t size, Ptr< SBuffer > buffer)
Validate request and probe ability to fullfil valid request.
std::map< std::string, Association004 > m_associations004
Ptr< Socket > GetSendSocketKMS(Ipv4Address kmsDstAddress)
Obtain send socket.
Ptr< QCenController > m_cen_controller
Asigned Q centralized controler for routing!
std::map< uint32_t, Ipv4Address > m_peerAddressTable
IP address of peer KM nodes.
uint32_t GetTotalRx() const
Get the total amount of bytes received.
void ScheduleReleaseAssociation(Time t, std::string action, std::string ksid, std::string surplusKeyId, uint32_t syncIndex)
void HttpKMSAddQuery(Ipv4Address dstKms, HttpQuery request)
remember HTTP request made to peer KMS
void ProcessRegisterRequest(HTTPMessage header, std::string ksid, Ptr< Socket > socket)
Ipv4Address GetDestinationKmsAddress(Ptr< Socket > socket)
std::string PacketToString(Ptr< Packet > packet)
Convert packet to string.
void HandleAcceptKMSs(Ptr< Socket > s, const Address &from)
Handle an incoming connection.
std::vector< Ptr< QBuffer > > m_qbuffersVector
The list of QBuffers is necessary for plotting.
std::map< Ipv4Address, std::pair< Ptr< Socket >, Ptr< Socket > > > m_socketPairsKMS
we do not know which KMS is going to initialize new TCP connection to peer KMS.
void ProcessPacketKMSs(HTTPMessage header, Ptr< Packet > packet, Ptr< Socket > socket)
QKD key manager system application process the request peer KMS, and complete certain actions to resp...
void ConnectionSucceeded(Ptr< Socket > socket)
@toDo:following functions
void ProcessRequestKMS(HTTPMessage header, Ptr< Socket > socket)
std::map< Ptr< Socket >, Ptr< Packet > > m_packetQueues
Buffering unsend messages due to connection problems.
nlohmann::json CreateKeyContainer(std::vector< Ptr< QKDKey > > keys)
Create key container data structure described in ETSI014 document.
void StartSBufferClients(uint32_t dstKmNodeId)
Start s-buffers control – monitoring.
std::map< uint32_t, uint32_t > m_link_states
Notified link states!
void SetId(std::string id)
Set key manager ID.
std::string GetAddressString(Ipv4Address address)
Get address as string.
void NewAppRequest(std::string ksid)
Make NEW_APP request to peer KMS.
void HttpKMSCompleteQuery(Ipv4Address dstKms)
remove mapped HTTP response from query
void ProcessPPRequest(HTTPMessage header, Ptr< Packet > packet, Ptr< Socket > socket)
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced Callback: received packets, source address.
void ProcessResponseKMS(HTTPMessage header, Ptr< Packet > packet, Ptr< Socket > socket)
void Fill(uint32_t dstKmNodeId, std::string direction, uint32_t amount)
Fill s-buffer.
void SetSocket(std::string type, Ptr< Socket > socket)
Set sink socket.
Ptr< Socket > GetSocket() const
Get sink socket.
static uint32_t nKMS
number of created KMSs - static value
void SetPeerKmAddress(uint32_t dstKmNodeId, Ipv4Address dstKmAddress)
Set peer KM node address.
Ptr< QBuffer > GetQBuffer(uint32_t remoteKmNodeId, std::string type="ns3::QBuffer")
Get q-buffer established with remote key manager.
QKDKeyManagerSystemApplication::RequestType FetchRequestType(std::string s)
Get request type.
HttpQuery GetProxyQuery(std::string reqId)
Get saved query.
std::multimap< std::string, Ptr< Socket > > m_http004App
void SBufferClientCheck(uint32_t dstKmNodeId)
check s-buffer levels
void ProcessCloseRequest(std::string ksid, HTTPMessage header, Ptr< Socket > socket)
void SetCenController(Ptr< QCenController > controller)
void HandleReadKMSs(Ptr< Socket > socket)
Handle a packet received by the KMS from KMS.
void HandlePeerError(Ptr< Socket > socket)
Handle an connection error.
void ProcessRelayResponse(HTTPMessage headerIn)
Process key relay response.
void HandlePeerClose(Ptr< Socket > socket)
Handle an connection close.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTraceKMSs
void RemoveProxyQuery(std::string reqId)
Remove proxy query when processed.
std::map< std::string, uint32_t > m_qkdmodules
QKD modules and KM node ID they connect to.
Ptr< QKDControl > GetController()
Get QKDN controller object.
void PacketReceivedKMSs(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Assemble byte stream to extract HTTPMessage.
std::map< uint32_t, Ptr< QBuffer > > m_qbuffers
Q-buffers for every QKD connection.
Ptr< SBuffer > GetSBuffer(uint32_t dstKmNodeId, std::string type)
void ProcessSKeyCreateResponse(HTTPMessage header, Ptr< Socket > socket)
process transform response
void ProcessGetKey004Request(std::string ksid, HTTPMessage header, Ptr< Socket > socket)
std::unordered_map< std::string, HttpQuery > m_httpProxyRequests
TracedCallback< const uint32_t &, const uint32_t &, const uint32_t &, const uint32_t & > m_keyConsumedRelay
void ProcessOpenConnectRequest(HTTPMessage header, Ptr< Socket > socket)
void ProcessNewAppResponse(HTTPMessage header, Ptr< Socket > socket)
Ptr< Socket > GetSocketFromHttp004AppQuery(std::string saeId)
void CreateQBuffer(uint32_t dstId, Ptr< QBuffer > bufferConf)
Create Q buffer shared with remote key manager node.
void SetAddress(Ipv4Address address)
Set local address.
void Relay(uint32_t dstKmNodeId, uint32_t amount)
Start key relay function.
void ProcessKMSCloseRequest(HTTPMessage header, Ptr< Socket > socket, std::string ksid)
process close request from peer KMS
RequestType HttpQueryMethod(Ipv4Address dstKms)
obtain method_type to map the HTTP response
void ProcessRelayRequest(HTTPMessage headerIn, Ptr< Socket > socket)
Process key relay request.
void ProcessKMSCloseResponse(HTTPMessage header, Ptr< Socket > socket)
process close response from peer KMS
TracedCallback< const std::string &, const std::string &, const uint32_t & > m_keyServedTrace
void DoDispose() override
Destructor implementation.
void AddKeyToAssociationDedicatedStore(std::string ksid, Ptr< QKDKey > key)
Add key to dedicated key store corresponding to association identified with KSID.
void HandlePeerErrorKMSs(Ptr< Socket > socket)
Handle an connection error.
std::string CreateKeyStreamSession(std::string srcSaeId, std::string dstSaeId, QKDKeyManagerSystemApplication::QoS inQos, std::string ksid)
Create a new assocation.
void UpdateLinkState(uint32_t dstKmNodeId)
Check the QKD link state to given destination.
std::map< uint32_t, Ptr< SBuffer > > m_keys_dec
LOCAL S-buffers for the inbound point-to-poit usage.
void SetController(Ptr< QKDControl > controller)
Assign QKDN controller.
~QKDKeyManagerSystemApplication() override
QKDKeyManagerSystemApplication destructor.
void SendToSocketPair(Ptr< Socket > socket, Ptr< Packet > packet)
Send packet to the pair socket.
void Http004AppQuery(std::string saeId, Ptr< Socket > socket)
std::vector< std::string > ReadUri(std::string s)
Read parameters from URI.
Ptr< SBuffer > CreateRelaySBuffer(uint32_t srcNodeId, uint32_t dstNodeId, std::string description)
Help function to create relay SBuffers.
uint32_t m_totalRxKMSs
Total bytes received between KMSs.
void StartApplication() override
Start KMS Application.
void HandleRead(Ptr< Socket > socket)
Handle a packet received by the KMS application.
TracedCallback< const uint32_t &, const uint32_t &, const uint32_t & > m_keyWasteRelay
void ProcessSKeyCreateRequest(HTTPMessage header, Ptr< Socket > socket)
process transform request
void ReadJsonQos(QKDKeyManagerSystemApplication::QoS &inQos, nlohmann::json jOpenConnectRequest)
Read the parameters from the JSON OPEN_CONNECT structure!
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_bufferKMS
Buffer for received packets(TCP segmentation)
Ptr< QKDControl > m_controller
Asigned QKDN controller.
std::map< uint32_t, Ptr< SBuffer > > m_keys_enc
LOCAL S-buffers for the outbound point-to-point usage.
TracedCallback< const std::string &, const std::string &, const uint32_t & > m_qkdKeyGeneratedTrace
TracedCallback< const uint32_t &, const uint32_t &, const uint32_t & > m_keyConsumedLink
void ProcessNewAppRequest(HTTPMessage header, Ptr< Socket > socket)
void EstablishKMLinkSockets(Ipv4Address remoteKmAddress)
Create sink socket to listen requests exchanged between KMSs.
void RegisterQKDModule(uint32_t dstId, std::string moduleId)
Registers a QKD module in key manager.
std::map< Ipv4Address, std::vector< HttpQuery > > m_httpRequestsQueryKMS
void PacketReceived(const Ptr< Packet > &p, const Address &from, Ptr< Socket > socket)
Assemble byte stream to extract HTTPMessage.
TracedCallback< Ptr< const Packet > > m_txTraceKMSs
void ReleaseAssociation(std::string ksid, std::string surplusKeyId, uint32_t syncIndex)
release key stream association
std::vector< Ptr< QBuffer > > GetQBuffersVector()
Get all QBuffers created on the KMS.
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...
void ScheduleCheckEtsi004Association(Time t, std::string action, std::string ksid)
schedule next event in an attempt to fill association buffer
TracedCallback< Ptr< const Packet > > m_txTrace
std::string GenerateRandomString(const int len, const uint32_t seed=0)
Generate random string with given length.
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_buffer
Buffer for received packets(TCP segmentation)
void CheckEtsi004Association(std::string ksid)
Check the state of a single assocation.
void CheckSocketsKMS(Ipv4Address dstSaeId)
Prepare send socket to communicate with peer KMS Application.
QKDKeyManagerSystemApplication()
QKDKeyManagerSystemApplication constructor.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:49
Universally unique identifier(UUID)
Definition uuid.h:35
uint16_t port
Definition dsdv-manet.cc:33
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition abort.h:65
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.