(一)基本要求
1、POX的forwarding.hub
- h1 ping h2
- h1 ping h3
- h2 ping h3
结论:将数据包广播转发
2、POX的forwarding.l2_learning - h1 ping h2
- h1 ping h3
- h2 ping h3
结论:只有相应主机可以抓到包 - 程序流程图
(二)进阶要求
1、重新搭建(一)的拓扑,此时交换机内无流表规则,拓扑内主机互不相通
ovs-ofctl交换机流表项
代码如下
from pox.core import core
import pox.openflow.libopenflow_01 as of
from pox.lib.util import dpid_to_str, str_to_dpid
from pox.lib.util import str_to_bool
import time
from pox.openflow.of_json import *
def _handle_ConnectionUp(event):
# 数据流从交换机的端口1转发出去
msg = of.ofp_flow_mod()
msg.priority = 1
msg.match.in_port = 1
msg.actions.append(of.ofp_action_output(port = 1))
msg.actions.append(of.ofp_action_output(port = 2))
msg.actions.append(of.ofp_action_output(port = 3))
event.connection.send(msg)
# 数据流从交换机的端口2转发出去
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 = 2))
msg.actions.append(of.ofp_action_output(port = 3))
event.connection.send(msg)
# 数据流从交换机的端口3转发出去
msg = of.ofp_flow_mod()
msg.priority = 1
msg.match.in_port = 3
msg.actions.append(of.ofp_action_output(port = 3))
msg.actions.append(of.ofp_action_output(port = 2))
msg.actions.append(of.ofp_action_output(port = 1))
event.connection.send(msg)
def launch():
core.openflow.addListenerByName("ConnectionUp", _handle_ConnectionUp)
2、基于进阶1的代码,完成ODL实验的硬超时功能。
代码如下
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 = 3
msg.match.in_port = 1
msg.hard_timeout = 10 #硬超时10秒
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 = of.OFPP_ALL))
event.connection.send(msg)
msg = of.ofp_flow_mod()
msg.priority = 3
msg.match.in_port = 3
msg.hard_timeout = 10
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 = of.OFPP_ALL))
event.connection.send(msg)
def launch():
core.registerNew(SendPoxHardTimeOut)
(三)个人总结
通过本次实验能够理解pox控制器的工作原理,基础部分会比较简单点,唯一的问题就是在开启pox的l2_learning出现下面这个问题
解决方法:把虚拟机重新启动一下就可以了。
进阶部分难度就提升了,特别是代码部分,进阶2不能直接在进阶1的上面添加硬超时10秒的代码,添加的后果就是超时30秒,需要重新写一个。
在运行pox的时候,出现了6633端口被占的情况,需要把占6633端口的给kill,用ps -ef |grep 6633查找。
在写SendPoxHardTimeOut文件时要在pox中写才能运行。