diff options
6 files changed, 36 insertions, 10 deletions
diff --git a/scripts/VyattaQosUtil.pm b/scripts/VyattaQosUtil.pm index 668f5c1..82dfd6b 100644 --- a/scripts/VyattaQosUtil.pm +++ b/scripts/VyattaQosUtil.pm @@ -17,7 +17,7 @@ package VyattaQosUtil; require Exporter; -@EXPORT = qw/getRate getBurstSize getProtocol getDsfield getIfIndex interfaceRate/; +@EXPORT = qw/getRate getPercent getBurstSize getProtocol getDsfield getIfIndex interfaceRate/; use strict; sub get_num { @@ -84,6 +84,23 @@ sub getRate { } } +sub getPercent { + my $percent = shift; + my ($num, $suffix) = get_num($percent); + + ($suffix eq '%') + or die "$percent incorrect suffix (expect %)\n"; + defined $num + or die "$percent is not a valid percent bandwidth (not a number)\n"; + ($num >= 0) + or die "$percent is not a acceptable percent bandwidth (negative value)\n"; + ($num <= 100) + or die "$percent is not a acceptable percent bandwidth (greater than 100%)\n"; + + return $num; +} + + # Default time units for tc are usec. my %timeunits = ( 's' => 1000000, diff --git a/scripts/vyatta-qos-util.pl b/scripts/vyatta-qos-util.pl index 1e842b8..8c3bafd 100755 --- a/scripts/vyatta-qos-util.pl +++ b/scripts/vyatta-qos-util.pl @@ -22,7 +22,10 @@ use lib "/opt/vyatta/share/perl5/"; use VyattaQosUtil; use Getopt::Long; +my ($percent, $rate, $burst, $protocol, $dsfield, $time); + GetOptions( + "percent-or-rate=s" => \$percent, "rate=s" => \$rate, "burst=s" => \$burst, "protocol=s" => \$protocol, @@ -31,6 +34,15 @@ GetOptions( "time=s" => \$time, ); +if ( defined $percent ) { + if ($percent =~ /%$/) { + my $p = VyattaQosUtil::getPercent($percent); + } else { + my $r = VyattaQosUtil::getRate($percent); + } + exit 0; +} + if ( defined $rate ) { my $r = VyattaQosUtil::getRate($rate); exit 0; @@ -57,7 +69,8 @@ if ( defined $time ) { } print <<EOF; -usage: vyatta-qos-util.pl --rate rate +usage: vyatta-qos-util.pl --percent-or-rate value + vyatta-qos-util.pl --rate rate vyatta-qos-util.pl --time time vyatta-qos-util.pl --burst size vyatta-qos-util.pl --protocol protocol diff --git a/templates/qos-policy/traffic-shaper/node.tag/class/node.tag/bandwidth/node.def b/templates/qos-policy/traffic-shaper/node.tag/class/node.tag/bandwidth/node.def index 2871b23..6f15037 100644 --- a/templates/qos-policy/traffic-shaper/node.tag/class/node.tag/bandwidth/node.def +++ b/templates/qos-policy/traffic-shaper/node.tag/class/node.tag/bandwidth/node.def @@ -1,8 +1,7 @@ type: txt default: "100%" help: Set the bandwidth used for this class -syntax:expression: exec "[[ \"$VAR(@)\" =~ '^[0-9]+(\.[0-9]*)?%$' ]] || \ - /opt/vyatta/sbin/vyatta-qos-util.pl --rate \"$VAR(@)\"" +syntax:expression: exec "/opt/vyatta/sbin/vyatta-qos-util.pl --percent-or-rate \"$VAR(@)\"" comp_help: Allowed values: <number> Bandwidth in Kbps <number>%% Percentage of overall rate (default 100%%) diff --git a/templates/qos-policy/traffic-shaper/node.tag/class/node.tag/ceiling/node.def b/templates/qos-policy/traffic-shaper/node.tag/class/node.tag/ceiling/node.def index 82c5ff0..11bf6b9 100644 --- a/templates/qos-policy/traffic-shaper/node.tag/class/node.tag/ceiling/node.def +++ b/templates/qos-policy/traffic-shaper/node.tag/class/node.tag/ceiling/node.def @@ -1,7 +1,6 @@ type: txt help: Set the bandwidth limit for this class -syntax:expression: exec "[[ \"$VAR(@)\" =~ '^[0-9]+(\.[0-9]*)?%$' ]] || \ - /opt/vyatta/sbin/vyatta-qos-util.pl --rate \"$VAR(@)\"" +syntax:expression: exec "/opt/vyatta/sbin/vyatta-qos-util.pl --percent-or-rate \"$VAR(@)\"" comp_help: Allowed values: <number> Limit in Kbps <number>%% Percentage of overall rate diff --git a/templates/qos-policy/traffic-shaper/node.tag/default/bandwidth/node.def b/templates/qos-policy/traffic-shaper/node.tag/default/bandwidth/node.def index 21b6e88..4d454d4 100644 --- a/templates/qos-policy/traffic-shaper/node.tag/default/bandwidth/node.def +++ b/templates/qos-policy/traffic-shaper/node.tag/default/bandwidth/node.def @@ -1,7 +1,6 @@ type: txt help: Set the bandwidth used for default traffic -syntax:expression: exec "[[ \"$VAR(@)\" =~ '^[0-9]+(\.[0-9]*)?%$' ]] || \ - /opt/vyatta/sbin/vyatta-qos-util.pl --rate \"$VAR(@)\"" +syntax:expression: exec "/opt/vyatta/sbin/vyatta-qos-util.pl --percent-or-rate \"$VAR(@)\"" comp_help: Allowed values: <number> Bandwidth in Kbps per second <number>%% Percentage of overall rate diff --git a/templates/qos-policy/traffic-shaper/node.tag/default/ceiling/node.def b/templates/qos-policy/traffic-shaper/node.tag/default/ceiling/node.def index 9b3c855..463c6bb 100644 --- a/templates/qos-policy/traffic-shaper/node.tag/default/ceiling/node.def +++ b/templates/qos-policy/traffic-shaper/node.tag/default/ceiling/node.def @@ -1,8 +1,7 @@ type: txt help: Set the bandwidth limit for default traffic default: "100%" -syntax:expression: exec "[[ \"$VAR(@)\" =~ '^[0-9]+(\.[0-9]*)?%$' ]] || \ - /opt/vyatta/sbin/vyatta-qos-util.pl --rate \"$VAR(@)\"" +syntax:expression: exec "/opt/vyatta/sbin/vyatta-qos-util.pl --percent-or-rate \"$VAR(@)\"" comp_help: Allowed values: <number> Limit in Kbps <number>%% Percentage of overall rate (default 100%%) |