其他分享
首页 > 其他分享> > 实验6:开源控制器实践——RYU

实验6:开源控制器实践——RYU

作者:互联网

一、实验目的

二、实验环境

三、实验要求

(一)基本要求

sudo mn --topo=single,3 --mac --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow10
ryu-manager ryu/ryu/app/gui_topology/gui_topology.py --observe-links

L2Switch.py

from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_0

class L2Switch(app_manager.RyuApp):
    OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]

    def __init__(self, *args, **kwargs):
        super(L2Switch, self).__init__(*args, **kwargs)

    @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
    def packet_in_handler(self, ev):
        msg = ev.msg
        dp = msg.datapath
        ofp = dp.ofproto
        ofp_parser = dp.ofproto_parser

        actions = [ofp_parser.OFPActionOutput(ofp.OFPP_FLOOD)]

        data = None
        if msg.buffer_id == ofp.OFP_NO_BUFFER:
             data = msg.data

        out = ofp_parser.OFPPacketOut(
            datapath=dp, buffer_id=msg.buffer_id, in_port=msg.in_port,
            actions=actions, data = data)
        dp.send_msg(out)

h1 ping h2

h1 ping h3

分析和POX的Hub模块有何不同:

二者均通过洪泛发送报文,但是L2Swtich的下发流表不可查看。

四、个人总结

标签:控制器,ryu,开源,ofp,msg,RYU,dp
来源: https://www.cnblogs.com/Mawlek/p/15426638.html