#!/usr/bin/env python
from mininet.topo import Topo
class MyTopo(Topo):
def __init__(self):
Topo.__init__(self)
#host
for i in range(1,9):
self.addHost("h"+str(i))
#switch
for i in range(1,11):
self.addSwitch("s"+str(i))
#-------------
for i in range(1,3):
for j in range(3,7):
self.addLink("s"+str(i),"s"+str(j))
#-------------
for i in range(3,5):
for j in range(7,9):
self.addLink("s"+str(i),"s"+str(j))
for i in range(5,7):
for j in range(9,11):
self.addLink("s"+str(i),"s"+str(j))
#-------------
for i in range(7,11):
for j in range((i-6)*2-1,(i-6)*2+1):
self.addLink("s"+str(i),"h"+str(j))
#使用stp协议需要在启动mininet时向命令中添加参数 --switch lxbr,stp=1 or --switch ovsbr,stp=1
topos = {'mytopo': (lambda: MyTopo())}
标签:__,进阶,python,self,#-------------,range,str,SDN,addLink
From: https://www.cnblogs.com/cnihyb/p/17722644.html