(一)基础要求
搭建下图所示SDN拓扑,协议使用Open Flow 1.0,控制器使用部署于本地的POX(默认监听6633端口)
阅读Hub模块代码,使用 tcpdump 验证Hub模块;
h1 ping h2时,h2和h3都能接收到数据包
阅读L2_learning模块代码,画出程序流程图,使用 tcpdump 验证Switch模块。
h1 ping h2时,只有h2能接收到数据包,h3接收不到数据包
(二)进阶要求
重新搭建(一)的拓扑,此时交换机内无流表规则,拓扑内主机互不相通
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 h3
h2 -> h1 h3
h3 -> h1 h2
*** Results: 0% dropped (6/6 received)
mininet> dpctl del-flows
*** s1 ------------------------------------------------------------------------
mininet> pingall
*** Ping: testing ping reachability
h1 -> X X
h2 -> X X
h3 -> X X
*** Results: 100% dropped (0/6 received)
编写Python程序自定义一个POX模块SendFlowInSingle3(文件命名为102299120),并且将拓扑连接至SendFlowInSingle3(默认端口6633),实现向s1发送流表规则使得所有主机两两互通。
Python代码
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)
基于进阶1的代码,完成ODL实验的硬超时功能。
Python代码
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() # 使用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(SendPoxHardTimeOut)
个人总结
这次的实验相比前面的实验还是比较容易的,就是刚开始的时候并没有那么熟悉对pox的应用,有时候会被一些小问题卡了一下,例如开启pox命令的时候需要在pox目录下进行,但总体上跟着文档进行得还是比较流畅的,
但进阶部分配置时稍微费了一些时间来查阅相关文档才得以实现,通过本次实验,我了解了POX控制器的实验原理及POX的forwarding.hub和forwarding.l2_learning模块及流表的配置。
标签:控制器,POX,开源,actions,action,ofp,msg,output,port From: https://www.cnblogs.com/HypocriSY966/p/16840044.html