[英]Passing a Custom Switch class to Mininet topology
這是稱為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()方法將創建自定義switch。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.