16#include "ns3/packet.h"
17#include "ns3/simulator.h"
19#include "ns3/boolean.h"
20#include "ns3/double.h"
21#include "ns3/uinteger.h"
37 .AddAttribute(
"SMinimal",
38 "The minimal amount of key material in Sbuffer (bits)",
42 .AddAttribute(
"SMaximal",
43 "The maximal amount of key material in Sbuffer (bits)",
47 .AddAttribute(
"SThreshold",
48 "The threshold amount of key material in Sbuffer (bits)",
52 .AddAttribute(
"SDefaultKeySize",
53 "The default key size of Sbuffer",
195 <<
"\nKey ID:\t" << key->GetId()
196 <<
"\nKey Size:\t" << key->GetSizeInBits()
197 <<
"\nKey State:\t" << key->GetStateString()
198 <<
"\nKey Value:\t" << key->ToString()
251 NS_LOG_FUNCTION(
this <<
"id:" <<
it->second->GetId() <<
"\t size:" <<
it->second->GetSizeInBits());
262 NS_LOG_FUNCTION(
this <<
"id:" <<
it->second->GetId() <<
"\t size:" <<
it->second->GetSizeInBits());
273 NS_LOG_FUNCTION(
this <<
"id:" <<
it->second->GetId() <<
"\t size:" <<
it->second->GetSizeInBits());
299 NS_LOG_DEBUG(
"Not enough keys in SBuffer to select a transform candidate");
311 NS_LOG_FUNCTION(
this <<
"id:" <<
it->second->GetId() <<
"\t size:" <<
it->second->GetSizeInBits());
344 NS_LOG_FUNCTION(
this <<
"id:" <<
it->second->GetId() <<
"\t size:" <<
it->second->GetSizeInBits());
352 for (
const auto& [
id, key] :
m_keys)
362 if (key->GetSizeInBits() >= size) {
398 value.erase(0, size/8);
405 NS_LOG_FUNCTION(
this << key->GetId() <<
" of size " << key->GetSizeInBits()<<
" bits is reduced to size " << key->GetSizeInBits() <<
" bits");
410 NS_LOG_FUNCTION(
this <<
"Update graphs to include details about key reduction!");
425 if(
it->second->GetSizeInBits() > size)
429 std::string
value =
it->second->GetKeyString();
431 value.erase(0, size/8);
438 NS_LOG_FUNCTION(
this << key->GetId() <<
" of size " << key->GetSizeInBits()<<
" bits is reduced to size " << key->GetSizeInBits() <<
" bits");
442 NS_LOG_FUNCTION(
this <<
"Update graphs to include details about key reduction!");
447 }
else if(
it->second->GetSizeInBits() == size){
465 if(
it->second->GetSizeInBits() == size &&
it->second->GetState() ==
QKDKey::READY){
494 m_stream_keys.insert(std::make_pair(std::stoi(key->GetId()), key));
549 <<
"\nKey ID:\t" << key->GetId()
550 <<
"\nKey Size:\t" << key->GetSizeInBits()
551 <<
"\nKey State:\t" << key->GetStateString()
552 <<
"\nKey Value:\t" << key->ToString()
564 <<
"\nLast key value:" <<
m_stream_keys.rbegin()->second->GetKeyString()
574 std::string
keyValue = key->GetKeyString();
679 NS_LOG_FUNCTION(
this <<
"we found the key with id " <<
keyId <<
" and it was in state: " <<
it->second->GetStateString());
685 it->second->SwitchToState(state);
686 NS_LOG_FUNCTION(
this <<
"1 Switching key with id " <<
keyId <<
" to NEW state: " <<
it->second->GetStateString());
693 it->second->SwitchToState(state);
694 NS_LOG_FUNCTION(
this <<
"2 Switching key with id " <<
keyId <<
" to NEW state: " <<
it->second->GetStateString());
virtual void DoInitialize()
Initialize() implementation.
Smart pointer class similar to boost::intrusive_ptr.
Qbuffer is a secure storage for QKD keys.
virtual void Configure(uint32_t Mmin, uint32_t Mthr, uint32_t Mmax, uint32_t Mcurrent, uint32_t defaultKeySize)
create QKD buffer configuration
uint32_t m_thresholdKeyBit
void Init(uint32_t dstKmNodeId, uint32_t Mmin, uint32_t Mthr, uint32_t Mmax, uint32_t Mcurrent, uint32_t defaultKeySize)
initialize QBuffer
std::unordered_map< std::string, Ptr< QKDKey > > m_keys
key database
void SetKeySize(uint32_t size)
Set default key size.
uint32_t GetKeySize() const
Get default size of keys stored in QBuffer.
uint32_t m_currentKeyBit
The current amount of key material in QKD key storage.
uint32_t m_bitsUsedInTimePeriod
Help value used for detection of average key usage.
virtual Ptr< QKDKey > GetKey(std::string keyID="", bool fireTraces=true)
get key from QBuffer
uint32_t m_defaultKeySize
TracedCallback< uint32_t > m_currentKeyBitChangeTrace
uint32_t GetKeyCount() const
get number of stored keys
void CheckState()
Update the state after some changes on the QBuffer.
virtual bool StoreKey(Ptr< QKDKey > key=nullptr, bool fireTraces=true)
store key in QBuffer
QKDKeyState_e
QKD Key States.
uint32_t m_currentStreamIndex
The last index when the S-Buffer is used for key stream sessions.
virtual void DoInitialize() override
Initialize() implementation.
void SetKeyLifetime(std::string keyId)
Assign a lifetime to a key.
uint32_t GetStreamIndex()
Ptr< QKDKey > GetHalfKey(std::string keyId, uint32_t size)
Get portion of key.
uint32_t m_minKeyBitSBufferDefault
Ptr< QKDKey > GetKey(uint32_t size)
Get key with given size.
void MarkKey(std::string keyId, QKDKey::QKDKeyState_e state)
Mark key.
std::map< std::string, Ptr< QKDKey > > m_supply_keys
Created keys which are ready for supply to crypto applications.
std::map< uint32_t, Ptr< QKDKey > > m_stream_keys
Key stream session.
void LogUpdate(uint32_t diffValue, bool positive) override
Log key consumption.
uint32_t GetSBitCount()
Get servable bit count.
uint32_t GetBitCount() const override
get amount of stored key material in bits
void StoreSupplyKey(Ptr< QKDKey > key)
Store supply key.
SBuffer()
QBuffer constructor.
Ptr< QKDKey > GetStreamKey()
Returns key chunk with lowest index.
Ptr< QKDKey > GetTransformCandidate(uint32_t size)
Get key candidate.
void SetType(Type type)
Set s-buffer type.
uint32_t GetStreamKeyCount()
uint32_t m_thresholdKeyBitSBufferDefault
Ptr< QKDKey > GetSupplyKey(std::string keyId)
Get supply key.
uint32_t m_notReadyBitCount
Amount of key material stored that are not in READY state.
uint32_t m_maxKeyBitSBufferDefault
Type GetType()
Get s-buffer type.
bool m_relayActive
The state of S-Buffer will not trigger relay if relay is active.
void SetRelayState(bool relayActive)
uint32_t m_notReadyKeyCount
Number of keys stored which are not in READY state.
SBuffer::Type m_type
S-Buffer type.
uint32_t m_defaultKeySizeSBufferDefault
uint32_t GetSKeyCount()
Get servable key count.
~SBuffer() override
QBuffer destructor.
void InsertKeyToStreamSession(Ptr< QKDKey > key)
Insert key to key stream session.
static TypeId GetTypeId()
Get the TypeId.
uint32_t GetDefaultKeyCount(uint32_t number=0)
Get number of keys that are in default size.
bool StoreKey(Ptr< QKDKey > key)
store key in SBuffer
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#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.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#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.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
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.