summaryrefslogtreecommitdiff
path: root/scripts/VyattaQosUtil.pm
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2008-05-14 11:40:18 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2008-05-14 11:40:18 -0700
commit216b27c681dfacba194c9f001eec6287008a750c (patch)
tree66a673a895ddb57ed2a73322995cdbf40f2f6b10 /scripts/VyattaQosUtil.pm
parent17cd83259313b16a0ef27bf94a09612be8fece96 (diff)
downloadvyatta-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.
Diffstat (limited to 'scripts/VyattaQosUtil.pm')
-rw-r--r--scripts/VyattaQosUtil.pm38
1 files changed, 38 insertions, 0 deletions
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,