将Custom Switch类传递给Mininet拓扑

时间:2014-02-21 01:49:13

标签: python networking openflow

这是一个名为mininet

的流行网络模拟器的拓扑文件

我创建了一个类MultiSwitch(),我希望将其传递给我的拓扑类以用作默认开关   有没有办法做到这一点?我对Python不是很精通

from mininet.topo import Topo
from mininet.node import OVSSwitch, Controller, RemoteController

# Two "external" controllers 
c0 = RemoteController( 'c1', ip='192.168.81.132')
c1 = RemoteController( 'c2', ip='192.168.81.130')

cmap = { 's1': c0, 's2': c0, 's3': c1,'s4':c1 }

class MultiSwitch( OVSSwitch ):
    def start( self, controllers ):
        return OVSSwitch.start( self, [ cmap[ self.name ] ] )

class OnosTopo( Topo ):

    "Simple topology example."
    def __init__( self ):

        "Create custom topo."
        # Initialize topology

        Topo.__init__( self )

        # Add hosts and switches
        h1 =  [ self.addHost( 'h1')]
        h2 =  [ self.addHost( 'h2')]
        h3 =  [ self.addHost( 'h3')]
        h4 =  [ self.addHost( 'h4')]

    s1 = [ self.addSwitch( 's1', dpid="0000000000000201")]
    s2 = [ self.addSwitch( 's2', dpid="0000000000000202")]
    s3 = [ self.addSwitch( 's3', dpid="0000000000000203")]
    s4 = [ self.addSwitch( 's4', dpid="0000000000000204")]

    #host to switch links
    self.addLink('s1','h1')
    self.addLink('s2','h2')
    self.addLink('s3','h3')
    self.addLink('s4','h4')


    #switch to swtich links
    self.addLink('s1','s2')
    self.addLink('s3','s4')

topos = { 'onostopo': ( lambda: OnosTopo() ) }

1 个答案:

答案 0 :(得分:1)

mininet.topo.py定义了一个名为add_switch()的方法,您可以尝试使用自定义add_switch()覆盖add_switch()方法,该方法会在您的自定义拓扑中添加自定义开关,因此每当您运行拓扑,add_switch()方法将创建自定义开关。