实验5:开源控制器实践——POX
一、实验目的
- 能够理解 POX 控制器的工作原理;
- 通过验证POX的forwarding.hub和forwarding.l2_learning模块,初步掌握POX控制器的使用方法;
- 能够运用 POX控制器编写自定义网络应用程序,进一步熟悉POX控制器流表下发的方法
二、实验环境
- Ubuntu 20.04 Desktop amd64
三、实验要求
(一)基本要求
1. tcpdunp验证hub模块
- h1 ping h2
![image]()
- h1 ping h3
![image]()
2. l2_learning模块代码程序流程图

3. tcpdunp验证switch模块
- h1 ping h2
![image]()
- h1 ping h3
![image]()
(二)进阶要求
- 重新搭建(一)的拓扑,此时交换机内无流表规则,拓扑内主机互不相通;编写Python程序自定义一个POX模块SendFlowInSingle3,并且将拓扑连接至SendFlowInSingle3(默认端口6633),实现向s1发送流表规则使得所有主机两两互通。
![image]()
- python代码
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实验的硬超时功能。
![image]()
- python代码
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)
msg = of.ofp_flow_mod()
msg.priority = 65535
msg.match.in_port = 1
msg.hard_timeout = 10
event.connection.send(msg)
def launch():
core.registerNew(SendFlowInSingle3)
四、个人总结
- 在做实验前阅读PDF文档时有点困难,但是理解后实验时相对就简单些,还有一些困难就是在做进阶实验时,一开始发现和预期结果不太符合,后来经过修改完成。
- 通过本次实验认识到了,通过运行pox的不同模块可以实现交换机不同的工作方式,运行hub模块时相当于是集线器,会将每个端口收到的信息转发到其他所有端口,l2_learn模块则相当于是交换机。还有就是学会了通过自定义python模块进行下发流表从而实现主机之间的通信。在编写模块时如果不对匹配的流表项定义动作,则默认丢弃。每次运行模块都会先将交换机的当前流表清空。







浙公网安备 33010602011771号