实验5:开源控制器实践——POX
一、实验要求
1.基本要求
(1)使用tcpdump验证Hub模块
h1 ping h2
h1 ping h3
(2) 阅读L2_learning模块代码,画出程序流程图
(3) 使用 tcpdump 验证Switch模块
h1 ping h2
h1 ping h3
2.进阶要求
(1)进阶1
重新搭建拓扑测试连通性
Python程序自定义一个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)
运行SendFlowSingle3,测试连通性,所有主机两两互通
(2) 基于进阶1的代码,完成ODL实验的硬超时功能
Python程序自定义一个POX模块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 = 15
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 = 15
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 = 15
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)
运行SendPoxHardTimeOut后结果截图
二、个人总结
通过本次实验,学到了POX 控制器的工作原理,在实验中通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法,在进阶实验中学会运用 POX控制器编写自定义网络应用程序,进一步熟悉POX控制器流表下发的方法。实验过程中遇到了在pox文件夹下无法新建文件的问题,在lab5目录的终端下建立SendFlowInSingle3.py后,用“sudo cp SendFlowInSingle3.py ../pox” 就能成功复制到pox目录下。
标签:控制器,POX,开源,actions,ofp,msg,output,port,append
From: https://www.cnblogs.com/zxcv12/p/16777192.html