A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
app-key-stream.h
Go to the documentation of this file.
1
/*
2
* Copyright(c) 2020 DOTFEESA www.tk.etf.unsa.ba
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
*
7
*
8
* Author: Emir Dervisevic <emir.dervisevic@etf.unsa.ba>
9
* Miralem Mehic <miralem.mehic@ieee.org>
10
*/
11
#ifndef KEY_STREAM_H
12
#define KEY_STREAM_H
13
14
#include <stdint.h>
15
#include <algorithm>
16
#include <stdint.h>
17
#include <
string.h
>
18
19
#include "ns3/packet.h"
20
#include "ns3/object.h"
21
#include "ns3/callback.h"
22
#include "ns3/assert.h"
23
#include "ns3/ptr.h"
24
#include "ns3/simulator.h"
25
#include "ns3/nstime.h"
26
#include "ns3/traced-callback.h"
27
#include "ns3/deprecated.h"
28
#include "
qkd-key.h
"
29
#include "
app-key.h
"
30
31
32
namespace
ns3
{
33
34
/**
35
* @ingroup qkd
36
* @brief key stream session
37
*/
38
class
KeyStreamSession
:
public
Object
{
39
public
:
40
41
enum
Type
42
{
43
EMPTY
,
44
ENCRYPTION
,
45
AUTHENTICATION
46
};
47
48
KeyStreamSession
() :
m_id
(
""
),
m_type
(
Type
::
ENCRYPTION
),
m_size
(0),
m_verified
(
false
),
m_stream
({}) {}
49
50
void
SetId
(std::string ksid) {
51
m_id
= ksid;
52
}
53
54
std::string
GetId
()
const
{
55
return
m_id
;
56
}
57
58
void
SetVerified
(
bool
isVerified
) {
59
m_verified
=
isVerified
;
60
}
61
62
bool
IsVerified
()
const
{
63
return
m_verified
;
64
}
65
66
void
AddKey
(
Ptr<AppKey>
key) {
67
m_stream
.insert(std::make_pair(key->GetIndex(), key));
68
}
69
70
Ptr<AppKey>
GetKey
(
uint32_t
packetSize
= 0) {
71
Ptr<AppKey>
key;
72
auto
it
{
m_stream
.begin()};
73
if
(
it
!=
m_stream
.end()) {
74
key =
it
->second;
75
if
(
GetType
() ==
ENCRYPTION
){
76
it
->second->UseLifetime(
packetSize
);
77
if
(
it
->second->GetLifetime() == 0)
78
m_stream
.erase(
it
);
79
}
else
{
80
m_stream
.erase(
it
);
81
}
82
}
83
84
return
key;
85
}
86
87
uint32_t
GetKeyCount
()
const
{
88
return
m_stream
.size();
89
}
90
91
void
SetSize
(
uint32_t
size) {
92
m_size
= size;
93
}
94
95
uint32_t
GetSize
()
const
{
96
return
m_size
;
97
}
98
99
bool
SyncStream
(
uint32_t
index) {
100
auto
it
=
m_stream
.find(index);
101
bool
inSync
{
m_stream
.begin() ==
it
};
102
if
(
it
!=
m_stream
.end()){
103
while
(
m_stream
.begin() !=
it
)
104
m_stream
.erase(
m_stream
.begin());
105
}
106
107
return
inSync
;
108
}
109
110
void
SetType
(
Type
type) {
111
m_type
= type;
112
}
113
114
Type
GetType
()
const
{
115
return
m_type
;
116
}
117
118
void
ClearStream
() {
119
m_id
.clear();
120
m_stream
.clear();
121
m_verified
=
false
;
122
}
123
124
125
private
:
126
127
std::string
m_id
;
128
Type
m_type
;
//<!Session type
129
uint32_t
m_size
;
//<!Key stream size at the application layer
130
bool
m_verified
;
//<!Is verified
131
std::map<uint32_t, Ptr<AppKey> >
m_stream
;
//<!Key streamW
132
133
};
134
135
}
// namespace ns3
136
137
#endif
/* KEY_STREAM_H */
app-key.h
ns3::KeyStreamSession
key stream session
Definition
app-key-stream.h:38
ns3::KeyStreamSession::m_verified
bool m_verified
Definition
app-key-stream.h:130
ns3::KeyStreamSession::GetKeyCount
uint32_t GetKeyCount() const
Definition
app-key-stream.h:87
ns3::KeyStreamSession::SetType
void SetType(Type type)
Definition
app-key-stream.h:110
ns3::KeyStreamSession::SetId
void SetId(std::string ksid)
Definition
app-key-stream.h:50
ns3::KeyStreamSession::KeyStreamSession
KeyStreamSession()
Definition
app-key-stream.h:48
ns3::KeyStreamSession::SetSize
void SetSize(uint32_t size)
Definition
app-key-stream.h:91
ns3::KeyStreamSession::SetVerified
void SetVerified(bool isVerified)
Definition
app-key-stream.h:58
ns3::KeyStreamSession::Type
Type
Definition
app-key-stream.h:42
ns3::KeyStreamSession::AUTHENTICATION
@ AUTHENTICATION
Definition
app-key-stream.h:45
ns3::KeyStreamSession::ENCRYPTION
@ ENCRYPTION
Definition
app-key-stream.h:44
ns3::KeyStreamSession::EMPTY
@ EMPTY
Definition
app-key-stream.h:43
ns3::KeyStreamSession::GetId
std::string GetId() const
Definition
app-key-stream.h:54
ns3::KeyStreamSession::GetSize
uint32_t GetSize() const
Definition
app-key-stream.h:95
ns3::KeyStreamSession::m_type
Type m_type
Definition
app-key-stream.h:128
ns3::KeyStreamSession::SyncStream
bool SyncStream(uint32_t index)
Definition
app-key-stream.h:99
ns3::KeyStreamSession::AddKey
void AddKey(Ptr< AppKey > key)
Definition
app-key-stream.h:66
ns3::KeyStreamSession::m_id
std::string m_id
Definition
app-key-stream.h:127
ns3::KeyStreamSession::IsVerified
bool IsVerified() const
Definition
app-key-stream.h:62
ns3::KeyStreamSession::m_stream
std::map< uint32_t, Ptr< AppKey > > m_stream
Definition
app-key-stream.h:131
ns3::KeyStreamSession::m_size
uint32_t m_size
Definition
app-key-stream.h:129
ns3::KeyStreamSession::GetType
Type GetType() const
Definition
app-key-stream.h:114
ns3::KeyStreamSession::GetKey
Ptr< AppKey > GetKey(uint32_t packetSize=0)
Definition
app-key-stream.h:70
ns3::KeyStreamSession::ClearStream
void ClearStream()
Definition
app-key-stream.h:118
ns3::Object
A base class which provides memory management and object aggregation.
Definition
object.h:78
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
uint32_t
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
qkd-key.h
string.h
ns3::StringValue attribute value declarations.
packetSize
static const uint32_t packetSize
Packet size generated at the AP.
Definition
wifi-power-adaptation-distance.cc:100
src
qkd
model
app-key-stream.h
Generated on Mon Dec 15 2025 15:22:03 for ns-3 by
1.9.8