A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
qkd-kms-queue-logic.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 * Author: Miralem Mehic <miralem.mehic@ieee.org>
9 * Emir Dervisevic <emir.dervisevic@etf.unsa.ba>
10 */
11
12#include "ns3/log.h"
13#include "ns3/pointer.h"
14#include "ns3/object-factory.h"
15#include "ns3/drop-tail-queue.h"
16#include "qkd-kms-queue-logic.h"
17
18namespace ns3 {
19
20NS_LOG_COMPONENT_DEFINE("QKDKMSQueueLogic");
21
22NS_OBJECT_ENSURE_REGISTERED(QKDKMSQueueLogic);
23
25{
26 static TypeId tid = TypeId("ns3::QKDKMSQueueLogic")
29 .AddAttribute("MaxSize", "The maximum number of packets accepted by this queue disc.",
30 UintegerValue(10),
33 .AddAttribute("NumberOfQueues", "The number of priority queues used.",
37 .AddTraceSource("EnqueueKMS", "Enqueue a packet in the queue disc",
39 "ns3::QueueItem::TracedCallback")
40 .AddTraceSource("DequeueKMS", "Dequeue a packet from the queue disc",
42 "ns3::QueueItem::TracedCallback")
43 .AddTraceSource("DropKMS", "Drop a packet from the queue disc",
45 "ns3::QueueItem::TracedCallback")
46 .AddTraceSource("PacketsInQueue", "Number of packets currently stored in the queue disc",
48 "ns3::TracedValueCallback::Uint32")
49 ;
50 return tid;
51}
52
54{
55 NS_LOG_FUNCTION(this);
56
57 for(uint32_t i = 0; i < m_numberOfQueues; i++){
58 std::vector<QKDKMSQueueEntry> nv;
59 m_queues.push_back(nv);
60 }
61}
62
67
68bool
70{
72
74 {
75 m_traceDroped(item.httpMessage);
76 NS_LOG_LOGIC("Queue disc limit exceeded -- dropping packet");
77 return false;
78 }
79
80 std::string payload = item.httpMessage.GetMessageBodyString();
81 nlohmann::json jOpenConnectRequest;
82
83 try{
84 jOpenConnectRequest = nlohmann::json::parse(payload);
85 }catch(...) {
86 NS_FATAL_ERROR( this << "JSON parse error!" << payload );
87 }
88
89 uint32_t priority = 0;
90 if(jOpenConnectRequest.contains("QoS")) {
91 if(jOpenConnectRequest["QoS"].contains("priority")){
92 priority = jOpenConnectRequest["QoS"]["priority"];
93 }
94 }
95
96 if(priority > m_numberOfQueues || priority < 0){ //Primitive validation of priority value
97 priority = 0;
98 }
99
100 m_queues[priority].push_back(item);
101 m_traceEnqueue(item.httpMessage);
102 m_nPackets++;
103
104 for(uint32_t i = 0; i < m_numberOfQueues; i++){
105 NS_LOG_LOGIC("Number of packets in queue " << i << ": " << m_queues[i].size() );
106 }
107
108 return true;
109}
110
113{
115
117 for(uint32_t i = 0; i < m_numberOfQueues; i++)
118 {
119 if(m_queues[i].size() > 0)
120 {
121 item = m_queues[i].back();
122 m_queues[i].pop_back();
123 m_traceDequeue(item.httpMessage);
124 m_nPackets--;
125 NS_LOG_LOGIC("Popped from queue " << i);
126 NS_LOG_LOGIC("Number of packets in queue " << i << ": " << m_queues[i].size());
127 return item;
128 }
129 }
130
131 NS_LOG_LOGIC("Queue empty");
132 return item;
133}
134
135} // namespace ns3
A base class which provides memory management and object aggregation.
Definition object.h:78
QKDKMSQueueLogic()
QKDKMSQueueLogic constructor.
TracedCallback< const HTTPMessage > m_traceDequeue
Traced callback: fired when a packet is dequeued.
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
TracedCallback< const HTTPMessage > m_traceDroped
Traced callback: fired when a packet is dropped.
bool Enqueue(QKDKMSQueueEntry item)
QKDKMSQueueLogic::QKDKMSQueueEntry Dequeue()
std::vector< std::vector< QKDKMSQueueEntry > > m_queues
static TypeId GetTypeId()
Get the type ID.
TracedCallback< const HTTPMessage > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
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_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.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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
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.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35