mininet连接两个ryu控制器的实现(2021.6.21)

克隆一个ryu虚拟机(1号) ,得到2号ryu虚拟机

开启1,2号ryu控制器:进入ryu/ryu/app目录,然后启动相应模块:sudo ryu-manager --verbose simple_switch_13.py ofctl_rest.py rest_topology.py

mininet虚拟机中,在桌面上自定义一个topo文件,如:sudo gedit 1.py

1.py的内容:

mininet连接两个ryu控制器的实现(2021.6.21)
#!/usr/bin/python

from mininet.net import Mininet
from mininet.node import Controller, RemoteController
from mininet.cli import CLI
from mininet.log import setLogLevel, info

def myNet():


    #c0
    c0_IP=192.168.231.131

    #c1
    c1_IP=192.168.231.133

    net = Mininet( topo=None, build=False)

    # Create nodes
    h1 = net.addHost( h1, mac=01:00:00:00:01:00, ip=192.168.0.1/24 )
    h2 = net.addHost( h2, mac=01:00:00:00:02:00, ip=192.168.0.2/24 )

    # Create switches
    s1 = net.addSwitch( s1, listenPort=6634, mac=00:00:00:00:00:01 )
    s2 = net.addSwitch( s2, listenPort=6634, mac=00:00:00:00:00:02 )

    print "*** Creating links"
    net.addLink(h1, s1, )
    net.addLink(h2, s2, )
    net.addLink(s1, s2, )

    # Add Controllers
    c0_ctrl = net.addController( c0, controller=RemoteController, ip=c0_IP, port=6653)

    c1_ctrl = net.addController( c1, controller=RemoteController, ip=c1_IP, port=6653)


    net.build()

    # Connect each switch to a different controller
    s1.start( [c0_ctrl] )
    s2.start( [c1_ctrl] )

    s1.cmdPrint(ovs-vsctl show)

    CLI( net )
    net.stop()

if __name__ == __main__:
    setLogLevel( info )
    myNet()
1.py

在终端运行该文件:sudo python 1.py

mininet连接两个ryu控制器的实现(2021.6.21)

 可以发现:交换机 s1的master控制器为1号ryu控制器,s2的master控制器为2号ryu控制器。

如果想进行控制器角色转换,比如s1的master控制器设置为2号ryu控制器,使用命令:

sudo ovs-vsctl set-controller s1 tcp:192.168.231.133:6653

此时再次查看sudo ovs-vsctl show,发现角色转变成功。

mininet连接两个ryu控制器的实现(2021.6.21)

 

mininet连接两个ryu控制器的实现(2021.6.21)

上一篇:web前端安全


下一篇:HTML的基本语法