def create_graph(self):
g = pydot.Dot(graph_type='digraph')
node_map = {}
for h in self.network.topology.hosts:
label = "<<B>%s</B><br/>%d %d<br/>%d>" % (h.name, h.receiving_cap, h.sending_cap, h.amp_factor)
n = pydot.Node(h.name, label=label, style='filled', margin=-0.8, width=0.5, height=0.5,
fontname=self.font_name, fontsize=self.node_fontsize)
if type(h) is Server:
if self.network.victims and h in self.network.victims:
n.set_shape('doublecircle')
else:
n.set_shape('Mcircle')
n.set_fillcolor(self.server_color)
elif type(h) is Router:
if self.network.victims and h in self.network.victims:
n.set_shape('doubleoctagon')
else:
n.set_shape('octagon')
n.set_fillcolor(self.server_color)
else:
if self.network.victims and h in self.network.victims:
n.set_shape('doublecircle')
else:
n.set_shape('circle')
if self.network.attackers and h in self.network.attackers:
n.set_fillcolor(self.attacker_color)
else:
n.set_fillcolor(self.host_color)
g.add_node(n)
node_map[h] = n
for l in self.network.topology.links:
v1 = node_map[l.h1]
v2 = node_map[l.h2]
e = pydot.Edge(v1, v2, dir='none', label=str(l.capacity), color=self.link_color, fontcolor=self.link_color,
fontname=self.font_name, fontsize=self.label_size)
g.add_edge(e)
if self.network.flows:
f1 = sum([f.get(l.h1, l.h2) for f in self.network.flows])
f2 = sum([f.get(l.h2, l.h1) for f in self.network.flows])
if f1 > 0:
g.add_edge(self.__create_link_flow(v1, v2, f1))
if f2 > 0:
g.add_edge(self.__create_link_flow(v2, v1, f2))
return g
评论列表
文章目录