实验5:开源控制器实践——POX

(一)基本要求

开启pox:

  • h1 ping h2的tcpdump抓包结果

  • h1 ping h3的tcpdump抓包结果

  • L2_learning模块代码流程图

开启pox,运行L2_learning模块:

  • h1 ping h2的tcpdump抓包结果(h2收到数据包,而h3没有收到数据包)

  • h1 ping h3的tcpdump抓包结果(h3收到数据包,而h2没有收到数据包)

(二)进阶要求

1.重新搭建(一)的拓扑,此时交换机内无流表规则,拓扑内主机互不相通;编写Python程序自定义一个POX模块SendFlowInSingle3,并且将拓扑连接至SendFlowInSingle3(默认端口6633),实现向s1发送流表规则使得所有主机两两互通:

  • SendFlowInSingle3.py:
from pox.core import core
import pox.openflow.libopenflow_01 as of
from pox.openflow.of_json import *

def SendFlowInSingle3(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", SendFlowInSingle3);

​ 2.基于进阶1的代码,完成ODL实验的硬超时功能

  • SendPoxHardTimeOut.py:
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()  # 使用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)

(三)个人总结

这次实验较前两次难度有所增加,也要处理一些实验报告中没有说明的细节。
通过本次实验,使我浅浅地理解了POX控制器的工作原理;实验中用到POX的forwarding.hub和forwarding.l2_learning模块,也使我初步掌握了POX控制器的使用方法。
在本次实验中,也遇到了不少拦路虎,比如在使用./pox.py运行forwarding.hub和forwarding.l2_learning模块时在命令后加了.py后缀,导致报错。后来发现要把后缀去掉。其次,代码阅读这一部分对我来说也是比较困难的,在资料和同学的帮助下也仿照着画出来了。
总的来看,这次实验花费时间较前两次较长,但也在实验过程中小有收获。

posted @ 2022-10-11 22:34  4月鸟  阅读(20)  评论(0)    收藏  举报