美文网首页
4. POX控制器介绍

4. POX控制器介绍

作者: YYFNB | 来源:发表于2019-04-02 20:04 被阅读0次

本系列教程是我在学习SDN课程的时候写下的笔记, 偏向实践, 环境为Mininet+openflow(POX 控制器)

POX是一个python编写的控制器,仅仅支持opneflow1.0

关于POX的资料非常少,唯一有参考价值的是官方的Wiki(英文):

https://openflow.stanford.edu/display/ONL/POX+Wiki.html

并且这个文档真的很难看懂,必须结合源代码和examples才能慢慢搞懂POX的使用, 本篇文章我尽量总结一些POX的使用方法。

1. 快速总览POX:

POX主要包括 : Listener, Control logic, Messenger.

首先要确定需要POX 监听何种event(e.g. ConnectionUp, PacketIn...)

然后使用logic来区分不同的flow并且执行相应action

最后给siwtches发message来安装新的rule到flow tables里面。

深入到代码里:

def lanch():

这个类似于main()函数,会自动执行。“This is the function where the application registers all event listeners, and creates objects of any application class. ”

Listeners:

There are two common ways for an application to register with the controller for events.

Register callback functions for specific events thrown by either the OpenFlow handler module or specific modules like Topology Discovery

From the launch or from the init of a class, perform core.openflow.addListenerByName(“EVENTNAME”, CALLBACK_FUNC, PRIORITY)

Register object with the OpenFlow handler module or specific modules like Topology Discovery

From typically the init of a class, perform addListeners(self). Once this is added, the controller will look for a function with the name _handle_EVENTNAME(self, event). This method is automatically registered as an event handler.  [1]

解析packets:

POX provides several primitives to parse well-known packets. The ethernet packet received through a packet_in event can be extracted using this command and then the match for the flow rules can be created using the from_packet function:

packet = event.parsed

src_mac = packet.src

dst_mac = packet.dst

if packet.type == ethernet.IP_TYPE:

    ipv4_packet = event.parsed.find("ipv4")

    # Do more processing of the IPv4 packet

    src_ip = ipv4_packet.srcip

    src_ip = ipv4_packet.dstip

POX provides a simple way to construct the match headers from an incoming packet:

match = of.ofp_match.from_packet(packet)      [1]

发message给switch:

Sending packet_out, flow_mod and other OpenFlow messages to program the switch is simple with POX. The steps are to construct the appropriate message object and populate it with the decision fields and the send to the switch using the connection object self.connection.send(). Here is an example from the hub implementation:

        msg = of.ofp_packet_out()              # Create packet out message

        msg.buffer_id = event.ofp.buffer_id    # Use the incoming packet as the data for the packet out

        msg.in_port = packet_in.in_port        # Set the in_port so that the switch knows

        msg.match = of.ofp_match.from_packet(packet)

        # Add an action to send to the specified port

        action = of.ofp_action_output(port = of.OFPP_FLOOD)

        msg.actions.append(action)

        # Send message to switch

        self.connection.send(msg)     [1]

2. 处理事件event

POX event 符合 publish/subscribe paradigm

会自动handle监听的对应事件

事件event主要来源于siwtch的message, 所有的events都具有以下属性

图1:event属性

PacketIn

Fired when the controller receives an OpenFlow packet-in message (ofp_packet_in / OFPT_PACKET_IN) from a switch, which indicates that a packet arriving at a switch port has either failed to match all entries in the table, or the matching entry included an action specifying to send the packet to the controller.

ConnectionUp:

it's simply fired in response to the establishment of a new control channel with a switch.

Ref:

[1].http://sdnhub.org/tutorials/pox/

[2].https://openflow.stanford.edu/display/ONL/POX+Wiki.html#POXWiki-OpenFlowMessages

相关文章

  • 4. POX控制器介绍

    本系列教程是我在学习SDN课程的时候写下的笔记, 偏向实践, 环境为Mininet+openflow(POX 控制...

  • POX 控制器

    默认拓扑 如果我们不指定控制器直接运行 Mininet 提供给我们的默认拓扑: 你会发现节点间是 ping 得通的...

  • POX 控制器 Error 处理

    在运行 POX 控制器时带上 --verbose 可以看到更多的提示信息,方便定位故障点。 处理 PACKET_I...

  • maven学习 Day2 2018-11-20

    一、maven基础 4. maven的常用命令: dos窗口进入项目pox.xml所在目录,执行命令:mvn to...

  • POX 控制器 API (一)——基础篇

    全网都找不到详尽的 API 介绍,自己试着从各处总结一些。 一种开始构建自己的 POX 模块的常用方法是将现有模块...

  • POX 控制器 API (二)—— OpenFlow 篇

    使用 POX 的主要目的之一是开发 OpenFlow 控制应用程序 - 也就是说,POX 充当 OpenFlow ...

  • 7. Jmeter-逻辑控制器

    逻辑控制器介绍与使用 如果(if)控制器 事物控制器 循环控制器 while controller critica...

  • Idea打包maven项目scala jar包

    在pox文件种添加下列代码

  • Spr

    1.前端控制器 2.映射器 3.适配器 4.控制器 5.视图解析器 一.前端控制器的配置 要点:@前端控制器的实现...

  • POX 控制器之 ofp_stats_reply 消息结构

    收到 ofp_stats_reply 数据包,但 POX 框架相关教程很少,没有解析方法教学。其实可以直接用 pr...

网友评论

      本文标题:4. POX控制器介绍

      本文链接:https://www.haomeiwen.com/subject/zmzgbqtx.html