20 #include "ns3/packet.h"
21 #include "ns3/assert.h"
30 #include <cryptopp/base64.h>
44 .AddTraceSource (
"StateTransition",
45 "Trace fired upon every QKDKey state transition.",
47 "ns3::Application::StateTransitionCallback")
69 : m_sizeInBits (size),
80 m_random = CreateObject<UniformRandomVariable> ();
89 std::string keyBinary;
90 for (std::size_t i = 0; i < randomString.size(); ++i){
91 keyBinary += std::bitset<8>(randomString.c_str()[i]).to_string();
94 CryptoPP::StringSource(keyBinary,
true,
95 new CryptoPP::Base64Encoder(
96 new CryptoPP::StringSink(
m_key)
119 m_random = CreateObject<UniformRandomVariable> ();
149 m_random = CreateObject<UniformRandomVariable> ();
165 m_random = CreateObject<UniformRandomVariable> ();
181 std::string keyBinary;
182 for (std::size_t i = 0; i <
m_key.size(); ++i){
183 keyBinary += std::bitset<8>(
m_key.c_str()[i]).to_string();
220 if(sizeInBytes%8 != 0)
NS_FATAL_ERROR(
this <<
"Key size must divided with 8!" );
246 uint8_t* temp =
new uint8_t [
m_key.length()];
297 static const char alphanum[] =
299 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
300 "abcdefghijklmnopqrstuvwxyz";
302 uint32_t randVal = 0;
303 for (
int i = 0; i < len; ++i){
305 tmp_s += alphanum[ randVal ];
336 return "TRANSFORMED";
349 return "FATAL_ERROR";
371 <<
" --> " << newState <<
".");
A base class which provides memory management and object aggregation.
Smart pointer class similar to boost::intrusive_ptr.
The QKD key is an elementary class of QKDNetSim.
void MarkUsed()
Mark the key as used.
std::string GenerateRandomString(const int len)
Get a random string.
void SetId(std::string value)
Set the key identifier.
Time GetKeyTimestamp()
Get the key timestamp.
std::string GetId(void) const
Get the key identifier.
std::string GetKeyString(void)
Get QKD key value.
std::string GetKeyBinary()
Get key value in bit notation.
void MarkReady()
Mark the key as ready.
QKDKeyState_e
The QKD key states.
std::string ConsumeKeyString(void)
Get the key value and switch the key state to SERVED.
uint8_t * GetKey(void)
Get key value in byte* format.
QKDKeyState_e m_state
The key state.
uint64_t GetSizeInBits(void) const
Get the key size in bits.
void MarkRestored()
Mark the key as restored.
ns3::TracedCallback< const std::string &, const std::string & > m_stateTransitionTrace
The StateTransition trace source.
void SetSize(uint64_t sizeInBytes)
Set the key size.
void MarkServed()
Mark the key as served.
std::string GetStateString() const
Get the current state of the key in a string format.
Ptr< UniformRandomVariable > m_random
void SwitchToState(QKDKeyState_e state)
Change the state of the key.
void MarkReserved()
Mark the key as reserved.
static TypeId GetTypeId(void)
Get the TypeId.
Ptr< QKDKey > Copy(void) const
Copy the key.
QKDKey(uint64_t keySize)
Constructor.
std::string ToString(void)
Get the key value.
QKDKeyState_e GetState() const
Get the current state of the key.
uint64_t GetSize(void) const
Get the key size in bytes.
void MarkTransformed()
Mark the key as transformed.
static uint64_t m_globalUid
static Time Now(void)
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.