text
stringlengths 0
93.6k
|
---|
# LOG.error("ERROR messages are printed")
|
# LOG.warning("WARNING messages are printed")
|
# LOG.info("INFO message are printed")
|
# LOG.debug("DEBUG messages are printed")
|
# If the user needs a detailed topology, use "record" shapes and draw
|
# individual ports on each shape.
|
# Otherwise, use "rectangle" shapes with multiple connections.
|
#
|
# Unfortunately, a detailed topology is not supported by Gephi.
|
# Disabling by default.
|
detailed = options.detailed_topo
|
# If enabled, HCAs (nodes) connected on the same switches are grouped in
|
# the same cluster. Unfortunately only 'dot' supports clustering at the
|
# moment, so I disable it by default.
|
useClusters = options.use_clusters
|
exportGexf = options.export_gexf
|
# Read the topology and build the graph in an OrderedDict
|
topology_file = options.topo_file
|
topology = OrderedDict()
|
num_of_switches = 0
|
num_of_hcas = 0
|
current_node = ""
|
with open(topology_file, mode='r', buffering=1) as f:
|
for line in f:
|
line = line.strip()
|
isinstance(line, str)
|
if line:
|
r = quick_regexp()
|
# This regexp will read the name of nodes and the number of
|
# ports (Switches or HCAs)
|
if r.search(
|
r"^(\w+)\s+(\d+)\s+\"(.+?)\"\s+#\s+\"(.+?)\"", line):
|
current_node = r.groups[2]
|
topology[current_node] = OrderedDict()
|
topology[current_node]['number_of_ports'] = int(
|
r.groups[1])
|
if len(r.groups) == 4:
|
# If we have a label, keep track of it
|
topology[current_node]['label'] = r.groups[3]
|
if r.groups[0] == 'Switch':
|
topology[current_node]['node_type'] = 'switch'
|
num_of_switches = num_of_switches + 1
|
else:
|
topology[current_node]['node_type'] = 'hca'
|
num_of_hcas = num_of_hcas + 1
|
# This regexp will read the port lines from a dump
|
if r.search(r"^\[(\d+)\].*?\"(.+?)\"\[(\d+)\]", line):
|
local_port = int(r.groups[0])
|
connected_to_remote_host = r.groups[1]
|
connected_to_remote_port = int(r.groups[2])
|
topology[current_node][local_port] = {
|
connected_to_remote_host: connected_to_remote_port}
|
# if len(topology) > 1000 and detailed:
|
# LOG.warn(
|
# ("The provided network contains %d nodes (too many) and you"
|
# " have chosen to draw a detailed topology.\n"
|
# "If the drawing state takes much longer than anticipated,"
|
# " please run the program again with the detailed topology"
|
# " switch turned off."), len(topology))
|
# print_(topology)
|
G = pgv.AGraph(name="Fat-tree", strict=False)
|
################
|
# Graphviz attribute list!
|
# www.graphviz.org/doc/info/attrs.html
|
################
|
# Graph attributes
|
G.graph_attr['rankdir'] = 'TB' # TB, BT, LR, RL
|
G.graph_attr['ranksep'] = 1.0
|
# G.graph_attr['nodesep'] = 0.0
|
# Type of the edges: (line, false), (spline, true), (none, ""),
|
# curved, polyline, ortho
|
G.graph_attr['splines'] = 'line'
|
# Do not allow nodes to overlap. Scale makes the compilation very fast
|
# but spreads the graph!
|
G.graph_attr['overlap'] = 'scale'
|
# The size of the output image in inches. Use a multiple of 7.75 and 10.25
|
# http://stackoverflow.com/questions/3489451/how-to-set-the-width-and-heigth-of-the-ouput-image-in-pygraphviz
|
G.graph_attr['size'] = "{},{}!".format(7.75 * 12, 10.25 * 12)
|
if options.optimize_black_bg:
|
G.graph_attr['bgcolor'] = '#000000'
|
# Node Attributes
|
G.node_attr['style'] = 'filled'
|
G.node_attr['margin'] = 0.2
|
G.node_attr['fontsize'] = 24
|
# Edge Attributes
|
G.edge_attr['penwidth'] = 4
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.