A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
);
86
/*
87
* \brief RedQueue Constructor
88
*
89
* Create a RED queue
90
*/
91
RedQueue
();
92
93
/*
94
* \brief Destructor
95
*
96
* Destructor
97
*/
98
virtual
~RedQueue
();
99
100
/*
101
* \brief Stats
102
*
103
*/
104
typedef
struct
105
{
106
// Early probability drops
107
uint32_t
unforcedDrop
;
108
// Forced drops, qavg > max threshold
109
uint32_t
forcedDrop
;
110
// Drops due to queue limits
111
uint32_t
qLimDrop
;
112
}
Stats
;
113
114
/*
115
* \brief Drop types
116
*
117
*/
118
enum
119
{
120
DTYPE_NONE
,
// Ok, no drop
121
DTYPE_FORCED
,
// A "forced" drop
122
DTYPE_UNFORCED
,
// An "unforced" (random) drop
123
};
124
125
/*
126
* \brief Set the operating mode of this queue.
127
* Set operating mode
128
*
129
* \param mode The operating mode of this queue.
130
*/
131
void
SetMode
(
RedQueue::QueueMode
mode);
132
133
/*
134
* \brief Get the encapsulation mode of this queue.
135
* Get the encapsulation mode of this queue
136
*
137
* \returns The encapsulation mode of this queue.
138
*/
139
RedQueue::QueueMode
GetMode
(
void
);
140
141
/*
142
* \brief Get the current value of the queue in bytes or packets.
143
*
144
* \returns The queue size in bytes or packets.
145
*/
146
uint32_t
GetQueueSize
(
void
);
147
148
/*
149
* \brief Set the limit of the queue.
150
*
151
* \param lim The limit in bytes or packets.
152
*/
153
void
SetQueueLimit
(uint32_t lim);
154
155
/*
156
* \brief Set the thresh limits of RED.
157
*
158
* \param min Minimum thresh in bytes or packets.
159
* \param max Maximum thresh in bytes or packets.
160
*/
161
void
SetTh
(
double
minTh,
double
maxTh);
162
163
/*
164
* \brief Get the RED statistics after running.
165
*
166
* \returns The drop statistics.
167
*/
168
Stats
GetStats
();
169
178
int64_t
AssignStreams
(int64_t stream);
179
180
private
:
181
virtual
bool
DoEnqueue
(
Ptr<Packet>
p);
182
virtual
Ptr<Packet>
DoDequeue
(
void
);
183
virtual
Ptr<const Packet>
DoPeek
(
void
)
const
;
184
185
// ...
186
void
InitializeParams
(
void
);
187
// Compute the average queue size
188
double
Estimator
(uint32_t nQueued, uint32_t m,
double
qAvg,
double
qW);
189
// Check if packet p needs to be dropped due to probability mark
190
uint32_t
DropEarly
(
Ptr<Packet>
p, uint32_t qSize);
191
// Returns a probability using these function parameters for the DropEarly funtion
192
double
CalculatePNew
(
double
qAvg,
double
maxTh,
bool
gentle,
double
vA,
193
double
vB,
double
vC,
double
vD,
double
maxP);
194
// Returns a probability using these function parameters for the DropEarly funtion
195
double
ModifyP
(
double
p, uint32_t count, uint32_t countBytes,
196
uint32_t meanPktSize,
bool
wait, uint32_t size);
197
198
std::list<Ptr<Packet> >
m_packets
;
199
200
uint32_t
m_bytesInQueue
;
201
bool
m_hasRedStarted
;
202
Stats
m_stats
;
203
204
// ** Variables supplied by user
205
// Bytes or packets?
206
QueueMode
m_mode
;
207
// Avg pkt size
208
uint32_t
m_meanPktSize
;
209
// Avg pkt size used during idle times
210
uint32_t
m_idlePktSize
;
211
// True for waiting between dropped packets
212
bool
m_isWait
;
213
// True to increases dropping prob. slowly when ave queue exceeds maxthresh
214
bool
m_isGentle
;
215
// Min avg length threshold (bytes)
216
double
m_minTh
;
217
// Max avg length threshold (bytes), should be >= 2*minTh
218
double
m_maxTh
;
219
// Queue limit in bytes / packets
220
uint32_t
m_queueLimit
;
221
// Queue weight given to cur q size sample
222
double
m_qW
;
223
// The max probability of dropping a packet
224
double
m_lInterm
;
225
// Ns-1 compatibility
226
bool
m_isNs1Compat
;
227
// Link bandwidth
228
DataRate
m_linkBandwidth
;
229
// Link delay
230
Time
m_linkDelay
;
231
232
// ** Variables maintained by RED
233
// Prob. of packet drop before "count"
234
double
m_vProb1
;
235
// v_prob = v_a * v_ave + v_b
236
double
m_vA
;
237
double
m_vB
;
238
// Used for "gentle" mode
239
double
m_vC
;
240
// Used for "gentle" mode
241
double
m_vD
;
242
// Current max_p
243
double
m_curMaxP
;
244
// Prob. of packet drop
245
double
m_vProb
;
246
// # of bytes since last drop
247
uint32_t
m_countBytes
;
248
// 0 when average queue first exceeds thresh
249
uint32_t
m_old
;
250
// 0/1 idle status
251
uint32_t
m_idle
;
252
// packet time constant in packets/second
253
double
m_ptc
;
254
// Average queue length
255
double
m_qAvg
;
256
// number of packets since last random number generation
257
uint32_t
m_count
;
258
/*
259
* 0 for default RED
260
* 1 experimental (see red-queue.cc)
261
* 2 experimental (see red-queue.cc)
262
* 3 use Idle packet size in the ptc
263
*/
264
uint32_t
m_cautious
;
265
// Start of current idle period
266
Time
m_idleTime
;
267
268
Ptr<UniformRandomVariable>
m_uv
;
269
};
270
271
};
// namespace ns3
272
273
#endif // RED_QUEUE_H
src
network
utils
red-queue.h
Generated on Tue Nov 13 2012 10:32:20 for ns-3 by
1.8.1.2