summaryrefslogtreecommitdiff
path: root/scripts/vyatta-qos.pl
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2008-03-05 15:05:42 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2008-03-05 15:05:42 -0800
commit4ef3988035e980e62da5d1557ebec817cba7f3a5 (patch)
tree6513a9e0f50deea7095a2880a48f73f2030f1812 /scripts/vyatta-qos.pl
parent095dfa147f6e3ea833e9c4a4824672a2060b1b2b (diff)
downloadvyatta-cfg-qos-4ef3988035e980e62da5d1557ebec817cba7f3a5.tar.gz
vyatta-cfg-qos-4ef3988035e980e62da5d1557ebec817cba7f3a5.zip
use object factory rather than hardcoded switch for policy config
Having a hardcoded switch statement is harder to update than using a hash.
Diffstat (limited to 'scripts/vyatta-qos.pl')
-rwxr-xr-xscripts/vyatta-qos.pl33
1 files changed, 22 insertions, 11 deletions
diff --git a/scripts/vyatta-qos.pl b/scripts/vyatta-qos.pl
index d5936f9..295b409 100755
--- a/scripts/vyatta-qos.pl
+++ b/scripts/vyatta-qos.pl
@@ -2,7 +2,6 @@
use lib "/opt/vyatta/share/perl5/";
use VyattaConfig;
-use VyattaQosPolicy;
use strict;
use Getopt::Long;
@@ -14,6 +13,13 @@ my @updatePolicy = ();
my @deletePolicy = ();
my $listPolicy = undef;
+# map from template name to perl object
+# TODO: subdirectory
+my %policies = (
+ 'traffic-shaper' => "VyattaQosTrafficShaper",
+ 'fair-queue' => "VyattaQosFairQueue",
+);
+
GetOptions(
"update-interface=s{3}" => \@updateInterface,
"delete-interface=s{2}" => \@deleteInterface,
@@ -45,7 +51,7 @@ sub delete_interface {
if ($direction eq "out" ) {
# delete old qdisc - will give error if no policy in place
- qx(sudo tc qdisc del dev "$interface" root 2>/dev/null);
+ qx(sudo /sbin/tc qdisc del dev "$interface" root 2>/dev/null);
}
}
@@ -58,12 +64,16 @@ sub update_interface {
( $direction eq "out" ) or die "Only out direction supported";
$config->setLevel('qos-policy');
- foreach my $policy ( $config->listNodes() ) {
- if ( $config->exists("$policy $name") ) {
- $config->setLevel("qos-policy $policy $name");
+ foreach my $type ( $config->listNodes() ) {
+ if ( $config->exists("$type $name") ) {
+ $config->setLevel("qos-policy $type $name");
+
+ my $class = $policies{$type};
+ # This means template exists but we don't know what it is.
+ defined $class or die "Unknown policy type $type";
- my $policy = VyattaQosPolicy->config( $config, $policy );
- defined $policy or die "undefined policy";
+ require "$class.pm";
+ my $shaper = $class->new($config, $name);
# When doing debugging just echo the commands
my $out;
@@ -71,19 +81,20 @@ sub update_interface {
open $out, '>-'
or die "can't open stdout: $!";
} else {
- open $out, "|-" or exec qw/sudo tc -batch -/
+ open $out, "|-" or exec qw:sudo /sbin/tc -batch -:
or die "Tc setup failed: $!\n";
}
- $policy->commands($out, $interface);
+ $shaper->commands($out, $interface);
if (! close $out && ! defined $debug) {
+ # cleanup any partial commands
delete_interface($interface, $direction);
# replay commands to stdout
open $out, '>-';
- $policy->commands($out, $interface);
+ $shaper->commands($out, $interface);
close $out;
- die "Conversion of configuration to tc command error\n";
+ die "TC command failed.";
}
exit 0;
}