编写Python脚本创建自定义网络拓扑,包括5台交换机5台主机
from mininet.topo import Topo
class RingTopo(Topo):
def __init__(self):
Topo.__init__(self)
# Create switches
s_num = 5
h_num = 5
switches = []
hosts = []
for i in range(s_num):
switches.append(self.addSwitch('s%d' % (i + 1)))
# Create hosts
for i in range(h_num):
hosts.append(self.addHost('h%d' % (i + 1)))
# Create links
for i in range(s_num - 1):
self.addLink(switches[i], switches[i + 1])
self.addLink(switches[0], switches[s_num-1])
for i in range(s_num):
self.addLink(switches[i], hosts[i])
topos = {'ring': (lambda: RingTopo())}
执行
mn --custom topo_ring.py --topo ring --controller=remote
标签:自定义,Python,self,网络拓扑,switches,range,num,hosts
From: https://www.cnblogs.com/huanfei/p/17371258.html