实验5 开源控制器实践——POX
基础部分
- Hub
- Switch
- L2_learning模块代码流程图
进阶部分
- 自定义一个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)
运行结果:
基于进阶1的代码,完成ODL实验的硬超时功能。(先运行SendFlowSingle3,先通再断 再恢复):
查看流表:
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)
运行结果:
个人总结:
本次实验难度适中,通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步了解掌握了POX控制器的一些使用方法,理解了POX控制器的工作原理。本次实验遇到的第一个问题是自己编写的python自定义程序运行不成功,后来发现是要将程序放在pox目录下,将文件移入pox文件夹又需要权限,最后通过网络搜索掌握了通过终端复制文件到另一目录的方法,成功解决问题。另一问题是在完成进阶1后继续完成进阶2,总是得不到预期的结果,后来经同学提醒,将拓扑关闭再重新建立,成功解决问题。
标签:控制器,POX,开源,actions,ofp,msg,output,port,append From: https://www.cnblogs.com/h2324037851/p/16784471.html