A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
red-queue-disc.h
Go to the documentation of this file.
1/*
2 * Copyright © 2011 Marcos Talau
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Marcos Talau (talau@users.sourceforge.net)
18 *
19 * Thanks to: Duy Nguyen<duy@soe.ucsc.edu> by RED efforts in NS3
20 *
21 *
22 * This file incorporates work covered by the following copyright and
23 * permission notice:
24 *
25 * Copyright (c) 1990-1997 Regents of the University of California.
26 * All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. Neither the name of the University nor of the Laboratory may be used
37 * to endorse or promote products derived from this software without
38 * specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
51 */
52
53/*
54 * PORT NOTE: This code was ported from ns-2 (queue/red.h). Almost all
55 * comments also been ported from NS-2.
56 * This implementation aims to be close to the results cited in [0]
57 * [0] S.Floyd, K.Fall http://icir.org/floyd/papers/redsims.ps
58 */
59
60#ifndef RED_QUEUE_DISC_H
61#define RED_QUEUE_DISC_H
62
63#include "queue-disc.h"
64
65#include "ns3/boolean.h"
66#include "ns3/data-rate.h"
67#include "ns3/nstime.h"
68#include "ns3/random-variable-stream.h"
69
70namespace ns3
71{
72
73class TraceContainer;
74
75/**
76 * \ingroup traffic-control
77 *
78 * \brief A RED packet queue disc
79 */
80class RedQueueDisc : public QueueDisc
81{
82 public:
83 /**
84 * \brief Get the type ID.
85 * \return the object TypeId
86 */
87 static TypeId GetTypeId();
88 /**
89 * \brief RedQueueDisc Constructor
90 *
91 * Create a RED queue disc
92 */
94
95 /**
96 * \brief Destructor
97 *
98 * Destructor
99 */
100 ~RedQueueDisc() override;
101
102 /**
103 * \brief Used in Feng's Adaptive RED
104 */
106 {
107 Above, //!< When m_qAvg > m_maxTh
108 Between, //!< When m_maxTh < m_qAvg < m_minTh
109 Below, //!< When m_qAvg < m_minTh
110 };
111
112 /**
113 * \brief Drop types
114 */
115 enum
116 {
117 DTYPE_NONE, //!< Ok, no drop
118 DTYPE_FORCED, //!< A "forced" drop
119 DTYPE_UNFORCED, //!< An "unforced" (random) drop
120 };
121
122 /**
123 * \brief Set the alpha value to adapt m_curMaxP.
124 *
125 * \param alpha The value of alpha to adapt m_curMaxP.
126 */
127 void SetAredAlpha(double alpha);
128
129 /**
130 * \brief Get the alpha value to adapt m_curMaxP.
131 *
132 * \returns The alpha value to adapt m_curMaxP.
133 */
134 double GetAredAlpha();
135
136 /**
137 * \brief Set the beta value to adapt m_curMaxP.
138 *
139 * \param beta The value of beta to adapt m_curMaxP.
140 */
141 void SetAredBeta(double beta);
142
143 /**
144 * \brief Get the beta value to adapt m_curMaxP.
145 *
146 * \returns The beta value to adapt m_curMaxP.
147 */
148 double GetAredBeta();
149
150 /**
151 * \brief Set the alpha value to adapt m_curMaxP in Feng's Adaptive RED.
152 *
153 * \param a The value of alpha to adapt m_curMaxP in Feng's Adaptive RED.
154 */
155 void SetFengAdaptiveA(double a);
156
157 /**
158 * \brief Get the alpha value to adapt m_curMaxP in Feng's Adaptive RED.
159 *
160 * \returns The alpha value to adapt m_curMaxP in Feng's Adaptive RED.
161 */
162 double GetFengAdaptiveA();
163
164 /**
165 * \brief Set the beta value to adapt m_curMaxP in Feng's Adaptive RED.
166 *
167 * \param b The value of beta to adapt m_curMaxP in Feng's Adaptive RED.
168 */
169 void SetFengAdaptiveB(double b);
170
171 /**
172 * \brief Get the beta value to adapt m_curMaxP in Feng's Adaptive RED.
173 *
174 * \returns The beta value to adapt m_curMaxP in Feng's Adaptive RED.
175 */
176 double GetFengAdaptiveB();
177
178 /**
179 * \brief Set the thresh limits of RED.
180 *
181 * \param minTh Minimum thresh in bytes or packets.
182 * \param maxTh Maximum thresh in bytes or packets.
183 */
184 void SetTh(double minTh, double maxTh);
185
186 /**
187 * Assign a fixed random variable stream number to the random variables
188 * used by this model. Return the number of streams (possibly zero) that
189 * have been assigned.
190 *
191 * \param stream first stream index to use
192 * \return the number of stream indices assigned by this model
193 */
194 int64_t AssignStreams(int64_t stream);
195
196 // Reasons for dropping packets
197 static constexpr const char* UNFORCED_DROP = "Unforced drop"; //!< Early probability drops
198 static constexpr const char* FORCED_DROP = "Forced drop"; //!< Forced drops, m_qAvg > m_maxTh
199 // Reasons for marking packets
200 static constexpr const char* UNFORCED_MARK = "Unforced mark"; //!< Early probability marks
201 static constexpr const char* FORCED_MARK = "Forced mark"; //!< Forced marks, m_qAvg > m_maxTh
202
203 protected:
204 /**
205 * \brief Dispose of the object
206 */
207 void DoDispose() override;
208
209 private:
210 bool DoEnqueue(Ptr<QueueDiscItem> item) override;
211 Ptr<QueueDiscItem> DoDequeue() override;
213 bool CheckConfig() override;
214
215 /**
216 * \brief Initialize the queue parameters.
217 *
218 * Note: if the link bandwidth changes in the course of the
219 * simulation, the bandwidth-dependent RED parameters do not change.
220 * This should be fixed, but it would require some extra parameters,
221 * and didn't seem worth the trouble...
222 */
223 void InitializeParams() override;
224 /**
225 * \brief Compute the average queue size
226 * \param nQueued number of queued packets
227 * \param m simulated number of packets arrival during idle period
228 * \param qAvg average queue size
229 * \param qW queue weight given to cur q size sample
230 * \returns new average queue size
231 */
232 double Estimator(uint32_t nQueued, uint32_t m, double qAvg, double qW);
233 /**
234 * \brief Update m_curMaxP
235 * \param newAve new average queue length
236 */
237 void UpdateMaxP(double newAve);
238 /**
239 * \brief Update m_curMaxP based on Feng's Adaptive RED
240 * \param newAve new average queue length
241 */
242 void UpdateMaxPFeng(double newAve);
243 /**
244 * \brief Check if a packet needs to be dropped due to probability mark
245 * \param item queue item
246 * \param qSize queue size
247 * \returns false for no drop/mark, true for drop
248 */
249 bool DropEarly(Ptr<QueueDiscItem> item, uint32_t qSize);
250 /**
251 * \brief Returns a probability using these function parameters for the DropEarly function
252 * \returns Prob. of packet drop before "count"
253 */
254 double CalculatePNew();
255 /**
256 * \brief Returns a probability using these function parameters for the DropEarly function
257 * \param p Prob. of packet drop before "count"
258 * \param size packet size
259 * \returns Prob. of packet drop
260 */
261 double ModifyP(double p, uint32_t size);
262
263 // ** Variables supplied by user
264 uint32_t m_meanPktSize; //!< Avg pkt size
265 uint32_t m_idlePktSize; //!< Avg pkt size used during idle times
266 bool m_isWait; //!< True for waiting between dropped packets
267 bool m_isGentle; //!< True to increase dropping prob. slowly when m_qAvg exceeds m_maxTh
268 bool m_isARED; //!< True to enable Adaptive RED
269 bool m_isAdaptMaxP; //!< True to adapt m_curMaxP
270 double m_minTh; //!< Minimum threshold for m_qAvg (bytes or packets)
271 double m_maxTh; //!< Maximum threshold for m_qAvg (bytes or packets), should be >= 2 * m_minTh
272 double m_qW; //!< Queue weight given to cur queue size sample
273 double m_lInterm; //!< The max probability of dropping a packet
274 Time m_targetDelay; //!< Target average queuing delay in ARED
275 Time m_interval; //!< Time interval to update m_curMaxP
276 double m_top; //!< Upper bound for m_curMaxP in ARED
277 double m_bottom; //!< Lower bound for m_curMaxP in ARED
278 double m_alpha; //!< Increment parameter for m_curMaxP in ARED
279 double m_beta; //!< Decrement parameter for m_curMaxP in ARED
280 Time m_rtt; //!< Rtt to be considered while automatically setting m_bottom in ARED
281 bool m_isFengAdaptive; //!< True to enable Feng's Adaptive RED
282 bool m_isNonlinear; //!< True to enable Nonlinear RED
283 double m_b; //!< Increment parameter for m_curMaxP in Feng's Adaptive RED
284 double m_a; //!< Decrement parameter for m_curMaxP in Feng's Adaptive RED
285 bool m_isNs1Compat; //!< Ns-1 compatibility
286 DataRate m_linkBandwidth; //!< Link bandwidth
287 Time m_linkDelay; //!< Link delay
288 bool m_useEcn; //!< True if ECN is used (packets are marked instead of being dropped)
289 bool m_useHardDrop; //!< True if packets are always dropped above max threshold
290
291 // ** Variables maintained by RED
292 double m_vA; //!< 1.0 / (m_maxTh - m_minTh)
293 double m_vB; //!< -m_minTh / (m_maxTh - m_minTh)
294 double m_vC; //!< (1.0 - m_curMaxP) / m_maxTh - used in "gentle" mode
295 double m_vD; //!< 2.0 * m_curMaxP - 1.0 - used in "gentle" mode
296 double m_curMaxP; //!< Current max_p
297 Time m_lastSet; //!< Last time m_curMaxP was updated
298 double m_vProb; //!< Prob. of packet drop
299 uint32_t m_countBytes; //!< Number of bytes since last drop
300 uint32_t m_old; //!< 0 when average queue first exceeds threshold
301 uint32_t m_idle; //!< 0/1 idle status
302 double m_ptc; //!< packet time constant in packets/second
303 double m_qAvg; //!< Average queue length
304 uint32_t m_count; //!< Number of packets since last random number generation
305 FengStatus m_fengStatus; //!< For use in Feng's Adaptive RED
306 /**
307 * 0 for default RED
308 * 1 experimental (see red-queue-disc.cc)
309 * 2 experimental (see red-queue-disc.cc)
310 * 3 use Idle packet size in the ptc
311 */
313 Time m_idleTime; //!< Start of current idle period
314
316};
317
318}; // namespace ns3
319
320#endif // RED_QUEUE_DISC_H
Class for representing data rates.
Definition: data-rate.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:184
A RED packet queue disc.
Time m_idleTime
Start of current idle period.
Time m_linkDelay
Link delay.
RedQueueDisc()
RedQueueDisc Constructor.
void UpdateMaxPFeng(double newAve)
Update m_curMaxP based on Feng's Adaptive RED.
DataRate m_linkBandwidth
Link bandwidth.
double m_vA
1.0 / (m_maxTh - m_minTh)
void SetFengAdaptiveB(double b)
Set the beta value to adapt m_curMaxP in Feng's Adaptive RED.
Time m_rtt
Rtt to be considered while automatically setting m_bottom in ARED.
static constexpr const char * FORCED_DROP
Forced drops, m_qAvg > m_maxTh.
FengStatus
Used in Feng's Adaptive RED.
@ Above
When m_qAvg > m_maxTh.
@ Between
When m_maxTh < m_qAvg < m_minTh.
@ Below
When m_qAvg < m_minTh.
static constexpr const char * UNFORCED_DROP
Early probability drops.
bool DoEnqueue(Ptr< QueueDiscItem > item) override
This function actually enqueues a packet into the queue disc.
double GetAredAlpha()
Get the alpha value to adapt m_curMaxP.
double ModifyP(double p, uint32_t size)
Returns a probability using these function parameters for the DropEarly function.
double m_a
Decrement parameter for m_curMaxP in Feng's Adaptive RED.
double GetFengAdaptiveB()
Get the beta value to adapt m_curMaxP in Feng's Adaptive RED.
void SetAredBeta(double beta)
Set the beta value to adapt m_curMaxP.
bool m_isAdaptMaxP
True to adapt m_curMaxP.
void SetTh(double minTh, double maxTh)
Set the thresh limits of RED.
uint32_t m_cautious
0 for default RED 1 experimental (see red-queue-disc.cc) 2 experimental (see red-queue-disc....
double m_alpha
Increment parameter for m_curMaxP in ARED.
bool m_isARED
True to enable Adaptive RED.
Time m_interval
Time interval to update m_curMaxP.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
bool CheckConfig() override
Check whether the current configuration is correct.
FengStatus m_fengStatus
For use in Feng's Adaptive RED.
bool m_useHardDrop
True if packets are always dropped above max threshold.
static constexpr const char * UNFORCED_MARK
Early probability marks.
double GetAredBeta()
Get the beta value to adapt m_curMaxP.
uint32_t m_old
0 when average queue first exceeds threshold
void SetFengAdaptiveA(double a)
Set the alpha value to adapt m_curMaxP in Feng's Adaptive RED.
Ptr< QueueDiscItem > DoDequeue() override
This function actually extracts a packet from the queue disc.
bool m_isWait
True for waiting between dropped packets.
bool m_useEcn
True if ECN is used (packets are marked instead of being dropped)
double m_maxTh
Maximum threshold for m_qAvg (bytes or packets), should be >= 2 * m_minTh.
static constexpr const char * FORCED_MARK
Forced marks, m_qAvg > m_maxTh.
bool m_isNonlinear
True to enable Nonlinear RED.
double m_minTh
Minimum threshold for m_qAvg (bytes or packets)
double m_top
Upper bound for m_curMaxP in ARED.
uint32_t m_meanPktSize
Avg pkt size.
double m_beta
Decrement parameter for m_curMaxP in ARED.
double m_lInterm
The max probability of dropping a packet.
uint32_t m_countBytes
Number of bytes since last drop.
void SetAredAlpha(double alpha)
Set the alpha value to adapt m_curMaxP.
bool m_isNs1Compat
Ns-1 compatibility.
double Estimator(uint32_t nQueued, uint32_t m, double qAvg, double qW)
Compute the average queue size.
double m_vB
-m_minTh / (m_maxTh - m_minTh)
double m_b
Increment parameter for m_curMaxP in Feng's Adaptive RED.
double m_bottom
Lower bound for m_curMaxP in ARED.
Time m_lastSet
Last time m_curMaxP was updated.
Time m_targetDelay
Target average queuing delay in ARED.
double m_ptc
packet time constant in packets/second
double m_vProb
Prob.
void InitializeParams() override
Initialize the queue parameters.
double CalculatePNew()
Returns a probability using these function parameters for the DropEarly function.
void UpdateMaxP(double newAve)
Update m_curMaxP.
bool m_isFengAdaptive
True to enable Feng's Adaptive RED.
static TypeId GetTypeId()
Get the type ID.
uint32_t m_count
Number of packets since last random number generation.
void DoDispose() override
Dispose of the object.
bool DropEarly(Ptr< QueueDiscItem > item, uint32_t qSize)
Check if a packet needs to be dropped due to probability mark.
Ptr< const QueueDiscItem > DoPeek() override
Return a copy of the next packet the queue disc will extract.
uint32_t m_idle
0/1 idle status
Ptr< UniformRandomVariable > m_uv
rng stream
double GetFengAdaptiveA()
Get the alpha value to adapt m_curMaxP in Feng's Adaptive RED.
~RedQueueDisc() override
Destructor.
double m_vD
2.0 * m_curMaxP - 1.0 - used in "gentle" mode
double m_qAvg
Average queue length.
@ DTYPE_UNFORCED
An "unforced" (random) drop.
@ DTYPE_FORCED
A "forced" drop.
@ DTYPE_NONE
Ok, no drop.
bool m_isGentle
True to increase dropping prob.
double m_vC
(1.0 - m_curMaxP) / m_maxTh - used in "gentle" mode
uint32_t m_idlePktSize
Avg pkt size used during idle times.
double m_qW
Queue weight given to cur queue size sample.
double m_curMaxP
Current max_p.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.