2

这是一个名为 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() ) }
4

1 回答 1

1

mininet.topo.py 定义了一个名为 add_switch() 的方法,也许您可​​以尝试使用自定义 add_switch() 覆盖 add_switch() 方法,该方法将自定义开关添加到自定义拓扑中,因此无论何时运行拓扑, add_switch() 方法将创建自定义 switch 。

于 2014-03-05T01:33:05.590 回答