基础要求只需要提交h1 ping h2、h2和h3的tcpdump抓包结果截图,外加L2_learning模块代码流程图,其余文字请勿赘述;
h1 ping h2
h1 ping h3
结论:无论h1 ping h2 还是 h1 ping h3 ,h2和h3均能抓到包,即验证了Hub模块的作用:将数据包广播转发。
h1 ping h2
h1 ping h3
结论:h1 ping h2 和h1 ping h3,只有相应主机可以抓到包,即验证了Switch模块的作用:让OpenFlow交换机实现L2自学习
程序流程图
进阶要求为选做,有完成的同学请提交相关代码和运行结果,以及ovs-ofctl交换机流表项截图,代码保存目录同要求2,形式不限,有完成比未完成的上机分数更高。
from pox.core import core
import pox.openflow.libopenflow_01 as of # POX convention
from pox.openflow.of_json import *
def SendFlowInSingle3(event):
msg = of.ofp_flow_mod() # 向交换机下发流表
msg.priority = 1
msg.match.in_port = 1 # 数据包进入端口1
msg.actions.append(of.ofp_action_output(port=2)) # 从端口2转发
msg.actions.append(of.ofp_action_output(port=3)) # 从端口3转发
event.connection.send(msg) #send flowmod to the switch.
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", SendFlowInSingle3)
h1 ping h2
h1 ping h3
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 #硬超时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)
h1 ping h2
h1 ping h3
个人总结,包括但不限于实验难度、实验过程遇到的困难及解决办法,个人感想,不少于200字。
1.执行POX模块是显示缩进有问题,最终发现是tab与空格不可同时混用。
在实现硬超时部分时运行SendFlowSingle3后,要按Ctrl+alt+c退出,再次运行SendPoxHardTimeOut。
本次实验难度还是有点大的,经过多方参考之后才完整的将其做了出来,也让自己对这一方面的知识有了更加深入的了解。