A Discrete-Event Network Simulator
API
red-queue-disc.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright © 2011 Marcos Talau
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Marcos Talau (talau@users.sourceforge.net)
19  *
20  * Thanks to: Duy Nguyen<duy@soe.ucsc.edu> by RED efforts in NS3
21  *
22  *
23  * This file incorporates work covered by the following copyright and
24  * permission notice:
25  *
26  * Copyright (c) 1990-1997 Regents of the University of California.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  * 1. Redistributions of source code must retain the above copyright
33  * notice, this list of conditions and the following disclaimer.
34  * 2. Redistributions in binary form must reproduce the above copyright
35  * notice, this list of conditions and the following disclaimer in the
36  * documentation and/or other materials provided with the distribution.
37  * 3. Neither the name of the University nor of the Laboratory may be used
38  * to endorse or promote products derived from this software without
39  * specific prior written permission.
40  *
41  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
42  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
45  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  */
53 
54 /*
55  * PORT NOTE: This code was ported from ns-2 (queue/red.h). Almost all
56  * comments also been ported from NS-2.
57  * This implementation aims to be close to the results cited in [0]
58  * [0] S.Floyd, K.Fall http://icir.org/floyd/papers/redsims.ps
59  */
60 
61 #ifndef RED_QUEUE_DISC_H
62 #define RED_QUEUE_DISC_H
63 
64 #include "ns3/queue-disc.h"
65 #include "ns3/nstime.h"
66 #include "ns3/boolean.h"
67 #include "ns3/data-rate.h"
68 #include "ns3/random-variable-stream.h"
69 
70 namespace ns3 {
71 
72 class TraceContainer;
73 
79 class RedQueueDisc : public QueueDisc
80 {
81 public:
86  static TypeId GetTypeId (void);
92  RedQueueDisc ();
93 
99  virtual ~RedQueueDisc ();
100 
105  {
109  };
110 
114  enum
115  {
119  };
120 
126  {
129  };
130 
136  void SetMode (QueueDiscMode mode);
137 
143  QueueDiscMode GetMode (void);
144 
150  uint32_t GetQueueSize (void);
151 
157  void SetAredAlpha (double alpha);
158 
164  double GetAredAlpha (void);
165 
171  void SetAredBeta (double beta);
172 
178  double GetAredBeta (void);
179 
185  void SetFengAdaptiveA (double a);
186 
192  double GetFengAdaptiveA (void);
193 
199  void SetFengAdaptiveB (double b);
200 
206  double GetFengAdaptiveB (void);
207 
213  void SetQueueLimit (uint32_t lim);
214 
221  void SetTh (double minTh, double maxTh);
222 
231  int64_t AssignStreams (int64_t stream);
232 
233  // Reasons for dropping packets
234  static constexpr const char* UNFORCED_DROP = "Unforced drop";
235  static constexpr const char* FORCED_DROP = "Forced drop";
236  // Reasons for marking packets
237  static constexpr const char* UNFORCED_MARK = "Unforced mark";
238  static constexpr const char* FORCED_MARK = "Forced mark";
239 
240 protected:
244  virtual void DoDispose (void);
245 
246 private:
247  virtual bool DoEnqueue (Ptr<QueueDiscItem> item);
248  virtual Ptr<QueueDiscItem> DoDequeue (void);
249  virtual Ptr<const QueueDiscItem> DoPeek (void) const;
250  virtual bool CheckConfig (void);
251 
260  virtual void InitializeParams (void);
269  double Estimator (uint32_t nQueued, uint32_t m, double qAvg, double qW);
274  void UpdateMaxP (double newAve);
279  void UpdateMaxPFeng (double newAve);
286  uint32_t DropEarly (Ptr<QueueDiscItem> item, uint32_t qSize);
291  double CalculatePNew (void);
298  double ModifyP (double p, uint32_t size);
299 
300  // ** Variables supplied by user
302  uint32_t m_meanPktSize;
303  uint32_t m_idlePktSize;
304  bool m_isWait;
305  bool m_isGentle;
306  bool m_isARED;
308  double m_minTh;
309  double m_maxTh;
310  uint32_t m_queueLimit;
311  double m_qW;
312  double m_lInterm;
315  double m_top;
316  double m_bottom;
317  double m_alpha;
318  double m_beta;
322  double m_b;
323  double m_a;
327  bool m_useEcn;
329 
330  // ** Variables maintained by RED
331  double m_vA;
332  double m_vB;
333  double m_vC;
334  double m_vD;
335  double m_curMaxP;
337  double m_vProb;
338  uint32_t m_countBytes;
339  uint32_t m_old;
340  uint32_t m_idle;
341  double m_ptc;
342  double m_qAvg;
343  uint32_t m_count;
345 
351  uint32_t m_cautious;
353 
355 };
356 
357 }; // namespace ns3
358 
359 #endif // RED_QUEUE_DISC_H
void SetMode(QueueDiscMode mode)
Set the operating mode of this queue disc.
bool m_isGentle
True to increase dropping prob.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
uint32_t GetQueueSize(void)
Get the current value of the queue in bytes or packets.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
double m_beta
Decrement parameter for m_curMaxP in ARED.
uint32_t m_count
Number of packets since last random number generation.
bool m_isARED
True to enable Adaptive RED.
void SetTh(double minTh, double maxTh)
Set the thresh limits of RED.
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)
This function actually enqueues a packet into the queue disc.
double GetFengAdaptiveA(void)
Get the alpha value to adapt m_curMaxP in Feng's Adaptive RED.
double m_qAvg
Average queue length.
Time m_linkDelay
Link delay.
void SetAredBeta(double beta)
Set the beta value to adapt m_curMaxP.
uint32_t m_idle
0/1 idle status
FengStatus m_fengStatus
For use in Feng's Adaptive RED.
QueueDiscMode GetMode(void)
Get the operating mode of this queue disc.
double m_vD
2.0 * m_curMaxP - 1.0 - used in "gentle" mode
void SetFengAdaptiveB(double b)
Set the beta value to adapt m_curMaxP in Feng's Adaptive RED.
double m_vC
(1.0 - m_curMaxP) / m_maxTh - used in "gentle" mode
bool m_useHardDrop
True if packets are always dropped above max threshold.
double m_qW
Queue weight given to cur queue size sample.
static constexpr const char * FORCED_MARK
Forced marks, m_qAvg > m_maxTh.
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:151
A RED packet queue disc.
double m_b
Increment parameter for m_curMaxP in Feng's Adaptive RED.
static constexpr const char * FORCED_DROP
Forced drops, m_qAvg > m_maxTh.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
double GetAredAlpha(void)
Get the alpha value to adapt m_curMaxP.
Time m_rtt
Rtt to be considered while automatically setting m_bottom in ARED.
static constexpr const char * UNFORCED_DROP
Early probability drops.
double m_alpha
Increment parameter for m_curMaxP in ARED.
Time m_lastSet
Last time m_curMaxP was updated.
bool m_isAdaptMaxP
True to adapt m_curMaxP.
static TypeId GetTypeId(void)
Get the type ID.
Class for representing data rates.
Definition: data-rate.h:88
double m_curMaxP
Current max_p.
void SetQueueLimit(uint32_t lim)
Set the limit of the queue.
Time m_idleTime
Start of current idle period.
double GetFengAdaptiveB(void)
Get the beta value to adapt m_curMaxP in Feng's Adaptive RED.
uint32_t m_queueLimit
Queue limit in bytes / packets.
virtual bool CheckConfig(void)
Check whether the current configuration is correct.
virtual void InitializeParams(void)
Initialize the queue parameters.
uint32_t m_cautious
0 for default RED 1 experimental (see red-queue-disc.cc) 2 experimental (see red-queue-disc.cc) 3 use Idle packet size in the ptc
Ptr< UniformRandomVariable > m_uv
rng stream
double m_vB
-m_minTh / (m_maxTh - m_minTh)
bool m_isNonlinear
True to enable Nonlinear RED.
bool m_useEcn
True if ECN is used (packets are marked instead of being dropped)
double m_minTh
Minimum threshold for m_qAvg (bytes or packets)
Use number of bytes for maximum queue disc size.
uint32_t m_idlePktSize
Avg pkt size used during idle times.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double m_vA
1.0 / (m_maxTh - m_minTh)
uint32_t m_countBytes
Number of bytes since last drop.
QueueDiscMode
Enumeration of the modes supported in the class.
double m_lInterm
The max probability of dropping a packet.
static constexpr const char * UNFORCED_MARK
Early probability marks.
uint32_t DropEarly(Ptr< QueueDiscItem > item, uint32_t qSize)
Check if a packet needs to be dropped due to probability mark.
RedQueueDisc()
RedQueueDisc Constructor.
double m_bottom
Lower bound for m_curMaxP in ARED.
virtual Ptr< QueueDiscItem > DoDequeue(void)
This function actually extracts a packet from the queue disc.
When m_qAvg > m_maxTh.
void UpdateMaxP(double newAve)
Update m_curMaxP.
FengStatus
Used in Feng's Adaptive RED.
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.
QueueDiscMode m_mode
Mode (Bytes or packets)
An "unforced" (random) drop.
DataRate m_linkBandwidth
Link bandwidth.
Time m_interval
Time interval to update m_curMaxP.
bool m_isWait
True for waiting between dropped packets.
Time m_targetDelay
Target average queuing delay in ARED.
double GetAredBeta(void)
Get the beta value to adapt m_curMaxP.
double m_ptc
packet time constant in packets/second
virtual ~RedQueueDisc()
Destructor.
double m_top
Upper bound for m_curMaxP in ARED.
double Estimator(uint32_t nQueued, uint32_t m, double qAvg, double qW)
Compute the average queue size.
uint32_t m_meanPktSize
Avg pkt size.
void UpdateMaxPFeng(double newAve)
Update m_curMaxP based on Feng's Adaptive RED.
bool m_isFengAdaptive
True to enable Feng's Adaptive RED.
double CalculatePNew(void)
Returns a probability using these function parameters for the DropEarly function. ...
void SetAredAlpha(double alpha)
Set the alpha value to adapt m_curMaxP.
virtual Ptr< const QueueDiscItem > DoPeek(void) const
This function returns a copy of the next packet the queue disc will extract.
virtual void DoDispose(void)
Dispose of the object.
double ModifyP(double p, uint32_t size)
Returns a probability using these function parameters for the DropEarly function. ...
a unique identifier for an interface.
Definition: type-id.h:58
double m_vProb
Prob.
Use number of packets for maximum queue disc size.
double m_maxTh
Maximum threshold for m_qAvg (bytes or packets), should be >= 2 * m_minTh.
When m_maxTh < m_qAvg < m_minTh.
When m_qAvg < m_minTh.
double m_a
Decrement parameter for m_curMaxP in Feng's Adaptive RED.
bool m_isNs1Compat
Ns-1 compatibility.