目录
一、基础要求
1. 验证hub
(1)h1 ping h2
(2)h1 ping h3
2. 验证switch
(1)h1 ping h2
(2)h1 ping h3
3. L2_learning模板代码流程图
进阶要求
1. SendFlowInSingle3
(1)代码
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)
(2)运行结果
(3)ovs-ofctl交换机流表项截图
2. SendPoxHardTime
(1)代码
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)
(2)运行结果
(3)ovs-ofctl交换机流表项截图
心得体会
1.刚开始运行时对pox的命令不太熟悉。
2.文档阅读比较困难,理解起来不太容易。
3.在编写SendFlowInSingle3和SendPoxHardTimeOut代码时,需要学习的API,同时要了解进程通信的知识和python实现。
4.在进阶部分2,运行阶段卡住了,到不到结果,之后看了下其他人博客,有以下操作:先运行SendFlowInSingle3,同时执行ping操作,之后执行SendPoxHardTimeOut,停止运行SendPoxHardTimeOut,再次运行运行SendFlowInSingle3,实现上次进阶一结果.
5.总体感觉这次实验偏难,有许多地方需要学习。
6.希望在后续实践中继续可以提高自己的能力。