A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
s-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 SBUFFER_H
13#define SBUFFER_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 <vector>
25#include <map>
26#include <unordered_map>
27#include "q-buffer.h"
28
29namespace ns3 {
30
31 /**
32 * @defgroup qkd Quantum Key Distribution(QKD)
33 * This section documents the API of the ns-3 QKD Network Simulation Module(QKDNetSim).
34 *
35 * Be sure to read the manual BEFORE going down to the API.
36 */
37
38 /**
39 * @ingroup qkd
40 * @class SBuffer
41 * @brief Sbuffer is a working buffer from which keys are served.
42 *
43 * @note Each QBuffer has a pair of SBuffers, one dedicated for the
44 * outbound(enc) and other for the inbound(dec) connection.
45 *
46 * The SBuffer is filled with certain amount of key material from QBuffer,
47 * and is accessed to serve cryptographic application request.
48 *
49 */
50 class SBuffer: public QBuffer {
51 public:
52
53 /**
54 * @brief S-Buffer Type
55 */
63
64 /**
65 * @brief Get the TypeId
66 * @return The TypeId for this class
67 */
68 static TypeId GetTypeId();
69
70 /**
71 * @brief QBuffer constructor
72 */
73 SBuffer();
74
75 /**
76 * @brief SBuffer constructor
77 * @param type SBuffer type
78 * @param size SBuffer default key size
79 */
80 SBuffer(SBuffer::Type type, uint32_t size);
81
82 /**
83 * @brief QBuffer destructor
84 */
85 ~SBuffer() override;
86
87 virtual void DoInitialize() override;
88
89 /**
90 * @brief Set s-buffer type
91 * @param type the s-buffer type
92 */
93 void SetType(Type type);
94
95 /**
96 * @brief Get s-buffer type
97 * @return SBufferType s-buffer type
98 */
99 Type GetType();
100
101 /**
102 * @brief Get servable key count
103 * @return uint32_t servable key count
104 *
105 * Get number of keys from s-buffer that are in READY state
106 */
108
109 /**
110 * @brief Get servable bit count
111 * @return uint32_t servable bit count
112 *
113 * Get amount of key material that is in READY state
114 */
116
117 /**
118 * @brief Get number of keys that are in default size
119 * @param uint32_t a target number of required keys
120 * @return uint32_t number of key in default size
121 *
122 * This function is important when cosidereing the RELAY operation.
123 * The RELAY procedure can not make desicion based on available key count,
124 * because it does not include the transform operation in parallel.
125 */
127
128 /**
129 * @brief Get key candidate
130 * @param size target key size
131 * @return Ptr on QKD key
132 *
133 * If the input size is equal to zero the function returns a random key
134 * from s-buffer. Otherwise, the funtion returns a key of the requested size.
135 * If such key is not available, larger key is modified and a portion of it
136 * is returned from the function, while remaining portion remains in s-buffer.
137 * Remaining key is marked as INIT, and is not servable until it gets in sync.
138 * This function is always called on s-buffers("enc").
139 */
141
142 /**
143 * @brief Get portion of key
144 * @param keyId key identifier
145 * @param size portion size
146 * @return Ptr on QKD key
147 *
148 * This function is called on s-buffer("dec"), as a counterpart to conditioned
149 * GetTransformCandidate function. It returns a portion of key, identified with
150 * keyId. In this case, the remaining portion is s-buffer remains in READY state.
151 */
152 Ptr<QKDKey> GetHalfKey(std::string keyId, uint32_t size);
153
154 /**
155 * @brief store key in SBuffer
156 * @param Ptr<QKey> key
157 * @return true if the key is added to the storage; False otherwise
158 */
160 return StoreKey(key, false);
161 }
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 uint32_t GetBitCount() const override
168 {
169 return m_currentKeyBit;
170 }
171
172 /**
173 * @brief store key in QBuffer
174 * @param Ptr<QKey> key
175 * @param bool fireTraces
176 * @return true if the key is added to the storage; False otherwise
177 */
178 bool StoreKey(Ptr <QKDKey> key, bool fireTraces) override;
179
180
181 /**
182 * @brief Get key with given size
183 * @param size size of the key
184 * @return Ptr on QKD key
185 *
186 * For relay purposes. We want to relay keys in default sizes!
187 * However, the LOCAL_SBUFFER contains keys in vaious sizes!
188 * Therefore, it is important to assure that we are getting the
189 * key which is in given size!
190 */
192
193 /**
194 * @brief Store supply key
195 * @param key key
196 */
197 void StoreSupplyKey(Ptr<QKDKey> key);
198
199 /**
200 * @brief Get supply key
201 * @param keyId key identifier
202 */
203 Ptr<QKDKey> GetSupplyKey(std::string keyId);
204
205 /**
206 * @brief Mark key
207 * @param keyId key identifier
208 * @param state new state
209 */
210 void MarkKey(
211 std::string keyId,
213 );
214
215 /**
216 * @brief Returns key chunk with lowest index.
217 * @return QKDKey secret key chunk
218 */
220
221 /**
222 * @brief Insert key to key stream session
223 * @param key secret key
224 *
225 * An input key may be reformated to create multiple key_chunks
226 * based on QoS criteria.
227 */
229
231
233
235
236 /**
237 * @brief Assign a lifetime to a key
238 * @param keyId key identifier
239 */
240 void SetKeyLifetime(std::string keyId);
241
242 void SetRelayState(bool relayActive);
243
244 bool IsRelayActive();
245
246
247 /**
248 * @brief get key from QBuffer
249 * @param keyID key identifier
250 * @return Ptr to the key
251 */
252 Ptr<QKDKey> GetKey(std::string keyID = "", bool fireTraces = true) override;
253
254 /**
255 * @brief Log key consumption
256 * @param diffValue key consumption in bits
257 * @param positive increment or negative
258 *
259 * It is utilized from derived class S-Buffer when a portion of key is
260 * obtained from m_keys, to account for this key usage.
261 */
262 void LogUpdate(uint32_t diffValue, bool positive) override;
263
264 private:
265
266 SBuffer::Type m_type; //!< S-Buffer type
267
268 uint32_t m_currentStreamIndex; //!< The last index when the S-Buffer is used for key stream sessions.
269
270 uint32_t m_notReadyKeyCount; //!< Number of keys stored which are not in READY state
271
272 uint32_t m_notReadyBitCount; //!< Amount of key material stored that are not in READY state
273
274 bool m_relayActive; //!< The state of S-Buffer will not trigger relay if relay is active
275
276 std::map<uint32_t, Ptr<QKDKey> > m_stream_keys; //!< Key stream session
277
278 std::map<std::string, Ptr<QKDKey> > m_supply_keys; //!< Created keys which are ready for supply to crypto applications
279
280 uint32_t m_minKeyBitSBufferDefault; //<! The minimal amount of key material in QKD key storage (SBuffer default)
281
282 uint32_t m_maxKeyBitSBufferDefault; //<! The maximal amount of key material in QKD key storage (SBuffer default)
283
284 uint32_t m_thresholdKeyBitSBufferDefault; //<! The threshold amount of key material in QKD key storage (SBuffer default)
285
286 uint32_t m_defaultKeySizeSBufferDefault; //<! Default key size for this QKD Buffer (SBuffer default)
287
288 };
289}
290
291#endif /* SBUFFER_H */
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
uint32_t m_currentKeyBit
The current amount of key material in QKD key storage.
Definition q-buffer.h:452
QKDKeyState_e
QKD Key States.
Definition qkd-key.h:65
Sbuffer is a working buffer from which keys are served.
Definition s-buffer.h:50
uint32_t m_currentStreamIndex
The last index when the S-Buffer is used for key stream sessions.
Definition s-buffer.h:268
virtual void DoInitialize() override
Initialize() implementation.
Definition s-buffer.cc:72
void SetKeyLifetime(std::string keyId)
Assign a lifetime to a key.
Definition s-buffer.cc:711
uint32_t GetStreamIndex()
Definition s-buffer.cc:651
Ptr< QKDKey > GetHalfKey(std::string keyId, uint32_t size)
Get portion of key.
Definition s-buffer.cc:420
uint32_t m_minKeyBitSBufferDefault
Definition s-buffer.h:280
Ptr< QKDKey > GetKey(uint32_t size)
Get key with given size.
Definition s-buffer.cc:459
void MarkKey(std::string keyId, QKDKey::QKDKeyState_e state)
Mark key.
Definition s-buffer.cc:669
std::map< std::string, Ptr< QKDKey > > m_supply_keys
Created keys which are ready for supply to crypto applications.
Definition s-buffer.h:278
std::map< uint32_t, Ptr< QKDKey > > m_stream_keys
Key stream session.
Definition s-buffer.h:276
uint32_t GetNextIndex()
Definition s-buffer.cc:658
void LogUpdate(uint32_t diffValue, bool positive) override
Log key consumption.
Definition s-buffer.cc:212
uint32_t GetSBitCount()
Get servable bit count.
Definition s-buffer.cc:181
uint32_t GetBitCount() const override
get amount of stored key material in bits
Definition s-buffer.h:167
void StoreSupplyKey(Ptr< QKDKey > key)
Store supply key.
Definition s-buffer.cc:487
SBuffer()
QBuffer constructor.
Definition s-buffer.cc:62
Ptr< QKDKey > GetStreamKey()
Returns key chunk with lowest index.
Definition s-buffer.cc:524
Ptr< QKDKey > GetTransformCandidate(uint32_t size)
Get key candidate.
Definition s-buffer.cc:288
bool IsRelayActive()
Definition s-buffer.cc:724
void SetType(Type type)
Set s-buffer type.
Definition s-buffer.cc:128
uint32_t GetStreamKeyCount()
Definition s-buffer.cc:637
uint32_t m_thresholdKeyBitSBufferDefault
Definition s-buffer.h:284
Ptr< QKDKey > GetSupplyKey(std::string keyId)
Get supply key.
Definition s-buffer.cc:505
uint32_t m_notReadyBitCount
Amount of key material stored that are not in READY state.
Definition s-buffer.h:272
uint32_t m_maxKeyBitSBufferDefault
Definition s-buffer.h:282
Type GetType()
Get s-buffer type.
Definition s-buffer.cc:135
bool m_relayActive
The state of S-Buffer will not trigger relay if relay is active.
Definition s-buffer.h:274
void SetRelayState(bool relayActive)
Definition s-buffer.cc:717
uint32_t m_notReadyKeyCount
Number of keys stored which are not in READY state.
Definition s-buffer.h:270
SBuffer::Type m_type
S-Buffer type.
Definition s-buffer.h:266
uint32_t m_defaultKeySizeSBufferDefault
Definition s-buffer.h:286
uint32_t GetSKeyCount()
Get servable key count.
Definition s-buffer.cc:171
~SBuffer() override
QBuffer destructor.
Definition s-buffer.cc:119
void InsertKeyToStreamSession(Ptr< QKDKey > key)
Insert key to key stream session.
Definition s-buffer.cc:546
static TypeId GetTypeId()
Get the TypeId.
Definition s-buffer.cc:32
uint32_t GetDefaultKeyCount(uint32_t number=0)
Get number of keys that are in default size.
Definition s-buffer.cc:143
bool StoreKey(Ptr< QKDKey > key)
store key in SBuffer
Definition s-buffer.h:159
Type
S-Buffer Type.
Definition s-buffer.h:56
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.