]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/ofed/management/infiniband-diags/scripts/ibclearcounters.in
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / ofed / management / infiniband-diags / scripts / ibclearcounters.in
1 #!/bin/sh
2
3 IBPATH=${IBPATH:-@IBSCRIPTPATH@}
4
5 function 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
11 function user_abort() {
12         echo "Aborted"
13         exit 1
14 }
15
16 trap user_abort SIGINT
17
18 gflags=""
19 verbose=""
20 v=0
21 topofile=""
22 ca_info=""
23
24 while [ "$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
52 done
53
54 if [ "$topofile" ]; then
55         netcmd="cat $topofile"
56 else
57         netcmd="$IBPATH/ibnetdiscover $ca_info"
58 fi
59
60 text="`eval $netcmd`"
61 rv=$?
62 echo "$text" | awk '
63
64 function clear_counters(lid)
65 {
66         if (system("'$IBPATH'/perfquery'"$ca_info"' '$gflags' -R -a " lid))
67                 nodeerr++
68 }
69
70 function 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
103 END {
104         printf "\n## Summary: %d nodes cleared %d errors\n", nnodes, nodeerr
105 }
106 '
107 exit $rv