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