A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
q-buffer.h
Go to the documentation of this file.
1/*
2 * Copyright(c) 2022 DOTFEESA www.tk.etf.unsa.ba
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 *
7 *
8 * Authors: Miralem Mehic <miralem.mehic@ieee.org>
9 * Emir Dervisevic <emir.dervisevic@etf.unsa.ba>
10 */
11
12#ifndef QBUFFER_H
13#define QBUFFER_H
14
15#include <queue>
16#include "ns3/packet.h"
17#include "ns3/object.h"
18#include "ns3/ipv4-header.h"
19#include "ns3/traced-value.h"
20#include "ns3/trace-source-accessor.h"
21#include "ns3/event-id.h"
22#include "qkd-key.h"
23#include "ns3/node.h"
24#include <map>
25#include <vector>
26#include <unordered_map>
27
28namespace ns3 {
29
30 /**
31 * @defgroup qkd Quantum Key Distribution(QKD)
32 * This section documents the API of the ns-3 QKD Network Simulation Module(QKDNetSim).
33 *
34 * Be sure to read the manual BEFORE going down to the API.
35 */
36
37 /**
38 * @ingroup qkd
39 * @class QBuffer
40 * @brief Qbuffer is a secure storage for QKD keys. QBuffer is assigned
41 * for each connection using QKDControl on each peer.
42 *
43 * @note The two QKD nodes that establish one or more logical QKD connections
44 * will implement QBuffer on each side which will be assigned by QKDControl entity.
45 * The purpose of the QBuffer is to collect enough key material for its
46 * subsequent use for cryptographic purposes. Due to the limited charging key
47 * rate of QKD protocols, QKD post-processing applications strive to save keys in
48 * QBuffers to generate as many keys in advance. However, warehouses have a
49 * limited capacity that is defined with a maximum value. They also have a minimum
50 * capacity that describes the minimum amount of key required to establish initial
51 * post-processing operations. Also, the buffer implements a threshold value that
52 * may indicate that the necessary actions are being taken before the buffer
53 * is completely emptied.
54 *
55 * It is important to note that a QKD link has full application only when there are
56 * enough keys to apply for cryptographic purposes. Therefore, constant monitoring
57 * of the state of the QKD buffer is necessary to identify the statuses in which the
58 * QBuffer can be found:
59 * READY - Amount of key is larger than threshold Mthr
60 * WARNING - Amount of key is lower then threshold and the amount of keys
61 * in the buffer is decreasing
62 * CHARGING - Amount of key is lower then threshold and the amount of keys
63 * in the buffer is increasing
64 * EMPTY - The amount of keys in the buffer is lower than the minimal value
65 *
66 * The states of the QBuffer do not directly affect the communication, but it
67 * can be used for easier prioritization of traffic depending on the state of
68 * the buffer. For example, in EMPTY state, QKD post-processing applications used
69 * to establish a new key material should have the highest priority in traffic processing.
70 */
71 class QBuffer: public Object {
72 public:
73
74 static const uint32_t QSTATUS_READY = 0; //!< QStatus READY
75 static const uint32_t QSTATUS_WARNING = 1; //!< QStatus WARNING
76 static const uint32_t QSTATUS_CHARGING = 2; //!< QStatus CHARGING
77 static const uint32_t QSTATUS_EMPTY = 3; //!< QStatus EMPTY
78
83
84 /**
85 * @brief Get the TypeId
86 * @return The TypeId for this class
87 */
88 static TypeId GetTypeId();
89
90 /**
91 * @brief QBuffer constructor
92 */
93 QBuffer();
94
95 //@ToDo add new constructors to avoid calling for Init!
96
97 /**
98 * @brief QBuffer destructor
99 */
100 ~QBuffer() override;
101
102 /**
103 * @brief initialize QBuffer
104 * @param dstKmNodeId remote key manager node identifier
105 * @param Mmin minimum amount(bits) of key material QBuffer should maintain
106 * @param Mthr thresold amount(bits) of key material
107 * @param Mmax maximum amount(bits) of key material QBuffer can store
108 * @param Mcurr current amount(bits) of key material QBuffer maintain
109 * @param defaultKeySize default size of stored keys
110 */
111 void Init(
118 );
119
120 /**
121 * @brief create QKD buffer configuration
122 * @param Mmin minimum amount(bits) of key material QKD buffer should maintain
123 * @param Mmax maximum amount(bits) of key material QKD buffer can store
124 * @param Mthr thresold amount(bits) of key material
125 * @param Mcurr current amount(bits) of key material QKD buffer maintain
126 * @param defaultKeySize default size of stored keys
127 */
128 virtual void Configure(
134 );
135
136 /**
137 * @brief destroy a QBuffer
138 *
139 * This is the pre-destructor function of the QBuffer.
140 */
141 void Dispose();
142
143 /**
144 * @brief store key in QBuffer
145 * @param Ptr<QKey> key
146 * @return true if the key is added to the storage; False otherwise
147 */
148 virtual bool StoreKey(Ptr <QKDKey> key = nullptr, bool fireTraces = true);
149
150 /**
151 * @brief get key from QBuffer
152 * @param keyID key identifier
153 * @return Ptr to the key
154 */
155 virtual Ptr<QKDKey> GetKey(std::string keyID = "", bool fireTraces = true);
156
157 /**
158 * @brief get number of stored keys
159 * @return int32_t key count
160 */
161 uint32_t GetKeyCount() const;
162
163 /**
164 * @brief get amount of stored key material in bits
165 * @return int32_t amount of stored key material in bits
166 */
167 virtual uint32_t GetBitCount() const
168 {
169 return m_currentKeyBit;
170 }
171
172 uint64_t GetMinKeySizeBit() const
173 {
174 return m_minKeyBit;
175 }
176
177 uint64_t GetMaxKeySizeBit() const
178 {
179 return m_maxKeyBit;
180 }
181
182 void SetDescription(std::string val)
183 {
185 }
186
187 std::string GetDescription() const
188 {
189 return m_description;
190 }
191
192
193 /**
194 * @brief Get default size of keys stored in QBuffer
195 * @return int32_t default key size
196 */
197 uint32_t GetKeySize() const;
198
199 /**
200 * @brief Log key consumption
201 * @param diffValue key consumption in bits
202 * @param positive increment or negative
203 *
204 * It is utilized from derived class S-Buffer when a portion of key is
205 * obtained from m_keys, to account for this key usage.
206 */
207 virtual void LogUpdate(uint32_t diffValue, bool positive);
208
209 /**
210 * Fetch the current state of the QBuffer
211 *
212 * QBuffer can be in one of the following states:
213 * – READY—when Mcur(t) ≥ Mthr ,
214 * – WARNING—when Mthr > Mcur(t) > Mmin and the previous state was READY,
215 * – CHARGING—when Mthr > Mcur(t) and the previous state was EMPTY,
216 * – EMTPY—when Mmin ≥ Mcur(t) and the previous state was WARNING or CHARGING
217 */
219
220 /**
221 * Fetch the previous state of the QBuffer. Help function used for ploting graphs
222 *
223 * @return int32_t integer representation of QKD Storage state
224 */
226
227 /**
228 * Update the state after some changes on the QBuffer
229 */
230 void CheckState();
231
232 /**
233 * Help function used for ploting graphs
234 */
235 void KeyCalculation();
236
237 /*
238 * Return time difference between the current time and time at which
239 * last key charging process finished
240 *
241 * @return int64_t deltaTime
242 */
243 int64_t GetDeltaTime();
244
245 /**
246 * Return time value about the time duration of last key charging process
247 *
248 * @return int64_t lastKeyChargingTimeDuration
249 */
251
252 /**
253 * Return average duration of key charging process in the long run
254 *
255 * @return double average duration of key charging period
256 */
258
259 /**
260 * Return the maximal number of values which are used
261 * for calculation of average key charging time period
262 *
263 * @return int32_t maximal number of recorded key charging time periods; default value 5
264 */
266
267 /**
268 * Help function used for ploting graphs; Previous - before latest change
269 *
270 * @return int32_t integer representation of the previous QKD storage key material;
271 */
273
274 uint32_t GetMmin() const;
275
276 uint32_t GetMmax() const;
277
278 /**
279 * Get the threshold value of QKD storage
280 * The threshold value Mthr(t) at the time of measurement t is used to indicate the
281 * state of QKD buffer where it holds that Mthr(t) ≤ Mmax .
282 *
283 * @return int32_t integer representation of the threshold value of the QKD storage
284 */
285 uint32_t GetMthr() const;
286
287 /**
288 * Set the threshold value of QKD storage
289 *
290 * @param int32_t integer set the threshold value of the QKD storage
291 */
292 void SetMthr(uint32_t thr);
293
294 /**
295 * Set default key size
296 *
297 * @param size key size
298 */
299 void SetKeySize(uint32_t size);
300
301 /**
302 * Help function for total graph ploting
303 */
304 void InitTotalGraph() const;
305
306 /**
307 * Get the QKD Storage/Buffer ID
308 *
309 * @return int32_t buffer unique ID
310 */
311 uint32_t GetId() const;
312
313 /**
314 * Assign operator
315 *
316 * @param o Other QBuffer
317 * @return True if buffers are identical; False otherwise
318 */
319 bool operator ==(QBuffer const & o) const;
320
321 /**
322 * Set the index of the buffer per local node
323 *
324 * @param int32_t index
325 */
326 void SetIndex(uint32_t);
327
328 /**
329 * Get the index of the buffer per local node
330 *
331 * @return int32_t index
332 */
334
335 /**
336 * Get the index of the remote node id
337 *
338 * @return int32_t index
339 */
341 {
342 return m_dstKmNodeId;
343 }
344
345 /**
346 * Set the index of the remote node id
347 *
348 * @param int32_t value
349 */
354
359
364
365
366 protected:
367
368 /**
369 * @brief destroy key from the QBuffer
370 * @param keyId key identifier
371 * @return bool function status
372 */
373 bool DestroyKey(std::string keyId);
374
375 uint32_t m_dstKmNodeId; //<! Remote KM node ID
376
377 //std::string m_id; //<! @toDo UUID id for each Q-Buffer
378
379 uint32_t m_bufferID; //!< unique buffer ID
380
381 static uint32_t nBuffers; //!< number of created buffers - static value
382
383 std::unordered_map< std::string, Ptr <QKDKey> > m_keys; //!< key database
384
386
387 std::string m_description;
388
389 /**
390 * ID of the next key to be generated
391 */
393
394 /**
395 * Help value used for graph ploting
396 */
398
399 /**
400 * Help value used for graph ploting
401 */
403
404 /**
405 * Help value used for graph ploting
406 */
408
409 /**
410 * Help value used for graph ploting and calculation of average
411 * post-processing duration
412 */
414
415 /**
416 * Help value used for detection of average key usage
417 */
419
420 /**
421 * The period of time(in seconds) to calculate average amount of the key in the buffer
422 * Default value 5 - used in routing protocols for detection of information freshness
423 */
425
426 /**
427 * Help vector used for graph ploting
428 */
429 std::vector < struct QBuffer::data > m_previousValues;
430
431 double m_c; //!< average amount of key in the buffer during the recalculate time period
432
433 bool m_isRisingCurve; //!< whether curve on graph is rising or not
434
435 uint32_t m_previousStatus; //<! Holds previous status; important for deciding about further status that can be selected
436
437 uint32_t m_minKeyBit; //<! The minimal amount of key material in QKD key storage
438
439 uint32_t m_maxKeyBit; //<! The maximal amount of key material in QKD key storage
440
441 uint32_t m_maxValueGraph; //<! The maximal value of the graph
442
443 uint32_t m_thresholdKeyBit; //<! The threshold amount of key material in QKD key storage
444
445 uint32_t m_defaultKeySize; //<! Default key size for this QKD Buffer
446
447 TracedCallback < uint32_t > m_thresholdKeyBitChangeTrace;
448
449 /**
450 * The current amount of key material in QKD key storage
451 */
453
454 /**
455 * The previous value of current amount of key material in QKD key storage
456 */
458
459 /**
460 * The timestamp of last key charging(when the new key material was added)
461 */
463
464 /**
465 * The timestamp of last key usage
466 */
468
469 /**
470 * The maximal number of values which are used for stored for calculation
471 * of average key charging time period
472 */
474
475 /**
476 * Vector of durations of several last charging time periods
477 */
478 std::vector < int64_t > m_chargingTimePeriods;
479
480 /**
481 * The state of the Net Device transmit state machine.
482 */
484
485 /**
486 * The average duration of key charging time period
487 */
489
491
494
495 TracedCallback < uint32_t > m_currentKeyBitChangeTrace;
496 TracedCallback < uint32_t > m_currentKeyBitIncreaseTrace;
497 TracedCallback < uint32_t > m_currentKeyBitDecreaseTrace;
498 TracedCallback < uint32_t > m_StatusChangeTrace;
499 TracedCallback < double > m_CMetricChangeTrace;
500 TracedCallback < double > m_averageKeyChargingTimePeriodTrace;
501
503
504 };
505}
506
507#endif /* QBUFFER_H */
An identifier for simulation events.
Definition event-id.h:45
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
Qbuffer is a secure storage for QKD keys.
Definition q-buffer.h:71
void Dispose()
destroy a QBuffer
Definition q-buffer.cc:183
virtual void Configure(uint32_t Mmin, uint32_t Mthr, uint32_t Mmax, uint32_t Mcurrent, uint32_t defaultKeySize)
create QKD buffer configuration
Definition q-buffer.cc:119
static const uint32_t QSTATUS_WARNING
QStatus WARNING.
Definition q-buffer.h:75
uint32_t m_maxValueGraph
Definition q-buffer.h:441
uint32_t m_thresholdKeyBit
Definition q-buffer.h:443
uint32_t GetMaxNumberOfRecordedKeyChargingTimePeriods() const
Return the maximal number of values which are used for calculation of average key charging time perio...
Definition q-buffer.cc:423
void SetIndex(uint32_t)
Set the index of the buffer per local node.
Definition q-buffer.cc:551
uint32_t m_recalculateTimePeriod
The period of time(in seconds) to calculate average amount of the key in the buffer Default value 5 -...
Definition q-buffer.h:424
void SetDescription(std::string val)
Definition q-buffer.h:182
TracedCallback< uint32_t > m_currentKeyBitDecreaseTrace
Definition q-buffer.h:497
bool operator==(QBuffer const &o) const
Assign operator.
Definition q-buffer.cc:467
uint32_t m_noEntry
Help value used for graph ploting.
Definition q-buffer.h:397
uint32_t m_maxKeyBit
Definition q-buffer.h:439
void SetMthr(uint32_t thr)
Set the threshold value of QKD storage.
Definition q-buffer.cc:543
uint32_t m_minKeyBit
Definition q-buffer.h:437
uint32_t m_maxNumberOfRecordedKeyChargingTimePeriods
The maximal number of values which are used for stored for calculation of average key charging time p...
Definition q-buffer.h:473
TracedCallback< uint32_t > m_currentKeyBitIncreaseTrace
Definition q-buffer.h:496
uint32_t m_nextKeyID
ID of the next key to be generated.
Definition q-buffer.h:392
uint32_t GetSrcKMSApplicationIndex() const
Definition q-buffer.h:360
void Init(uint32_t dstKmNodeId, uint32_t Mmin, uint32_t Mthr, uint32_t Mmax, uint32_t Mcurrent, uint32_t defaultKeySize)
initialize QBuffer
Definition q-buffer.cc:136
static const uint32_t QSTATUS_CHARGING
QStatus CHARGING.
Definition q-buffer.h:76
int64_t GetLastKeyChargingTimeDuration()
Return time value about the time duration of last key charging process.
Definition q-buffer.cc:490
uint32_t m_period
Help value used for graph ploting.
Definition q-buffer.h:402
uint32_t GetMmax() const
Definition q-buffer.cc:274
QBuffer()
QBuffer constructor.
Definition q-buffer.cc:113
std::unordered_map< std::string, Ptr< QKDKey > > m_keys
key database
Definition q-buffer.h:383
static const uint32_t QSTATUS_READY
QStatus READY.
Definition q-buffer.h:74
void SetKeySize(uint32_t size)
Set default key size.
Definition q-buffer.cc:557
bool m_isRisingCurve
whether curve on graph is rising or not
Definition q-buffer.h:433
std::string m_description
Definition q-buffer.h:387
uint32_t GetKeySize() const
Get default size of keys stored in QBuffer.
Definition q-buffer.cc:190
uint32_t m_currentKeyBit
The current amount of key material in QKD key storage.
Definition q-buffer.h:452
std::vector< struct QBuffer::data > m_previousValues
Help vector used for graph ploting.
Definition q-buffer.h:429
uint32_t m_dstKmNodeId
Definition q-buffer.h:375
std::vector< int64_t > m_chargingTimePeriods
Vector of durations of several last charging time periods.
Definition q-buffer.h:478
uint32_t GetMthr() const
Get the threshold value of QKD storage The threshold value Mthr(t) at the time of measurement t is us...
Definition q-buffer.cc:537
uint32_t m_bitsUsedInTimePeriod
Help value used for detection of average key usage.
Definition q-buffer.h:418
static TypeId GetTypeId()
Get the TypeId.
Definition q-buffer.cc:32
uint32_t m_srcKMSApplicationIndex
Definition q-buffer.h:385
int64_t m_lastKeyChargingTimeDuration
The timestamp of last key usage.
Definition q-buffer.h:467
uint32_t m_bitsChargedInTimePeriod
Help value used for graph ploting and calculation of average post-processing duration.
Definition q-buffer.h:413
TracedCallback< double > m_CMetricChangeTrace
Definition q-buffer.h:499
virtual Ptr< QKDKey > GetKey(std::string keyID="", bool fireTraces=true)
get key from QBuffer
Definition q-buffer.cc:360
virtual uint32_t GetBitCount() const
get amount of stored key material in bits
Definition q-buffer.h:167
double GetAverageKeyChargingTimePeriod()
Return average duration of key charging process in the long run.
Definition q-buffer.cc:509
double m_c
average amount of key in the buffer during the recalculate time period
Definition q-buffer.h:431
uint32_t m_status
The state of the Net Device transmit state machine.
Definition q-buffer.h:483
void SetSrcKMSApplicationIndex(uint32_t &value)
Definition q-buffer.h:355
TracedCallback< Ptr< QKDKey > > m_newKeyAddedTrace
Definition q-buffer.h:492
uint32_t GetId() const
Get the QKD Storage/Buffer ID.
Definition q-buffer.cc:474
uint32_t GetIndex()
Get the index of the buffer per local node.
Definition q-buffer.cc:562
std::string GetDescription() const
Definition q-buffer.h:187
int64_t m_lastKeyChargingTimeStamp
The timestamp of last key charging(when the new key material was added)
Definition q-buffer.h:462
void SetRemoteNodeId(uint32_t value)
Set the index of the remote node id.
Definition q-buffer.h:350
uint32_t m_bufferID
unique buffer ID
Definition q-buffer.h:379
virtual void LogUpdate(uint32_t diffValue, bool positive)
Log key consumption.
Definition q-buffer.cc:230
uint32_t m_srcNodeBufferListIndex
Definition q-buffer.h:502
uint32_t m_currentKeyBitPrevious
The previous value of current amount of key material in QKD key storage.
Definition q-buffer.h:457
uint32_t m_defaultKeySize
Definition q-buffer.h:445
static uint32_t nBuffers
number of created buffers - static value
Definition q-buffer.h:381
void InitTotalGraph() const
Help function for total graph ploting.
Definition q-buffer.cc:480
uint32_t GetMmin() const
Definition q-buffer.cc:269
double m_averageKeyChargingTimePeriod
The average duration of key charging time period.
Definition q-buffer.h:488
TracedCallback< uint32_t > m_currentKeyBitChangeTrace
Definition q-buffer.h:495
uint32_t GetKeyCount() const
get number of stored keys
Definition q-buffer.cc:279
~QBuffer() override
QBuffer destructor.
Definition q-buffer.cc:176
static const uint32_t QSTATUS_EMPTY
QStatus EMPTY.
Definition q-buffer.h:77
uint64_t GetMinKeySizeBit() const
Definition q-buffer.h:172
void CheckState()
Update the state after some changes on the QBuffer.
Definition q-buffer.cc:429
uint32_t GetPreviousState()
Fetch the previous state of the QBuffer.
Definition q-buffer.cc:523
uint32_t GetState()
Fetch the current state of the QBuffer.
Definition q-buffer.cc:516
uint32_t GetMCurrentPrevious() const
Help function used for ploting graphs; Previous - before latest change.
Definition q-buffer.cc:530
uint32_t m_noAddNewValue
Help value used for graph ploting.
Definition q-buffer.h:407
uint32_t GetRemoteNodeId() const
Get the index of the remote node id.
Definition q-buffer.h:340
EventId m_calculateRoutingMetric
Definition q-buffer.h:490
uint64_t GetMaxKeySizeBit() const
Definition q-buffer.h:177
TracedCallback< uint32_t > m_StatusChangeTrace
Definition q-buffer.h:498
uint32_t m_previousStatus
Definition q-buffer.h:435
TracedCallback< Ptr< QKDKey > > m_keyServedTrace
Definition q-buffer.h:493
int64_t GetDeltaTime()
Definition q-buffer.cc:501
TracedCallback< uint32_t > m_thresholdKeyBitChangeTrace
Definition q-buffer.h:447
bool DestroyKey(std::string keyId)
destroy key from the QBuffer
Definition q-buffer.cc:409
void KeyCalculation()
Help function used for ploting graphs.
Definition q-buffer.cc:201
virtual bool StoreKey(Ptr< QKDKey > key=nullptr, bool fireTraces=true)
store key in QBuffer
Definition q-buffer.cc:285
TracedCallback< double > m_averageKeyChargingTimePeriodTrace
Definition q-buffer.h:500
a unique identifier for an interface.
Definition type-id.h:49
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.
static unsigned int value(char c)
uint32_t position
Definition q-buffer.h:81