diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2008-05-14 11:40:18 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2008-05-14 11:40:18 -0700 |
commit | 216b27c681dfacba194c9f001eec6287008a750c (patch) | |
tree | 66a673a895ddb57ed2a73322995cdbf40f2f6b10 /scripts | |
parent | 17cd83259313b16a0ef27bf94a09612be8fece96 (diff) | |
download | vyatta-cfg-qos-216b27c681dfacba194c9f001eec6287008a750c.tar.gz vyatta-cfg-qos-216b27c681dfacba194c9f001eec6287008a750c.zip |
new qos-policy type rate-limit
Add new QoS policy type "rate-limit" which is a wrapper around the
the Token Bucket Filter (TBF) qdisc.
Rate limit provides a simple way to do basic bandwidth limitation without
the complexity of the doing multiple classes in the traffic shaper
policy.
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/VyattaQosRateLimiter.pm | 58 | ||||
-rw-r--r-- | scripts/VyattaQosUtil.pm | 38 | ||||
-rwxr-xr-x | scripts/vyatta-qos-util.pl | 7 | ||||
-rwxr-xr-x | scripts/vyatta-qos.pl | 2 |
4 files changed, 105 insertions, 0 deletions
diff --git a/scripts/VyattaQosRateLimiter.pm b/scripts/VyattaQosRateLimiter.pm new file mode 100644 index 0000000..548526b --- /dev/null +++ b/scripts/VyattaQosRateLimiter.pm @@ -0,0 +1,58 @@ +# This is a wrapper around Token Bucket Filter (TBF) queue discipline +# +# +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2008 Vyatta, Inc. +# All Rights Reserved. +# **** End License **** + +package VyattaQosRateLimiter; + +use strict; + +require VyattaConfig; +use VyattaQosUtil; + +my %fields = ( + _rate => undef, + _burst => undef, + _latency => undef, +); + +sub new { + my ( $that, $config ) = @_; + my $level = $config->setLevel(); + my $class = ref($that) || $that; + my $self = {%fields}; + + $self->{_rate} = VyattaQosUtil::getRate($config->returnValue("bandwidth")); + defined $self->{_rate} or die "$level bandwidth not defined\n"; + + $self->{_burst} = $config->returnValue("burst"); + defined $self->{_burst} or die "$level burst not defined\n"; + + $self->{_latency} = VyattaQosUtil::getTime($config->returnValue("latency")); + defined $self->{_latency} or die "$level latency not defined\n"; + + return bless $self, $class; +} + +sub commands { + my ( $self, $out, $dev ) = @_; + + + printf {$out} "qdisc add dev %s root tbf rate %s latency %s burst %s\n", + $dev, $self->{_rate}, $self->{_latency}, $self->{_burst}; +} + +1; diff --git a/scripts/VyattaQosUtil.pm b/scripts/VyattaQosUtil.pm index 87e9519..a4fd3f2 100644 --- a/scripts/VyattaQosUtil.pm +++ b/scripts/VyattaQosUtil.pm @@ -84,6 +84,44 @@ sub getRate { } } +# Default time units for tc are usec. +my %timeunits = ( + 's' => 1000000, + 'sec' => 1000000, + 'secs' => 1000000, + 'ms' => 1000, + 'msec' => 1000, + 'msecs' => 1000, + 'us' => 1, + 'usec' => 1, + 'usecs' => 1, +); + +sub getTime { + my $time = shift; + my ($num, $suffix) = get_num($time); + + defined $num + or die "$time is not a valid time interval (not a number)\n"; + ($num >= 0) + or die "$time is not a valid time interval (negative value)\n"; + + if (defined $suffix) { + my $scale = $timeunits{lc $suffix}; + + if (defined $scale) { + return $num * $scale; + } + + die "$time is not a valid time interval (unknown suffix)\n"; + } else { + # No suffix implies ms + return $num * 1000; + } +} + + + my %scales = ( 'b' => 1, 'k' => 1024, diff --git a/scripts/vyatta-qos-util.pl b/scripts/vyatta-qos-util.pl index 545e766..1e842b8 100755 --- a/scripts/vyatta-qos-util.pl +++ b/scripts/vyatta-qos-util.pl @@ -28,6 +28,7 @@ GetOptions( "protocol=s" => \$protocol, "dscp=s" => \$dsfield, "tos=s" => \$dsfield, + "time=s" => \$time, ); if ( defined $rate ) { @@ -50,8 +51,14 @@ if ( defined $dsfield ) { exit 0; } +if ( defined $time ) { + my $t = VyattaQosUtil::getTime($time); + exit 0; +} + print <<EOF; usage: vyatta-qos-util.pl --rate rate + vyatta-qos-util.pl --time time vyatta-qos-util.pl --burst size vyatta-qos-util.pl --protocol protocol vyatta-qos-util.pl --dscp tos|dsfield diff --git a/scripts/vyatta-qos.pl b/scripts/vyatta-qos.pl index e946551..ad97617 100755 --- a/scripts/vyatta-qos.pl +++ b/scripts/vyatta-qos.pl @@ -47,9 +47,11 @@ GetOptions( my %policies = ( 'traffic-shaper' => "VyattaQosTrafficShaper", 'fair-queue' => "VyattaQosFairQueue", + 'rate-limit' => "VyattaQosRateLimiter", ); use VyattaQosTrafficShaper; use VyattaQosFairQueue; +use VyattaQosRateLimiter; sub make_policy { my ($config, $type, $name) = @_; |