-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpid-queue-disc.h
137 lines (112 loc) · 5.62 KB
/
pid-queue-disc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) October 2021 : R. Olusegun Alli-Oke
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: R. Olusegun Alli-Oke <[email protected]>, <[email protected]>
*/
#ifndef PID_QUEUE_DISC_H
#define PID_QUEUE_DISC_H
#include "ns3/queue-disc.h"
#include "ns3/nstime.h"
#include "ns3/boolean.h"
#include "ns3/data-rate.h"
#include "ns3/timer.h"
#include "ns3/event-id.h"
#include "ns3/random-variable-stream.h"
namespace ns3 {
class TraceContainer;
class UniformRandomVariable;
/**
* \ingroup traffic-control
*
* \brief Implements Pid Active Queue Management discipline
*/
class PidQueueDisc : public QueueDisc
{
public:
/**
* \brief Get the type ID.
* \return the object TypeId
*/
static TypeId GetTypeId (void);
/**
* \brief PidQueueDisc Constructor
*/
PidQueueDisc ();
/**
* \brief PidQueueDisc Destructor
*/
virtual ~PidQueueDisc ();
// Reasons for dropping packets
static constexpr const char* UNFORCED_DROP = "Unforced drop"; //!< Early probability drops: proactive
static constexpr const char* FORCED_DROP = "Forced drop"; //!< Drops due to queue limit: reactive
protected:
/**
* \brief Dispose of the object
*/
virtual void DoDispose (void);
private:
// ** Variables supplied by user
Time m_sUpdate; //!< Start time to use CalculateP () method to compute drop ratio
Time m_tUpdate; //!< compute drop probability every m_tUpdate secs (i.e. 1/m_tUpdate is the sampling frequency of discrete PID controller)
Time m_sStep; //!< start step-change to desired queue-length from linearation equilibrium queue-length
QueueSize m_queueLimit; //!< maximum queue-size of qdisc (internal) queue
QueueSize m_QsizeRef; //!< variable for storing m_QsizeRefEQ or m_QsizeRefDQ
QueueSize m_QsizeRefEQ; //!< Linearization equilibrium queue size
QueueSize m_QsizeRefDQ; //!< Desired set-point reference queue size
double m_a; //!< a parameter to PID difference-equation controller
double m_b; //!< b parameter to PID difference-equation controller
double m_c; //!< c parameter to PID difference-equation controller
double m_d; //!< d parameter to PID difference-equation controller
double m_e; //!< e parameter to PID difference-equation controller
double m_u0; //!< Linearization equilbrium packet-loss ratio
// ** Variables maintained by PID
QueueSize m_Qsize; //!< current value of external queue size
double m_dropProb; //!< Variable used in calculation of drop probability
double m_dropProb0; //!< current-step current value of of drop probability
double m_dropProb1; //!< 1-step previous value of drop probability
double m_dropProb2; //!< 2-step previous value of drop probability
double m_ErrQsize0; //!< current-step current value of queue-size error
double m_ErrQsize1; //!< 1-step previous value of queue-size error
double m_ErrQsize2; //!< 2-step previous value of queue-size error
EventId m_rtrsEvent1; //!< Event used to start (periodioc) computation of drop probability
EventId m_rtrsEvent2; //!< Event used to repeatedly-schedule (periodioc) computation of drop probability
Ptr<UniformRandomVariable> m_uv; //!< Rng stream, random variable for comparison with computed drop probability
/**
* \brief Check if a packet needs to be dropped due to probability drop
* \param item queue item
* \param qSize queue size
* \returns 0 for no drop, 1 for drop
*/
bool DropEarly (Ptr<QueueDiscItem> item);
/**
* Periodically update the drop probability based on the delay samples:
* not only the current delay sample but also the trend where the delay
* is going, up or down
*/
void CalculateP ();
virtual bool CheckConfig (void);
/**
* \brief Initialize the queue parameters.
*/
virtual void InitializeParams (void);
virtual Ptr<QueueDiscItem> DoDequeue (void);
virtual bool DoEnqueue (Ptr<QueueDiscItem> item);
virtual void QSizeRefUpdate ();
virtual void PWMUpdate ();
};
}; // namespace ns3
#endif