3 # Copyright (c) 2007-2008 Voltaire, Inc. All rights reserved.
4 # Copyright (c) 2006 The Regents of the University of California.
6 # This software is available to you under a choice of one of two
7 # licenses. You may choose to be licensed under the terms of the GNU
8 # General Public License (GPL) Version 2, available from the file
9 # COPYING in the main directory of this source tree, or the
10 # OpenIB.org BSD license below:
12 # Redistribution and use in source and binary forms, with or
13 # without modification, are permitted provided that the following
16 # - Redistributions of source code must retain the above
17 # copyright notice, this list of conditions and the following
20 # - Redistributions in binary form must reproduce the above
21 # copyright notice, this list of conditions and the following
22 # disclaimer in the documentation and/or other materials
23 # provided with the distribution.
25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43 print "Usage: $prog [-Rh]\n";
45 " Validate LIDs and GUIDs (check for zero and duplicates) in the local subnet\n";
46 print " -h This help message\n";
48 " -R Recalculate ibnetdiscover information (Default is to reuse ibnetdiscover output)\n";
52 my $argv0 = `basename $0`;
53 my $regenerate_map = undef;
56 if (!getopts("hR")) { usage_and_exit $argv0; }
57 if (defined $Getopt::Std::opt_h) { usage_and_exit $argv0; }
58 if (defined $Getopt::Std::opt_R) { $regenerate_map = $Getopt::Std::opt_R; }
60 sub validate_non_zero_lid
62 my ($lid) = shift(@_);
63 my ($nodeguid) = shift(@_);
64 my ($nodetype) = shift(@_);
67 print "LID 0 found for $nodetype NodeGUID $nodeguid\n";
73 sub validate_non_zero_guid
75 my ($lid) = shift(@_);
76 my ($guid) = shift(@_);
77 my ($nodetype) = shift(@_);
80 print "$nodetype GUID 0x0 found with LID $lid\n";
86 $insert_lid::lids = undef;
87 $insert_nodeguid::nodeguids = undef;
88 $insert_portguid::portguids = undef;
92 my ($lid) = shift(@_);
93 my ($nodeguid) = shift(@_);
94 my ($nodetype) = shift(@_);
98 $status = validate_non_zero_lid($lid, $nodeguid, $nodetype);
100 if (defined($insert_lid::lids{$lid})) {
102 "LID $lid already defined for NodeGUID $insert_lid::lids{$lid}->{nodeguid}\n";
104 $rec = {lid => $lid, nodeguid => $nodeguid};
105 $insert_lid::lids{$lid} = $rec;
112 my ($lid) = shift(@_);
113 my ($nodeguid) = shift(@_);
114 my ($nodetype) = shift(@_);
118 $status = validate_non_zero_guid($lid, $nodeguid, $nodetype);
120 if (defined($insert_nodeguid::nodeguids{$nodeguid})) {
122 "NodeGUID $nodeguid already defined for LID $insert_nodeguid::nodeguids{$nodeguid}->{lid}\n";
124 $rec = {lid => $lid, nodeguid => $nodeguid};
125 $insert_nodeguid::nodeguids{$nodeguid} = $rec;
130 sub validate_portguid
132 my ($portguid) = shift(@_);
133 my ($firstport) = shift(@_);
135 if (defined($insert_nodeguid::nodeguids{$portguid})
136 && ($firstport ne "yes"))
138 print "PortGUID $portguid is invalid duplicate of a NodeGUID\n";
144 my ($lid) = shift(@_);
145 my ($portguid) = shift(@_);
146 my ($nodetype) = shift(@_);
147 my ($firstport) = shift(@_);
151 $status = validate_non_zero_guid($lid, $portguid, $nodetype);
153 if (defined($insert_portguid::portguids{$portguid})) {
155 "PortGUID $portguid already defined for LID $insert_portguid::portguids{$portguid}->{lid}\n";
157 $rec = {lid => $lid, portguid => $portguid};
158 $insert_portguid::portguids{$portguid} = $rec;
159 validate_portguid($portguid, $firstport);
167 || !(-f "$IBswcountlimits::cache_dir/ibnetdiscover.topology"))
169 generate_ibnetdiscover_topology;
172 open IBNET_TOPO, "<$IBswcountlimits::cache_dir/ibnetdiscover.topology"
173 or die "Failed to open ibnet topology: $!\n";
182 while ($line = <IBNET_TOPO>) {
184 if ($line =~ /^caguid=(.*)/ || $line =~ /^rtguid=(.*)/) {
189 if ($line =~ /^switchguid=(.*)/) {
194 if ($line =~ /^switchguid=(.*)\((.*)\)/) {
196 $portguid = "0x" . $2;
199 if ($line =~ /^Switch.*\"S-(.*)\"\s+# (.*) port.* lid (\d+) .*/) {
200 $nodetype = "switch";
203 insert_lid($lid, $nodeguid, $nodetype);
204 insert_nodeguid($lid, $nodeguid, $nodetype);
205 if ($portguid ne "") {
206 insert_portguid($lid, $portguid, $nodetype, $firstport);
209 if ($line =~ /^Ca.*/) {
213 if ($line =~ /^Rt.*/) {
214 $nodetype = "router";
218 if ($nodetype eq "ca" || $nodetype eq "router") {
219 if ($line =~ /"S-(.*)\# lid (\d+) .*/) {
221 insert_lid($lid, $nodeguid, $nodetype);
222 if ($firstport eq "yes") {
223 insert_nodeguid($lid, $nodeguid, $nodetype);
227 if ($line =~ /^.*"H-(.*)\# lid (\d+) .*/) {
229 insert_lid($lid, $nodeguid, $nodetype);
230 if ($firstport eq "yes") {
231 insert_nodeguid($lid, $nodeguid, $nodetype);
235 if ($line =~ /^.*"R-(.*)\# lid (\d+) .*/) {
237 insert_lid($lid, $nodeguid, $nodetype);
238 if ($firstport eq "yes") {
239 insert_nodeguid($lid, $nodeguid, $nodetype);
243 if ($line =~ /^\[(\d+)\]\((.*)\)/) {
244 $portguid = "0x" . $2;
245 insert_portguid($lid, $portguid, $nodetype, $firstport);