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 
77 /*
78  * \ingroup queue
79  *
80  * \brief A RED packet queue
81  */
82 class RedQueue : public Queue
83 {
84 public:
85  static TypeId GetTypeId (void);
91  RedQueue ();
92 
98  virtual ~RedQueue ();
99 
104  typedef struct
105  {
106  uint32_t unforcedDrop;
107  uint32_t forcedDrop;
108  uint32_t qLimDrop;
109  } Stats;
110 
115  enum
116  {
120  };
121 
128  void SetMode (RedQueue::QueueMode mode);
129 
137 
143  uint32_t GetQueueSize (void);
144 
150  void SetQueueLimit (uint32_t lim);
151 
158  void SetTh (double minTh, double maxTh);
159 
165  Stats GetStats ();
166 
175  int64_t AssignStreams (int64_t stream);
176 
177 private:
178  virtual bool DoEnqueue (Ptr<Packet> p);
179  virtual Ptr<Packet> DoDequeue (void);
180  virtual Ptr<const Packet> DoPeek (void) const;
181 
182  // ...
183  void InitializeParams (void);
184  // Compute the average queue size
185  double Estimator (uint32_t nQueued, uint32_t m, double qAvg, double qW);
186  // Check if packet p needs to be dropped due to probability mark
187  uint32_t DropEarly (Ptr<Packet> p, uint32_t qSize);
188  // Returns a probability using these function parameters for the DropEarly funtion
189  double CalculatePNew (double qAvg, double maxTh, bool gentle, double vA,
190  double vB, double vC, double vD, double maxP);
191  // Returns a probability using these function parameters for the DropEarly funtion
192  double ModifyP (double p, uint32_t count, uint32_t countBytes,
193  uint32_t meanPktSize, bool wait, uint32_t size);
194 
195  std::list<Ptr<Packet> > m_packets;
196 
197  uint32_t m_bytesInQueue;
200 
201  // ** Variables supplied by user
202  // Bytes or packets?
204  // Avg pkt size
205  uint32_t m_meanPktSize;
206  // Avg pkt size used during idle times
207  uint32_t m_idlePktSize;
208  // True for waiting between dropped packets
209  bool m_isWait;
210  // True to increases dropping prob. slowly when ave queue exceeds maxthresh
212  // Min avg length threshold (bytes)
213  double m_minTh;
214  // Max avg length threshold (bytes), should be >= 2*minTh
215  double m_maxTh;
216  // Queue limit in bytes / packets
217  uint32_t m_queueLimit;
218  // Queue weight given to cur q size sample
219  double m_qW;
220  // The max probability of dropping a packet
221  double m_lInterm;
222  // Ns-1 compatibility
224  // Link bandwidth
226  // Link delay
228 
229  // ** Variables maintained by RED
230  // Prob. of packet drop before "count"
231  double m_vProb1;
232  // v_prob = v_a * v_ave + v_b
233  double m_vA;
234  double m_vB;
235  // Used for "gentle" mode
236  double m_vC;
237  // Used for "gentle" mode
238  double m_vD;
239  // Current max_p
240  double m_curMaxP;
241  // Prob. of packet drop
242  double m_vProb;
243  // # of bytes since last drop
244  uint32_t m_countBytes;
245  // 0 when average queue first exceeds thresh
246  uint32_t m_old;
247  // 0/1 idle status
248  uint32_t m_idle;
249  // packet time constant in packets/second
250  double m_ptc;
251  // Average queue length
252  double m_qAvg;
253  // number of packets since last random number generation
254  uint32_t m_count;
255  /*
256  * 0 for default RED
257  * 1 experimental (see red-queue.cc)
258  * 2 experimental (see red-queue.cc)
259  * 3 use Idle packet size in the ptc
260  */
261  uint32_t m_cautious;
262  // Start of current idle period
264 
266 };
267 
268 }; // namespace ns3
269 
270 #endif // RED_QUEUE_H
uint32_t m_bytesInQueue
Definition: red-queue.h:197
uint32_t qLimDrop
Forced drops, qavg > max threshold.
Definition: red-queue.h:108
Ptr< UniformRandomVariable > m_uv
Definition: red-queue.h:265
QueueMode m_mode
Definition: red-queue.h:203
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
uint32_t DropEarly(Ptr< Packet > p, uint32_t qSize)
Definition: red-queue.cc:441
virtual ~RedQueue()
Destructor.
Definition: red-queue.cc:161
void SetMode(RedQueue::QueueMode mode)
Set the operating mode of this queue.
Definition: red-queue.cc:167
double m_ptc
Definition: red-queue.h:250
void SetQueueLimit(uint32_t lim)
Set the limit of the queue.
Definition: red-queue.cc:181
virtual Ptr< Packet > DoDequeue(void)
Definition: red-queue.cc:613
uint32_t m_cautious
Definition: red-queue.h:261
virtual bool DoEnqueue(Ptr< Packet > p)
Definition: red-queue.cc:212
DataRate m_linkBandwidth
Definition: red-queue.h:225
uint32_t m_queueLimit
Definition: red-queue.h:217
Stats m_stats
Definition: red-queue.h:199
Abstract base class for packet Queues.
Definition: queue.h:45
Class for representing data rates.
Definition: data-rate.h:71
bool m_isGentle
Definition: red-queue.h:211
uint32_t GetQueueSize(void)
Get the current value of the queue in bytes or packets.
Definition: red-queue.cc:595
double m_vProb
Definition: red-queue.h:242
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:204
Time m_linkDelay
Definition: red-queue.h:227
std::list< Ptr< Packet > > m_packets
Definition: red-queue.h:195
double m_vA
Definition: red-queue.h:233
RedQueue::QueueMode GetMode(void)
Get the encapsulation mode of this queue.
Definition: red-queue.cc:174
Stats GetStats()
Get the RED statistics after running.
Definition: red-queue.cc:197
uint32_t m_countBytes
Definition: red-queue.h:244
virtual Ptr< const Packet > DoPeek(void) const
Definition: red-queue.cc:642
uint32_t m_meanPktSize
Definition: red-queue.h:205
RedQueue()
RedQueue Constructor.
Definition: red-queue.cc:151
bool m_isNs1Compat
Definition: red-queue.h:223
double m_lInterm
Definition: red-queue.h:221
static TypeId GetTypeId(void)
Definition: red-queue.cc:75
double Estimator(uint32_t nQueued, uint32_t m, double qAvg, double qW)
Definition: red-queue.cc:421
void SetTh(double minTh, double maxTh)
Set the thresh limits of RED.
Definition: red-queue.cc:188
uint32_t m_count
Definition: red-queue.h:254
uint32_t m_idle
Definition: red-queue.h:248
double ModifyP(double p, uint32_t count, uint32_t countBytes, uint32_t meanPktSize, bool wait, uint32_t size)
Definition: red-queue.cc:543
void InitializeParams(void)
Definition: red-queue.cc:342
uint32_t m_old
Definition: red-queue.h:246
bool m_hasRedStarted
Definition: red-queue.h:198
double CalculatePNew(double qAvg, double maxTh, bool gentle, double vA, double vB, double vC, double vD, double maxP)
Definition: red-queue.cc:502
QueueMode
Enumeration of the modes supported in the class.
Definition: queue.h:122
double m_vProb1
Definition: red-queue.h:231
uint32_t m_idlePktSize
Definition: red-queue.h:207
Time m_idleTime
Definition: red-queue.h:263
uint32_t forcedDrop
Early probability drops.
Definition: red-queue.h:107
double m_qW
Definition: red-queue.h:219
double m_qAvg
Definition: red-queue.h:252
double m_vB
Definition: red-queue.h:234
uint32_t unforcedDrop
Definition: red-queue.h:106
double m_vC
Definition: red-queue.h:236
double m_maxTh
Definition: red-queue.h:215
double m_curMaxP
Definition: red-queue.h:240
a unique identifier for an interface.
Definition: type-id.h:49
double m_minTh
Definition: red-queue.h:213
double m_vD
Definition: red-queue.h:238