Module: DOT
- Defined in:
- generators/gen_dot.rb
Overview
Produce a Graphviz dot file of the IB network. Render with dot -Tsvg -o file.svg file Nb. Our network is a bit large for this :)
Class Method Summary (collapse)
-
+ (Object) gen(ib, file = 'iblinkinfo.dot', dot_cmd = nil)
Generate a dot formated file from the IBLinkinfo data for use with graphviz.
-
+ (Object) process_switch(fd, s, switches)
Process a switch.
Class Method Details
+ (Object) gen(ib, file = 'iblinkinfo.dot', dot_cmd = nil)
Generate a dot formated file from the IBLinkinfo data for use with graphviz.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'generators/gen_dot.rb', line 9 def self.gen(ib, file='iblinkinfo.dot', dot_cmd=nil) #Output dot graph of switches File.open(file, "w") do |fd| fd.puts <<-EOF digraph g { graph [ rankdir = "TB" ratio = auto; ]; EOF ib.switches.each do |k,v| fd.puts "\"#{k}\" [" #Node name fd.print "label=<<table><tr><td>\"#{v[1][9]}\"</td></tr>" #First port (2..36).each do |i| fd.print "<tr><td>#{v[i][9]}</td></tr>" #Other 35 ports end fd.print "</table>>\nshape = \"Mrecord\"\n" fd.puts "];" end @been_there = {} backbone = [ # These should be in a config file. Defined to make picture centered on the core. "MF0;ib0-is5200-a2-bip-m:IS5200/S01/U1", "MF0;ib0-is5200-a2-bip-m:IS5200/S02/U1", "MF0;ib0-is5200-a2-bip-m:IS5200/S03/U1", "MF0;ib0-is5200-a2-bip-m:IS5200/S04/U1", "MF0;ib0-is5200-a2-bip-m:IS5200/S05/U1", "MF0;ib0-is5200-a2-bip-m:IS5200/S06/U1", "MF0;ib0-is5300-c4-bip-m:IS5300/S01/U1", "MF0;ib0-is5300-c4-bip-m:IS5300/S02/U1", "MF0;ib0-is5300-c4-bip-m:IS5300/S03/U1", "MF0;ib0-is5300-c4-bip-m:IS5300/S04/U1", "MF0;ib0-is5300-c4-bip-m:IS5300/S05/U1", "MF0;ib0-is5300-c4-bip-m:IS5300/S06/U1", "MF0;ib0-is5300-c4-bip-m:IS5300/S07/U1", "MF0;ib0-is5300-c4-bip-m:IS5300/S08/U1", "MF0;ib0-is5300-c4-bip-m:IS5300/S09/U1", "MF0;ib-sx6036-a2-001-m:SX6036/U1", "MF0;ib-sx6036-a2-002-m:SX6036/U1", "MF0;ib-sx6036-a2-003-m:SX6036/U1", ] @sub_switches = backbone while @sub_switches != nil && @sub_switches.length > 0 do @next_layer = @sub_switches @sub_switches = [] @next_layer.each do |l| process_switch(fd, l, ib.switches) end end fd.puts "}" end #system("#{dot_cmd} -Tpng -o #{file.gsub(/\..+$/,'')}.png -Tcmapx -o #{file.gsub(/\..+$/,'')}_map.html #{file}") if dot_cmd != nil system("#{dot_cmd} -Tpng -o #{file.gsub(/\..+$/,'')}.png #{file}") if dot_cmd != nil end |
+ (Object) process_switch(fd, s, switches)
Process a switch
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'generators/gen_dot.rb', line 76 def self.process_switch(fd, s, switches) v = switches[s] #get port array if v == nil puts "***** switch #{s} not found" return end (1..36).each do |i| #Each switch is 36 ports target = v[i][9] #Potential target switch if switches[target] != nil && #It is a switch if @been_there[s] == nil @been_there[s] = [target] go = true elsif @been_there[s].member?(target) == false @been_there[s] << target go = true end if @been_there[target] == nil @been_there[target] = [s] go = true elsif @been_there[target].member?(s) == false @been_there[target] << s go = true end if go fd.puts "\"#{s}\" -> \"#{target}\"" #Dot link format, representing a physical linke between switches @sub_switches << target end end end end |