From 6306f6edae447d824cf1d3beacb7b64f0f00d116 Mon Sep 17 00:00:00 2001
From: Stephen Hemminger <stephen.hemminger@vyatta.com>
Date: Mon, 14 Jun 2010 08:43:33 -0700
Subject: Add default for traffic limiter

This adds:
   set traffic-policy limiter TL default bandwidth 1mbit
---
 lib/Vyatta/Qos/TrafficLimiter.pm                    | 21 ++++++++++++++++++---
 .../limiter/node.tag/default/bandwidth/node.def     |  8 ++++++++
 .../limiter/node.tag/default/burst/node.def         |  7 +++++++
 .../limiter/node.tag/default/description/node.def   |  2 ++
 .../limiter/node.tag/default/priority/node.def      |  8 ++++++++
 5 files changed, 43 insertions(+), 3 deletions(-)
 create mode 100644 templates/traffic-policy/limiter/node.tag/default/bandwidth/node.def
 create mode 100644 templates/traffic-policy/limiter/node.tag/default/burst/node.def
 create mode 100644 templates/traffic-policy/limiter/node.tag/default/description/node.def
 create mode 100644 templates/traffic-policy/limiter/node.tag/default/priority/node.def

diff --git a/lib/Vyatta/Qos/TrafficLimiter.pm b/lib/Vyatta/Qos/TrafficLimiter.pm
index c48e616..bec2b27 100644
--- a/lib/Vyatta/Qos/TrafficLimiter.pm
+++ b/lib/Vyatta/Qos/TrafficLimiter.pm
@@ -68,7 +68,12 @@ sub _define {
         die "$level can not match on both ip and other types\n";
     }
 
-    foreach my $id ( $config->listNodes("class") ) {
+    if ($config->exists('default')) {
+	$config->setLevel("$level default");
+        push @classes, new Vyatta::Qos::LimiterClass( $config, 0 );
+    }
+
+    foreach my $id ( $config->listNodes('class') ) {
         $config->setLevel("$level class $id");
         push @classes, new Vyatta::Qos::LimiterClass( $config, $id );
     }
@@ -88,15 +93,25 @@ sub commands {
 	printf "qdisc add dev %s handle %x: prio\n", $dev, $parent;
     }
 
+    # find largest class id (to use for default)
+    my $maxid = 0;
+    foreach my $class (@$classes) {
+	my $id = $class->{id};
+	$maxid = $id if ($id > $maxid);
+    }
+
     foreach my $class (@$classes) {
         foreach my $match ( $class->matchRules() ) {
+	    my $id = $class->{id};
+	    $id = $maxid + 1 if ($id == 0);
+
 	    my $police = " police rate " . $class->{rate}
 	    	. " action drop burst " . $class->{burst};
 
-	    $match->filter( $dev, $parent, $class->{id}, $class->{priority},
-			    undef, $police );
+	    $match->filter( $dev, $parent, $id, $class->{priority}, undef, $police );
         }
     }
+    
 }
 
 1;
diff --git a/templates/traffic-policy/limiter/node.tag/default/bandwidth/node.def b/templates/traffic-policy/limiter/node.tag/default/bandwidth/node.def
new file mode 100644
index 0000000..13c70ee
--- /dev/null
+++ b/templates/traffic-policy/limiter/node.tag/default/bandwidth/node.def
@@ -0,0 +1,8 @@
+type: txt
+help: Set the traffic-limit used for this class [REQUIRED]
+syntax:expression: exec "/opt/vyatta/sbin/vyatta-qos-util.pl --rate $VAR(@)"
+comp_help: Allowed values:
+ <number>          Bandwidth in Kbps
+ <number><suffix>  Value with scaling suffix
+                   bits per sec (kbit, mbit, gbit)
+                   bytes per sec (kbps, mbps, gbps)
diff --git a/templates/traffic-policy/limiter/node.tag/default/burst/node.def b/templates/traffic-policy/limiter/node.tag/default/burst/node.def
new file mode 100644
index 0000000..e22453c
--- /dev/null
+++ b/templates/traffic-policy/limiter/node.tag/default/burst/node.def
@@ -0,0 +1,7 @@
+type: txt
+help: Set the burst size for this class (default: 15kb)
+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/traffic-policy/limiter/node.tag/default/description/node.def b/templates/traffic-policy/limiter/node.tag/default/description/node.def
new file mode 100644
index 0000000..d4241e7
--- /dev/null
+++ b/templates/traffic-policy/limiter/node.tag/default/description/node.def
@@ -0,0 +1,2 @@
+type: txt
+help: Set description for this traffic class
diff --git a/templates/traffic-policy/limiter/node.tag/default/priority/node.def b/templates/traffic-policy/limiter/node.tag/default/priority/node.def
new file mode 100644
index 0000000..a99400d
--- /dev/null
+++ b/templates/traffic-policy/limiter/node.tag/default/priority/node.def
@@ -0,0 +1,8 @@
+type: u32
+help: Set priority for rule evaluation
+default: 20
+syntax:expression: $VAR(@) >= 0 && $VAR(@) <= 20 ; \
+		   "priority must be between 0 and 20"
+help: Priority value
+comp_help: Priority for traffic limiting evaluation
+ <0-20> (default 20)
-- 
cgit v1.2.3