~ubuntu-branches/ubuntu/vivid/ibutils/vivid

« back to all changes in this revision

Viewing changes to ibdm/Clusters/topo2subnet

  • Committer: Bazaar Package Importer
  • Author(s): Benoit Mortier
  • Date: 2010-01-11 22:22:00 UTC
  • Revision ID: james.westby@ubuntu.com-20100111222200-53kum2et5nh13rv3
Tags: upstream-1.2-OFED-1.4.2
ImportĀ upstreamĀ versionĀ 1.2-OFED-1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# the next line restarts using tclsh \
 
3
        exec ibdmsh "$0" "$@"
 
4
 
 
5
#
 
6
set Usage "Usage: $argv0 -t topo-file"
 
7
 
 
8
set Help "
 
9
    Convert Topo File into OpenSM Subnet file
 
10
   -------------------------------------------
 
11
 
 
12
Usage:
 
13
  $Usage
 
14
 
 
15
Description:
 
16
  The utility reads in a topology file and generate an OpenSM
 
17
subnet.lst file (in local dir) to match the specified topology.
 
18
It 'invents' guids and lids sequentially.
 
19
 
 
20
TODO: Randomize missmatches ...
 
21
"
 
22
 
 
23
###########################################################################
 
24
 
 
25
# return the string representing the given port in the subnet.lst
 
26
proc getPortStr {port} {
 
27
   global IB_SW_NODE
 
28
   set portFormat "{ CA%s Ports:%02x SystemGUID:%s NodeGUID:%s PortGUID:%s VenID:000002C9 DevID:%s Rev:000000A1 {%s} LID:%04x PN:%02x }"
 
29
   set node [IBPort_p_node_get $port]
 
30
   set sysName [IBSystem_name_get [IBNode_p_system_get $node]]
 
31
   if {[IBNode_type_get $node] == $IB_SW_NODE} {
 
32
      # we assume all switches are IS3
 
33
      set devId B9240000
 
34
      set desc "$sysName MT47396 Infiniscale-III Mellanox Technologies"
 
35
   } else {
 
36
      # we assume all CAs are Tavors:
 
37
      set devId 5A440000
 
38
      set desc "$sysName MT23108 Infinihost-II Mellanox Technologies"
 
39
   }
 
40
   return [format $portFormat \
 
41
              "" \
 
42
              [IBNode_numPorts_get $node] \
 
43
              [string range [IBNode_guid_get $node] 2 end] \
 
44
              [string range [IBNode_guid_get $node] 2 end] \
 
45
              [string range [IBPort_guid_get $port] 2 end] \
 
46
              $devId \
 
47
              $desc \
 
48
              [IBPort_base_lid_get $port] \
 
49
              [IBPort_num_get $port] \
 
50
             ]
 
51
}
 
52
 
 
53
# return the string of the link in subnet.lst format
 
54
proc getLinkStr {port1 port2} {
 
55
   set linkFormat "%s %s PHY=%s LOG=%s SPD=%s"
 
56
   set p1 [getPortStr $port1]
 
57
   set p2 [getPortStr $port2]
 
58
   set width [IBPort_width_get $port1]
 
59
   set speed [IBPort_speed_get $port1]
 
60
   return [format $linkFormat $p1 $p2 $width "ACT" $speed]
 
61
}
 
62
 
 
63
 
 
64
###########################################################################
 
65
 
 
66
#
 
67
# MAIN FLOW:
 
68
#
 
69
package require ibdm
 
70
package require getopt
 
71
 
 
72
while { [ set err [ getopt $argv "t:" opt arg ]] } {
 
73
        if { $err < 0 } then {
 
74
                Usage
 
75
                exit 2
 
76
        } else {
 
77
                switch -exact $opt {
 
78
                        h {puts $Help; exit 0}
 
79
         t {set topoFile $arg}
 
80
         default {
 
81
            puts "-E- Unsupported option:$opt"
 
82
            puts $Usage
 
83
            exit 1
 
84
         }
 
85
      }
 
86
   }
 
87
}
 
88
 
 
89
# handle extra args
 
90
set left_args [ lrange $argv $optind end ]
 
91
if {[llength $left_args]} {
 
92
   puts "-E- extra parameter(s) used : $left_args"
 
93
   puts $Usage
 
94
   exit 1
 
95
}
 
96
 
 
97
if {[catch {set of [open subnet.lst w]} e]} {
 
98
   puts "-E- $e"
 
99
   exit 1
 
100
}
 
101
 
 
102
set fabric [new_IBFabric ]
 
103
if {[IBFabric_parseTopology $fabric $topoFile]} {
 
104
   puts "-E- Fail to parse topo:$topoFile"
 
105
   exit
 
106
}
 
107
 
 
108
# we track the number of allocated guids and lids
 
109
set curGuid 1
 
110
set curLid 1
 
111
 
 
112
# go node by node and assign guids and lids,
 
113
foreach nodeDef [IBFabric_NodeByName_get $fabric ] {
 
114
   set node [lindex $nodeDef 1]
 
115
 
 
116
   # make sure the node has a guid and lid
 
117
   set guid [IBNode_guid_get $node]
 
118
   if {$guid == 0} {
 
119
      incr curGuid
 
120
      IBNode_guid_set $node [format "0x0002c900%08x" $curGuid]
 
121
   }
 
122
 
 
123
   # loop on all ports:
 
124
   foreach port [IBNode_Ports_get $node] {
 
125
      # assign port base lid and guid:
 
126
      IBPort_guid_set $port [format "0x0002c900%08x" $curGuid]
 
127
      IBPort_base_lid_set $port $curLid
 
128
 
 
129
      # non switches require new lid and new guid to each port:
 
130
      if {[IBNode_type_get $node] != $IB_SW_NODE} {
 
131
         incr curGuid
 
132
         incr curLid
 
133
      }
 
134
   }
 
135
 
 
136
   # we have assigned at least one guid and lid ...
 
137
   if {[IBNode_type_get $node] == $IB_SW_NODE} {
 
138
      incr curGuid
 
139
      incr curLid
 
140
   }
 
141
}
 
142
 
 
143
# second iteration we are ready for output
 
144
 
 
145
# go node by node and assign guids and lids,
 
146
foreach nodeDef [IBFabric_NodeByName_get $fabric ] {
 
147
   set node [lindex $nodeDef 1]
 
148
 
 
149
   foreach port [IBNode_Ports_get $node] {
 
150
      set remPort [IBPort_p_remotePort_get $port]
 
151
 
 
152
      # only interested in links
 
153
      if {$remPort != ""} {
 
154
         puts $of [getLinkStr $port $remPort]
 
155
      }
 
156
   }
 
157
}
 
158
 
 
159
close $of