本文整理汇总了Python中mininet.topo.Topo.links方法的典型用法代码示例。如果您正苦于以下问题:Python Topo.links方法的具体用法?Python Topo.links怎么用?Python Topo.links使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mininet.topo.Topo
的用法示例。
在下文中一共展示了Topo.links方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MininetWrapper
# 需要导入模块: from mininet.topo import Topo [as 别名]
# 或者: from mininet.topo.Topo import links [as 别名]
class MininetWrapper(object):
def __init__(self):
self.mininet_client = None
self.topology = []
self.delay = None
def set_delay(self, delay):
delay = str(int(delay)) + 'ms'
self.delay = delay
def run_mininet(self, topology_string):
""" Create and run multiple link network
"""
self.topo_client = Topo()
hosts = set()
switches = set()
relations = re.sub(r's', '', topology_string)
relations = [i.split(':') for i in relations.split(',')
if 'h' not in i]
relations = [[int(y) - 1 for y in x] for x in relations]
builtin.log(relations, 'DEBUG')
verticles_count = len(set(list(itertools.chain(*relations))))
builtin.log(self.topology, 'DEBUG')
for i in xrange(verticles_count):
temp = []
for j in xrange(verticles_count):
temp.append(-1)
self.topology.append(temp[:])
builtin.log(self.topology, 'DEBUG')
for i in relations:
self.topology[i[0]][i[1]] = 1
self.topology[i[1]][i[0]] = 1
builtin.log(self.topology, 'DEBUG')
for v1, v2 in [x.split(':') for x in str(topology_string).split(',')]:
if 'h' in v1 and v1 not in hosts:
self.topo_client.addHost(v1)
hosts.add(v1)
if 'h' in v2 and v2 not in hosts:
self.topo_client.addHost(v2)
hosts.add(v2)
if 's' in v1 and v1 not in switches:
self.topo_client.addSwitch(v1)
switches.add(v1)
if 's' in v2 and v2 not in switches:
self.topo_client.addSwitch(v2)
switches.add(v2)
if self.delay:
self.topo_client.addLink(v1, v2, delay=self.delay)
else:
self.topo_client.addLink(v1, v2)
self.mininet_client = Mininet(switch=user_switch,
controller=remote_controller,
topo=self.topo_client, link=TCLink)
self.mininet_client.start()
builtin.log('Links info:')
for link in self.topo_client.links(withKeys=True, withInfo=True):
builtin.log(link)
# self.mininet_client.waitConnected(timeout=20)
sleep(20)
def stop_mininet(self):
if self.mininet_client is not None:
self.mininet_client.stop()
if self.topology:
self.topology = []
self.delay = None
cleanup()
sleep(20)
def kill_link(self, host1, host2):
host1, host2 = str(host1), str(host2)
self.mininet_client.configLinkStatus(host1, host2, 'down')
if 'h' not in host1 and 'h' not in host2:
num_1 = int(host1[1:]) - 1
num_2 = int(host2[1:]) - 1
self.topology[num_1][num_2] = -1
self.topology[num_2][num_1] = -1
builtin.log(self.topology, 'DEBUG')
builtin.log('Down link {0} - {1}'.format(host1, host2),
'DEBUG')
def check_link(self, host1, host2):
switch = self.mininet_client.getNodeByName(host1)
connections = switch.connectionsTo(host2)
if connections:
return True
else:
return False
#.........这里部分代码省略.........