Class: Dot
- Inherits:
-
Object
- Object
- Dot
- Defined in:
- generators/gen_dot_topology.rb
Overview
Generate a Graphviz dot file, showing the switches and the interconnections between them. Does not go further, and run dot to generate a png.
Instance Method Summary (collapse)
-
- (Dot) initialize(switches, target_file)
constructor
Creates dot (Graphviz) diagram as a png.
-
- (Object) put_header(fd)
Dot file header.
-
- (Object) put_links(fd)
Output link relationships between the switches.
-
- (Object) put_rank(fd)
Ensure the core switches are grouped together.
-
- (Object) put_switches(fd)
Dot file body, for each switch.
Constructor Details
- (Dot) initialize(switches, target_file)
Creates dot (Graphviz) diagram as a png.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'generators/gen_dot_topology.rb', line 7 def initialize(switches, target_file) @switches = switches @links = {} File.open(target_file, "w") do |fd| put_header(fd) #dot file lead in. put_switches(fd) #The switch definitions put_rank(fd) #Group the core switches put_links(fd) #Output the interswitch link definitions fd.puts "}" #Closing } for the dot file. end end |
Instance Method Details
- (Object) put_header(fd)
Dot file header
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'generators/gen_dot_topology.rb', line 21 def put_header(fd) fd.puts <<-EOF digraph g { ranksep = 2.0; splines=false; graph [ ]; node [ fontsize = "16" shape = "ellipse" ]; edge [ ]; EOF end |
- (Object) put_links(fd)
Output link relationships between the switches
77 78 79 80 |
# File 'generators/gen_dot_topology.rb', line 77 def put_links(fd) i = 0 @links.each { |k,v| fd.puts "#{v} [ id = #{i} ];"; i = i + 1} end |
- (Object) put_rank(fd)
Ensure the core switches are grouped together
70 71 72 73 |
# File 'generators/gen_dot_topology.rb', line 70 def put_rank(fd) fd.puts '{ rank=same; "bnt-a2-001-m" ; "bnt-a2-002-m"; }' #External BNTs fd.puts '{ rank=same; "bnt-c2-003-m" ; "bnt-c2-004-m"; }' #Private Core end |
- (Object) put_switches(fd)
Dot file body, for each switch
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 |
# File 'generators/gen_dot_topology.rb', line 38 def put_switches(fd) @switches.each do |n, s| s.ports.each do |k,p| if p.remote_switch_name != nil && @switches[p.remote_switch_name] != nil && @switches[p.remote_switch_name].ports[p.port_number] == nil #puts "#{p.remote_switch_name} #{p.port_number} #{p.remote_port_name}" @switches[p.remote_switch_name].ports[p.port_number] = Port.new(p.port_number) @switches[p.remote_switch_name].ports[p.port_number].port_name = "#{p.port_number}/#{p.remote_port_name}" @switches[p.remote_switch_name].ports[p.port_number].remote_switch_name = s.name @switches[p.remote_switch_name].ports[p.port_number].remote_port_name = p.port_name @switches[p.remote_switch_name].ports[p.port_number].remote_port_number = p.port_number @switches[p.remote_switch_name].ports[p.port_number].remote_mac = s.mac end end end @switches.each do |n, s| fd.puts "\"#{s.name}\" [" fd.print "label = \"" out = [] out << "<h0> #{s.name}" s.ports.each do |k,p| if p.remote_switch_name != nil && @switches[p.remote_switch_name] != nil && p.remote_port_name !~ /MGT[AB]/ && p.port_name !~ /MGT[AB]/ out << "<p#{p.port_number}> #{p.port_name}" @links["#{s.name}:p#{p.port_number}"] = "\"#{s.name}\":p#{p.port_number} -> \"#{p.remote_switch_name}\":p#{p.remote_port_number}" #if @links["#{p.remote_switch_name}:p#{p.remote_port_number}"] == nil end end fd.puts "#{out.join(' | ')}\"" fd.puts "shape = \"record\"\n];" end end |