summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--scripts/show-input-policy.pl184
-rw-r--r--templates/show/input-policy/adsl/node.def2
-rw-r--r--templates/show/input-policy/adsl/node.tag/node.def6
-rw-r--r--templates/show/input-policy/bonding/node.def2
-rw-r--r--templates/show/input-policy/bonding/node.tag/node.def3
-rw-r--r--templates/show/input-policy/ethernet/node.def2
-rw-r--r--templates/show/input-policy/ethernet/node.tag/node.def3
-rw-r--r--templates/show/input-policy/input/node.def2
-rw-r--r--templates/show/input-policy/input/node.tag/node.def3
-rw-r--r--templates/show/input-policy/node.def2
-rw-r--r--templates/show/input-policy/pppoe/node.def2
-rw-r--r--templates/show/input-policy/pppoe/node.tag/node.def3
-rw-r--r--templates/show/input-policy/pseudo-ethernet/node.def2
-rw-r--r--templates/show/input-policy/serial/node.def2
-rw-r--r--templates/show/input-policy/serial/node.tag/node.def6
-rw-r--r--templates/show/input-policy/tunnel/node.def2
-rw-r--r--templates/show/input-policy/wireless/node.def2
-rw-r--r--templates/show/input-policy/wireless/node.tag/node.def3
19 files changed, 232 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index bb85963..c12ba26 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,6 +2,7 @@ opdir = $(datadir)/vyatta-op/templates
bin_SCRIPTS = scripts/vyatta-show-queue
bin_SCRIPTS += scripts/vyatta-show-queueing.pl
+bin_SCRIPTS += scripts/show-input-policy.pl
cpiop = find . ! -regex '\(.*~\|.*\.bak\|.*\.swp\|.*\#.*\#\)' -print0 | \
cpio -0pd
diff --git a/scripts/show-input-policy.pl b/scripts/show-input-policy.pl
new file mode 100644
index 0000000..41ea209
--- /dev/null
+++ b/scripts/show-input-policy.pl
@@ -0,0 +1,184 @@
+#!/usr/bin/perl
+#
+# Module: show-input-policy.pl
+#
+# **** 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) 2007 Vyatta, Inc.
+# All Rights Reserved.
+#
+# Author: Stephen Hemminger
+# Date: July 2008
+# Description: Script to display QoS information in pretty form
+#
+# **** End License ****
+#
+
+use strict;
+use warnings;
+
+use Getopt::Long;
+
+use lib "/opt/vyatta/share/perl5/";
+use Vyatta::Interface;
+use Vyatta::Misc;
+
+my $INGRESS = 0xffff;
+
+sub ingress_interface {
+ my @interfaces;
+
+ # Read base qdisc list to find ingress
+ open( my $tc, '-|', '/sbin/tc qdisc ls' )
+ or die 'tc qdisc command failed';
+
+ while (<$tc>) {
+ chomp;
+ # qdisc ingress ffff: dev eth0 parent ffff:fff1 -------------------
+ my (undef, $qdisc, undef, undef, $dev) = split;
+ next unless ($qdisc eq 'ingress');
+ push @interfaces, $dev;
+ }
+ close $tc;
+
+ return @interfaces;
+}
+
+sub qminor {
+ my $id = shift;
+
+ return hex($1) if ( $id =~ /:(.*)$/ );
+}
+
+sub get_filter {
+ my ($interface) = @_;
+
+ open( my $tc, '-|',
+ "/sbin/tc -s -s filter show dev $interface parent ffff:" )
+ or die 'tc filter command failed: $!';
+
+ my $id = $INGRESS;
+ my ($rate, $policy);
+ my %filters;
+
+ while (<$tc>) {
+ chomp;
+ /^filter/ && do {
+ # filter protocol all pref 20 u32
+ # filter protocol all pref 20 u32 fh 800: ht divisor 1
+ # filter protocol all pref 20 u32 fh 800::800 order 2048 ... flowid ffff:2
+ my @field = split;
+ next unless $#field >= 16 && $field[15] eq 'flowid';
+ $id = qminor($field[16]);
+ };
+ /^\s+police/ && do {
+ # police 0x3 rate 80000Kbit burst 16Kb
+ (undef, undef, undef, $rate) = split;
+ $rate =~ s/bit$//;
+ $policy = 'limit';
+ };
+ /^\s+action/ && do {
+ # action order 1: mirred (Egress Redirect to device ifb0) stolen
+ my (undef, undef, undef, undef, undef, $action) = split;
+ $policy = lc($action);
+ };
+ /^\s+Sent/ && do {
+ # Sent 960 bytes 88 pkts (dropped 0, overlimits 0)
+ my ( undef, $sent, undef, undef, undef, undef,
+ $drop, undef, $over ) = split;
+
+ $drop =~ s/,$//;
+ $over =~ s/\)$//;
+
+ $filters{$id} = [ $policy, $sent, $drop, $over, $rate, ];
+ $id = $INGRESS;
+ $policy = undef;
+ $rate = undef;
+ };
+ }
+
+ return \%filters;
+}
+
+sub show {
+ my $interface = shift;
+ my $filters = get_filter($interface);
+ return unless $filters;
+
+ print "\n$interface input:\n";
+
+ my $fmt = "%-10s %-10s %-10s %-9s %-9s %s\n";
+ printf $fmt, 'Class', 'Policy', 'Received', 'Dropped', 'Overlimit', 'Rate';
+
+ foreach my $id (sort keys %{$filters}) {
+ my @args = @{$filters->{$id}};
+ my $class = ($id eq $INGRESS) ? 'default' : $id;
+ my $rate = pop @args;
+ $rate = '-' unless defined($rate);
+
+ printf $fmt, $class, @args, $rate;
+ }
+}
+
+sub show_brief {
+ my @interfaces = ingress_interface();
+
+ my $fmt = "%-10s %-10s %-10s %-9s %-9s\n";
+ printf $fmt, 'Interface', 'Policy', 'Received', 'Dropped', 'Overlimit';
+
+ foreach my $intf (sort @interfaces) {
+ my $filters = get_filter($intf);
+ my $policy;
+ my $receive = 0;
+ my $dropped = 0;
+ my $overlimit = 0;
+
+ foreach my $id (keys %{$filters}) {
+ my @args = @{$filters->{$id}};
+ $policy = $args[0];
+ $receive += $args[1];
+ $dropped += $args[2];
+ $overlimit += $args[3];
+ }
+ printf $fmt, $intf, $policy, $receive, $dropped, $overlimit;
+ }
+ exit 0;
+}
+
+sub usage {
+ print "Usage: $0 [--type={ethernet,serial}] --brief\n";
+ print " $0 interface(s)\n";
+ exit 1;
+}
+
+my ($intf_type, $brief);
+
+GetOptions(
+ 'type=s' => \$intf_type,
+ 'brief' => \$brief,
+) or usage();
+
+show_brief() if $brief;
+
+if ( $#ARGV == -1 ) {
+ foreach my $ifname ( getInterfaces() ) {
+ if ($intf_type) {
+ my $intf = new Vyatta::Interface($ifname);
+ next unless ( $intf && $intf_type eq $intf->type() );
+ }
+ push @ARGV, $ifname;
+ }
+}
+
+foreach my $interface ( sort @ARGV ) {
+ show($interface);
+}
diff --git a/templates/show/input-policy/adsl/node.def b/templates/show/input-policy/adsl/node.def
new file mode 100644
index 0000000..8a1cd8c
--- /dev/null
+++ b/templates/show/input-policy/adsl/node.def
@@ -0,0 +1,2 @@
+help: Show adsl input-policy information
+run: ${vyatta_bindir}/show-input-policy.pl --type=adsl
diff --git a/templates/show/input-policy/adsl/node.tag/node.def b/templates/show/input-policy/adsl/node.tag/node.def
new file mode 100644
index 0000000..af1473f
--- /dev/null
+++ b/templates/show/input-policy/adsl/node.tag/node.def
@@ -0,0 +1,6 @@
+help: Show specified adsl interface information
+allowed:
+ local -a array ;
+ array=( /sys/class/net/adsl* ) ;
+ echo -n ${array[@]##*/}
+run: ${vyatta_bindir}/show-input-policy.pl "$4"
diff --git a/templates/show/input-policy/bonding/node.def b/templates/show/input-policy/bonding/node.def
new file mode 100644
index 0000000..6af91c0
--- /dev/null
+++ b/templates/show/input-policy/bonding/node.def
@@ -0,0 +1,2 @@
+help: Show bonding input-policy information
+run: ${vyatta_bindir}/show-input-policy.pl --type=bonding
diff --git a/templates/show/input-policy/bonding/node.tag/node.def b/templates/show/input-policy/bonding/node.tag/node.def
new file mode 100644
index 0000000..23138fe
--- /dev/null
+++ b/templates/show/input-policy/bonding/node.tag/node.def
@@ -0,0 +1,3 @@
+help: Show specified bonding interface information
+allowed: ${vyatta_sbindir}/vyatta-interfaces.pl --show=bonding
+run: ${vyatta_bindir}/show-input-policy.pl "$4"
diff --git a/templates/show/input-policy/ethernet/node.def b/templates/show/input-policy/ethernet/node.def
new file mode 100644
index 0000000..f8f400e
--- /dev/null
+++ b/templates/show/input-policy/ethernet/node.def
@@ -0,0 +1,2 @@
+help: Show ethernet input-policy information
+run: ${vyatta_bindir}/show-input-policy.pl --type=ethernet
diff --git a/templates/show/input-policy/ethernet/node.tag/node.def b/templates/show/input-policy/ethernet/node.tag/node.def
new file mode 100644
index 0000000..c9df0f9
--- /dev/null
+++ b/templates/show/input-policy/ethernet/node.tag/node.def
@@ -0,0 +1,3 @@
+help: Show specified ethernet interface information
+allowed: ${vyatta_sbindir}/vyatta-interfaces.pl --show=ethernet
+run: ${vyatta_bindir}/show-input-policy.pl "$4"
diff --git a/templates/show/input-policy/input/node.def b/templates/show/input-policy/input/node.def
new file mode 100644
index 0000000..d1daf52
--- /dev/null
+++ b/templates/show/input-policy/input/node.def
@@ -0,0 +1,2 @@
+help: Show input input-policy information
+run: ${vyatta_bindir}/show-input-policy.pl --type=input
diff --git a/templates/show/input-policy/input/node.tag/node.def b/templates/show/input-policy/input/node.tag/node.def
new file mode 100644
index 0000000..05afd76
--- /dev/null
+++ b/templates/show/input-policy/input/node.tag/node.def
@@ -0,0 +1,3 @@
+help: Show specified input interface information
+allowed: ${vyatta_sbindir}/vyatta-interfaces.pl --show=input
+run: ${vyatta_bindir}/show-input-policy.pl "$4"
diff --git a/templates/show/input-policy/node.def b/templates/show/input-policy/node.def
new file mode 100644
index 0000000..410e1d6
--- /dev/null
+++ b/templates/show/input-policy/node.def
@@ -0,0 +1,2 @@
+help: Show ethernet input-policy information
+run: ${vyatta_bindir}/show-input-policy.pl --brief
diff --git a/templates/show/input-policy/pppoe/node.def b/templates/show/input-policy/pppoe/node.def
new file mode 100644
index 0000000..5f02564
--- /dev/null
+++ b/templates/show/input-policy/pppoe/node.def
@@ -0,0 +1,2 @@
+help: Show pppoe interface input-policy information
+run: ${vyatta_bindir}/show-input-policy.pl --type=pppoe
diff --git a/templates/show/input-policy/pppoe/node.tag/node.def b/templates/show/input-policy/pppoe/node.tag/node.def
new file mode 100644
index 0000000..67a0eae
--- /dev/null
+++ b/templates/show/input-policy/pppoe/node.tag/node.def
@@ -0,0 +1,3 @@
+help: Show specified pppoe interface information
+allowed: ${vyatta_sbindir}/vyatta-interfaces.pl --show=pppoe
+run: ${vyatta_bindir}/show-input-policy.pl "$4"
diff --git a/templates/show/input-policy/pseudo-ethernet/node.def b/templates/show/input-policy/pseudo-ethernet/node.def
new file mode 100644
index 0000000..05ec8c9
--- /dev/null
+++ b/templates/show/input-policy/pseudo-ethernet/node.def
@@ -0,0 +1,2 @@
+help: Show tunnel input-policy information
+run: ${vyatta_bindir}/show-input-policy.pl --type=pseudo-ethernet
diff --git a/templates/show/input-policy/serial/node.def b/templates/show/input-policy/serial/node.def
new file mode 100644
index 0000000..93d7188
--- /dev/null
+++ b/templates/show/input-policy/serial/node.def
@@ -0,0 +1,2 @@
+help: Show serial input-policy information
+run: ${vyatta_bindir}/show-input-policy.pl --type=serial
diff --git a/templates/show/input-policy/serial/node.tag/node.def b/templates/show/input-policy/serial/node.tag/node.def
new file mode 100644
index 0000000..36fde57
--- /dev/null
+++ b/templates/show/input-policy/serial/node.tag/node.def
@@ -0,0 +1,6 @@
+help: Show specified adsl interface information
+allowed:
+ local -a array ;
+ array=( /sys/class/net/wan* ) ;
+ echo -n ${array[@]##*/}
+run: ${vyatta_bindir}/show-input-policy.pl "$4"
diff --git a/templates/show/input-policy/tunnel/node.def b/templates/show/input-policy/tunnel/node.def
new file mode 100644
index 0000000..69965f2
--- /dev/null
+++ b/templates/show/input-policy/tunnel/node.def
@@ -0,0 +1,2 @@
+help: Show tunnel input-policy information
+run: ${vyatta_bindir}/show-input-policy.pl --type=tunnel
diff --git a/templates/show/input-policy/wireless/node.def b/templates/show/input-policy/wireless/node.def
new file mode 100644
index 0000000..521848a
--- /dev/null
+++ b/templates/show/input-policy/wireless/node.def
@@ -0,0 +1,2 @@
+help: Show wireless input-policy information
+run: ${vyatta_bindir}/show-input-policy.pl --type=wireless
diff --git a/templates/show/input-policy/wireless/node.tag/node.def b/templates/show/input-policy/wireless/node.tag/node.def
new file mode 100644
index 0000000..8e4170c
--- /dev/null
+++ b/templates/show/input-policy/wireless/node.tag/node.def
@@ -0,0 +1,3 @@
+help: Show specified wireless interface information
+allowed: ${vyatta_sbindir}/vyatta-interfaces.pl --show=wireless
+run: ${vyatta_bindir}/show-input-policy.pl "$4"