summaryrefslogtreecommitdiff
path: root/package/qos-scripts/files/usr/bin/qos-stat
blob: 78d163888b3e9410e72899221a159b8453e0c226 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
# Copyright (C) 2011 OpenWrt.org

. /lib/functions.sh

include /lib/network

get_ifname() {
	local interface="$1"
	local cfgt

	scan_interfaces
	config_get cfgt "$interface" TYPE
	[ "$cfgt" == "interface" ] && config_get "$interface" ifname
}

config_cb() {
	config_get TYPE "$CONFIG_SECTION" TYPE
	[ "interface" == "$TYPE" ] && {
		config_get device "$CONFIG_SECTION" ifname
		[ -z "$device" ] && device="$(get_ifname ${CONFIG_SECTION})"
		config_set "$CONFIG_SECTION" device "$device"
	}
}

config_load qos

print_comments() {
	echo ''
	echo '# Interface: '"$1"
	echo '# Direction: '"$2"
	echo '# Stats:     '"$3"
	echo ''
}	

get_device() {
	( config_load network; scan_interfaces; config_get "$1" ifname )
}

interface_stats() {
	local interface="$1"
	local device

	device="$(get_device "$interface")"
	[ -z "$device" ] && config_get device "$interface" device
	config_get_bool enabled "$interface" enabled 1
	[ -z "$device" -o 1 -ne "$enabled" ] && {
		return 1
	}
	config_get_bool halfduplex "$interface" halfduplex 0

	if [ 1 -ne "$halfduplex" ]; then
		unset halfduplex
		print_comments "$interface" "Egress" "Start"
		tc -s class show dev "$device"
		print_comments "$interface" "Egress" "End"
		id="root"
	else
		id=""
	fi

	print_comments "$interface" "Ingress${halfduplex:+/Egress}" "Start"
	tc -s class show dev "$(tc filter show dev $device $id | grep mirred | sed -e 's,.*\(ifb.*\)).*,\1,')"
	print_comments "$interface" "Ingress${halfduplex:+/Egress}" "End"
}

[ -z "$1" ] && config_foreach interface_stats interface || interface_stats "$1"