def show_topology(self):
if self.pre_link_to_port != self.link_to_port and setting.TOSHOW:
# It means the link_to_port table has changed.
_graph = self.graph.copy()
print "\n---------------------Link Port---------------------"
print '%6s' % ('switch'),
for node in sorted([node for node in _graph.nodes()], key=lambda node: node):
print '%6d' % node,
print
for node1 in sorted([node for node in _graph.nodes()], key=lambda node: node):
print '%6d' % node1,
for node2 in sorted([node for node in _graph.nodes()], key=lambda node: node):
if (node1, node2) in self.link_to_port.keys():
print '%6s' % str(self.link_to_port[(node1, node2)]),
else:
print '%6s' % '/',
print
print
self.pre_link_to_port = self.link_to_port.copy()
if self.pre_access_table != self.access_table and setting.TOSHOW:
# It means the access_table has changed.
print "\n----------------Access Host-------------------"
print '%10s' % 'switch', '%10s' % 'port', '%22s' % 'Host'
if not self.access_table.keys():
print " NO found host"
else:
for sw in sorted(self.access_table.keys()):
print '%10d' % sw[0], '%10d ' % sw[1], self.access_table[sw]
print
self.pre_access_table = self.access_table.copy()
# nx.draw(self.graph)
# plt.savefig("/home/huangmc/exe/matplotlib/%d.png" % int(time.time()))
评论列表
文章目录