st=>start: Start cond1=>condition: transparent=False且Ethertype为LLDP或数据包的目的地址是网桥过滤地址吗? cond2=>condition: 目的地是多播吗? cond3=>condition: 目的地址的端口在表中吗? cond4=>condition: 输出端口和输入端口相同吗? op1=>operation: 使用源地址和交换机端口更新地址 op2=>operation: 丢弃数据包 op3=>operation: 暂时丢弃数据包和类似数据包 op4=>operation: 在交换机中安装流量表条目 op5=>operation: 将数据包发送到适当的端口 e=>end: End st->op1->cond1(yes)->op2->e cond1(no)->cond2(yes)->op2->e cond2(no)->cond3(no)->op2->e cond3(yes)->cond4(yes)->op3 cond4(no)->op4->op5->e
from pox.core import core import pox.openflow.libopenflow_01 as of from pox.lib.util import dpidToStr log = core.getLogger() def _handle_ConnectionUp(event): msg = of.ofp_flow_mod() msg.actions.append(of.ofp_action_output(port=of.OFPP_FLOOD)) event.connection.send(msg) log.info("Hubifying %s", dpidToStr(event.dpid)) def _handle_PacketIn(event): msg = of.ofp_packet_out() msg.data = event.ofp msg.actions.append(of.ofp_action_output(port=of.OFPP_FLOOD)) event.connection.send(msg) event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=1), priority=42, match=of.ofp_match(dl_type=0x800, nw_dst="10.0.0.1", tp_dst=80))) event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=2), priority=42, match=of.ofp_match(dl_type=0x800, nw_dst="10.0.0.2", tp_dst=80))) event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=3), priority=42, match=of.ofp_match(dl_type=0x800, nw_dst="10.0.0.3", tp_dst=80))) def launch(reactive=False): if reactive: core.openflow.addListenerByName("PacketIn", _handle_PacketIn) log.info("Reactive hub running.") else: core.openflow.addListenerByName("ConnectionUp", _handle_ConnectionUp) log.info("Proactive hub running.")
·在基本要求这边,刚开始以为顺畅的做完,结果hub和l2_learning做出来的抓包结果没有差别,才发现原来启动pox的命令错了,张炜龙同学的博文里有特别提到这个点。还有如果做了多次的话,要注意修改端口号,或者关闭相应的进程,否则会显示端口号被占用。
·进阶的话,本来是想写一整个代码,结果运行了跑不出来。看了张炜龙同学的博文我又有了思路,我往hub.py的_handle_PacketIn中添加了下发流表的代码就大功告成了。
·以上都不是最让人感到无奈的!无奈的是试着第一次用markdown做流程图,结果因为空格语法错误找了好久,在typora做出来的图代码贴过来居然没反应。大晚上的,等待救赎中。。。