实验5:开源控制器实践——POX

(一)基本要求

使用 tcpdump 验证Hub模块

h1 ping h2(都抓到了包)

h1 ping h3(都抓到包)

验证switch模块

h1 ping h3(只有和h3抓到,h2没有)

L2_learning模块代码流程图

二、进阶要求

自定义一个POX模块SendFlowInSingle

code:

from pox.core import core
import pox.openflow.libopenflow_01 as of

class SendFlowInSingle3(object):
    def __init__(self):
        core.openflow.addListeners(self)
    def _handle_ConnectionUp(self, event):
        msg = of.ofp_flow_mod()  # 使用ofp_flow_mod()方法向交换机下发流表
        msg.priority = 1
        msg.match.in_port = 1  # 使数据包进入端口1
       # msg.actions.append(of.ofp_action_output(port=2))  # 从端口2转发出去
        msg.actions.append(of.ofp_action_output(port=3))  # 从端口3转发出去
        event.connection.send(msg)

        msg = of.ofp_flow_mod()  # 使用ofp_flow_mod()方法向交换机下发流表
        msg.priority = 1
        msg.match.in_port = 2  # 使数据包进入端口2
       # msg.actions.append(of.ofp_action_output(port=1))  # 从端口1转发出去
        msg.actions.append(of.ofp_action_output(port=3))  # 从端口3转发出去
        event.connection.send(msg)

        msg = of.ofp_flow_mod()  # 使用ofp_flow_mod()方法向交换机下发流表
        msg.priority = 1
        msg.match.in_port = 3  # 使数据包进入端口3
        msg.actions.append(of.ofp_action_output(port=1))  # 从端口1转发出去
        msg.actions.append(of.ofp_action_output(port=2))  # 从端口2转发出去
        event.connection.send(msg)

def launch():
    core.registerNew(SendFlowInSingle3)

运行结果

硬超时功能

code:



from pox.core import core
import pox.openflow.libopenflow_01 as of

class SendFlowInSingle3(object):
    def __init__(self):
        core.openflow.addListeners(self)
    def _handle_ConnectionUp(self, event):
        msg = of.ofp_flow_mod()  # 使用ofp_flow_mod()方法向交换机下发流表
        msg.priority = 1
        msg.match.in_port = 1  # 使数据包进入端口1
       # msg.actions.append(of.ofp_action_output(port=2))  # 从端口2转发出去
        msg.actions.append(of.ofp_action_output(port=3))  # 从端口3转发出去
        event.connection.send(msg)

        msg = of.ofp_flow_mod()  # 使用ofp_flow_mod()方法向交换机下发流表
        msg.priority = 1
        msg.match.in_port = 2  # 使数据包进入端口2
       # msg.actions.append(of.ofp_action_output(port=1))  # 从端口1转发出去
        msg.actions.append(of.ofp_action_output(port=3))  # 从端口3转发出去
        event.connection.send(msg)

        msg = of.ofp_flow_mod()  # 使用ofp_flow_mod()方法向交换机下发流表
        msg.priority = 1
        msg.match.in_port = 3  # 使数据包进入端口3
        msg.actions.append(of.ofp_action_output(port=1))  # 从端口1转发出去
        msg.actions.append(of.ofp_action_output(port=2))  # 从端口2转发出去
        event.connection.send(msg)

def launch():
    core.registerNew(SendFlowInSingle3)

运行结果:

心得体会

1、.本次实验难度较之前要大,理解PDF的内容需要花费一定的时间,而且初次遇到POX,不知道其功能作用,学习起来较有难度。初步了解掌握了POX控制器的一些使用方法,理解了POX控制器的工作原理,熟悉了POX控制器流表下发的方法。
2、 遇到的困难pox文档全英文,英文基础不好读起来很费劲,使得写进阶题时候十分困难了解了Hub:h1 ping h2时h2和h3都能收到报文,说明Hub模块在每个交换机上安装洪泛通配符规则,广播转发数据包。
而Switch:h1 ping h2时,只有h2可以收到报文,说明Switch模块让Openflow交换机实现了L2自学习,只有目的主机可以抓取到报文

posted @ 2022-10-11 20:38  落影殇城  阅读(41)  评论(0)    收藏  举报