实验5:开源控制器实践——POX
(一)基础要求
-
h1 ping h2
结果:h2、h3都收到数据包。
-
h1 ping h3
结果:h2、h3都收到数据包。
-
阅读L2_learning模块代码,画出程序流程图,使用 tcpdump 验证Switch模块
-
程序流程图
-
验证结果
(1) h1 ping h2
结果:h2收到数据包,h3没有收到。
(2) h1 ping h3
结果:h2没有收到数据包,h3收到。
(二)进阶要求
-
- 模块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)
- 开始pingall不通,下发流表后pingall通。
-
- 模块SendPoxHardTimeOut
点击查看代码
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)
- 开始SendFlowInSingle后ping通,然后执行SendPoxHardTimeOut后不可达,再次SendFlowInSingle后又ping通。
-
- ovs-ofctl交换机流表项
- 执行SendPoxHardTimeOut后,可以看出s1中流表h1少了output至h3的action,h3少了output至h1的action,导致h1 ping h3时不可达。
(三)总结
- 1.完成基础要求时按照实验说明ppt可以顺利完成,提高了对pox的基本使用,但理解L2_learning的代码时需要查阅下资料,耗费了较长时间。
- 2.完成进阶要求时理解了下发流表和硬超时的原理,但在编写代码时需要查阅下资料并努力理解每一行代码的含义,耗费了较长时间。