text stringlengths 0 93.6k |
|---|
# Colors |
if options.optimize_black_bg: |
HCA_Color = '#cccccc' |
HCA_Edge_Color = '#ff0000' |
Switch_Color = '#ffffff' |
Switch_Edge_Color = '#a0a0a0' |
else: |
HCA_Color = '#ff8080' |
HCA_Edge_Color = '#ff0000' |
Switch_Color = '#d5f6ff' |
Switch_Edge_Color = '#000000' |
Cluster_Color = "yellow" |
if detailed: |
G.node_attr['shape'] = "Mrecord" |
else: |
G.node_attr['shape'] = "rectangle" |
G.add_nodes_from(topology) |
if exportGexf: |
# gephi_edge_id = G.number_of_nodes() |
gephi_edge_id = 0 |
root_node = et.Element('gexf') |
root_node.attrib['xmlns'] = "http://www.gexf.net/1.3" |
root_node.attrib['version'] = "1.3" |
root_node.attrib['xmlns:viz'] = "http://www.gexf.net/1.3/viz" |
root_node.attrib['xmlns:xsi'] = ( |
"http://www.w3.org/2001/XMLSchema-instance") |
root_node.attrib['xsi:schemaLocation'] = ( |
"http://www.gexf.net/1.3 http://www.gexf.net/1.3/gexf.xsd") |
meta_node = et.SubElement( |
root_node, 'meta', attrib={ |
'lastmodifieddate': time.strftime("%Y-%m-%d") |
} |
) |
creator_node = et.SubElement(meta_node, 'creator') |
creator_node.text = PROGRAM_NAME |
description_node = et.SubElement(meta_node, 'description') |
description_node.text = "Graph generated from file '{}'".format( |
os.path.realpath(topology_file)) |
graph_node = et.SubElement(root_node, 'graph') |
graph_node.attrib['defaultedgetype'] = "undirected" |
graph_node.attrib['mode'] = "static" |
nodes_node = et.SubElement(graph_node, 'nodes') |
edges_node = et.SubElement(graph_node, 'edges') |
# Cluster id for the subgraphs |
if useClusters: |
global_cluster_id = 0 |
# Add ports and edges |
for node in G.nodes(): |
if useClusters: |
Subgraph_For_Current_Switch = None |
numPorts = topology[node.name]['number_of_ports'] |
if topology[node.name]['node_type'] == 'switch': |
node.attr['fillcolor'] = Switch_Color |
node.attr['color'] = Switch_Color |
elif topology[node.name]['node_type'] == 'hca': |
node.attr['fillcolor'] = HCA_Color |
node.attr['color'] = HCA_Color |
label = topology[node.name]['label'] if 'label' in topology[node.name] else node.name |
if exportGexf: |
node_node = et.SubElement( |
nodes_node, 'node', attrib={ |
'id': node.name, 'label': label |
} |
) |
r, g, b = hex_to_rgb(node.attr['color']) |
et.SubElement( |
node_node, 'viz:color', attrib={ |
'r': str(r), 'g': str(g), 'b': str(b), 'a': "0.0" |
} |
) |
if numPorts > 0: |
for port in range(1, numPorts + 1): |
if detailed: |
if port == 1: |
separator = "" |
else: |
separator = "|" |
label = "{}|<{}> {}".format(label, port, port) |
if port in topology[node.name].keys(): |
remote_port = list(topology[node.name][port].values())[0] |
remote_host = list(topology[node.name][port].keys())[0] |
try: |
# Check if there is already a link established... |
# If not, the 'get_edge' command will raise a |
# KeyError exception and a new edge will be added |
G.get_edge(remote_host, node.name, |
key="{}-{}".format(port, remote_port)) |
except KeyError: |
if detailed: |
G.add_edge( |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.