1 | 1 | simandl | #!/usr/bin/perl |
2 | | | # Show classes on selected device |
3 | | | # |
4 | | | # author: Dzus |
5 | | | # version: 1.0.0 |
6 | | | # |
7 | | | # Changelog: |
8 | 22 | simandl | # 09/11/07 [simandl] prejmenovano |
9 | 1 | simandl | # 22/09/03 [dzus] Doplnen changelog a cislo verze - skript uvolnen pro verejnost |
10 | | | # 13/09/03 [dzus] Vytvoreni zakladni verze skriptu |
11 | | | # |
12 | | | # ToDo: |
13 | | | # * barevny vystup |
14 | | | # * moznost nastaveni udaju co se budou zobrazovat parametry na prikazove radce |
15 | | | # |
16 | | | |
17 | | | $IFACE=$ARGV[0]; |
18 | | | |
19 | | | $CLASSINFOFILENAME='classinfo'; |
20 | | | |
21 | | | if (!defined ($IFACE)) { |
22 | 22 | simandl | $IFACE = "ath0"; |
23 | 1 | simandl | print "Default device selected ($IFACE)\n"; |
24 | | | } |
25 | | | |
26 | | | #$TC = `which tc`; |
27 | | | $TC = "/sbin/tc"; |
28 | | | $TC =~ tr/\n/ /; |
29 | | | |
30 | | | foreach $row (`$TC -s class show dev $IFACE`) { |
31 | | | if ($row =~ /^class\s+\w+\s+(\d+:\d+)\s+(root)?(parent\s+(\d+:\d+))?.*rate\s+(\w+).*ceil\s+(\w+).*burst\s+(\w+).*$/) { |
32 | | | $id = $1; |
33 | | | @classinfo = ($4,$5,$6,$7); |
34 | | | $classlist{$id}=[ @classinfo ]; |
35 | | | if (defined($2)) { |
36 | | | $rootclassid = $id; |
37 | | | } |
38 | | | } |
39 | | | elsif ($row =~ /^\s*Sent\s+(\d+).*\s+(\d+)\s+pkts.*dropped\s+(\d+).*overlimits\s+(\d+)/) { |
40 | | | $classlist{$id}[4]=$1; |
41 | | | $classlist{$id}[5]=$2; |
42 | | | $classlist{$id}[6]=$3; |
43 | | | $classlist{$id}[7]=$4; |
44 | | | } |
45 | | | } |
46 | | | |
47 | | | if (open (classinfofile,$CLASSINFOFILENAME)) { |
48 | | | while ($row = <classinfofile>) { |
49 | | | if ($row =~ /^\s*interface\s+$IFACE\s+{\s*$/) { |
50 | | | $infofound='yes'; |
51 | | | } |
52 | | | elsif (($infofound=~/yes/) and ($row =~ /^\s*(\d+:\d+)\s+\'(.*)\'\s*$/)) { |
53 | | | $classinfo{$1} = $2; |
54 | | | } |
55 | | | elsif (($infofound=~/yes/) and ($row =~ /^\s*}\s*$/)) { |
56 | | | break; |
57 | | | } |
58 | | | } |
59 | | | } |
60 | | | |
61 | | | if ($rootclassid) { |
62 | | | print "Classes for device $IFACE\n"; |
63 | | | print_class($rootclassid,1); |
64 | | | } |
65 | | | |
66 | | | sub print_class { |
67 | | | my ($myclsid,$clsid,$level,$i); |
68 | | | $myclsid = shift; |
69 | | | $level = shift; |
70 | | | |
71 | | | for ($i = 0; $i<$level; ++$i) { print "-"; } |
72 | | | print " $myclsid"; |
73 | | | if (($infofound =~ /yes/) and $classinfo{$myclsid}) { |
74 | | | print " - $classinfo{$myclsid}\n"; |
75 | | | } |
76 | | | else { |
77 | | | print "\n"; |
78 | | | } |
79 | | | for ($i = 0; $i<$level; ++$i) { print "-"; } |
80 | | | print " rate $classlist{$myclsid}[1] ceil $classlist{$myclsid}[2] burst $classlist{$myclsid}[3]\n"; |
81 | | | for ($i = 0; $i<$level; ++$i) { print "-"; } |
82 | | | print " sent $classlist{$myclsid}[4]B $classlist{$myclsid}[5]pkts (dropped $classlist{$myclsid}[6] overlimits $classlist{$myclsid}[7])\n"; |
83 | | | |
84 | | | foreach $clsid (sort class_sort keys %classlist) { |
85 | | | if ($classlist{$clsid}[0] =~ /^$myclsid$/) { |
86 | | | print_class ($clsid,$level+1); |
87 | | | } |
88 | | | } |
89 | | | } |
90 | | | |
91 | | | sub class_sort { |
92 | | | my ($tmp); |
93 | | | |
94 | | | $a =~ /\d+:(\d+)/; |
95 | | | $tmp = $1; |
96 | | | $b =~ /\d+:(\d+)/; |
97 | | | $tmp <=> $1; |
98 | | | } |