A Discrete-Event Network Simulator
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
32namespace ns3 {
33
34/**
35 * @ingroup qkd
36 * @brief key stream session
37 */
38 class KeyStreamSession : public Object {
39 public:
40
47
49
50 void SetId(std::string ksid) {
51 m_id = ksid;
52 }
53
54 std::string GetId() const {
55 return m_id;
56 }
57
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
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
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 */
key stream session
uint32_t GetKeyCount() const
void SetType(Type type)
void SetId(std::string ksid)
void SetSize(uint32_t size)
void SetVerified(bool isVerified)
std::string GetId() const
uint32_t GetSize() const
bool SyncStream(uint32_t index)
void AddKey(Ptr< AppKey > key)
std::map< uint32_t, Ptr< AppKey > > m_stream
Ptr< AppKey > GetKey(uint32_t packetSize=0)
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
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.
ns3::StringValue attribute value declarations.
static const uint32_t packetSize
Packet size generated at the AP.