标签:mic uap pen 广播 parser init png end div
controller目录下的ofo_event.py定义了OpenFlow事件,handler.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)] out = ofp_parser.OFPPacketOut( datapath=dp, buffer_id=msg.buffer_id, in_port=msg.in_port, actions=actions) dp.send_msg(out)
新增的代码中加入了新方法packet_in_handler,当Ryu收到OpenFlow交换机送来的packet_in消息时调用,set_ev_cls的第一个参数也声明了。
set_ev_cls的第二个参数MAIN_DISPATCHER意味着当Ryu和交换机握手过程(即hello, features request/reply, Set Config等)完毕,才会调用packet_in_handler。
之后定义packet_in消息数据结构,交换机datapath,OpenFlow协议和解析过程;
定义发给交换机packet_out的动作,要求交换机将数据包泛洪广播;定义Ryu向交换机发送的packet_out内容,最后发送消息。
至此,一个能够接收packet和转发packet的交换机完成了(接收packet,广播packet)。
标签:mic uap pen 广播 parser init png end div
原文地址:https://www.cnblogs.com/dream397/p/12951164.html