1#!/bin/sh
2
3IBPATH=${IBPATH:-@IBSCRIPTPATH@}
4
5function usage() {
6	echo Usage: `basename $0` "[-h] [<topology-file>" \
7	    "| -C ca_name -P ca_port -t(imeout) timeout_ms]"
8	exit -1
9}
10
11function user_abort() {
12	echo "Aborted"
13	exit 1
14}
15
16trap user_abort SIGINT
17
18gflags=""
19verbose=""
20v=0
21topofile=""
22ca_info=""
23
24while [ "$1" ]; do
25	case $1 in
26	-h)
27		usage
28		;;
29	-P | -C | -t | -timeout)
30		case $2 in
31		-*)
32			usage
33			;;
34		esac
35		if [ x$2 = x ] ; then
36			usage
37		fi
38		ca_info="$ca_info $1 $2"
39		shift
40		;;
41	-*)
42		usage
43		;;
44	*)
45		if [ "$topofile" ]; then
46			usage
47		fi
48		topofile="$1"
49		;;
50	esac
51	shift
52done
53
54if [ "$topofile" ]; then
55	netcmd="cat $topofile"
56else
57	netcmd="$IBPATH/ibnetdiscover $ca_info"
58fi
59
60text="`eval $netcmd`"
61rv=$?
62echo "$text" | awk '
63
64function clear_counters(lid)
65{
66	if (system("'$IBPATH'/perfquery'"$ca_info"' '$gflags' -R -a " lid))
67		nodeerr++
68}
69
70function clear_port_counters(lid, port)
71{
72	if (system("'$IBPATH'/perfquery'"$ca_info"' '$gflags' -R " lid " " port))
73		nodeerr++
74}
75
76/^Ca/ || /^Switch/ || /^Rt/ {
77			nnodes++
78			ntype=$1; nodeguid=substr($3, 4, 16); ports=$2
79			if (ntype != "Switch")
80				next
81
82			lid = substr($0, index($0, "port 0 lid ") + 11)
83			lid = substr(lid, 1, index(lid, " ") - 1)
84			clear_counters(lid)
85		}
86
87/^\[/   {
88			port = $1
89			sub("\\(.*\\)", "", port)
90			gsub("[\\[\\]]", "", port)
91			if (ntype != "Switch") {
92				lid = substr($0, index($0, " lid ") + 5)
93				lid = substr(lid, 1, index(lid, " ") - 1)
94				clear_port_counters(lid, port)
95			}
96		}
97
98/^ib/	{print $0; next}
99/ibpanic:/	{print $0}
100/ibwarn:/	{print $0}
101/iberror:/	{print $0}
102
103END {
104	printf "\n## Summary: %d nodes cleared %d errors\n", nnodes, nodeerr
105}
106'
107exit $rv
108