From 216b27c681dfacba194c9f001eec6287008a750c Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 14 May 2008 11:40:18 -0700 Subject: 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. --- scripts/VyattaQosRateLimiter.pm | 58 +++++++++++++++++++++++++++++++++++++++++ scripts/VyattaQosUtil.pm | 38 +++++++++++++++++++++++++++ scripts/vyatta-qos-util.pl | 7 +++++ scripts/vyatta-qos.pl | 2 ++ 4 files changed, 105 insertions(+) create mode 100644 scripts/VyattaQosRateLimiter.pm (limited to 'scripts') 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 < "VyattaQosTrafficShaper", 'fair-queue' => "VyattaQosFairQueue", + 'rate-limit' => "VyattaQosRateLimiter", ); use VyattaQosTrafficShaper; use VyattaQosFairQueue; +use VyattaQosRateLimiter; sub make_policy { my ($config, $type, $name) = @_; -- cgit v1.2.3