qos-stat 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. # Copyright (C) 2011 OpenWrt.org
  3. . /lib/functions.sh
  4. include /lib/network
  5. get_ifname() {
  6. local interface="$1"
  7. local cfgt
  8. scan_interfaces
  9. config_get cfgt "$interface" TYPE
  10. [ "$cfgt" = "interface" ] && config_get "$interface" ifname
  11. }
  12. config_cb() {
  13. config_get TYPE "$CONFIG_SECTION" TYPE
  14. [ "interface" = "$TYPE" ] && {
  15. config_get device "$CONFIG_SECTION" ifname
  16. [ -z "$device" ] && device="$(get_ifname ${CONFIG_SECTION})"
  17. config_set "$CONFIG_SECTION" device "$device"
  18. }
  19. }
  20. config_load qos
  21. print_comments() {
  22. echo ''
  23. echo '# Interface: '"$1"
  24. echo '# Direction: '"$2"
  25. echo '# Stats: '"$3"
  26. echo ''
  27. }
  28. get_device() {
  29. ( config_load network; scan_interfaces; config_get "$1" ifname )
  30. }
  31. interface_stats() {
  32. local interface="$1"
  33. local device
  34. device="$(get_device "$interface")"
  35. [ -z "$device" ] && config_get device "$interface" device
  36. config_get_bool enabled "$interface" enabled 1
  37. [ -z "$device" -o 1 -ne "$enabled" ] && {
  38. return 1
  39. }
  40. config_get_bool halfduplex "$interface" halfduplex 0
  41. if [ 1 -ne "$halfduplex" ]; then
  42. unset halfduplex
  43. print_comments "$interface" "Egress" "Start"
  44. tc -s class show dev "$device"
  45. print_comments "$interface" "Egress" "End"
  46. id="root"
  47. else
  48. id=""
  49. fi
  50. print_comments "$interface" "Ingress${halfduplex:+/Egress}" "Start"
  51. tc -s class show dev "$(tc filter show dev $device $id | grep mirred | sed -e 's,.*\(ifb.*\)).*,\1,')"
  52. print_comments "$interface" "Ingress${halfduplex:+/Egress}" "End"
  53. }
  54. [ -z "$1" ] && config_foreach interface_stats interface || interface_stats "$1"