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 | |
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.
-rw-r--r-- | Makefile.am | 1 | ||||
-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 | ||||
-rw-r--r-- | templates/qos-policy/rate-limit/node.def | 8 | ||||
-rw-r--r-- | templates/qos-policy/rate-limit/node.tag/bandwidth/node.def | 9 | ||||
-rw-r--r-- | templates/qos-policy/rate-limit/node.tag/burst/node.def | 7 | ||||
-rw-r--r-- | templates/qos-policy/rate-limit/node.tag/description/node.def | 2 | ||||
-rw-r--r-- | templates/qos-policy/rate-limit/node.tag/latency/node.def | 7 |
10 files changed, 139 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index 54c5031..23e2bfa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,6 +10,7 @@ sbin_SCRIPTS += scripts/vyatta-qos-util.pl share_perl5_DATA += scripts/VyattaQosUtil.pm share_perl5_DATA += scripts/VyattaQosFairQueue.pm share_perl5_DATA += scripts/VyattaQosTrafficShaper.pm +share_perl5_DATA += scripts/VyattaQosRateLimiter.pm share_perl5_DATA += scripts/VyattaQosMatch.pm cpiop = find . ! -regex '\(.*~\|.*\.bak\|.*\.swp\|.*\#.*\#\)' -print0 | \ 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) = @_; diff --git a/templates/qos-policy/rate-limit/node.def b/templates/qos-policy/rate-limit/node.def new file mode 100644 index 0000000..55728a7 --- /dev/null +++ b/templates/qos-policy/rate-limit/node.def @@ -0,0 +1,8 @@ +tag: +type: txt +help: Set rate limiting policy +syntax:expression: pattern $VAR(@) "^[[:alnum:]][-_[:alnum:]]*$" + ; "only alpha-numeric policy name allowed" +create: /opt/vyatta/sbin/vyatta-qos.pl --create-policy "$VAR(.)" "$VAR(@)" +delete: /opt/vyatta/sbin/vyatta-qos.pl --delete-policy "$VAR(@)" +update: /opt/vyatta/sbin/vyatta-qos.pl --update-policy "$VAR(.)" "$VAR(@)" diff --git a/templates/qos-policy/rate-limit/node.tag/bandwidth/node.def b/templates/qos-policy/rate-limit/node.tag/bandwidth/node.def new file mode 100644 index 0000000..3e48fd3 --- /dev/null +++ b/templates/qos-policy/rate-limit/node.tag/bandwidth/node.def @@ -0,0 +1,9 @@ +type: txt +help: Set the bandwidth limit +syntax:expression: exec "/opt/vyatta/sbin/vyatta-qos-util.pl --rate \"$VAR(@)\"" +comp_help: Allowed values: + <number> Bandwidth in Kbps per second + <number><suffix> Value with scaling suffix + bits per sec (kbit, mbit, gbit) + bytes per sec (kbps, mbps, gbps) + diff --git a/templates/qos-policy/rate-limit/node.tag/burst/node.def b/templates/qos-policy/rate-limit/node.tag/burst/node.def new file mode 100644 index 0000000..56174bb --- /dev/null +++ b/templates/qos-policy/rate-limit/node.tag/burst/node.def @@ -0,0 +1,7 @@ +type: txt +help: Set the burst size +default: "15k" +syntax:expression: exec "/opt/vyatta/sbin/vyatta-qos-util.pl --burst \"$VAR(@)\"" +comp_help: Allowed values: + <number> Burst size in bytes + <number><suffix> Size with scaling suffix (kb, mb, gb) diff --git a/templates/qos-policy/rate-limit/node.tag/description/node.def b/templates/qos-policy/rate-limit/node.tag/description/node.def new file mode 100644 index 0000000..1e8e64f --- /dev/null +++ b/templates/qos-policy/rate-limit/node.tag/description/node.def @@ -0,0 +1,2 @@ +type: txt +help: Set description for this queuing policy diff --git a/templates/qos-policy/rate-limit/node.tag/latency/node.def b/templates/qos-policy/rate-limit/node.tag/latency/node.def new file mode 100644 index 0000000..486bfa3 --- /dev/null +++ b/templates/qos-policy/rate-limit/node.tag/latency/node.def @@ -0,0 +1,7 @@ +type: txt +syntax:expression: exec "/opt/vyatta/sbin/vyatta-qos-util.pl --time \"$VAR(@)\"" +default: "50ms" +help: Set maximum latency +comp_help: Limit on the queue size based on latency + <number> Latency in milliseconds + <number><suffix> Time with suffx (secs, ms, us) |