2014-02-21 43 views
2

這是)被稱爲mininet流行的網絡模擬器傳遞一個自定義開關類Mininet拓撲

我創建了一個類複合開關(下面我想傳遞給我的拓撲結構類被用作拓撲文件默認開關 有沒有辦法做到這一點?我不是在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()) } 
+0

如果你已經解決了你的問題,你能告訴我們具體到底是什麼嗎?我目前正在嘗試解決相同的問題,但無法做到這一點,因爲我沒有經驗的Python。謝謝 – MalaKa

回答

1

的mininet.topo.py定義了一個稱爲add_switch()方法,可能是你可以嘗試過用書面方式自定義add_switch(在add_switch()方法),其中增加您的自定義拓撲中的自定義開關,所以無論何時運行拓撲,add_switch()方法都會創建自定義開關。