]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ofed/management/infiniband-diags/scripts/ibdatacounters.in
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ofed / management / infiniband-diags / scripts / ibdatacounters.in
1 #!/bin/sh
2
3 IBPATH=${IBPATH:-@IBSCRIPTPATH@}
4
5 function usage() {
6         echo Usage: `basename $0` "[-h] [-b] [-v] [-N | -nocolor]" \
7             "[<topology-file> \| -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 brief=""
21 v=0
22 ntype=""
23 nodeguid=""
24 topofile=""
25 ca_info=""
26
27 while [ "$1" ]; do
28         case $1 in
29         -h)
30                 usage
31                 ;;
32         -N|-nocolor)
33                 gflags=-N
34                 ;;
35         -v)
36                 verbose=-v
37                 brief=""
38                 v=1
39                 ;;
40         -b)
41                 brief=-b
42                 verbose=""
43                 ;;
44         -P | -C | -t | -timeout)
45                 case $2 in
46                 -*)
47                         usage
48                         ;;
49                 esac
50                 if [ x$2 = x ] ; then
51                         usage
52                 fi
53                 ca_info="$ca_info $1 $2"
54                 shift
55                 ;;
56         -*)
57                 usage
58                 ;;
59         *)
60                 if [ "$topofile" ]; then
61                         usage
62                 fi
63                 topofile="$1"
64                 ;;
65         esac
66         shift
67 done
68
69 if [ "$topofile" ]; then
70         netcmd="cat $topofile"
71 else
72         netcmd="$IBPATH/ibnetdiscover $ca_info"
73 fi
74
75 text="`eval $netcmd`"
76 rv=$?
77 echo "$text" | awk '
78 BEGIN {
79         ne=0
80 }
81 function check_node(lid, port)
82 {
83         if (system("'$IBPATH'/ibchecknode '"$ca_info"' '$gflags' '$verbose' " lid)) {
84                 ne++
85                 print "\n# " ntype ": nodeguid 0x" nodeguid " failed"
86                 return 1;
87         }
88         return system("'$IBPATH'/ibcheckerrs '"$ca_info"' '$gflags' '$verbose' '$brief' " lid " " port);
89 }
90
91 /^Ca/ || /^Switch/ || /^Rt/ {
92                         nnodes++
93                         ntype=$1; nodeguid=substr($3, 4, 16); ports=$2
94                         if ('$v')
95                                 print "\n# Checking " ntype ": nodeguid 0x" nodeguid
96
97                         err = 0;
98                         if (ntype != "Switch")
99                                 next
100
101                         lid = substr($0, index($0, "port 0 lid ") + 11)
102                         lid = substr(lid, 1, index(lid, " ") - 1)
103                         err = check_node(lid, 255)
104                 }
105 /^\[/   {
106                 nports++
107                 port = $1
108                 sub("\\(.*\\)", "", port)
109                 gsub("[\\[\\]]", "", port)
110                 if (ntype != "Switch") {
111                         lid = substr($0, index($0, " lid ") + 5)
112                         lid = substr(lid, 1, index(lid, " ") - 1)
113                         check_node(lid, port)
114                 } else if (err)
115                         system("'$IBPATH'/ibdatacounts '"$ca_info"' '$gflags' '$verbose' '$brief' " lid " " port);
116 }
117
118 /^ib/   {print $0; next}
119 /ibpanic:/      {print $0}
120 /ibwarn:/       {print $0}
121 /iberror:/      {print $0}
122
123 END {
124         printf "\n## Summary: %d nodes checked, %d bad nodes found\n", nnodes, ne
125         printf "##          %d ports checked\n", nports
126         exit (ne )
127 }
128 '
129 exit $rv