搜索

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


发布时间: 2022-11-24 18:03:07    浏览次数:8 次

一、基础要求

1. 验证hub

h1 ping h2 与h1 ping h3

2. 验证switch

h1 ping h2 与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)运行结果

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)运行结果

三、心得体会

在做基础部分还是比较得心应手,难度卡在了进阶部分2。我一开始以为只能同时运行,但没办法同时运行。看了下其他人博客,是先运行SendFlowInSingle3,同时执行ping操作,之后执行SendPoxHardTimeOut,停止运SendPoxHardTimeOut,再次运行运行SendFlowInSingle3。按照这种操着,很快得出了想要的结果。

免责声明 实验5:开源控制器实践——POX,资源类别:文本, 浏览次数:8 次, 文件大小:-- , 由本站蜘蛛搜索收录2022-11-24 06:03:07。此页面由程序自动采集,只作交流和学习使用,本站不储存任何资源文件,如有侵权内容请联系我们举报删除, 感谢您对本站的支持。 原文链接:https://www.cnblogs.com/Luyti/p/16784051.html