添加遥控器mininet编码

问题描述 投票:0回答:1

我正在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个回答
0
投票

您可以在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()
© www.soinside.com 2019 - 2024. All rights reserved.