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

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

一、实验目的

  1. 能够理解 POX 控制器的工作原理;
  2. 通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;
  3. 能够运用 POX控制器编写自定义网络应用程序,进一步熟悉POX控制器流表下发的方法。

二、实验环境

Ubuntu 20.04 Desktop amd64

三、实验要求

(一)基本要求

  1. 阅读Hub模块代码,使用 tcpdump 验证Hub模块;
  • h1 ping h2,可以看见h3端口也能收到数据包

  2.阅读L2_learning模块代码,画出程序流程图,使用 tcpdump 验证Switch模块。

  • h1分别ping h2和h3, 而h2和h3都只能收到自己的数据包

h1 ping h3

  • L2_learning程序流程图

 

(二)进阶要求

  1. 重新搭建(一)的拓扑,此时交换机内无流表规则,拓扑内主机互不相通;编写Python程序自定义一个POX模块SendFlowInSingle3,并且将拓扑连接至SendFlowInSingle3(默认端口6633),实现向s1发送流表规则使得所有主机两两互通。
    1. 截图:

  

    2.代码:

SendFlowInSingle3.py

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)

 

  2.基于进阶1的代码,完成ODL实验的硬超时功能。

    1.截图:

  

 

    2.代码:

SendPoxHardTimeOut.py

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

class SendPoxHardTimeOut(object):
    def __init__(self):
        core.openflow.addListeners(self)
    def _handle_ConnectionUp(self, event):
 
 
        msg = of.ofp_flow_mod()  
        msg.priority = 3
        msg.match.in_port = 1 
        msg.hard_timeout = 10  
        event.connection.send(msg)
        
        msg = of.ofp_flow_mod()  
        msg.priority = 1
        msg.match.in_port = 1 
        msg.actions.append(of.ofp_action_output(port = of.OFPP_ALL)) 
        event.connection.send(msg)

        
        msg = of.ofp_flow_mod()  
        msg.priority = 3
        msg.match.in_port = 3 
        msg.hard_timeout = 10
        event.connection.send(msg)
        
        msg = of.ofp_flow_mod() 
        msg.priority = 1
        msg.match.in_port = 3  
        msg.actions.append(of.ofp_action_output(port = of.OFPP_ALL))
        event.connection.send(msg)

def launch():
    core.registerNew(SendPoxHardTimeOut)

(三)实验报告

  1. 本次实验主要内容在于了解及认识POX控制器,还有动手验证POX中Hub、L2_Learning基础模块的功能,初步掌握POX控制器的使用方法,基础部分都较简单。根据上课提到过的内容能够做出来。 遇到的问题是在刚搭建拓扑时,使用了OpenFlow1.3的环境,导致没有成功验证,之后发现是因为POX仅支持OpenFlow1.0。 本次实验与理论课的知识相结合,令我对POX 控制器的工作原理有了更加形象、深刻的认识与理解。同时,通过动手实际操作来验证POX的forwarding.hub和forwarding.l2_learning模块,也使我初步掌握POX控制器的一些使用方法,进一步熟悉流表下发的操作。然而,在使用Python编写自定义模块的时候,我仍感觉到自己在POX原理和使用上仍有很大不足之处有待进一步的学习来补完。
posted @ 2022-10-15 16:16  阿决  阅读(35)  评论(0)    收藏  举报