A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
s-buffer.cc
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
13#include <algorithm>
14#include <numeric>
15#include <random>
16#include "ns3/packet.h"
17#include "ns3/simulator.h"
18#include "ns3/log.h"
19#include "ns3/boolean.h"
20#include "ns3/double.h"
21#include "ns3/uinteger.h"
22
23#include "s-buffer.h"
24
25namespace ns3 {
26
27 NS_LOG_COMPONENT_DEFINE("SBuffer");
28
30
31 TypeId
33 {
34 static TypeId tid = TypeId("ns3::SBuffer")
37 .AddAttribute("SMinimal",
38 "The minimal amount of key material in Sbuffer (bits)",
39 UintegerValue(10),
42 .AddAttribute("SMaximal",
43 "The maximal amount of key material in Sbuffer (bits)",
44 UintegerValue(128000),
47 .AddAttribute("SThreshold",
48 "The threshold amount of key material in Sbuffer (bits)",
49 UintegerValue(32000),
52 .AddAttribute("SDefaultKeySize",
53 "The default key size of Sbuffer",
54 UintegerValue(512),
57
58 ;
59 return tid;
60 }
61
70
71 void
98
100 {
101 NS_LOG_FUNCTION(this << size);
102 SetKeySize(size);
103 SetType(type);
104 if(type == STREAM_SBUFFER) //Must be able to store keys
105 Configure(
106 0,
107 500000000,
108 500000000,
109 0,
110 size
111 );
115 m_relayActive = false;
116 }
117
118
120 {
121 NS_LOG_FUNCTION (this);
122 m_keys.clear();
123 m_stream_keys.clear();
124 m_supply_keys.clear();
125 }
126
127 void
129 {
130 NS_LOG_FUNCTION(this);
131 m_type = type;
132 }
133
136 {
137 NS_LOG_FUNCTION(this);
138 return m_type;
139 }
140
141
144 {
145 NS_LOG_FUNCTION(this << number);
146 uint32_t keyCount {0};
147
148 for(auto it = m_keys.begin(); it != m_keys.end(); ++it)
149 {
150 /*
151 NS_LOG_FUNCTION(this
152 << "\nKey ID:\t" << it->second->GetId()
153 << "\nKey State:\t" << it->second->GetState()
154 << "\nKey Size:\t" << it->second->GetSizeInBits()
155 << "\nGetKeySize():\t" << GetKeySize()
156 );
157 */
158
159 if(it->second->GetSizeInBits() == GetKeySize() && it->second->GetState() == QKDKey::READY)
160 keyCount++;
161
162 if(number && keyCount == number)
163 break;
164 }
165
166 NS_LOG_FUNCTION(this << number << keyCount << m_keys.size());
167 return keyCount;
168 }
169
172 {
174 //Note 'state' is cosidered READY. We are requesting number of keys in READY state
177 return 0;
178 }
179
182 {
184 //Note 'state' is cosidered READY. We are requesting amount of key in READY state
187 return 0;
188 }
189
190
191 bool
193 {
194 NS_LOG_FUNCTION(this
195 << "\nKey ID:\t" << key->GetId()
196 << "\nKey Size:\t" << key->GetSizeInBits()
197 << "\nKey State:\t" << key->GetStateString()
198 << "\nKey Value:\t" << key->ToString()
199 << "\nGetBitCount():\t" << GetBitCount()
200 << "\nfireTraces:\t" << fireTraces
201 );
202 //Sbuffer should never fire traces in Qbuffer!
203 bool output = QBuffer::StoreKey(key, false);
204 if(output && key->GetState() == QKDKey::READY && fireTraces)
205 {
206 LogUpdate(key->GetSizeInBits(), true);
207 }
208 return output;
209 }
210
211 void
213 {
215
216 if(positive)
217 {
221 }else{
222
224 diffValue = 0;
225
229 }
230
231 NS_LOG_FUNCTION(this << "m_currentKeyBit: " << m_currentKeyBit);
233 NS_LOG_FUNCTION(this << "GetSBitCount(): " << sbitcount);
234 //NS_ASSERT(m_currentKeyBit == sbitcount);
235
237 NS_LOG_FUNCTION(this << "keyCount: " << keycount);
239 NS_LOG_FUNCTION(this << "keySize: " << keySize);
240 //NS_ASSERT(m_currentKeyBit == keycount* keySize);
241
242
243 ///////////////////////////////// TEMP TEMP TEMP /////////////////////////////////
244 // Collect all keys in READY state
245
246 NS_LOG_FUNCTION(this << "m_keys.size(): " << m_keys.size());
248 for (auto it = m_keys.begin(); it != m_keys.end(); ++it) {
249 if (it->second->GetState() == QKDKey::READY) {
250 totalReadyKeyCount += it->second->GetSizeInBits();
251 NS_LOG_FUNCTION(this << "id:" << it->second->GetId() << "\t size:" << it->second->GetSizeInBits());
252 }
253 }
254 NS_LOG_FUNCTION(this << "m_currentKeyBit: " << m_currentKeyBit);
255 NS_LOG_FUNCTION(this << "totalReadyKeyCount: " << totalReadyKeyCount);
256
257
258 NS_LOG_FUNCTION(this << "m_stream_keys.size(): " << m_stream_keys.size());
259 for (auto it = m_stream_keys.begin(); it != m_stream_keys.end(); ++it) {
260 if (it->second->GetState() == QKDKey::READY) {
261 totalReadyKeyCount += it->second->GetSizeInBits();
262 NS_LOG_FUNCTION(this << "id:" << it->second->GetId() << "\t size:" << it->second->GetSizeInBits());
263 }
264 }
265 NS_LOG_FUNCTION(this << "m_currentKeyBit: " << m_currentKeyBit);
266 NS_LOG_FUNCTION(this << "totalReadyKeyCount: " << totalReadyKeyCount);
267
268
269 NS_LOG_FUNCTION(this << "m_supply_keys.size(): " << m_supply_keys.size());
270 for (auto it = m_supply_keys.begin(); it != m_supply_keys.end(); ++it) {
271 if (it->second->GetState() == QKDKey::READY) {
272 totalReadyKeyCount += it->second->GetSizeInBits();
273 NS_LOG_FUNCTION(this << "id:" << it->second->GetId() << "\t size:" << it->second->GetSizeInBits());
274 }
275 }
276 NS_LOG_FUNCTION(this << "m_currentKeyBit: " << m_currentKeyBit);
277 NS_LOG_FUNCTION(this << "totalReadyKeyCount: " << totalReadyKeyCount);
278
280
281 ///////////////////////////////// TEMP TEMP TEMP /////////////////////////////////
282
283
284 CheckState();
285 }
286
289 {
290 NS_LOG_FUNCTION(this << size );
291 NS_LOG_FUNCTION(this << GetSBitCount());
292
293 //return random key from s-buffer(key must be READY)
294 if(size == 0)
295 {
297 NS_LOG_FUNCTION(this << "keyCount: " << keyCount);
298 if (!keyCount) {
299 NS_LOG_DEBUG("Not enough keys in SBuffer to select a transform candidate");
300 return nullptr;
301 }
302
303 // Collect all keys in READY state
304 NS_LOG_FUNCTION(this << "m_keys.size(): " << m_keys.size());
306 std::vector<decltype(m_keys)::iterator> readyKeys;
307 for (auto it = m_keys.begin(); it != m_keys.end(); ++it) {
308 if (it->second->GetState() == QKDKey::READY) {
309 readyKeys.push_back(it);
310 totalReadyKeyCount += it->second->GetSizeInBits();
311 NS_LOG_FUNCTION(this << "id:" << it->second->GetId() << "\t size:" << it->second->GetSizeInBits());
312 }
313 }
314
315 NS_LOG_FUNCTION(this << "totalReadyKeyCount: " << totalReadyKeyCount);
316 NS_LOG_FUNCTION(this << "m_currentKeyBit: " << m_currentKeyBit);
318
319
320 if (readyKeys.empty()) {
321 NS_LOG_DEBUG("No READY keys available in SBuffer!");
322 // Alternatively:
323 return nullptr;
324 }
325
326 // Pick random READY key
327 auto chosenIt = readyKeys[std::rand() % readyKeys.size()];
328 NS_LOG_FUNCTION(this << "get a key " << chosenIt->second->GetId() << " of size " << chosenIt->second->GetSizeInBits() );
329
330 return GetKey(chosenIt->second->GetId());
331
332 } else {
333
334 Ptr<QKDKey> optimalKey = nullptr; // Smallest ready key ≥ size
335 Ptr<QKDKey> largestReadyKey = nullptr; // Largest ready key
336
337 NS_LOG_FUNCTION(this << "m_keys.size(): " << m_keys.size());
339 std::vector<decltype(m_keys)::iterator> readyKeys;
340 for (auto it = m_keys.begin(); it != m_keys.end(); ++it) {
341 if (it->second->GetState() == QKDKey::READY) {
342 readyKeys.push_back(it);
343 totalReadyKeyCount += it->second->GetSizeInBits();
344 NS_LOG_FUNCTION(this << "id:" << it->second->GetId() << "\t size:" << it->second->GetSizeInBits());
345 }
346 }
347 NS_LOG_FUNCTION(this << "totalReadyKeyCount: " << totalReadyKeyCount);
348 NS_LOG_FUNCTION(this << "m_currentKeyBit: " << m_currentKeyBit);
350
351
352 for (const auto& [id, key] : m_keys)
353 {
354 if (key->GetState() != QKDKey::READY)
355 continue;
356
357 // Track largest ready key
358 if (!largestReadyKey || key->GetSizeInBits() > largestReadyKey->GetSizeInBits())
359 largestReadyKey = key;
360
361 // Track smallest ready key ≥ size
362 if (key->GetSizeInBits() >= size) {
363 if (!optimalKey || key->GetSizeInBits() < optimalKey->GetSizeInBits())
364 optimalKey = key;
365 }
366 }
367
368 if (!optimalKey && !largestReadyKey) {
369 return nullptr;
370 }
371
372 if(!optimalKey)
373 {
374 NS_LOG_FUNCTION(this << "largestReadyKey size: " << largestReadyKey->GetSizeInBits() );
375
377 return GetKey(largestReadyKey->GetId()); //This will remove key from s-buffer and fire traces
378 }
379
380 if(optimalKey->GetSizeInBits() == size)
381 {
382 NS_LOG_FUNCTION(this << "optimalKey size: " << largestReadyKey->GetSizeInBits() );
383 return GetKey(optimalKey->GetId()); //This will remove key from s-buffer and fire traces
384 }
385
386 NS_LOG_FUNCTION(this << ">>>>>>>>>>>>>>>>>>>>");
387 LogUpdate(0, true);
388 NS_LOG_FUNCTION(this << "<<<<<<<<<<<<<<<<<<<<");
389
390 NS_LOG_FUNCTION(this << "optimalKey keyId: " << optimalKey->GetId() << " of size " << optimalKey->GetSizeInBits() << " bits");
391 //Optimal key in this case is not removed, its value is updated and it is marked as INIT
392 std::string keyId = optimalKey->GetId();
393 std::string value = optimalKey->GetKeyString();
394 std::string rKeyValue = value.substr(0, size/8);
395
396 uint32_t oldKeySizeInBits = optimalKey->GetSizeInBits();
397 NS_LOG_FUNCTION(this << "oldKeySizeInBits1: " << oldKeySizeInBits);
398 value.erase(0, size/8);
399
401 key->SwitchToState(QKDKey::INIT);
402
403 auto it = m_keys.find(optimalKey->GetId()); //Find the key in s-buffer
404 it->second->SetValue(value); //Set the key value
405 NS_LOG_FUNCTION(this << key->GetId() << " of size " << key->GetSizeInBits()<< " bits is reduced to size " << key->GetSizeInBits() << " bits");
406
407 oldKeySizeInBits -= key->GetSizeInBits();
408 NS_LOG_FUNCTION(this << "oldKeySizeInBits2: " << oldKeySizeInBits);
409
410 NS_LOG_FUNCTION(this << "Update graphs to include details about key reduction!");
411 LogUpdate(key->GetSizeInBits(), false);
412
414
415 return key;
416 }
417 }
418
421 {
422 NS_LOG_FUNCTION(this << keyId << size);
423 auto it = m_keys.find(keyId);
424 if(it!=m_keys.end()){
425 if(it->second->GetSizeInBits() > size)
426 {
427 uint32_t oldKeySizeInBits = it->second->GetSizeInBits();
428 NS_LOG_FUNCTION(this << "oldKeySizeInBits1: " << oldKeySizeInBits);
429 std::string value = it->second->GetKeyString();
430 std::string rValue = value.substr(0, size/8);
431 value.erase(0, size/8);
432 NS_LOG_FUNCTION(this << value);
433
435 NS_LOG_FUNCTION(this << key->GetId() << key->GetSizeInBits());
436 it->second->SetValue(value);
437
438 NS_LOG_FUNCTION(this << key->GetId() << " of size " << key->GetSizeInBits()<< " bits is reduced to size " << key->GetSizeInBits() << " bits");
439 oldKeySizeInBits -= key->GetSizeInBits();
440 NS_LOG_FUNCTION(this << "oldKeySizeInBits2: " << oldKeySizeInBits);
441
442 NS_LOG_FUNCTION(this << "Update graphs to include details about key reduction!");
443 LogUpdate(key->GetSizeInBits(), false);
444
445 //Key remains in READY state!
446 return key;
447 }else if(it->second->GetSizeInBits() == size){
448
449 return GetKey(keyId);
450 }
451 }else{
452 NS_FATAL_ERROR(this << "Key " << keyId << " was not found!");
453 }
454
455 return nullptr;
456 }
457
460 {
461 NS_LOG_FUNCTION(this << size);
462 Ptr<QKDKey> key;
463 //for(auto it : m_keys.begin())
464 for(auto it = m_keys.begin(); it != m_keys.end(); ++it)
465 if(it->second->GetSizeInBits() == size && it->second->GetState() == QKDKey::READY){
466 key = GetKey(it->second->GetId()); //This will fire traces and remove the key!
467 break;
468 }
469
470 return key;
471 }
472
473
474 //NOTE: Function is allowed to return NULL value. Processing is left to the KM.
477 {
478 Ptr<QKDKey> key = QBuffer::GetKey(keyId, false);
479 if(key && key->GetState() == QKDKey::READY && fireTraces)
480 LogUpdate(key->GetSizeInBits(), false);
481
482 CheckState();
483 return key;
484 }
485
486 void
488 {
489 NS_LOG_FUNCTION(this << key->GetId() << key->GetSizeInBits());
490
492 {
493 NS_LOG_FUNCTION(this << "Store in m_stream_keys!");
494 m_stream_keys.insert(std::make_pair(std::stoi(key->GetId()), key));
495 } else {
496 NS_LOG_FUNCTION(this << "Store in m_supply_keys!");
497 m_supply_keys.insert(std::make_pair(key->GetId(), key));
498 }
499
500 if(key->GetState() == QKDKey::READY)
501 LogUpdate(key->GetSizeInBits(), true);
502 }
503
506 {
507 NS_LOG_FUNCTION(this << keyId);
508 auto it = m_supply_keys.find(keyId);
509 if(it != m_supply_keys.end()){
510 Ptr<QKDKey> sKey = it->second;
511 m_supply_keys.erase(it); //Remove Key
512 if(sKey && sKey->GetState() == QKDKey::READY) {
513 LogUpdate(sKey->GetSizeInBits(), false);
514 CheckState();
515 }
516 return sKey;
517 }else{
518 NS_LOG_ERROR(this);
519 return nullptr;
520 }
521 }
522
525 {
526 NS_LOG_FUNCTION(this);
527 auto it = m_stream_keys.begin();
529 if(it != m_stream_keys.end())
530 {// && it->second->GetSizeInBits() == GetKeySize())
531 streamKey = it->second;
532 NS_LOG_FUNCTION(this << it->second->GetId() << streamKey->GetSizeInBits() );
533 m_stream_keys.erase(it);
534 if(streamKey && streamKey->GetState() == QKDKey::READY)
535 {
536 LogUpdate(streamKey->GetSizeInBits(), false);
537 CheckState();
538 }
539 }else
540 NS_LOG_ERROR(this << "No chunk key available!");
541
542 return streamKey;
543 }
544
545 void
547 {
548 NS_LOG_FUNCTION(this
549 << "\nKey ID:\t" << key->GetId()
550 << "\nKey Size:\t" << key->GetSizeInBits()
551 << "\nKey State:\t" << key->GetStateString()
552 << "\nKey Value:\t" << key->ToString()
553 << "\nGetBitCount():\t" << GetBitCount()
554 << "\nm_currentStreamIndex:\t" << m_currentStreamIndex
555 );
556
557 //Take last stored index m_currentStreamIndex
558 bool startingInReady {true};
560 if(m_stream_keys.rbegin() != m_stream_keys.rend())
561 {
562 startingIndex = m_stream_keys.rbegin()->first;
563 NS_LOG_FUNCTION(this << "\nLast key index:" << m_stream_keys.rbegin()->second->GetId()
564 << "\nLast key value:" << m_stream_keys.rbegin()->second->GetKeyString()
565 );
566 if(m_stream_keys.rbegin()->second->GetSizeInBits() != GetKeySize())
567 startingInReady = false;
568 else
570 }
571
572 //NS_LOG_FUNCTION(this << "Chunk size(bytes), Start Index, Start Ready" << GetKeySize()/8 << startingIndex << startingInReady);
573 //copy
574 std::string keyValue = key->GetKeyString();
575 while(!keyValue.empty())
576 {
577 if(!startingInReady)
578 {
579 NS_LOG_FUNCTION(this << "!startingInReady");
580 uint32_t diff = GetKeySize()/8 -(m_stream_keys.rbegin()->second)->GetSize(); //In bytes
581 //Check the size of the keyValue, is it enough to fill the diff
582 std::string incompleteChunkKey =(m_stream_keys.rbegin()->second)->GetKeyString();
583 if(keyValue.size() >= diff)
584 {
585 std::string initKeyValue = keyValue;
586 std::string diffKey = keyValue.substr(0, diff);
587 std::string temp = keyValue.substr(diff);
588 keyValue = temp;
589 std::string completeKey = incompleteChunkKey + diffKey;
590 (m_stream_keys.rbegin()->second)->SetValue(completeKey); //Set the value of the key
591
592 NS_LOG_FUNCTION(this << "initKeyValue.size()" << initKeyValue.size() * 8);
593 NS_LOG_FUNCTION(this << "diffKey.size()" << diffKey.size() * 8);
594 NS_LOG_FUNCTION(this << "keyValue.size()" << keyValue.size() * 8 );
595 NS_LOG_FUNCTION(this << "incompleteChunkKey.size()" << incompleteChunkKey.size() * 8 );
596 NS_LOG_FUNCTION(this << "completeKey.size()" << completeKey.size() * 8);
597
598 if(key->GetState() == QKDKey::READY)
599 LogUpdate(diffKey.size() * 8, true);
600
602 startingInReady = true;
603 }else{
605 (m_stream_keys.rbegin()->second)->SetValue(completeKey); //Set the value of the key
606 LogUpdate(keyValue.size() * 8, true);
607 keyValue.clear();
608 startingIndex++; //Increase index
609 }
610
611 }else{
612
613 NS_LOG_FUNCTION(this << "startingInReady == TRUE");
614 uint32_t len; //len is in bytes
615 if(keyValue.size() >= GetKeySize()/8)
616 len = GetKeySize()/8;
617 else
618 len = keyValue.size();
619
620 std::string keyTemp {keyValue.substr(0, len)};
621 std::string temp {keyValue.substr(len)};
622 keyValue = temp;
623
626 startingIndex++; //Increase index
627
628 }
629 }
630
632 NS_LOG_FUNCTION( this << "Last index stored is " << m_currentStreamIndex );
633
634 }
635
638 {
639 NS_LOG_FUNCTION(this << m_stream_keys.size());
641 if(!m_stream_keys.empty()){
643 if( m_stream_keys.rbegin()->second->GetSizeInBits() != GetKeySize() )
645 }
646
647 return streamKeyCount;
648 }
649
656
659 {
660 NS_LOG_FUNCTION(this);
662 if(!m_stream_keys.empty())
663 nextIndex = m_stream_keys.begin()->first;
664
665 return nextIndex;
666 }
667
668 void
670 std::string keyId,
672 )
673 {
674 NS_LOG_FUNCTION(this << keyId << state);
675
676 auto it = m_keys.find(keyId);
677 if(it != m_keys.end())
678 {
679 NS_LOG_FUNCTION(this << "we found the key with id " << keyId << " and it was in state: " << it->second->GetStateString());
680 //Fire traces
681 if(it->second->GetState() == QKDKey::READY && state != QKDKey::READY)
682 {
684 m_notReadyBitCount += it->second->GetSizeInBits();
685 it->second->SwitchToState(state);
686 NS_LOG_FUNCTION(this << "1 Switching key with id " << keyId << " to NEW state: " << it->second->GetStateString());
687 LogUpdate(it->second->GetSizeInBits(), false);
688 }else if(it->second->GetState() != QKDKey::READY && state == QKDKey::READY){
689 NS_LOG_FUNCTION(this << "2 previous" << m_notReadyBitCount << m_notReadyKeyCount << it->second->GetSizeInBits() << "to READY 0 ");
690 if(m_notReadyBitCount < it->second->GetSizeInBits() || m_notReadyKeyCount == 0) NS_FATAL_ERROR(this << "to READY 0 - not ready");
692 m_notReadyBitCount -= it->second->GetSizeInBits();
693 it->second->SwitchToState(state);
694 NS_LOG_FUNCTION(this << "2 Switching key with id " << keyId << " to NEW state: " << it->second->GetStateString());
695 LogUpdate(it->second->GetSizeInBits(), true);
696 }else if(state == QKDKey::OBSOLETE){
697 NS_LOG_FUNCTION(this << "3 previous" << m_notReadyBitCount << m_notReadyKeyCount << it->second->GetSizeInBits() << "to OBSOLETE 0 ");
698 if(m_notReadyBitCount < it->second->GetSizeInBits() || m_notReadyKeyCount == 0) NS_FATAL_ERROR(this << "to OBSOLETE 0 - not ready");
700 m_notReadyBitCount -= it->second->GetSizeInBits();
701 GetKey(keyId);
702 }
703
704 NS_LOG_FUNCTION(this << "m_notReadyKeyCount:" << m_notReadyKeyCount << m_notReadyBitCount);
705 NS_LOG_FUNCTION(this << "m_notReadyBitCount:" << m_notReadyBitCount << m_notReadyBitCount);
706 }else
707 NS_FATAL_ERROR(this << "Key not found for marking!" << keyId << state);
708 }
709
710 void
712 {
713 NS_LOG_FUNCTION(this);
714 }
715
716 void
722
723 bool
725 {
726 NS_LOG_FUNCTION(this);
727 return m_relayActive;
728 }
729
730} // namespace ns3
virtual void DoInitialize()
Initialize() implementation.
Definition object.cc:440
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
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
uint32_t m_thresholdKeyBit
Definition q-buffer.h:443
uint32_t m_maxKeyBit
Definition q-buffer.h:439
uint32_t m_minKeyBit
Definition q-buffer.h:437
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
std::unordered_map< std::string, Ptr< QKDKey > > m_keys
key database
Definition q-buffer.h:383
void SetKeySize(uint32_t size)
Set default key size.
Definition q-buffer.cc:557
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
uint32_t m_dstKmNodeId
Definition q-buffer.h:375
uint32_t m_bitsUsedInTimePeriod
Help value used for detection of average key usage.
Definition q-buffer.h:418
virtual Ptr< QKDKey > GetKey(std::string keyID="", bool fireTraces=true)
get key from QBuffer
Definition q-buffer.cc:360
uint32_t m_defaultKeySize
Definition q-buffer.h:445
TracedCallback< uint32_t > m_currentKeyBitChangeTrace
Definition q-buffer.h:495
uint32_t GetKeyCount() const
get number of stored keys
Definition q-buffer.cc:279
void CheckState()
Update the state after some changes on the QBuffer.
Definition q-buffer.cc:429
virtual bool StoreKey(Ptr< QKDKey > key=nullptr, bool fireTraces=true)
store key in QBuffer
Definition q-buffer.cc:285
QKDKeyState_e
QKD Key States.
Definition qkd-key.h:65
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
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
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.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
static unsigned int value(char c)
uint32_t GetSize(Ptr< const Packet > packet, const WifiMacHeader *hdr, bool isAmpdu)
Return the total size of the packet after WifiMacHeader and FCS trailer have been added.