1. 程式人生 > >【SDN】mininet2.1環境下構建胖樹結構的TOPO

【SDN】mininet2.1環境下構建胖樹結構的TOPO

from mininet.net import Mininet
from mininet.node import UserSwitch, OVSKernelSwitch
from mininet.topo import Topo
from mininet.log import lg
from mininet.util import irange
from mininet.node import RemoteController
from functools import partial
from mininet.cli import CLI
import sys
flush =sys.stdout.flush

class TestTopo( Topo ):
    
    def __init__( self,N,**params ):
        "Create custom topo."

        # Initialize topology
        Topo.__init__( self,**params )
		# Add hosts
        hosts = [ self.addHost('h%s' % h)
		          for h in irange( 0 , N ) ]
		# Add switches
	switches = [ self.addSwitch('s%s' % s )
		             for s in irange( 0, N ) ]
        for sww in range(4,N,1):
		self.addLink(switches[0],switches[sww])
		self.addLink(switches[1],switches[sww])
		self.addLink(switches[2],switches[sww])
		self.addLink(switches[3],switches[sww])
		sw1=(sww-4)*2
		self.addLink(hosts[sw1],switches[sww])
		sw1=sw1+1
    def MyNetwork( lengths ):
		results = {}
		switchCount=8
		hostCount=8
		switches={'Open vSwitch kernel' : OVSKernelSwitch }

		topo = TestTopo( hostCount )

		Switch=OVSKernelSwitch

		net=Mininet(topo=topo, switch=Switch, controller=partial( RemoteController, ip='192.168.80.129', port=6633 ))
		net.start()
		print "Dumping host connections"
		dumpNodeConnections(net.hosts)
		print "Testing network connectivity"
		net.pingAll()
		net.stop()
	
	if __name__ == '__main__':
		# Tell mininet to print useful information
		setLogLevel('info')
		MyNetwork(10)