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/packet.h"
65 #include "ns3/queue-disc.h"
66 #include "ns3/nstime.h"
67 #include "ns3/boolean.h"
68 #include "ns3/data-rate.h"
69 #include "ns3/nstime.h"
70 #include "ns3/random-variable-stream.h"
71 
72 namespace ns3 {
73 
74 class TraceContainer;
75 
81 class RedQueueDisc : public QueueDisc
82 {
83 public:
88  static TypeId GetTypeId (void);
94  RedQueueDisc ();
95 
101  virtual ~RedQueueDisc ();
102 
106  typedef struct
107  {
108  uint32_t unforcedDrop;
109  uint32_t forcedDrop;
110  uint32_t qLimDrop;
111  } Stats;
112 
116  enum
117  {
121  };
122 
129  void SetMode (Queue::QueueMode mode);
130 
137  Queue::QueueMode GetMode (void);
138 
144  uint32_t GetQueueSize (void);
145 
151  void SetAredAlpha (double alpha);
152 
158  double GetAredAlpha (void);
159 
165  void SetAredBeta (double beta);
166 
172  double GetAredBeta (void);
173 
179  void SetQueueLimit (uint32_t lim);
180 
187  void SetTh (double minTh, double maxTh);
188 
194  Stats GetStats ();
195 
204  int64_t AssignStreams (int64_t stream);
205 
206 protected:
210  virtual void DoDispose (void);
211 
212 private:
213  virtual bool DoEnqueue (Ptr<QueueDiscItem> item);
214  virtual Ptr<QueueDiscItem> DoDequeue (void);
215  virtual Ptr<const QueueDiscItem> DoPeek (void) const;
216  virtual bool CheckConfig (void);
217 
226  virtual void InitializeParams (void);
235  double Estimator (uint32_t nQueued, uint32_t m, double qAvg, double qW);
241  void UpdateMaxP (double newAve, Time now);
248  uint32_t DropEarly (Ptr<QueueDiscItem> item, uint32_t qSize);
261  double CalculatePNew (double qAvg, double , bool gentle, double vA,
262  double vB, double vC, double vD, double maxP);
273  double ModifyP (double p, uint32_t count, uint32_t countBytes,
274  uint32_t meanPktSize, bool wait, uint32_t size);
275 
277 
278  // ** Variables supplied by user
280  uint32_t m_meanPktSize;
281  uint32_t m_idlePktSize;
282  bool m_isWait;
283  bool m_isGentle;
284  bool m_isARED;
286  double m_minTh;
287  double m_maxTh;
288  uint32_t m_queueLimit;
289  double m_qW;
290  double m_lInterm;
293  double m_top;
294  double m_bottom;
295  double m_alpha;
296  double m_beta;
301 
302  // ** Variables maintained by RED
303  double m_vProb1;
304  double m_vA;
305  double m_vB;
306  double m_vC;
307  double m_vD;
308  double m_curMaxP;
310  double m_vProb;
311  uint32_t m_countBytes;
312  uint32_t m_old;
313  uint32_t m_idle;
314  double m_ptc;
315  double m_qAvg;
316  uint32_t m_count;
317 
323  uint32_t m_cautious;
325 
327 };
328 
329 }; // namespace ns3
330 
331 #endif // RED_QUEUE_DISC_H
bool m_isGentle
True to increases 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 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
double m_vD
2.0 * m_curMaxP - 1.0 - used in "gentle" mode
double m_vC
(1.0 - m_curMaxP) / m_maxTh - used in "gentle" mode
double m_qW
Queue weight given to cur queue size sample.
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:205
A RED packet queue disc.
Stats m_stats
RED statistics.
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.
double m_alpha
Increment parameter for m_curMaxP in ARED.
Time m_lastSet
Last time m_curMaxP was updated.
void UpdateMaxP(double newAve, Time now)
Update m_curMaxP.
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.
QueueMode
Enumeration of the modes supported in the class.
Definition: queue.h:130
void SetQueueLimit(uint32_t lim)
Set the limit of the queue.
Time m_idleTime
Start of current idle period.
uint32_t forcedDrop
Forced drops, qavg > max threshold.
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.cc) 2 experimental (see red-queue.cc) 3 use Idle packet size in the ptc
uint32_t qLimDrop
Drops due to queue limits.
Ptr< UniformRandomVariable > m_uv
rng stream
Queue::QueueMode m_mode
Mode (Bytes or packets)
double m_vB
-m_minTh / (m_maxTh - m_minTh)
double m_minTh
Min avg length threshold (bytes)
uint32_t m_idlePktSize
Avg pkt size used during idle times.
double m_vProb1
Prob.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double m_vA
1.0 / (m_maxTh - m_minTh)
double CalculatePNew(double qAvg, double, bool gentle, double vA, double vB, double vC, double vD, double maxP)
Returns a probability using these function parameters for the DropEarly function. ...
uint32_t m_countBytes
Number of bytes since last drop.
double m_lInterm
The max probability of dropping a packet.
Queue::QueueMode GetMode(void)
Get the encapsulation mode of this queue.
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.
An "unforced" (random) drop.
virtual Ptr< QueueDiscItem > DoDequeue(void)
This function actually extracts a packet from the queue disc.
uint32_t m_old
0 when average queue first exceeds threshold
double ModifyP(double p, uint32_t count, uint32_t countBytes, uint32_t meanPktSize, bool wait, uint32_t size)
Returns a probability using these function parameters for the DropEarly function. ...
DataRate m_linkBandwidth
Link bandwidth.
Time m_interval
Time interval to update m_curMaxP.
void SetMode(Queue::QueueMode mode)
Set the operating mode of this queue.
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 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.
a unique identifier for an interface.
Definition: type-id.h:58
double m_vProb
Prob.
Stats GetStats()
Get the RED statistics after running.
double m_maxTh
Max avg length threshold (bytes), should be >= 2*minTh.
uint32_t unforcedDrop
Early probability drops.
bool m_isNs1Compat
Ns-1 compatibility.