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

这个作业属于哪个课程https://edu.cnblogs.com/campus/fzzcxy/FZUZCSDN202201
这个作业要求在哪里https://edu.cnblogs.com/campus/fzzcxy/FZUZCSDN202201/homework/12708
这个作业的目标能够理解 POX 控制器的工作原理
通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法
能够运用 POX控制器编写自定义网络应用程序,进一步熟悉POX控制器流表下发的方法

(一)基本要求

1. 搭建下图所示SDN拓扑,协议使用Open Flow 1.0,控制器使用部署于本地的POX(默认监听6633端口)


生成拓扑sudo mn --topo=single,3 --mac --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow10
开启POX./pox.py log.level --DEBUG forwarding.hub

2. 阅读Hub模块代码,使用 tcpdump 验证Hub模块;

  1. 开启主机终端
    mininet> xterm h1 h2 h3
  2. 抓取数据包
    tcpdump -nn -i h2-eth0
    tcpdump -nn -i h3-eth0

集线器(HUB)作为物理层的网络连接设备,可以对信号进行放大和再生,但是,集线器只能进行原始比特流的传送,不可能对数据流量进行任何隔离或过滤,因此由集线器连接的网段属于同一个冲突域;共享式集线器采用广播方式,每一个端口上的计算机都可以收到集线上的广播数据,两个端口上的站点同时发送数据就会产生冲突。

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

  1. 开启主机终端
    mininet> xterm h1 h2 h3
  2. 抓取数据包
    tcpdump -nn -i h2-eth0
    tcpdump -nn -i h3-eth0

交换机是数据链路层的互连设备,具有依据第二层地址进行数据帧过滤的能力。由交换机的不同端口所连的网段属于不同的冲突域;交换机是并行工作的,它可以同时支持多个信源和信宿端口之间的通信,从而提高大大了数据转发的速度。

  1. 程序流程图

(二)进阶要求

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

  1. 生成拓扑 sudo mn --topo=single,3 --mac --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow10
  2. SendFlowInSingle3代码
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):
        
        #设置数据包从端口1进,从端口2和端口3出
        msg = of.ofp_flow_mod()# 使用ofp_flow_mod()的方法向交换机来下发流表
        msg.priority = 1#设置msg的优先级
        msg.match.in_port = 1#设置在端口1接收数据包
        msg.actions.append(of.ofp_action_output(port = of.OFPP_ALL))#增加转发向所有端口的动作
        event.connection.send(msg)#通过send函数向交换机发送所设定的消息

        #设置数据包从端口2进,从端口1和端口3出
        msg = of.ofp_flow_mod()
        msg.priority = 1
        msg.match.in_port = 2
        msg.actions.append(of.ofp_action_output(port = of.OFPP_ALL))
        event.connection.send(msg)

        #设置数据包从端口3进,从端口1和端口2出
        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(SendFlowInSingle3)
  1. 运行SendFlowSingle3
    ./pox.py log.level --DEBUG forwarding.SendFlowInSingle3

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

SendPoxHardTimeOut代码

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  #硬超时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)
  • 运行SendPoxHardTimeOut
    ./pox.py log.level --DEBUG forwarding.SendPoxHardTimeOut

个人总结

  1. 实验难度比上次难,参考了其他人的实验报告(论巨人的重要性.)
  2. 在pox目录下创建 SendFlowInSingle3.pySendPoxHardTimeOut.py 文件时需要加 sudo ,否则无法创建成功
  3. 基础要求部分,一开始对如何开启主机终端很是疑惑,后来看了其他人的实验报告知道了xterm h1 h2 h3即可
  4. 对POX控制器的工作原理和使用方法有了一定的了解
posted @ 2022-10-09 13:40  Accepted_1  阅读(109)  评论(0编辑  收藏  举报