]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ofed/management/infiniband-diags/scripts/ibswitches.in
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ofed / management / infiniband-diags / scripts / ibswitches.in
1 #!/bin/sh
2
3 IBPATH=${IBPATH:-@IBSCRIPTPATH@}
4
5 function usage() {
6         echo Usage: `basename $0` "[-h] [<topology-file> | -C ca_name" \
7             "-P ca_port -t(imeout) timeout_ms]"
8         exit -1
9 }
10
11 topofile=""
12 ca_info=""
13
14 while [ "$1" ]; do
15         case $1 in
16         -h)
17                 usage
18                 ;;
19         -P | -C | -t | -timeout)
20                 case $2 in
21                 -*)
22                         usage
23                         ;;
24                 esac
25                 if [ x$2 = x ] ; then
26                         usage
27                 fi
28                 ca_info="$ca_info $1 $2"
29                 shift
30                 ;;
31         -*)
32                 usage
33                 ;;
34         *)
35                 if [ "$topofile" ]; then
36                         usage
37                 fi
38                 topofile="$1"
39                 ;;
40         esac
41         shift
42 done
43
44 if [ "$topofile" ]; then
45         netcmd="cat $topofile"
46 else
47         netcmd="$IBPATH/ibnetdiscover $ca_info"
48 fi
49
50 text="`eval $netcmd`"
51 rv=$?
52 echo "$text" | awk '
53 /^Switch/       {
54                         l=$0
55                         desc=substr(l, match(l, "#[ \t]*")+RLENGTH)
56                         pi=match(desc, "port 0.*")
57                         pinfo=substr(desc, pi)
58                         desc=substr(desc, 1, pi-2)
59                         type="base"
60                         ti=match(desc, type)
61                         if (ti==0) {
62                                 type="enhanced"
63                                 ti=match(desc, type)
64                                 if (ti!=0)
65                                         desc=substr(desc, 1, ti-2)
66                         } else
67                                 desc=substr(desc, 1, ti-2)
68                         if (ti==0)
69                                 print $1 "\t: 0x" substr($3, 4, 16) " ports " $2 " "\
70                                         desc " " pinfo
71                         else
72                                 print $1 "\t: 0x" substr($3, 4, 16) " ports " $2 " "\
73                                         desc " " type " " pinfo}
74 /^ib/   {print $0; next}
75 /ibpanic:/      {print $0}
76 /ibwarn:/       {print $0}
77 /iberror:/      {print $0}
78 '
79 exit $rv