A Discrete-Event Network Simulator
API
qkd-buffer.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: Miralem Mehic <miralem.mehic@ieee.org>
19  */
20 
21 #ifndef QKDBUFFER_H
22 #define QKDBUFFER_H
23 
24 #include <queue>
25 #include "ns3/packet.h"
26 #include "ns3/object.h"
27 #include "ns3/ipv4-header.h"
28 #include "ns3/traced-value.h"
29 #include "ns3/trace-source-accessor.h"
30 #include "ns3/event-id.h"
31 #include "ns3/qkd-key.h"
32 #include "ns3/node.h"
33 #include <vector>
34 #include <map>
35 
36 namespace ns3 {
37 
79  class QKDBuffer: public Object {
80  public:
81 
82  static
83  const uint32_t QKDSTATUS_READY = 0;
84  static
85  const uint32_t QKDSTATUS_WARNING = 1;
86  static
87  const uint32_t QKDSTATUS_CHARGING = 2;
88  static
89  const uint32_t QKDSTATUS_EMPTY = 3;
90 
94  struct data {
95  uint32_t value;
96  uint32_t position;
97  };
98 
102  struct KeyStorage {
105  std::map < uint32_t, QKDKey > keys;
108  };
109 
115  static TypeId GetTypeId(void);
116 
120  QKDBuffer();
121 
125  virtual~QKDBuffer();
126 
138  void Init(
139  Ptr <Node> srcNode,
140  Ptr <Node> dstNode,
141  uint32_t Mmin,
142  uint32_t Mthr,
143  uint32_t Mmax,
144  uint32_t Mcurrent,
145  bool useRealStorages
146  );
147 
153  void Dispose(void);
154 
162  bool AddNewKey(Ptr <QKDKey> key, uint32_t keyTransformed);
163 
175  uint32_t FetchState(void);
176 
182  uint32_t FetchPreviousState(void);
183 
187  void CheckState(void);
188 
192  void KeyCalculation();
193 
194  /*
195  * \brief Get the time difference between the current time and time at which
196  * last key charging process finished.
197  *
198  * \return The time difference.
199  */
200  int64_t FetchDeltaTime();
201 
208 
215 
223 
228  uint32_t GetMCurrentPrevious(void) const;
229 
238  uint32_t GetMthr(void) const;
239 
244  void SetMthr(uint32_t thr);
245 
249  void InitTotalGraph() const;
250 
255  uint32_t GetId(void) const;
256 
261  void SetSrcNode(Ptr <Node> );
262 
268 
273  void SetDstNode(Ptr <Node> );
274 
280 
285  void SetIndex(uint32_t);
290  uint32_t GetIndex();
291 
298  const & o) const;
299 
302  uint32_t m_bufferID;
303  static uint32_t nBuffers;
304 
309  uint32_t GetKeySize();
310 
315  uint64_t GetKeyCountBit();
316 
324  uint64_t GetReadyKeyCountBit();
325 
330  uint64_t GetTargetKeyCountBit();
331 
336  uint32_t GetKeyCount();
337 
342  uint32_t GetMinKeyCount();
343 
348  uint32_t GetMaxKeyCount();
349 
354  uint64_t GetMaxKeyCountBit();
355 
360  uint32_t GetMinKeySize();
361 
366  uint64_t GetMinKeySizeBit();
367 
372  uint64_t GetMaxKeySizeBit();
373 
379  uint32_t GetKeyCount (uint32_t keySize);
380 
387  bool ProbeKeyStatus (std::string keyId, QKDKey::QKDKeyState_e keyState);
388 
394  Ptr<QKDKey> FetchKeyBySize( const uint32_t& keySize);
395 
401  Ptr <QKDKey> FetchKeyByID(std::string keyID);
402 
409  Ptr <QKDKey> FetchKeyByID(std::string keyID, uint32_t fillProcessActive);
410 
415  void ReserveKey (std::string keyId);
416 
421  void ReleaseReservation (std::string keyId);
422 
430  void RecordTargetSize (uint32_t size);
431 
440  Ptr<QKDKey> SearchOptimalKeyToTransform (uint32_t targetSize);
441 
447 
453 
459 
465 
466  private:
467 
468  std::vector<uint32_t> m_targetSizeSet;
469  uint32_t m_defaultKeySize;
470  bool m_useRealStorages; //<! Whether to use real storages or virtual buffers (still in development).
471  uint32_t m_nextKeyID;
472  std::map < std::string, Ptr <QKDKey> > m_keys;
473 
474  uint32_t m_noEntry;
475  uint32_t m_period;
476  uint32_t m_noAddNewValue;
478 
480  std::vector < struct QKDBuffer::data > m_previousValues;
481 
482  double m_c;
484  uint32_t m_previousStatus;
485  uint32_t m_minKeyBit;
486  uint32_t m_maxKeyBit;
487  uint32_t m_thresholdKeyBit;
488  uint32_t m_minimalKeyCount;
489  uint32_t m_maximalKeyCount;
490 
494 
495  uint32_t m_currentKeyBit;
506  std::vector < int64_t > m_lastChargedKeySizes;
507  std::vector < int64_t > m_lastConsumedKeySizes;
508  std::vector < int64_t > m_chargingTimePeriods;
509  std::vector < int64_t > m_consumptionTimePeriods;
510  uint32_t m_status;
527 
530 
532 
533  std::map < uint32_t, QKDBuffer::KeyStorage > m_destinations; //<! A map of QKD destinations and respective QKD buffers.
534 
535  };
536 }
537 
538 #endif /* QKDBUFFER_H */
An identifier for simulation events.
Definition: event-id.h:54
A base class which provides memory management and object aggregation.
Definition: object.h:88
QKD buffer is a secure storage for QKD keys.
Definition: qkd-buffer.h:79
uint32_t m_srcNodeBufferListIndex
The index in the source node buffer list.
Definition: qkd-buffer.h:531
double m_averageKeyChargingTimePeriod
The average duration of the key charging time period.
Definition: qkd-buffer.h:511
double m_averageKeyConsumptionSize
The average key consumption size.
Definition: qkd-buffer.h:514
int64_t m_lastKeyChargingTimeStamp
The timestamp of a last key charging (when the new key material was added).
Definition: qkd-buffer.h:500
uint32_t m_noEntry
Help value used for graph ploting.
Definition: qkd-buffer.h:474
double m_averageKeyConsumptionRate
The average key consumption rate.
Definition: qkd-buffer.h:516
double m_averageKeyGenerationRate
The average key generation rate.
Definition: qkd-buffer.h:515
TracedCallback< Ptr< QKDKey > > m_keyReservedTrace
A trace for reserved keys.
Definition: qkd-buffer.h:521
static const uint32_t QKDSTATUS_WARNING
QKDStatus WARNING.
Definition: qkd-buffer.h:85
std::vector< int64_t > m_lastChargedKeySizes
The size of the several last generated keys.
Definition: qkd-buffer.h:506
bool m_useRealStorages
Definition: qkd-buffer.h:470
void UpdateKeyConsumptionStatistics(Ptr< QKDKey > key)
Update key consumption statistics.
Definition: qkd-buffer.cc:532
uint32_t m_bufferID
The unique buffer identifier.
Definition: qkd-buffer.h:302
bool operator==(QKDBuffer const &o) const
Define equal operator on the QKD buffer object.
Definition: qkd-buffer.cc:816
void UpdateKeyGenerationStatistics(Ptr< QKDKey > key)
Update key generation statistics.
Definition: qkd-buffer.cc:604
uint64_t GetMinKeySizeBit()
Get the minimum key size that can be served in bits.
Definition: qkd-buffer.cc:303
TracedCallback< double > m_CMetricChangeTrace
A trace of c metric changes.
Definition: qkd-buffer.h:526
TracedCallback< uint32_t > m_currentKeyBitDecreaseTrace
A trace of decrease in amount of key bits.
Definition: qkd-buffer.h:524
uint32_t GetMinKeySize()
Get the minimum key size that can be served.
std::map< std::string, Ptr< QKDKey > > m_keys
The list of available keys with their identifiers.
Definition: qkd-buffer.h:472
uint32_t GetMaxKeyCount()
Get the maximum number of stored keys.
Definition: qkd-buffer.cc:283
uint32_t GetKeyCount()
Get the number of stored keys.
Definition: qkd-buffer.cc:275
uint32_t m_thresholdKeyBit
The threshold amount of key material in the QKD key storage.
Definition: qkd-buffer.h:487
int64_t FetchDeltaTime()
Definition: qkd-buffer.cc:853
Ptr< QKDKey > SearchOptimalKeyToTransform(uint32_t targetSize)
Serach for the optimal key to transform.
Definition: qkd-buffer.cc:716
uint32_t m_maxKeyBit
The maximal amount of key material in the QKD key storage.
Definition: qkd-buffer.h:486
double FetchAverageKeyChargingTimePeriod()
Get the average duration of key charging process in the long run.
Definition: qkd-buffer.cc:861
uint32_t m_maxNumberOfRecordedKeyChargingTimePeriods
The maximal number of values which are used for calculation of the average key charging time period.
Definition: qkd-buffer.h:504
uint32_t m_period
Help value used for graph ploting.
Definition: qkd-buffer.h:475
uint32_t m_minimalKeyCount
The minimal number of stored keys.
Definition: qkd-buffer.h:488
uint32_t m_status
The state of the Net Device transmit state machine.
Definition: qkd-buffer.h:510
Ptr< QKDKey > FetchKeyBySize(const uint32_t &keySize)
Get the key of a given size.
Definition: qkd-buffer.cc:475
uint32_t m_currentKeyBitReally
The current amount of key material used for real tracking of storage (transform!).
Definition: qkd-buffer.h:496
int64_t m_lastKeyChargingTimeDuration
The timestamp of a last key usage.
Definition: qkd-buffer.h:502
TracedCallback< uint32_t > m_thresholdKeyBitChangeTrace
A traceback for available key bits.
Definition: qkd-buffer.h:491
static const uint32_t QKDSTATUS_CHARGING
QKDStatus CHARGING.
Definition: qkd-buffer.h:87
std::vector< int64_t > m_lastConsumedKeySizes
The size of the several last consumed keys.
Definition: qkd-buffer.h:507
uint64_t GetMaxKeySizeBit()
Get the maximal key size that can be served in bits.
Definition: qkd-buffer.cc:307
virtual ~QKDBuffer()
Destructor.
Definition: qkd-buffer.cc:219
uint32_t GetIndex()
Get the index of the buffer per local node.
Definition: qkd-buffer.cc:931
Ptr< Node > GetSrcNode()
Get the QKD source node.
Definition: qkd-buffer.cc:913
double m_averageKeyConsumptionTimePeriod
The average duration of the key consumption time period.
Definition: qkd-buffer.h:512
Ptr< Node > GetDstNode()
Get the QKD destination node.
Definition: qkd-buffer.cc:922
TracedCallback< uint32_t > m_thresholdKeyBitDecreaseTrace
A traceback for consumed key bits.
Definition: qkd-buffer.h:493
double m_averageKeyChargingSize
The average key charging size.
Definition: qkd-buffer.h:513
uint32_t m_bitsUsedInTimePeriod
Help value used for graph ploting.
Definition: qkd-buffer.h:477
TracedCallback< uint32_t > m_currentKeyBitChangeTrace
A trace for current bit change.
Definition: qkd-buffer.h:522
int64_t m_lastKeyConsumptionTimeStamp
The timestamp of a last key consumption (when the last key material was fetched).
Definition: qkd-buffer.h:501
void Dispose(void)
Destroy a QKD buffer.
Definition: qkd-buffer.cc:228
bool AddNewKey(Ptr< QKDKey > key, uint32_t keyTransformed)
Add new key to the storage.
Definition: qkd-buffer.cc:318
uint32_t m_maximalKeyCount
The maximal number of stored keys.
Definition: qkd-buffer.h:489
std::vector< struct QKDBuffer::data > m_previousValues
Help vector used for graph ploting.
Definition: qkd-buffer.h:480
uint32_t m_maxNumberOfRecordedKeyConsumptionTimePeriods
The maximal number of values which are used for calculation of the average key consumption time perio...
Definition: qkd-buffer.h:505
uint32_t FetchPreviousState(void)
Get the previous state of the QKD buffer.
Definition: qkd-buffer.cc:874
bool ProbeKeyStatus(std::string keyId, QKDKey::QKDKeyState_e keyState)
Check if the state of the key equals to a given state.
Definition: qkd-buffer.cc:455
std::vector< int64_t > m_chargingTimePeriods
The durations of the serveral last charging time periods.
Definition: qkd-buffer.h:508
uint32_t m_defaultKeySize
The default key size as required by the ETSI QKD 014 interface details.
Definition: qkd-buffer.h:469
TracedCallback< Ptr< QKDKey > > m_newKeyAddedTrace
A trace of newly added keys.
Definition: qkd-buffer.h:518
void SetIndex(uint32_t)
Set the index of the buffer per local node.
Definition: qkd-buffer.cc:927
uint64_t GetTargetKeyCountBit()
Get tge amount of key material in bits that is ready to be served and belongs to a set of targeted ke...
Definition: qkd-buffer.cc:298
void KeyCalculation()
Help function used for ploting graphs.
Definition: qkd-buffer.cc:245
uint32_t m_currentKeyBit
The current amount of key material in the QKD key storage.
Definition: qkd-buffer.h:495
std::map< uint32_t, QKDBuffer::KeyStorage > m_destinations
Definition: qkd-buffer.h:533
uint32_t GetId(void) const
Get the QKD buffer identifier.
Definition: qkd-buffer.cc:823
uint64_t GetMaxKeyCountBit()
Get the maximum amount of stored keys in bits.
double m_c
The average amount of key in the buffer during the recalculate time period.
Definition: qkd-buffer.h:482
void ReserveKey(std::string keyId)
Reserve the QKD key.
Definition: qkd-buffer.cc:665
TracedCallback< double > m_averageKeyConsumptionRateTrace
A trace of the average key consumption rate.
Definition: qkd-buffer.h:529
TracedCallback< uint32_t > m_currentKeyBitIncreaseTrace
A trace of increase in amount of key bits.
Definition: qkd-buffer.h:523
static const uint32_t QKDSTATUS_READY
QKDStatus READY.
Definition: qkd-buffer.h:83
void SetSrcNode(Ptr< Node >)
Set the QKD source node.
Definition: qkd-buffer.cc:909
TracedCallback< double > m_averageKeyGenerationRateTrace
A trace of the average key generation rate.
Definition: qkd-buffer.h:528
void SetMthr(uint32_t thr)
Set the threshold value of the QKD storage.
Definition: qkd-buffer.cc:894
uint32_t GetMinKeyCount()
Get the minimum number of stored keys.
Definition: qkd-buffer.cc:279
double GetAverageKeyGenerationRate()
Get average key generation rate.
Definition: qkd-buffer.cc:431
uint32_t FetchMaxNumberOfRecordedKeyChargingTimePeriods()
Get the maximal number of values which are used for calculation of average key charging time period.
Definition: qkd-buffer.cc:437
TracedCallback< Ptr< QKDKey > > m_transformedKeyAddedTrace
A trace for tranformed keys.
Definition: qkd-buffer.h:519
static uint32_t nBuffers
The number of the created buffers - a static value.
Definition: qkd-buffer.h:303
Ptr< QKDKey > FetchKeyByID(std::string keyID)
Get the key of a given identifier.
Definition: qkd-buffer.cc:498
std::vector< int64_t > m_consumptionTimePeriods
The durations of the serveral last consumption time periods.
Definition: qkd-buffer.h:509
uint32_t GetKeySize()
Get default size of the key (ETSI QKD 014).
Definition: qkd-buffer.cc:235
int64_t FetchLastKeyChargingTimeDuration()
Get the time value about the time duration of last key charging process.
Definition: qkd-buffer.cc:842
std::vector< uint32_t > m_targetSizeSet
The list of requested key sizes.
Definition: qkd-buffer.h:468
static const uint32_t QKDSTATUS_EMPTY
QKDStatus EMPTY.
Definition: qkd-buffer.h:89
void ReleaseReservation(std::string keyId)
Release the key reservation.
Definition: qkd-buffer.cc:697
int64_t m_lastKeyConsumptionTimeDuration
The timestamp of a last key fetch operation.
Definition: qkd-buffer.h:503
Ptr< Node > m_srcNode
The source node.
Definition: qkd-buffer.h:300
uint32_t m_previousStatus
The previous status; important for deciding about further status that can be selected.
Definition: qkd-buffer.h:484
uint32_t GetMthr(void) const
Get the threshold value of QKD storage.
Definition: qkd-buffer.cc:888
uint32_t m_recalculateTimePeriod
The period of time (in seconds) to calculate average amount of the key in the buffer.
Definition: qkd-buffer.h:479
TracedCallback< uint32_t > m_StatusChangeTrace
A trace of status changes.
Definition: qkd-buffer.h:525
bool m_isRisingCurve
Whether curve on graph is rising or not.
Definition: qkd-buffer.h:483
uint64_t m_currentReadyKeyBit
The current amount of key material in the QKD buffer that are ready to be served.
Definition: qkd-buffer.h:497
Ptr< Node > m_dstNode
The destination node.
Definition: qkd-buffer.h:301
void SetDstNode(Ptr< Node >)
Set the QKD destination node.
Definition: qkd-buffer.cc:918
TracedCallback< Ptr< QKDKey > > m_keyServedTrace
A trace for served keys.
Definition: qkd-buffer.h:520
double GetAverageKeyConsumptionRate()
Get average key consumption rate.
Definition: qkd-buffer.cc:366
uint32_t GetMCurrentPrevious(void) const
Get previous - before latest change.
Definition: qkd-buffer.cc:881
static TypeId GetTypeId(void)
Get the TypeId.
Definition: qkd-buffer.cc:40
QKDBuffer()
Constructor.
Definition: qkd-buffer.cc:166
TracedCallback< uint32_t > m_thresholdKeyBitIncreaseTrace
A traceback for generated key bits.
Definition: qkd-buffer.h:492
EventId m_calculateRoutingMetric
The event to calculate routing metric.
Definition: qkd-buffer.h:517
void InitTotalGraph() const
Initialize total graph.
Definition: qkd-buffer.cc:829
uint32_t m_minKeyBit
The minimal amount of key material in the QKD key storage.
Definition: qkd-buffer.h:485
void CheckState(void)
Update the state of the buffer.
Definition: qkd-buffer.cc:778
uint32_t m_nextKeyID
The identifie of the next key to be generated.
Definition: qkd-buffer.h:471
uint32_t m_noAddNewValue
Help value used for graph ploting.
Definition: qkd-buffer.h:476
uint32_t FetchState(void)
Get the current state of the QKD buffer.
Definition: qkd-buffer.cc:867
void RecordTargetSize(uint32_t size)
Record the key target size.
Definition: qkd-buffer.cc:769
uint64_t m_currentTargetKeyBit
The current amount of key material in the QKD buffer that is already targeted.
Definition: qkd-buffer.h:498
void Init(Ptr< Node > srcNode, Ptr< Node > dstNode, uint32_t Mmin, uint32_t Mthr, uint32_t Mmax, uint32_t Mcurrent, bool useRealStorages)
Initialize a QKD buffer.
Definition: qkd-buffer.cc:172
uint32_t m_currentKeyBitPrevious
The previous value of current amount of key material in the QKD key storage.
Definition: qkd-buffer.h:499
uint64_t GetReadyKeyCountBit()
Get the amount of the key material in bits that is ready to be served.
Definition: qkd-buffer.cc:293
uint64_t GetKeyCountBit()
Get the amount of stored keys in bits.
Definition: qkd-buffer.cc:288
QKDKeyState_e
The QKD key states.
Definition: qkd-key.h:76
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
The key storage description.
Definition: qkd-buffer.h:102
std::map< uint32_t, QKDKey > keys
Definition: qkd-buffer.h:105
Data specific variables.
Definition: qkd-buffer.h:94