利用Python脚本完成

利用Python脚本完成

利用Python脚本完成如下图所示的一个Fat-tree型的拓扑(交换机和主机名需与图中一致,即s1h8)

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController,CPULimitedHost
from mininet.link import TCLink
from mininet.util import dumpNodeConnections class MyTopo( Topo ):
"Simple topology example." def __init__( self ):
"Create custom topo." # Initialize topology
Topo.__init__( self )
L1 = 2
L2 = L1 * 2
s = [] # add core ovs
for i in range( L1 ):
sw = self.addSwitch( 's{}'.format( i + 1 ) )
s.append( sw ) # add aggregation ovs
for i in range( L2 ):
sw = self.addSwitch( 's{}'.format( i + L1 + 1 ) )
s.append( sw ) # add links between core and aggregation/edge ovs
for i in range( L1 ):
sw1 = s[i]
for j in range( L2 ):
sw2 = s[L1 + j]
self.addLink( sw2, sw1 ) #add hosts and its links with aggregation/edge ovs
count = 1
for sw1 in s[L1::1]:
for i in range(2):
host = self.addHost( 'h{}'.format( count ) )
self.addLink( sw1, host )
count += 1
topos = { 'mytopo': ( lambda: MyTopo() ) }
05-08 08:04