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

一、实验目的

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

二、实验环境

Ubuntu 20.04 Desktop amd64

三、实验要求

(一)基本要求

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

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

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

  1. ①Hub模块

    h1 ping h2

    h1 ping h3

    ②Switch模块

    h1 ping h2

​ h1 ping h3

流程图

(二)进阶要求

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

  2. 基于进阶1的代码,完成ODL实验的硬超时功能。(先运行SendFlowSingle3,先通再断 再恢复)

  1. 基于进阶1的代码,完成ODL实验的硬超时功能。(直接运行SendPoxHardTimeOut, 先断后通,能验证流表项生效即可

代码
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 = of.OFPP_ALL))
        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 = of.OFPP_ALL))
        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(SendFlowInSingle3)

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)

(三)总结

1.每一次抓包都重新开启一次命令行终端

2.Linux tcpdump命令用于倾倒网络传输数据。

3.Hud模块抓包:h1 ping h2时h3也可以抓到包,同理h1 ping h3时h2也可以抓到包.Hub模块在每个交换机上安装洪泛通配符规则 而switch模块h1 ping h2 时h3则抓不到,h1 ping h3时h2也抓不到.switch模块让Openflow交换机实现了L2自学习,只有目的主机可以抓取到报文

posted @   X1aomai  阅读(6)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示