summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2009-05-19 11:30:29 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-05-19 11:30:29 -0700
commit597ca71de3372a36dd5ea74922b08f2b8d982db5 (patch)
treef740917a0ae638c08a49698ed51c04a128c0e3e8 /lib
parent41d59aa4009874009e1aabf7923fc47874ef6fca (diff)
downloadvyatta-cfg-qos-597ca71de3372a36dd5ea74922b08f2b8d982db5.tar.gz
vyatta-cfg-qos-597ca71de3372a36dd5ea74922b08f2b8d982db5.zip
Move RED parameter computation to common code
Useful for WRED and shaper RED class.
Diffstat (limited to 'lib')
-rw-r--r--lib/Vyatta/Qos/ShaperClass.pm27
-rw-r--r--lib/Vyatta/Qos/Util.pm19
2 files changed, 33 insertions, 13 deletions
diff --git a/lib/Vyatta/Qos/ShaperClass.pm b/lib/Vyatta/Qos/ShaperClass.pm
index 4d95f42..5e1db8d 100644
--- a/lib/Vyatta/Qos/ShaperClass.pm
+++ b/lib/Vyatta/Qos/ShaperClass.pm
@@ -158,24 +158,19 @@ sub fifoQdisc {
# burst := (2 * min + max) / (3 * average)
sub redQdisc {
my ( $self, $dev, $rate ) = @_;
+ my $avg = 1000;
+ my ($qmin, $qmax, $burst) = RedParam($rate, 500, $avg);
+
my $limit = $self->{_limit};
- my $avg = 1000;
my $qlimit;
-
- if ( defined $limit ) {
- $qlimit = $limit * $avg; # red limit in bytes
- }
- else {
-
- # rate is in bits/sec so queue-limit = 8 * 500ms * rate
- $qlimit = $rate / 2;
+ if ($limit) {
+ $qlimit = $limit * $avg;
+ } else {
+ $qlimit = 4 * $qmax;
}
- my $qmax = $qlimit / 8;
- my $qmin = $qmax / 3;
printf "red limit %d min %d max %d avpkt %d", $qlimit, $qmin, $qmax, $avg;
- printf " burst %d probability 0.02 bandwidth %d ecn\n",
- ( 2 * $qmin + $qmax ) / ( 3 * $avg ), $rate / 1000;
+ printf " burst %d probability 0.02 bandwidth %d ecn\n", $burst, $rate / 1000;
}
my %qdiscOptions = (
@@ -185,6 +180,12 @@ my %qdiscOptions = (
'drop-tail' => \&fifoQdisc,
);
+sub get_rate {
+ my ($self, $speed) = @_;
+
+ return _getPercentRate( $self->{_rate}, $speed );
+}
+
sub gen_class {
my ( $self, $dev, $qdisc, $parent, $speed ) = @_;
my $rate = _getPercentRate( $self->{_rate}, $speed );
diff --git a/lib/Vyatta/Qos/Util.pm b/lib/Vyatta/Qos/Util.pm
index 3aefbd8..72b4963 100644
--- a/lib/Vyatta/Qos/Util.pm
+++ b/lib/Vyatta/Qos/Util.pm
@@ -319,4 +319,23 @@ sub ethtoolRate {
return $rate;
}
+# Compute parameters for RED algorithim based on bandwidth and latency
+#
+# 0.01 * Bandwidth Share * Desired Latency * Network Bandwidth
+# Maximum Threshold = -------------------------------------------------------------------
+# 8 bits/byte* 1000 ms/sec
+#
+# Minimum Threshold = 1/2 * Maximum Threshold
+# Avpkt = Average Packet Length
+# Burst = ( 2 * MinThreshold + MaxThreshold) / ( 3 * Avpkt )
+# Limit = 4 * MaxThreshold
+sub RedParam {
+ my ($bandwidth, $latency, $avgpkt) = @_;
+ my $qmax = ($bandwidth * $latency) / 8000;
+ my $qmin = $qmax / 2;
+ my $burst = ( 2 * $qmin + $qmax ) / ( 3 * $avgpkt );
+
+ return ($qmin, $qmax, $burst);
+}
+
1;