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

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

基础实验

  1. hub
    image

分析:
由于在hub模式下,采取广播帧的模式,交换机每收到一帧,会向所有端口进行广播,因而h1发给h2的数据包在h3的端口也能监听到

  1. switch
    image

分析:
由于在自学习模式下,交换机会根据mac高速缓存信息进行发送数据包,因而在实验过程中,对于h1发给h2的数据包,h3只能捕捉到h1对h2的arp请求,并不能捕捉到数据包

  1. 流程图
    image

进阶实验

  1. 自定义一个POX模块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)
    

结果:
image

  1. 硬超时功能
    2.1 利用1编写的代码,手工开启、断开、再开启
    image

流表查看:
image

2.2 直接运行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 = 2
        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=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 = 2
        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)

image
流表查看:
image

实验总结

本次实验主要学习POX控制器的使用方法,通过实验学习,我对比了集线器和交换机传输帧的区别,切实地感受到交换机自学习算法能够有效地减少广播风暴。并且,通过此次实验,我了解了如何通过编写代码实现硬实时功能、下发流表功能,颇有收获。

posted @ 2022-10-04 22:24  盒什么饭  阅读(93)  评论(0编辑  收藏  举报