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

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

一、实验目的

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

二、实验环境

Ubuntu 20.04 Desktop amd64

三、实验要求

(一)基本要求

  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

 

 

 

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

进入pox:./pox.py log.level --DEBUG forwarding.hub

在topo终端输入:xterm h2 h3开启主机终端

在h2主机终端输入:tcpdump -nn -i h2-eth0

在h3主机终端输入:tcpdump -nn -i h3-eth0

在topo终端输入:h1 ping h2查看主机终端

 

 

 

 

 

 

关闭所有终端

重新搭建上面拓扑:sudo mn --topo=single,3 --mac --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow10

打开新终端输入:sudo mn -c清除拓扑

进入pox:./pox.py log.level --DEBUG forwarding.l2_learning

在topo终端输入:xterm h2 h3开启主机终端

在h2主机终端输入:tcpdump -nn -i h2-eth0

在h3主机终端输入:tcpdump -nn -i h3-eth0

在topo终端输入:h1 ping h2查看主机终端

 

 

 

 

 

 

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

 

 

 (二)进阶要求

搭建拓扑:sudo mn --topo=single,3 --mac --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow10

进入pox文件夹 输入:./pox.py SendFlowInSingle3

在mininet>输入:h1 ping h3

此时应该ping通,10s后 ctrl+C 停止SendFlowInSingle3

新建终端进入pox:./pox.py SendPoxHardTimeOut实现中断,10s后 ctrl+C停止SendPoxHardTimeOut

回到SendFlowInSingle3终端 输入:./pox.py 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):
        msg = of.ofp_flow_mod()  
        msg.priority = 1
        msg.match.in_port = 1 
        msg.actions.append(of.ofp_action_output(port=2))  
        msg.actions.append(of.ofp_action_output(port=3)) 
        event.connection.send(msg)

        msg = of.ofp_flow_mod()  
        msg.priority = 1
        msg.match.in_port = 2  
        msg.actions.append(of.ofp_action_output(port=1))  
        msg.actions.append(of.ofp_action_output(port=3))  
        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=1)) 
        msg.actions.append(of.ofp_action_output(port=2))
        event.connection.send(msg)

def launch():
    core.registerNew(SendFlowInSingle3)




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 = 2
        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 = 2)) 
        msg.actions.append(of.ofp_action_output(port = 3)) 
        event.connection.send(msg)

        
        msg = of.ofp_flow_mod()  
        msg.priority = 2
        msg.match.in_port = 2 
        msg.hard_timeout = 10
        event.connection.send(msg)
        
        msg = of.ofp_flow_mod() 
        msg.priority = 1
        msg.match.in_port = 2  
        msg.actions.append(of.ofp_action_output(port = 1)) 
        msg.actions.append(of.ofp_action_output(port = 3)) 
        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 = 1)) 
        msg.actions.append(of.ofp_action_output(port = 2)) 
        event.connection.send(msg)

def launch():
    core.registerNew(SendPoxHardTimeOut)

 

 

 

 

 

 总结

 对POX控制器有了一定的了解,对于hub模块有了更进一步的认识,在h1 ping h2时 h2 和 h3,都能收到ICMP报文,说明Hub模块在每个交换机上安装泛洪通配符规则,将数据包广播转发,此时交换机等效于集线器或广播交换机。ping的过程中实现断开功能 采用交替流表数据的形式 发送SendFlowInSingle3进行中止,再次发送SendPoxHardTimeOut中止,然后再次发送SendFlowInSingle3流表就好了。

posted @ 2022-10-20 08:46  戴晨轩  阅读(113)  评论(0)    收藏  举报