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

基础要求

1.验证hub

(1)h1 ping h2

(2)h1 ping h3

2.验证switch

(1)h1 ping h2

(2)h1 ping h3

3.L2_learning模块代码流程图

进阶要求

1.SendFlowInSingle3

(1)代码

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)

(2)运行结果

(3)ovs-ofctl交换机流表项截图

2.SendPoxHardTime

(1)代码

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

def _handle_ConnectionUp(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.openflow.addListenerByName("ConnectionUp", _handle_ConnectionUp)

(2)运行结果

(3)ovs-ofctl交换机流表项截图

心得体会

感觉这次试验的难度偏大,文档阅读会比之前的实验困难,需要学习的知识点多而杂。
基础部分要先学习用h2、h3端口抓包,按照文档按部就班地进行可以顺利做出来。但画L2_learning程序流程图需要仔细阅读L2_learning代码,这部分培养了我阅读能力和学习能力,通过POX验证hub和l2_learning模块,使我初步掌握了POX控制器的使用。
进阶部分较为困难,首先在SendFlowInSingle3和SendPoxHardTimeOut代码的编写上,需要先去学习了解用python程序进行通信管理。最难的是在进阶1的基础上实现硬超时,因为文档中对于步骤的介绍比较简洁,具体的操作需要我自己摸索和尝试:要先Pox运行SendFlowInSingle3(和ping同步),在一定时间后中短并运行SendPoxHardTimeOut,这时候就ping不通了,要再次ping通,就应该中断SendPoxHardTimeOut后再运行Pox运行SendFlowInSingle3。这个流程的摸索花费了我大部分时间。

posted @ 2022-10-10 21:40  这里是中国  阅读(35)  评论(0)    收藏  举报