实验5:开源控制器实践——POX
(一)基本要求
1.搭建下图所示SDN拓扑,协议使用Open Flow 1.0,控制器使用部署于本地的POX(默认监听6633端口)


2.阅读Hub模块代码,使用 tcpdump 验证Hub模块;
- a)h1 ping h2 tcpdump结果,h2,h3都能抓到包
![]()
- b)h1 ping h3 tcpdump结果,h2,h3都能抓到包
![]()
3.阅读L2_learning模块代码,画出程序流程图,使用 tcpdump 验证Switch模块。
- a)h1 ping h2 tcpdump结果,只有h2能抓到包
![]()
- b)h1 ping h3 tcpdump结果,只有h3能抓到包
![]()
- c)L2_learning模块流程图
![]()
(二)进阶要求
1.重新搭建(一)的拓扑,此时交换机内无流表规则,拓扑内主机互不相通;编写Python程序自定义一个POX模块SendFlowInSingle3,并且将拓扑连接至SendFlowInSingle3(默认端口6633),实现向s1发送流表规则使得所有主机两两互通。
- a)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):
#设置数据包从端口1进,从端口2和3出
msg = of.ofp_flow_mod() # 使用ofp_flow_mod()方法向交换机下发流表
msg.priority = 1 #设置msg优先级
msg.match.in_port = 1 #在端口1接收数据包
msg.actions.append(of.ofp_action_output(port=2)) #设置数据包从端口2转发
msg.actions.append(of.ofp_action_output(port=3)) # 设置数据包从端口3转发
event.connection.send(msg) #通过send函数向交换机发送设定的消息
#设置数据包从端口2进,从端口1和3出
msg = of.ofp_flow_mod() # 使用ofp_flow_mod()方法向交换机下发流表
msg.priority = 1 #设置msg优先级
msg.match.in_port = 2 # 在端口2接收数据包
msg.actions.append(of.ofp_action_output(port=1)) # 设置数据包从端口1转发
msg.actions.append(of.ofp_action_output(port=3)) # 设置数据包从端口3转发
event.connection.send(msg) #通过send函数向交换机发送设定的消息
#设置数据包从端口3进,从端口1和2出
msg = of.ofp_flow_mod() #使用ofp_flow_mod()方法向交换机下发流表
msg.priority = 1 #设置msg优先级
msg.match.in_port = 3 # 使数据包进入端口3
msg.actions.append(of.ofp_action_output(port=1)) # 设置数据包从端口1转发
msg.actions.append(of.ofp_action_output(port=2)) # 设置数据包从端口2转发
event.connection.send(msg) #通过send函数向交换机发送设定的消息
def launch():
core.registerNew(SendFlowInSingle3) #注册SendFlowInSingle3组件
2.基于进阶1的代码,完成ODL实验的硬超时功能。
- a)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):
#设置数据包从端口1进,从端口2和3出
msg = of.ofp_flow_mod() # 使用ofp_flow_mod()方法向交换机下发流表
msg.priority = 1 #设置msg优先级
msg.match.in_port = 1 #在端口1接收数据包
msg.actions.append(of.ofp_action_output(port=2)) #设置数据包从端口2转发
#msg.actions.append(of.ofp_action_output(port=3)) # 设置数据包从端口3转发
event.connection.send(msg) #通过send函数向交换机发送设定的消息
#设置数据包从端口2进,从端口1和3出
msg = of.ofp_flow_mod() # 使用ofp_flow_mod()方法向交换机下发流表
msg.priority = 1 #设置msg优先级
msg.match.in_port = 2 # 在端口2接收数据包
msg.actions.append(of.ofp_action_output(port=1)) # 设置数据包从端口1转发
msg.actions.append(of.ofp_action_output(port=3)) # 设置数据包从端口3转发
event.connection.send(msg) #通过send函数向交换机发送设定的消息
#设置数据包从端口3进,从端口1和2出
msg = of.ofp_flow_mod() #使用ofp_flow_mod()方法向交换机下发流表
msg.priority = 1 #设置msg优先级
msg.match.in_port = 3 # 使数据包进入端口3
#msg.actions.append(of.ofp_action_output(port=1)) # 设置数据包从端口1转发
msg.actions.append(of.ofp_action_output(port=2)) # 设置数据包从端口2转发
event.connection.send(msg) #通过send函数向交换机发送设定的消息
def launch():
core.registerNew(SendPoxHardTimeOut) #注册SendPoxHardTimeOut组件
-
c)类型二,直接运行SendPoxHardTimeOut,先断后通
![]()
-
d)交换机流表
![]()
(三)个人总结
1.基础部分的实验内容根据pdf指引按步骤进行不是很难,创建topo,分别运行hub模块和L2_learning模块查看结果即可(通过“xterm h1 h2 h3”调出主机命令行);
2.进阶部分对我来说比较难,第一步构建SendFlowInSingle3模块,在查阅了pdf内给出的资料后,代码运行成功;但进阶二的内容不太理解具体怎么操作,首先没有理解SendPoxHardTimeOut模块代码应该怎么写,然后就是对于进阶二的两项操作流程不理解,只能按照自己的想法操作:
第一项:
先构建topo,然后运行SendFlowInSingle3,在mininet上进行h1 ping h3,停止SendFlowInSingle3,运行SendPoxHardTimeOut后再立刻停止,最后运行SendFlowInSingle3,得出与pdf相符的中断结果;
第二项:
先构建topo,直接运行SendPoxHardTimeOut,在mininet上进行h1 ping h3,等待后会出现unreachable,然后停止SendPoxHardTimeOut,最后再运行SendFlowInSingle3,得出报告中进阶二的结果。
3.对于pox整个文件夹解锁,我使用的是“sudo chmod -R 777 pox”,运行后整个文件夹都解锁方便移动新建的python代码。







浙公网安备 33010602011771号