一、基础要求
1. Hub
- h1 ping h2
- h1 ping h3
2. Switch
- h1 ping h2
- h1 ping h3
3. L2_learning模块代码流程图
二、进阶要求
1. 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()
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)
#设置数据包从端口2进,从端口1和3出
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)
#设置数据包从端口3进,从端口1和2出
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)
- 运行结果
2. 硬超时
- 代码
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))
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=2))
event.connection.send(msg)
def launch():
core.registerNew(SendFlowInSingle3)
- 流表
- 运行结果
三、个人总结
本次实验难度偏难,首先是源码中的各种方法看得有点费劲,消息中的一些参数也忘了,去复习了下之前的实验。实操过程中也有一些结果不符合预期,网上搜索一些总结后才得以结局。研究forwarding.l2_learning的代码时看着有些费劲,结合他人的经验后才理解了forwarding.l2_learning模块的作用。感觉forwarding.hub模块有点像集线器,forwarding.l2_learning有点像交换机,可以自学习,所以才会出现主机间互相ping时出现了不同的结果。
进阶模式中要自己写代码,而之前oftp各种消息类型也忘得差不多了,故而整个过程有些痛苦,最后多多向同学请教也逐渐理解了pox控制器的一些用法,也算是初步学会一些pox控制器的操作,。
标签:控制器,POX,开源,actions,ofp,msg,output,port,append From: https://www.cnblogs.com/032002134yjd/p/16782190.html