1. 程式人生 > >一個簡單的mininet搭建拓撲python模版

一個簡單的mininet搭建拓撲python模版

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
from mininet.cli import CLI

class MyTopo( Topo ):
    "Simple topology example."

    def __init__( self ):
        "Create custom topo."

        # Initialize topology
        Topo.__init__( self )

        # Add hosts and switches
        leftHost1 = self.addHost( 'h1' )
        leftHost2 = self.addHost( 'h2' )
        leftSwitch = self.addSwitch( 's3' )
        rightSwitch = self.addSwitch( 's4' )
        rightHost1 = self.addHost( 'h5' )
        rightHost2 = self.addHost( 'h6' ) 

        # Add links
        self.addLink( leftHost1, leftSwitch )
        self.addLink( leftHost2, leftSwitch )
        self.addLink( leftSwitch, rightSwitch )
        self.addLink( rightSwitch, rightHost1 )
        self.addLink( rightSwitch, rightHost2 )


#topos = { 'mytopo': ( lambda: MyTopo() ) }

if __name__=='__main__':
    setLogLevel('info')
    topo=MyTopo()
    net=Mininet(topo,controller=None)
    net.addController('c0',controller=RemoteController,ip='211.69.197.180',port=6653)
    net.start()
    dumpNodeConnections(net.hosts)

    CLI(net)