A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
red-queue.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_H
62 #define RED_QUEUE_H
63 
64 #include <queue>
65 #include "ns3/packet.h"
66 #include "ns3/queue.h"
67 #include "ns3/nstime.h"
68 #include "ns3/boolean.h"
69 #include "ns3/data-rate.h"
70 #include "ns3/nstime.h"
71 
72 namespace ns3 {
73 
74 class TraceContainer;
75 class UniformRandomVariable;
76 
82 class RedQueue : public Queue
83 {
84 public:
89  static TypeId GetTypeId (void);
95  RedQueue ();
96 
102  virtual ~RedQueue ();
103 
107  typedef struct
108  {
109  uint32_t unforcedDrop;
110  uint32_t forcedDrop;
111  uint32_t qLimDrop;
112  } Stats;
113 
117  enum
118  {
122  };
123 
130  void SetMode (RedQueue::QueueMode mode);
131 
139 
145  uint32_t GetQueueSize (void);
146 
152  void SetQueueLimit (uint32_t lim);
153 
160  void SetTh (double minTh, double maxTh);
161 
167  Stats GetStats ();
168 
177  int64_t AssignStreams (int64_t stream);
178 
179 private:
180  virtual bool DoEnqueue (Ptr<Packet> p);
181  virtual Ptr<Packet> DoDequeue (void);
182  virtual Ptr<const Packet> DoPeek (void) const;
183 
192  void InitializeParams (void);
201  double Estimator (uint32_t nQueued, uint32_t m, double qAvg, double qW);
208  uint32_t DropEarly (Ptr<Packet> p, uint32_t qSize);
221  double CalculatePNew (double qAvg, double , bool gentle, double vA,
222  double vB, double vC, double vD, double maxP);
233  double ModifyP (double p, uint32_t count, uint32_t countBytes,
234  uint32_t meanPktSize, bool wait, uint32_t size);
235 
236  std::list<Ptr<Packet> > m_packets;
237 
238  uint32_t m_bytesInQueue;
241 
242  // ** Variables supplied by user
244  uint32_t m_meanPktSize;
245  uint32_t m_idlePktSize;
246  bool m_isWait;
247  bool m_isGentle;
248  double m_minTh;
249  double m_maxTh;
250  uint32_t m_queueLimit;
251  double m_qW;
252  double m_lInterm;
256 
257  // ** Variables maintained by RED
258  double m_vProb1;
259  double m_vA;
260  double m_vB;
261  double m_vC;
262  double m_vD;
263  double m_curMaxP;
264  double m_vProb;
265  uint32_t m_countBytes;
266  uint32_t m_old;
267  uint32_t m_idle;
268  double m_ptc;
269  double m_qAvg;
270  uint32_t m_count;
271 
277  uint32_t m_cautious;
279 
281 };
282 
283 }; // namespace ns3
284 
285 #endif // RED_QUEUE_H
uint32_t m_bytesInQueue
bytes in the queue
Definition: red-queue.h:238
uint32_t qLimDrop
Drops due to queue limits.
Definition: red-queue.h:111
Ptr< UniformRandomVariable > m_uv
rng stream
Definition: red-queue.h:280
QueueMode m_mode
Mode (Bytes or packets)
Definition: red-queue.h:243
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
uint32_t DropEarly(Ptr< Packet > p, uint32_t qSize)
Check if packet p needs to be dropped due to probability mark.
Definition: red-queue.cc:440
virtual ~RedQueue()
Destructor.
Definition: red-queue.cc:160
void SetMode(RedQueue::QueueMode mode)
Set the operating mode of this queue.
Definition: red-queue.cc:166
double m_ptc
packet time constant in packets/second
Definition: red-queue.h:268
void SetQueueLimit(uint32_t lim)
Set the limit of the queue.
Definition: red-queue.cc:180
virtual Ptr< Packet > DoDequeue(void)
Pull a packet from the queue.
Definition: red-queue.cc:612
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
Definition: red-queue.h:277
virtual bool DoEnqueue(Ptr< Packet > p)
Push a packet in the queue.
Definition: red-queue.cc:211
DataRate m_linkBandwidth
Link bandwidth.
Definition: red-queue.h:254
uint32_t m_queueLimit
Queue limit in bytes / packets.
Definition: red-queue.h:250
Stats m_stats
RED statistics.
Definition: red-queue.h:240
Abstract base class for packet Queues.
Definition: queue.h:45
Class for representing data rates.
Definition: data-rate.h:71
bool m_isGentle
True to increases dropping prob.
Definition: red-queue.h:247
uint32_t GetQueueSize(void)
Get the current value of the queue in bytes or packets.
Definition: red-queue.cc:594
double m_vProb
Prob.
Definition: red-queue.h:264
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: red-queue.cc:203
Time m_linkDelay
Link delay.
Definition: red-queue.h:255
std::list< Ptr< Packet > > m_packets
packets in the queue
Definition: red-queue.h:236
double m_vA
1.0 / (m_maxTh - m_minTh)
Definition: red-queue.h:259
RedQueue::QueueMode GetMode(void)
Get the encapsulation mode of this queue.
Definition: red-queue.cc:173
Stats GetStats()
Get the RED statistics after running.
Definition: red-queue.cc:196
uint32_t m_countBytes
Number of bytes since last drop.
Definition: red-queue.h:265
virtual Ptr< const Packet > DoPeek(void) const
Peek the front packet in the queue.
Definition: red-queue.cc:641
uint32_t m_meanPktSize
Avg pkt size.
Definition: red-queue.h:244
An "unforced" (random) drop.
Definition: red-queue.h:121
RedQueue()
RedQueue Constructor.
Definition: red-queue.cc:150
bool m_isNs1Compat
Ns-1 compatibility.
Definition: red-queue.h:253
double m_lInterm
The max probability of dropping a packet.
Definition: red-queue.h:252
static TypeId GetTypeId(void)
Get the type ID.
Definition: red-queue.cc:74
double Estimator(uint32_t nQueued, uint32_t m, double qAvg, double qW)
Compute the average queue size.
Definition: red-queue.cc:420
void SetTh(double minTh, double maxTh)
Set the thresh limits of RED.
Definition: red-queue.cc:187
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. ...
Definition: red-queue.cc:501
uint32_t m_count
Number of packets since last random number generation.
Definition: red-queue.h:270
uint32_t m_idle
0/1 idle status
Definition: red-queue.h:267
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. ...
Definition: red-queue.cc:542
void InitializeParams(void)
Initialize the queue parameters.
Definition: red-queue.cc:341
bool m_isWait
True for waiting between dropped packets.
Definition: red-queue.h:246
uint32_t m_old
0 when average queue first exceeds threshold
Definition: red-queue.h:266
bool m_hasRedStarted
True if RED has started.
Definition: red-queue.h:239
QueueMode
Enumeration of the modes supported in the class.
Definition: queue.h:126
double m_vProb1
Prob.
Definition: red-queue.h:258
uint32_t m_idlePktSize
Avg pkt size used during idle times.
Definition: red-queue.h:245
Time m_idleTime
Start of current idle period.
Definition: red-queue.h:278
uint32_t forcedDrop
Forced drops, qavg > max threshold.
Definition: red-queue.h:110
A RED packet queue.
Definition: red-queue.h:82
double m_qW
Queue weight given to cur queue size sample.
Definition: red-queue.h:251
double m_qAvg
Average queue length.
Definition: red-queue.h:269
double m_vB
-m_minTh / (m_maxTh - m_minTh)
Definition: red-queue.h:260
uint32_t unforcedDrop
Early probability drops.
Definition: red-queue.h:109
double m_vC
(1.0 - m_curMaxP) / m_maxTh - used in "gentle" mode
Definition: red-queue.h:261
double m_maxTh
Max avg length threshold (bytes), should be >= 2*minTh.
Definition: red-queue.h:249
double m_curMaxP
Current max_p.
Definition: red-queue.h:263
a unique identifier for an interface.
Definition: type-id.h:49
double m_minTh
Min avg length threshold (bytes)
Definition: red-queue.h:248
A "forced" drop.
Definition: red-queue.h:120
double m_vD
2.0 * m_curMaxP - 1.0 - used in "gentle" mode
Definition: red-queue.h:262