├── .gitignore
├── LICENSE
├── README.rst
├── src
└── ibtopotool.py
└── tests
├── 1.topo
├── 2.topo
├── 3.topo
├── 4.topo
├── notes.rst
└── run_tests.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | *.py[cod]
2 |
3 | # C extensions
4 | *.so
5 |
6 | # Packages
7 | *.egg
8 | *.egg-info
9 | dist
10 | build
11 | eggs
12 | parts
13 | bin
14 | var
15 | sdist
16 | develop-eggs
17 | .installed.cfg
18 | lib
19 | lib64
20 | __pycache__
21 |
22 | # Installer logs
23 | pip-log.txt
24 |
25 | # Unit test / coverage reports
26 | .coverage
27 | .tox
28 | nosetests.xml
29 |
30 | # Translations
31 | *.mo
32 |
33 | # Mr Developer
34 | .mr.developer.cfg
35 | .project
36 | .pydevproject
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Mozilla Public License Version 2.0
2 | ==================================
3 |
4 | 1. Definitions
5 | --------------
6 |
7 | 1.1. "Contributor"
8 | means each individual or legal entity that creates, contributes to
9 | the creation of, or owns Covered Software.
10 |
11 | 1.2. "Contributor Version"
12 | means the combination of the Contributions of others (if any) used
13 | by a Contributor and that particular Contributor's Contribution.
14 |
15 | 1.3. "Contribution"
16 | means Covered Software of a particular Contributor.
17 |
18 | 1.4. "Covered Software"
19 | means Source Code Form to which the initial Contributor has attached
20 | the notice in Exhibit A, the Executable Form of such Source Code
21 | Form, and Modifications of such Source Code Form, in each case
22 | including portions thereof.
23 |
24 | 1.5. "Incompatible With Secondary Licenses"
25 | means
26 |
27 | (a) that the initial Contributor has attached the notice described
28 | in Exhibit B to the Covered Software; or
29 |
30 | (b) that the Covered Software was made available under the terms of
31 | version 1.1 or earlier of the License, but not also under the
32 | terms of a Secondary License.
33 |
34 | 1.6. "Executable Form"
35 | means any form of the work other than Source Code Form.
36 |
37 | 1.7. "Larger Work"
38 | means a work that combines Covered Software with other material, in
39 | a separate file or files, that is not Covered Software.
40 |
41 | 1.8. "License"
42 | means this document.
43 |
44 | 1.9. "Licensable"
45 | means having the right to grant, to the maximum extent possible,
46 | whether at the time of the initial grant or subsequently, any and
47 | all of the rights conveyed by this License.
48 |
49 | 1.10. "Modifications"
50 | means any of the following:
51 |
52 | (a) any file in Source Code Form that results from an addition to,
53 | deletion from, or modification of the contents of Covered
54 | Software; or
55 |
56 | (b) any new file in Source Code Form that contains any Covered
57 | Software.
58 |
59 | 1.11. "Patent Claims" of a Contributor
60 | means any patent claim(s), including without limitation, method,
61 | process, and apparatus claims, in any patent Licensable by such
62 | Contributor that would be infringed, but for the grant of the
63 | License, by the making, using, selling, offering for sale, having
64 | made, import, or transfer of either its Contributions or its
65 | Contributor Version.
66 |
67 | 1.12. "Secondary License"
68 | means either the GNU General Public License, Version 2.0, the GNU
69 | Lesser General Public License, Version 2.1, the GNU Affero General
70 | Public License, Version 3.0, or any later versions of those
71 | licenses.
72 |
73 | 1.13. "Source Code Form"
74 | means the form of the work preferred for making modifications.
75 |
76 | 1.14. "You" (or "Your")
77 | means an individual or a legal entity exercising rights under this
78 | License. For legal entities, "You" includes any entity that
79 | controls, is controlled by, or is under common control with You. For
80 | purposes of this definition, "control" means (a) the power, direct
81 | or indirect, to cause the direction or management of such entity,
82 | whether by contract or otherwise, or (b) ownership of more than
83 | fifty percent (50%) of the outstanding shares or beneficial
84 | ownership of such entity.
85 |
86 | 2. License Grants and Conditions
87 | --------------------------------
88 |
89 | 2.1. Grants
90 |
91 | Each Contributor hereby grants You a world-wide, royalty-free,
92 | non-exclusive license:
93 |
94 | (a) under intellectual property rights (other than patent or trademark)
95 | Licensable by such Contributor to use, reproduce, make available,
96 | modify, display, perform, distribute, and otherwise exploit its
97 | Contributions, either on an unmodified basis, with Modifications, or
98 | as part of a Larger Work; and
99 |
100 | (b) under Patent Claims of such Contributor to make, use, sell, offer
101 | for sale, have made, import, and otherwise transfer either its
102 | Contributions or its Contributor Version.
103 |
104 | 2.2. Effective Date
105 |
106 | The licenses granted in Section 2.1 with respect to any Contribution
107 | become effective for each Contribution on the date the Contributor first
108 | distributes such Contribution.
109 |
110 | 2.3. Limitations on Grant Scope
111 |
112 | The licenses granted in this Section 2 are the only rights granted under
113 | this License. No additional rights or licenses will be implied from the
114 | distribution or licensing of Covered Software under this License.
115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a
116 | Contributor:
117 |
118 | (a) for any code that a Contributor has removed from Covered Software;
119 | or
120 |
121 | (b) for infringements caused by: (i) Your and any other third party's
122 | modifications of Covered Software, or (ii) the combination of its
123 | Contributions with other software (except as part of its Contributor
124 | Version); or
125 |
126 | (c) under Patent Claims infringed by Covered Software in the absence of
127 | its Contributions.
128 |
129 | This License does not grant any rights in the trademarks, service marks,
130 | or logos of any Contributor (except as may be necessary to comply with
131 | the notice requirements in Section 3.4).
132 |
133 | 2.4. Subsequent Licenses
134 |
135 | No Contributor makes additional grants as a result of Your choice to
136 | distribute the Covered Software under a subsequent version of this
137 | License (see Section 10.2) or under the terms of a Secondary License (if
138 | permitted under the terms of Section 3.3).
139 |
140 | 2.5. Representation
141 |
142 | Each Contributor represents that the Contributor believes its
143 | Contributions are its original creation(s) or it has sufficient rights
144 | to grant the rights to its Contributions conveyed by this License.
145 |
146 | 2.6. Fair Use
147 |
148 | This License is not intended to limit any rights You have under
149 | applicable copyright doctrines of fair use, fair dealing, or other
150 | equivalents.
151 |
152 | 2.7. Conditions
153 |
154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155 | in Section 2.1.
156 |
157 | 3. Responsibilities
158 | -------------------
159 |
160 | 3.1. Distribution of Source Form
161 |
162 | All distribution of Covered Software in Source Code Form, including any
163 | Modifications that You create or to which You contribute, must be under
164 | the terms of this License. You must inform recipients that the Source
165 | Code Form of the Covered Software is governed by the terms of this
166 | License, and how they can obtain a copy of this License. You may not
167 | attempt to alter or restrict the recipients' rights in the Source Code
168 | Form.
169 |
170 | 3.2. Distribution of Executable Form
171 |
172 | If You distribute Covered Software in Executable Form then:
173 |
174 | (a) such Covered Software must also be made available in Source Code
175 | Form, as described in Section 3.1, and You must inform recipients of
176 | the Executable Form how they can obtain a copy of such Source Code
177 | Form by reasonable means in a timely manner, at a charge no more
178 | than the cost of distribution to the recipient; and
179 |
180 | (b) You may distribute such Executable Form under the terms of this
181 | License, or sublicense it under different terms, provided that the
182 | license for the Executable Form does not attempt to limit or alter
183 | the recipients' rights in the Source Code Form under this License.
184 |
185 | 3.3. Distribution of a Larger Work
186 |
187 | You may create and distribute a Larger Work under terms of Your choice,
188 | provided that You also comply with the requirements of this License for
189 | the Covered Software. If the Larger Work is a combination of Covered
190 | Software with a work governed by one or more Secondary Licenses, and the
191 | Covered Software is not Incompatible With Secondary Licenses, this
192 | License permits You to additionally distribute such Covered Software
193 | under the terms of such Secondary License(s), so that the recipient of
194 | the Larger Work may, at their option, further distribute the Covered
195 | Software under the terms of either this License or such Secondary
196 | License(s).
197 |
198 | 3.4. Notices
199 |
200 | You may not remove or alter the substance of any license notices
201 | (including copyright notices, patent notices, disclaimers of warranty,
202 | or limitations of liability) contained within the Source Code Form of
203 | the Covered Software, except that You may alter any license notices to
204 | the extent required to remedy known factual inaccuracies.
205 |
206 | 3.5. Application of Additional Terms
207 |
208 | You may choose to offer, and to charge a fee for, warranty, support,
209 | indemnity or liability obligations to one or more recipients of Covered
210 | Software. However, You may do so only on Your own behalf, and not on
211 | behalf of any Contributor. You must make it absolutely clear that any
212 | such warranty, support, indemnity, or liability obligation is offered by
213 | You alone, and You hereby agree to indemnify every Contributor for any
214 | liability incurred by such Contributor as a result of warranty, support,
215 | indemnity or liability terms You offer. You may include additional
216 | disclaimers of warranty and limitations of liability specific to any
217 | jurisdiction.
218 |
219 | 4. Inability to Comply Due to Statute or Regulation
220 | ---------------------------------------------------
221 |
222 | If it is impossible for You to comply with any of the terms of this
223 | License with respect to some or all of the Covered Software due to
224 | statute, judicial order, or regulation then You must: (a) comply with
225 | the terms of this License to the maximum extent possible; and (b)
226 | describe the limitations and the code they affect. Such description must
227 | be placed in a text file included with all distributions of the Covered
228 | Software under this License. Except to the extent prohibited by statute
229 | or regulation, such description must be sufficiently detailed for a
230 | recipient of ordinary skill to be able to understand it.
231 |
232 | 5. Termination
233 | --------------
234 |
235 | 5.1. The rights granted under this License will terminate automatically
236 | if You fail to comply with any of its terms. However, if You become
237 | compliant, then the rights granted under this License from a particular
238 | Contributor are reinstated (a) provisionally, unless and until such
239 | Contributor explicitly and finally terminates Your grants, and (b) on an
240 | ongoing basis, if such Contributor fails to notify You of the
241 | non-compliance by some reasonable means prior to 60 days after You have
242 | come back into compliance. Moreover, Your grants from a particular
243 | Contributor are reinstated on an ongoing basis if such Contributor
244 | notifies You of the non-compliance by some reasonable means, this is the
245 | first time You have received notice of non-compliance with this License
246 | from such Contributor, and You become compliant prior to 30 days after
247 | Your receipt of the notice.
248 |
249 | 5.2. If You initiate litigation against any entity by asserting a patent
250 | infringement claim (excluding declaratory judgment actions,
251 | counter-claims, and cross-claims) alleging that a Contributor Version
252 | directly or indirectly infringes any patent, then the rights granted to
253 | You by any and all Contributors for the Covered Software under Section
254 | 2.1 of this License shall terminate.
255 |
256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257 | end user license agreements (excluding distributors and resellers) which
258 | have been validly granted by You or Your distributors under this License
259 | prior to termination shall survive termination.
260 |
261 | ************************************************************************
262 | * *
263 | * 6. Disclaimer of Warranty *
264 | * ------------------------- *
265 | * *
266 | * Covered Software is provided under this License on an "as is" *
267 | * basis, without warranty of any kind, either expressed, implied, or *
268 | * statutory, including, without limitation, warranties that the *
269 | * Covered Software is free of defects, merchantable, fit for a *
270 | * particular purpose or non-infringing. The entire risk as to the *
271 | * quality and performance of the Covered Software is with You. *
272 | * Should any Covered Software prove defective in any respect, You *
273 | * (not any Contributor) assume the cost of any necessary servicing, *
274 | * repair, or correction. This disclaimer of warranty constitutes an *
275 | * essential part of this License. No use of any Covered Software is *
276 | * authorized under this License except under this disclaimer. *
277 | * *
278 | ************************************************************************
279 |
280 | ************************************************************************
281 | * *
282 | * 7. Limitation of Liability *
283 | * -------------------------- *
284 | * *
285 | * Under no circumstances and under no legal theory, whether tort *
286 | * (including negligence), contract, or otherwise, shall any *
287 | * Contributor, or anyone who distributes Covered Software as *
288 | * permitted above, be liable to You for any direct, indirect, *
289 | * special, incidental, or consequential damages of any character *
290 | * including, without limitation, damages for lost profits, loss of *
291 | * goodwill, work stoppage, computer failure or malfunction, or any *
292 | * and all other commercial damages or losses, even if such party *
293 | * shall have been informed of the possibility of such damages. This *
294 | * limitation of liability shall not apply to liability for death or *
295 | * personal injury resulting from such party's negligence to the *
296 | * extent applicable law prohibits such limitation. Some *
297 | * jurisdictions do not allow the exclusion or limitation of *
298 | * incidental or consequential damages, so this exclusion and *
299 | * limitation may not apply to You. *
300 | * *
301 | ************************************************************************
302 |
303 | 8. Litigation
304 | -------------
305 |
306 | Any litigation relating to this License may be brought only in the
307 | courts of a jurisdiction where the defendant maintains its principal
308 | place of business and such litigation shall be governed by laws of that
309 | jurisdiction, without reference to its conflict-of-law provisions.
310 | Nothing in this Section shall prevent a party's ability to bring
311 | cross-claims or counter-claims.
312 |
313 | 9. Miscellaneous
314 | ----------------
315 |
316 | This License represents the complete agreement concerning the subject
317 | matter hereof. If any provision of this License is held to be
318 | unenforceable, such provision shall be reformed only to the extent
319 | necessary to make it enforceable. Any law or regulation which provides
320 | that the language of a contract shall be construed against the drafter
321 | shall not be used to construe this License against a Contributor.
322 |
323 | 10. Versions of the License
324 | ---------------------------
325 |
326 | 10.1. New Versions
327 |
328 | Mozilla Foundation is the license steward. Except as provided in Section
329 | 10.3, no one other than the license steward has the right to modify or
330 | publish new versions of this License. Each version will be given a
331 | distinguishing version number.
332 |
333 | 10.2. Effect of New Versions
334 |
335 | You may distribute the Covered Software under the terms of the version
336 | of the License under which You originally received the Covered Software,
337 | or under the terms of any subsequent version published by the license
338 | steward.
339 |
340 | 10.3. Modified Versions
341 |
342 | If you create software not governed by this License, and you want to
343 | create a new license for such software, you may create and use a
344 | modified version of this License if you rename the license and remove
345 | any references to the name of the license steward (except to note that
346 | such modified license differs from this License).
347 |
348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary
349 | Licenses
350 |
351 | If You choose to distribute Source Code Form that is Incompatible With
352 | Secondary Licenses under the terms of this version of the License, the
353 | notice described in Exhibit B of this License must be attached.
354 |
355 | Exhibit A - Source Code Form License Notice
356 | -------------------------------------------
357 |
358 | This Source Code Form is subject to the terms of the Mozilla Public
359 | License, v. 2.0. If a copy of the MPL was not distributed with this
360 | file, You can obtain one at http://mozilla.org/MPL/2.0/.
361 |
362 | If it is not possible or desirable to put the notice in a particular
363 | file, then You may include the notice in a location (such as a LICENSE
364 | file in a relevant directory) where a recipient would be likely to look
365 | for such a notice.
366 |
367 | You may add additional accurate notices of copyright ownership.
368 |
369 | Exhibit B - "Incompatible With Secondary Licenses" Notice
370 | ---------------------------------------------------------
371 |
372 | This Source Code Form is "Incompatible With Secondary Licenses", as
373 | defined by the Mozilla Public License, v. 2.0.
374 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | ==========
2 | ibtopotool
3 | ==========
4 |
5 | ibtopotool is a tool that can parse an Infiniband topology file (as
6 | generated by 'ibnetdiscover'), and do things. So far it supports:
7 |
8 | - Generate a graphviz dot file for visualizing the IB network.
9 |
10 | - Generate a slurm topology.conf configuration file.
11 |
12 |
13 | Dependencies
14 | ============
15 |
16 | This tool uses the `NetworkX library `_
17 | version 2.x or newer to represent the nodes and links between
18 | them. The easiest way is probably to use the Anaconda python
19 | distribution.
20 |
21 | In order to generate a slurm topology file, the `python-hostlist
22 | library `_ is
23 | required. It's not available in Anaconda, but you can install it with
24 | pip, like "pip install -U --user python-hostlist".
25 |
26 | To generate graphviz output (the default), one needs the pydot
27 | library.
28 |
--------------------------------------------------------------------------------
/src/ibtopotool.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | # -*- mode: python; -*-
3 | # -*- coding: utf-8 -*-
4 | # vim: set fileencoding=utf-8
5 |
6 | """
7 | ibtopotool, a tool to do things with Infiniband topology.
8 | Copyright (C) 2013-2020 Janne Blomqvist
9 |
10 | This Source Code Form is subject to the terms of the Mozilla Public
11 | License, v. 2.0. If a copy of the MPL was not distributed with this
12 | file, You can obtain one at http://mozilla.org/MPL/2.0/.
13 | """
14 |
15 | import networkx as nx
16 |
17 |
18 | def speed2weight(speed):
19 | """Convert an IB speed to an edge weight
20 |
21 | See e.g. https://en.wikipedia.org/wiki/InfiniBand#Performance single lane (1x)
22 |
23 | """
24 | ss = speed.split('x')
25 | nlinks = int(ss[0])
26 | s1 = ss[1]
27 | if s1 == 'SDR':
28 | s = 2
29 | elif s1 == 'DDR':
30 | s = 4
31 | elif s1 == 'QDR':
32 | s = 8
33 | elif s1 == 'FDR10':
34 | s = 10
35 | elif s1 == 'FDR':
36 | s = 13.64
37 | elif s1 == 'EDR':
38 | s = 25
39 | elif s1 == 'HDR':
40 | s = 50
41 | elif s1 == 'NDR':
42 | s = 100
43 | elif s1 == 'XDR':
44 | s = 200
45 | else:
46 | raise NotImplementedError('Support for Infiniband speed %s not implemented' % s1)
47 | return nlinks * s
48 |
49 |
50 | def parse_ibtopo(topofile, shortlabel):
51 | """
52 | Parse an Infiniband topology file as generated by ibnetdiscover.
53 |
54 | Returns: A networkx graph representing the IB network
55 | """
56 | g = nx.DiGraph()
57 | switchidx = 0 # Index switches sequentially
58 | with open(topofile, 'r') as f:
59 | inblock = False # Switch or Host (Channel Adapter) block
60 | for line in f:
61 | if line.startswith('Switch'):
62 | inblock = True
63 | guid = line.split()[2][1:-1]
64 | i = line.index('#')
65 | s = line[i:].split('"')
66 | nodedesc = s[1]
67 | sid = "s%d" % switchidx
68 | if shortlabel:
69 | label = sid
70 | elif options.mermaid or options.markdown:
71 | label = "%s %s" % (guid, nodedesc)
72 | else:
73 | label = "%s\n%s" % (guid, nodedesc)
74 | g.add_node(guid, desc=nodedesc, type='Switch', label=label)
75 | switchidx += 1
76 | elif line.startswith('Ca'):
77 | inblock = True
78 | guid = line.split()[2][1:-1]
79 | i = line.index('#')
80 | s = line[i:].split('"')
81 | nodedesc = s[1].split()[0]
82 | g.add_node(guid, label=nodedesc, type='Host')
83 | elif len(line) == 0 or line.isspace():
84 | inblock = False
85 | elif inblock:
86 | ls = line.split()
87 | destguid = ls[1].split('"')[1]
88 | w = speed2weight(ls[-1])
89 | # If the edge already exists, add the weigth to it
90 | try:
91 | g[guid][destguid]['weight'] += w
92 | g[guid][destguid]['penwidth'] += 1
93 | except KeyError:
94 | g.add_edge(guid, destguid, weight=w)
95 | g[guid][destguid]['penwidth'] = 1
96 | return g
97 |
98 | def gen_dot(graph, out):
99 | from networkx.drawing.nx_pydot import write_dot
100 | write_dot(graph, out)
101 |
102 | def gen_mermaid(g, out):
103 | """
104 | g: A networkx graph representing the IB network
105 | out: Output file-like object, mermaid or markdown
106 | """
107 | if options.markdown:
108 | out.write('```mermaid\n')
109 | out.write('graph TD\n')
110 | ##In case some particular topology would render more cleanly on elk:
111 | #out.write('%%{init: {"flowchart": {"defaultRenderer": "elk"}} }%%\n')
112 | for n, nbrs in g.adjacency():
113 | switches = []
114 | nodes = []
115 | for nbr in nbrs:
116 | if g.nodes[nbr]['type'] == 'Switch':
117 | switches.append('%s(%s)' % (nbr, g.nodes[nbr]['label']))
118 | else:
119 | nodes.append('%s(%s)' % (nbr, g.nodes[nbr]['label']))
120 | if len(switches) > 0:
121 | for sw in switches:
122 | out.write('%s(%s) --> %s\n' % (n, g.nodes[n]['label'], sw))
123 | if len(nodes) > 0:
124 | for ibnode in nodes:
125 | out.write('%s(%s) --> %s\n' % (n, g.nodes[n]['label'], ibnode))
126 | if options.markdown:
127 | out.write('```\n')
128 |
129 | def gen_slurm(g, out):
130 | """
131 | g: A networkx graph representing the IB network
132 | out: Output file-like object
133 | """
134 | try:
135 | import hostlist
136 | except ImportError:
137 | print("""To generate a slurm topology.conf, you need to install
138 | python-hostlist, https://pypi.python.org/pypi/python-hostlist""")
139 | raise
140 | out.write('# topology.conf generated by ibtopo2dot.py\n')
141 | for n, nbrs in g.adjacency():
142 | if g.nodes[n]['type'] == 'Switch':
143 | switches = []
144 | nodes = []
145 | for nbr in nbrs:
146 | if g.nodes[nbr]['type'] == 'Switch':
147 | switches.append(g.nodes[nbr]['label'])
148 | else:
149 | nodename = g.nodes[nbr]['label']
150 | nodes.append(nodename)
151 | switchstring = ""
152 | if len(switches) > 0:
153 | switches.sort()
154 | switchstring = " Switches=" + hostlist.collect_hostlist(switches)
155 | nodestr = ''
156 | if len(nodes) > 0:
157 | nodes.sort()
158 | nodestr = " Nodes=" + hostlist.collect_hostlist(nodes)
159 | out.write('SwitchName=%s%s%s\n' % (g.nodes[n]['label'],
160 | switchstring, nodestr))
161 |
162 |
163 | def treeify(g, rootfile):
164 | """Generate a DAG with roots given in the file rootfile"""
165 | roots = []
166 | with open(rootfile, 'r') as f:
167 | for line in f:
168 | l = line.strip()
169 | if l.startswith('#') or len(l) == 0:
170 | continue
171 | ii = l.find('#')
172 | if ii >= 1:
173 | l = l[:ii].rstrip()
174 | roots.append(l)
175 |
176 | for root in roots:
177 | # Mark the roots with color for graphviz
178 | g.nodes[root]['fillcolor'] = 'red'
179 | g.nodes[root]['style'] = 'filled'
180 | # Mark the roots as roots for graphviz
181 | g.nodes[root]['root'] = 'true'
182 | g.nodes[root]['rank'] = 0
183 |
184 | # Calculate distance from roots for all nodes
185 | for n in g.nodes():
186 | if n in roots:
187 | continue
188 | l = []
189 | for root in roots:
190 | l.append(nx.shortest_path_length(g, n, root))
191 | g.nodes[n]['rank'] = min(l)
192 |
193 | # Drop all edges that go towards the roots, based on the ranks we
194 | # just computed
195 | todel = []
196 | for n, nbrs in g.adjacency():
197 | for nbr in nbrs:
198 | if g.nodes[n]['rank'] > g.nodes[nbr]['rank']:
199 | todel.append((n, nbr))
200 | g2 = nx.Graph(g)
201 | g2.remove_edges_from(todel)
202 | return g2
203 |
204 | def only_switches(g):
205 | """Filter out nodes that are not switches"""
206 | return g.subgraph([n for n in g.nodes() if g.nodes()[n]['type']
207 | == 'Switch'])
208 |
209 | def relabel_switch_tree(g):
210 | """If shortlabels and treeify is in effect, relabel switches taking
211 | into account the rank (distance from root(s)) in the tree.
212 |
213 | """
214 | srl = {} # rank:labelindex dict
215 | for n in g.nodes():
216 | if g.nodes[n]['type'] == 'Switch':
217 | r = g.nodes[n]['rank']
218 | if not r in srl:
219 | srl[r] = 0
220 | g.nodes[n]['label'] = 's%d-%d' % (r, srl[r])
221 | srl[r] += 1
222 |
223 | if __name__ == '__main__':
224 | from optparse import OptionParser
225 | import sys
226 | usage = """%prog [options] ibtopofile
227 |
228 | ibtopofile is a file containing the output of 'ibnetdiscover'."""
229 | parser = OptionParser(usage)
230 | parser.add_option('-s', '--switches', dest='switches',
231 | action='store_true',
232 | help='Include only switch nodes')
233 | parser.add_option('-o', '--output', dest='output',
234 | help='Output file, if omitted stdout')
235 | parser.add_option('--mermaid', dest='mermaid', action='store_true',
236 | help='Output in mermaid format.')
237 | parser.add_option('--markdown', dest='markdown', action='store_true',
238 | help='Output in markdown encapsulated mermaid format. Implies --mermaid.')
239 | parser.add_option('--slurm', dest='slurm', action='store_true',
240 | help='Output in slurm topology.conf format. Implies --shortlabels.')
241 | parser.add_option('-t', '--treeify', dest='treeify',
242 | help="Give a file containing GUID's for spine switches")
243 | parser.add_option('--shortlabels', dest='shortlabels', action='store_true',
244 | help='Use short labels for switches')
245 | (options, args) = parser.parse_args()
246 | if len(args) == 0:
247 | parser.print_help()
248 | sys.exit(1)
249 | if options.slurm:
250 | options.shortlabels = True
251 | graph = parse_ibtopo(args[0], options.shortlabels)
252 | if options.output:
253 | out = open(options.output, 'w')
254 | else:
255 | out = sys.stdout
256 | if options.switches:
257 | graph = only_switches(graph)
258 | if options.treeify:
259 | graph = treeify(graph, options.treeify)
260 | if options.shortlabels:
261 | relabel_switch_tree(graph)
262 | if options.slurm:
263 | gen_slurm(graph, out)
264 | elif (options.mermaid or options.markdown):
265 | gen_mermaid(graph, out)
266 | else:
267 | gen_dot(graph, out)
268 |
--------------------------------------------------------------------------------
/tests/1.topo:
--------------------------------------------------------------------------------
1 | #
2 | # Topology file: generated on Tue Jun 5 14:15:10 2007
3 | #
4 | # Max of 3 hops discovered
5 | # Initiated from node 0008f10403960558 port 0008f10403960559
6 |
7 | Non-Chassis Nodes
8 |
9 | vendid=0x8f1
10 | devid=0x5a06
11 | sysimgguid=0x5442ba00003000
12 | switchguid=0x5442ba00003080(5442ba00003080)
13 | Switch 24 "S-005442ba00003080" # "ISR9024 Voltaire" base port 0 lid 6 lmc 0
14 | [22] "H-0008f10403961354"[1](8f10403961355) # "MT23108 InfiniHost Mellanox Technologies" lid 4 4xSDR
15 | [10] "S-0008f10400410015"[1] # "SW-6IB4 Voltaire" lid 3 4xSDR
16 | [8] "H-0008f10403960558"[2](8f1040396055a) # "MT23108 InfiniHost Mellanox Technologies" lid 14 4xSDR
17 | [6] "S-0008f10400410015"[3] # "SW-6IB4 Voltaire" lid 3 4xSDR
18 | [12] "H-0008f10403960558"[1](8f10403960559) # "MT23108 InfiniHost Mellanox Technologies" lid 10 4xSDR
19 |
20 | vendid=0x8f1
21 | devid=0x5a05
22 | switchguid=0x8f10400410015(8f10400410015)
23 | Switch 8 "S-0008f10400410015" # "SW-6IB4 Voltaire" base port 0 lid 3 lmc 0
24 | [6] "H-0008f10403960984"[1](8f10403960985) # "MT23108 InfiniHost Mellanox Technologies" lid 16 4xSDR
25 | [4] "H-005442b100004900"[1](5442b100004901) # "MT23108 InfiniHost Mellanox Technologies" lid 12 4xSDR
26 | [1] "S-005442ba00003080"[10] # "ISR9024 Voltaire" lid 6 1xSDR
27 | [3] "S-005442ba00003080"[6] # "ISR9024 Voltaire" lid 6 4xSDR
28 |
29 | vendid=0x2c9
30 | devid=0x5a44
31 | caguid=0x8f10403960984
32 | Ca 2 "H-0008f10403960984" # "MT23108 InfiniHost Mellanox Technologies"
33 | [1](8f10403960985) "S-0008f10400410015"[6] # lid 16 lmc 1 "SW-6IB4 Voltaire" lid 3 4xSDR
34 |
35 | vendid=0x2c9
36 | devid=0x5a44
37 | caguid=0x5442b100004900
38 | Ca 2 "H-005442b100004900" # "MT23108 InfiniHost Mellanox Technologies"
39 | [1](5442b100004901) "S-0008f10400410015"[4] # lid 12 lmc 1 "SW-6IB4 Voltaire" lid 3 4xSDR
40 |
41 | vendid=0x2c9
42 | devid=0x5a44
43 | caguid=0x8f10403961354
44 | Ca 2 "H-0008f10403961354" # "MT23108 InfiniHost Mellanox Technologies"
45 | [1](8f10403961355) "S-005442ba00003080"[22] # lid 4 lmc 1 "ISR9024 Voltaire" lid 6 4xSDR
46 |
47 | vendid=0x2c9
48 | devid=0x5a44
49 | caguid=0x8f10403960558
50 | Ca 2 "H-0008f10403960558" # "MT23108 InfiniHost Mellanox Technologies"
51 | [2](8f1040396055a) "S-005442ba00003080"[8] # lid 14 lmc 1 "ISR9024 Voltaire" lid 6 4xSDR
52 | [1](8f10403960559) "S-005442ba00003080"[12] # lid 10 lmc 1 "ISR9024 Voltaire" lid 6 1xSDR
53 |
--------------------------------------------------------------------------------
/tests/2.topo:
--------------------------------------------------------------------------------
1 | #
2 | # Topology file: generated on Wed May 6 15:14:42 2009
3 | #
4 | # Max of 2 hops discovered
5 | # Initiated from node 0002c9030002847c port 0002c9030002847e
6 |
7 | vendid=0x2c9
8 | devid=0xa87c
9 | switchguid=0xb8cffff0053ee(b8cffff0053ee)
10 | Switch 8 "S-000b8cffff0053ee" # "MT43132 Mellanox Technologies" base port 0 lid 3 lmc 0
11 | [1] "H-0002c902002789ac"[1](2c902002789ad) # "compute-00-01 HCA-1" lid 1 4xSDR
12 | [2] "H-0002c9030002847c"[2](2c9030002847e) # "compute-00-00 HCA-1" lid 2 4xSDR
13 |
14 | vendid=0x2c9
15 | devid=0x5a44
16 | sysimgguid=0x2c902002789af
17 | caguid=0x2c902002789ac
18 | Ca 2 "H-0002c902002789ac" # "compute-00-01 HCA-1"
19 | [1](2c902002789ad) "S-000b8cffff0053ee"[1] # lid 1 lmc 0 "MT43132 Mellanox Technologies" lid 3 4xSDR
20 |
21 | vendid=0x2c9
22 | devid=0x6340
23 | sysimgguid=0x2c9030002847f
24 | caguid=0x2c9030002847c
25 | Ca 2 "H-0002c9030002847c" # "compute-00-00 HCA-1"
26 | [2](2c9030002847e) "S-000b8cffff0053ee"[2] # lid 2 lmc 0 "MT43132 Mellanox Technologies" lid 3 4xSDR
27 |
--------------------------------------------------------------------------------
/tests/3.topo:
--------------------------------------------------------------------------------
1 | src/query_smp.c:195; umad (DR path slid 0; dlid 0; 0,1,1,31 Attr 0x11:0) bad status 110; Connection timed out
2 | #
3 | # Topology file: generated on Mon Jul 25 11:30:26 2016
4 | #
5 | # Initiated from node 0002c9030004e938 port 0002c9030004e939
6 |
7 | vendid=0x2c9
8 | devid=0xcb20
9 | sysimgguid=0xe41d2d030003e470
10 | switchguid=0xe41d2d030003e470(e41d2d030003e470)
11 | Switch 36 "S-e41d2d030003e470" # "SwitchIB Mellanox Technologies" base port 0 lid 268 lmc 0
12 | [1] "S-e41d2d030003e470"[2] # "SwitchIB Mellanox Technologies" lid 268 4xEDR
13 | [2] "S-e41d2d030003e470"[1] # "SwitchIB Mellanox Technologies" lid 268 4xEDR
14 | [3] "S-f4521403005764b0"[1] # "MF0;switch-de779e:SX6012/U1" lid 174 4xFDR
15 | [19] "S-e41d2d030003e470"[21] # "SwitchIB Mellanox Technologies" lid 268 4xEDR
16 | [21] "S-e41d2d030003e470"[19] # "SwitchIB Mellanox Technologies" lid 268 4xEDR
17 | [29] "S-e41d2d030003e470"[30] # "SwitchIB Mellanox Technologies" lid 268 4xEDR
18 | [30] "S-e41d2d030003e470"[29] # "SwitchIB Mellanox Technologies" lid 268 4xEDR
19 | [34] "H-e41d2d030061f957"[1](e41d2d030061f957) # "r-ufm216 HCA-2" lid 2 4xEDR
20 | [35] "H-0002c903003421b0"[2](2c903003421b2) # "r-ufm111 HCA-1" lid 3 4xFDR
21 |
22 | vendid=0x2c9
23 | devid=0xc738
24 | sysimgguid=0xf4521403005764b0
25 | switchguid=0xf4521403005764b0(f4521403005764b0)
26 | Switch 12 "S-f4521403005764b0" # "MF0;switch-de779e:SX6012/U1" enhanced port 0 lid 174 lmc 0
27 | [1] "S-e41d2d030003e470"[3] # "SwitchIB Mellanox Technologies" lid 268 4xFDR
28 | [2] "H-0002c9030004e938"[1](2c9030004e939) # "r-ufm101 HCA-1" lid 27 4xQDR
29 | [3] "H-0002c9030006ba5a"[1](2c9030006ba5b) # "r-ufm101 HCA-2" lid 30 4xQDR
30 | [6] "H-0002c90300337140"[1](2c90300337141) # "r-ufm100 HCA-2" lid 28 4xFDR
31 | [8] "H-e41d2d03005cf1f8"[1](e41d2d03005cf1f8) # "r-ufm96 HCA-1" lid 1 4xSDR
32 |
33 | vendid=0x2c9
34 | devid=0x1003
35 | sysimgguid=0x2c903003421b3
36 | caguid=0x2c903003421b0
37 | Ca 2 "H-0002c903003421b0" # "r-ufm111 HCA-1"
38 | [2](2c903003421b2) "S-e41d2d030003e470"[35] # lid 3 lmc 0 "SwitchIB Mellanox Technologies" lid 268 4xFDR
39 |
40 | vendid=0x2c9
41 | devid=0x1013
42 | sysimgguid=0xe41d2d030061f956
43 | caguid=0xe41d2d030061f957
44 | Ca 1 "H-e41d2d030061f957" # "r-ufm216 HCA-2"
45 | [1](e41d2d030061f957) "S-e41d2d030003e470"[34] # lid 2 lmc 0 "SwitchIB Mellanox Technologies" lid 268 4xEDR
46 |
47 | vendid=0x2c9
48 | devid=0x673c
49 | sysimgguid=0x2c9030006ba5d
50 | caguid=0x2c9030006ba5a
51 | Ca 2 "H-0002c9030006ba5a" # "r-ufm101 HCA-2"
52 | [1](2c9030006ba5b) "S-f4521403005764b0"[3] # lid 30 lmc 0 "MF0;switch-de779e:SX6012/U1" lid 174 4xQDR
53 |
54 | vendid=0x2c9
55 | devid=0x1003
56 | sysimgguid=0x2c90300337143
57 | caguid=0x2c90300337140
58 | Ca 2 "H-0002c90300337140" # "r-ufm100 HCA-2"
59 | [1](2c90300337141) "S-f4521403005764b0"[6] # lid 28 lmc 0 "MF0;switch-de779e:SX6012/U1" lid 174 4xFDR
60 |
61 | vendid=0x2c9
62 | devid=0x1013
63 | sysimgguid=0xe41d2d03005cf1f8
64 | caguid=0xe41d2d03005cf1f8
65 | Ca 1 "H-e41d2d03005cf1f8" # "r-ufm96 HCA-1"
66 | [1](e41d2d03005cf1f8) "S-f4521403005764b0"[8] # lid 1 lmc 0 "MF0;switch-de779e:SX6012/U1" lid 174 4xSDR
67 |
68 | vendid=0x2c9
69 | devid=0x673c
70 | sysimgguid=0x2c9030004e93b
71 | caguid=0x2c9030004e938
72 | Ca 1 "H-0002c9030004e938" # "r-ufm101 HCA-1"
73 | [1](2c9030004e939) "S-f4521403005764b0"[2] # lid 27 lmc 0 "MF0;switch-de779e:SX6012/U1" lid 174 4xQDR
74 |
--------------------------------------------------------------------------------
/tests/4.topo:
--------------------------------------------------------------------------------
1 | #
2 | # Topology file: generated on Sat Apr 13 22:28:55 2002
3 | #
4 | # Max of 1 hops discovered
5 | # Initiated from node 0021283a8389a0a0 port 0021283a8389a0a0
6 | vendid=0x2c9
7 | devid=0xbd36
8 | sysimgguid=0x21283a8389a0a3
9 | switchguid=0x21283a8389a0a0(21283a8389a0a0)
10 | Switch 36 "S-0021283a8389a0a0" # "Sun DCS 36 QDR switch localhost" enhanced port 0 lid 15 lmc 0
11 | [23] "H-0003ba000100e388"[2](3ba000100e38a) # "nsn33-43 HCA-1" lid 14 4xQDR
12 |
13 | vendid=0x2c9
14 | devid=0x673c
15 | sysimgguid=0x3ba000100e38b
16 | caguid=0x3ba000100e388
17 | Ca 2 "H-0003ba000100e388" # "nsn33-43 HCA-1"
18 | [2](3ba000100e38a) "S-0021283a8389a0a0"[23] # lid 14 lmc 0 "Sun DCS 36 QDR switch localhost" lid 15 4xQDR
19 |
--------------------------------------------------------------------------------
/tests/notes.rst:
--------------------------------------------------------------------------------
1 | ==========
2 | Test notes
3 | ==========
4 |
5 |
6 | How to run
7 | ==========
8 |
9 | ``cd tests``
10 |
11 | ``./run_tests.sh``
12 |
13 | Test topology sources
14 | =====================
15 |
16 | * 1.topo: ``man ibnetdiscover``
17 | * 2.topo: https://www.ibm.com/support/pages/troubleshooting-infiniband-network-issues-platform-cluster-manager
18 | * 3.topo: https://enterprise-support.nvidia.com/s/article/howto-find-the-path-between-two-lids-in-infiniband-network-using-ibdiagpath
19 | * 4.topo: https://docs.oracle.com/cd/E19197-01/835-0784-05/z400014e1393438.html
20 |
--------------------------------------------------------------------------------
/tests/run_tests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | for TOPO in *.topo; do
4 |
5 | # For now, use a bulk extension ".out" for all output cases
6 | OUTFILE=${TOPO%.*topo}.out
7 |
8 | # Assign the first found switch as a single treeify root
9 | grep -E '^Switch' ${TOPO} | head -1 | awk '{print $3}' | sed 's/"//g' > t.tmp
10 |
11 | CMD_ARRAY=(
12 | "python3 ../src/ibtopotool.py -o ${OUTFILE} ${TOPO}"
13 | "python3 ../src/ibtopotool.py -s -o ${OUTFILE} ${TOPO}"
14 | "python3 ../src/ibtopotool.py -t t.tmp -o ${OUTFILE} ${TOPO}"
15 | "python3 ../src/ibtopotool.py -s -t t.tmp -o ${OUTFILE} ${TOPO}"
16 | "python3 ../src/ibtopotool.py -s --shortlabels -o ${OUTFILE} ${TOPO}"
17 | "python3 ../src/ibtopotool.py -t t.tmp --shortlabels -o ${OUTFILE} ${TOPO}"
18 | "python3 ../src/ibtopotool.py -s -t t.tmp --shortlabels -o ${OUTFILE} ${TOPO}"
19 | "python3 ../src/ibtopotool.py --slurm -o ${OUTFILE} ${TOPO}"
20 | "python3 ../src/ibtopotool.py --slurm -t t.tmp -o ${OUTFILE} ${TOPO}"
21 | "python3 ../src/ibtopotool.py --slurm -s -o ${OUTFILE} ${TOPO}"
22 | "python3 ../src/ibtopotool.py --slurm -s -t t.tmp -o ${OUTFILE} ${TOPO}"
23 | "python3 ../src/ibtopotool.py --mermaid -o ${OUTFILE} ${TOPO}"
24 | "python3 ../src/ibtopotool.py --markdown -o ${OUTFILE} ${TOPO}"
25 | "python3 ../src/ibtopotool.py --markdown -s -o ${OUTFILE} ${TOPO}"
26 | "python3 ../src/ibtopotool.py --markdown -s -t t.tmp -o ${OUTFILE} ${TOPO}"
27 | "python3 ../src/ibtopotool.py --markdown --shortlabels -o ${OUTFILE} ${TOPO}"
28 | )
29 |
30 | # Execute tests
31 | for (( i = 0; i < ${#CMD_ARRAY[@]}; i++ ))
32 | do
33 | CMD="${CMD_ARRAY[$i]}"
34 | ${CMD}
35 | CMD_RESULT="((1-$?))"
36 | (( ${CMD_RESULT} )) && echo "Success: ${CMD}"
37 | (( ${CMD_RESULT} )) || echo "Failure: ${CMD}"
38 | done
39 |
40 | # Cleanup
41 | if stat *.out 1>/dev/null 2>/dev/null; then rm *.out; fi
42 | if stat t.tmp 1>/dev/null 2>/dev/null; then rm t.tmp; fi
43 |
44 | done
45 |
--------------------------------------------------------------------------------