jablonka.czprosek.czf

qos

Subversion Repositories:
[/] [trunk/] [qosshow] - Rev 28 Go to most recent revision

Compare with Previous - Blame - Download


#!/usr/bin/perl
# Show classes on selected device
#
# author:   Dzus
# version:  1.0.0
#
# Changelog:
# 09/11/07 [simandl] prejmenovano
# 22/09/03 [dzus]  Doplnen changelog a cislo verze - skript uvolnen pro verejnost
# 13/09/03 [dzus]  Vytvoreni zakladni verze skriptu
#
# ToDo:
# * barevny vystup
# * moznost nastaveni udaju co se budou zobrazovat parametry na prikazove radce
#

$IFACE=$ARGV[0];

$CLASSINFOFILENAME='classinfo';

if (!defined ($IFACE)) {
    $IFACE = "ath0";
    print "Default device selected ($IFACE)\n";
}

#$TC = `which tc`;
$TC = "/sbin/tc";
$TC =~ tr/\n/ /;

foreach $row (`$TC -s class show dev $IFACE`) {
    if ($row =~ /^class\s+\w+\s+(\d+:\d+)\s+(root)?(parent\s+(\d+:\d+))?.*rate\s+(\w+).*ceil\s+(\w+).*burst\s+(\w+).*$/) {
        $id = $1;
        @classinfo = ($4,$5,$6,$7);
        $classlist{$id}=[ @classinfo ];
        if (defined($2)) {
            $rootclassid = $id;
        }
    }
    elsif ($row =~ /^\s*Sent\s+(\d+).*\s+(\d+)\s+pkt.*dropped\s+(\d+).*overlimits\s+(\d+)/) {
        $classlist{$id}[4]=$1;
        $classlist{$id}[5]=$2;
        $classlist{$id}[6]=$3;
        $classlist{$id}[7]=$4;
    }
}

if (open (classinfofile,$CLASSINFOFILENAME)) {
    while ($row = <classinfofile>) {
        if ($row =~ /^\s*interface\s+$IFACE\s+{\s*$/) {
            $infofound='yes';
        }
        elsif (($infofound=~/yes/) and ($row =~ /^\s*(\d+:\d+)\s+\'(.*)\'\s*$/)) {
            $classinfo{$1} = $2;
        }
        elsif (($infofound=~/yes/) and ($row =~ /^\s*}\s*$/)) {
            break;
        }
    }
}

if ($rootclassid) {
    print "Classes for device $IFACE\n";
    print_class($rootclassid,1);
}

sub print_class {
    my ($myclsid,$clsid,$level,$i);
    $myclsid = shift;
    $level = shift;

    for ($i = 0; $i<$level; ++$i) { print "-"; }
    print " $myclsid";
    if (($infofound =~ /yes/) and $classinfo{$myclsid}) {
        print " - $classinfo{$myclsid}\n";
    }
    else {
        print "\n";
    }
    for ($i = 0; $i<$level; ++$i) { print "-"; }
    print "     rate $classlist{$myclsid}[1] ceil $classlist{$myclsid}[2] burst $classlist{$myclsid}[3]\n";
    for ($i = 0; $i<$level; ++$i) { print "-"; }
    print "     sent $classlist{$myclsid}[4]B $classlist{$myclsid}[5]pkts (dropped $classlist{$myclsid}[6] overlimits $classlist{$myclsid}[7])\n";

    foreach $clsid (sort class_sort keys %classlist) {
        if ($classlist{$clsid}[0] =~ /^$myclsid$/) {
            print_class ($clsid,$level+1);
        }
    }
}

sub class_sort {
    my ($tmp);

    $a =~ /\d+:(\d+)/;
    $tmp = $1;
    $b =~ /\d+:(\d+)/;
    $tmp <=> $1;
}

Powered by WebSVN 2.2.1