gpt4 book ai didi

python - 将自定义开关类传递给 Mininet 拓扑

转载 作者:太空宇宙 更新时间:2023-11-04 06:06:11 27 4
gpt4 key购买 nike

这是一个名为 mininet 的流行网络模拟器的拓扑文件

我创建了一个 MultiSwitch() 类,我想将其传递给我的 Topology 类以用作默认开关 有没有办法做到这一点?我对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() ) }

最佳答案

mininet.topo.py 定义了一个名为 add_switch() 的方法,也许你可以尝试用自定义 add_switch() 重写 add_switch() 方法,它会在你的自定义拓扑中添加你的自定义开关,所以无论何时你运行您的拓扑,add_switch() 方法将创建自定义开关。

关于python - 将自定义开关类传递给 Mininet 拓扑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21923620/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com