The First Ryu Application
来源:互联网 发布:加内特职业生涯总数据 编辑:程序博客网 时间:2024/06/05 22:30
- 如果你想管理网络节点(如交换机,路由器,或者其他的)按照自己的方式,你需要写一个你自己的RYuApp,你的应用再去告诉Ryu你想怎样去管理这些节点,然后Ryu控制这些节点通过使用Openflow协议,或者其他的协议。
from ryu.base import app_managerclass L2Switch(app_manager.RyuApp): def __init__(self, *args, **kwargs): super(L2Switch, self).__init__(*args, **kwargs)
上边是一段Ryu代码,Ryu使用Python编写,创建了一个子类,需要继承app_manager.RyuApp,再定义一个初始化方法,保存之后这段代码便可以运行,但是没有任何功能。
from ryu.base import app_managerfrom ryu.controller import ofp_eventfrom ryu.controller.handler import MAIN_DISPATCHERfrom ryu.controller.handler import set_ev_clsfrom 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): 这是基于上边的代码添加的新方法,当Ryu收到Openflow的packet_in包时被调用 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)
@set_ev_cls是一个装饰器,监听事件,
1、装饰器的第一个参数(ofp_event.EventOFPPacketIn)表示调用函数的事件,
每当Ryu收到packet_in数据包时,就调用该方法。
2、第二个参数(MAIN_DISPATCHER)指示交换机的状态,Probably, youwant to ignore packet_in messages before the negotiation between Ryuand the switch finishes. Using 'MAIN_DISPATCHER' as the secondargument means this function is called only after the negotiationcompletes.
- ev.msg是一个对象,表示packet_in的数据结构
- msg.datapath是一个对象,表示数据通路(switch)
- dp.ofproto和dp.ofproto_parser也是一个对象,表示Ryu与switch之间的Openflow协议。
- OFPActionOutput类,使用一个packet_out消息指定要发送的数据包到一个交换机端口,需要switch发送到所以的端口,所以使用OFPP_FLOOD
- OFPPacketOut class 是用来建立一个packet_out 消息.
- If you call Datapath class's send_msg method with a OpenFlow messageclass object, Ryu builds and send the on-wire data format to the switch.
阅读全文
1 0
- The First Ryu Application
- The First MFC Application
- The first Android application
- MeeGo程序开发---The First Application
- Silverlight – 02 :The first Silverlight Application
- Ryu application API原文加翻译(一)
- HowTO Build the FiRst GWT Application On Tomcat
- Struts2 Notes(1)----set up the first sturts2 application
- Should I design the application or model (database) first?
- Ryu Application API 原文加翻译(二)
- Your First Struts Application
- Your First Struts Application
- My First Symbian Application
- My First Hibernate Application
- My First DirectShow Application
- My first WPF application
- MY first android application
- my first php application
- 【项目实战】——Tree树显示过程核心
- 容斥原理模板
- 上传图片时,Input file图片预览的实现
- Hadoop HA 高可用集群搭建
- 移动端meta整合
- The First Ryu Application
- 在Ubuntu16.04上安装QQ
- UVA
- 退了实验室之后的生活
- 图片在块级元素中的对齐问题(取消图片在垂直和水平方向上的空隙)
- HDU 6043 KazaQ's Socks【规律】
- Mac下的解压命令
- 使用wsimport生成客户端java类
- 动态顺序表的实现