【问题标题】:Add remote controller mininet cod添加遥控器 mininet cod
【发布时间】:2020-08-29 21:34:24
【问题描述】:

我正在 mininet 中构建自定义拓扑代码,但在连接 3 个路由器和 4 个交换机时遇到了困难。如果你能帮助我,我做错了我只想在路由器和交换机之间连接。

from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController

class MyTopo( Topo ):
    "Simple topology example."

    def __init__( self ):
        "Create custom topo."

        # Initialize topology
        Topo.__init__( self )

        net = Mininet(topo=None,
                      build=False)
        #Add controllers
        c1 = net.addController(name='c1',
                               controller=RemoteController)
        c2 = net.addController(name= 'c2',
                               controller=RemoteController)

        # Add hosts and switches
        HostOne = self.addHost( 'h1' )
        HostTwo = self.addHost( 'h2' )
        HostTree = self.addHost( 'h3' )
        HostFour = self.addHost( 'h4' )
        SwitchOne = self.addSwitch( 's1' )
        SwitchTwo = self.addSwitch( 's2' )
        SwitchTree = self.addSwitch( 's3' )
        SwitchFour = self.addSwitch( 's4' )

        # Add links
        self.addLink( c1, SwitchOne )
        self.addLink( c1, SwitchTwo )
        self.addLink( c1, SwitchTree )
        self.addLink( c1, SwitchFour )
        self.addLink( c2, SwitchOne )
        self.addLink( c2, SwitchTwo )
        self.addLink( c2, SwitchTree )
        self.addLink( c2, SwitchFour )




【问题讨论】:

    标签: python mininet topology


    【解决方案1】:

    您可以在 Mininet GitHub 存储库examples 上找到很多示例

    我认为你应该看看multiController example

    我修改了示例以满足您的需求:

    #!/usr/bin/python
    
    from mininet.net import Mininet
    from mininet.node import OVSSwitch, RemoteController
    from mininet.topo import Topo
    from mininet.log import setLogLevel
    from mininet.cli import CLI
    
    setLogLevel( 'info' )
    
    # Two remote controllers
    c1 = RemoteController( 'c1', ip='127.0.0.1', port=6634 )
    c2 = RemoteController( 'c2', ip='127.0.0.1', port=6633 )
    
    # You dont need the links between the controller and the switches,
    # You can connect with the personalized mapping
    cmap = { 's1': c1, 's2': c1, 's3': c2 , 's4': c2}
    
    class MultiSwitch( OVSSwitch ):
        "Custom Switch() subclass that connects to different controllers"
        def start( self, controllers ):
            return OVSSwitch.start( self, [ cmap[ self.name ] ] )
    
    class MyTopo(Topo):
        def build(self):
            HostOne = self.addHost( 'h1' )
            HostTwo = self.addHost( 'h2' )
            HostTree = self.addHost( 'h3' )
            HostFour = self.addHost( 'h4' )
            SwitchOne = self.addSwitch( 's1' )
            SwitchTwo = self.addSwitch( 's2' )
            SwitchTree = self.addSwitch( 's3' )
            SwitchFour = self.addSwitch( 's4' )
    
            self.addLink(SwitchTwo, SwitchOne)
            self.addLink(SwitchTree, SwitchFour)
            self.addLink(HostOne, SwitchOne)
            self.addLink(HostTwo, SwitchTwo)
            self.addLink(HostTree, SwitchTree)
            self.addLink(HostFour, SwitchFour)
    
    topo = MyTopo()
    net = Mininet( topo=topo, switch=MultiSwitch, build=False )
    for c in [ c1, c2 ]:
        net.addController(c)
    net.build()
    net.start()
    CLI( net )
    net.stop()
    

    【讨论】:

    • 我改用这个例子,但它给了我一个来自 hopts 的错误
    • 你试过我发给你的例子吗?如果是,具体错误是什么?如果没有,您能展示一下您制作的新脚本吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-09
    • 2021-01-13
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 2012-10-09
    • 2014-07-03
    相关资源
    最近更新 更多