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

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

(一)基本要求

搭建下图所示SDN拓扑,协议使用Open Flow 1.0,控制器使用部署于本地的POX(默认监听6633端口)

sudo mn --topo=single,3 --mac --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow10

阅读Hub模块代码,使用 tcpdump 验证Hub模块

  • h1 ping h2的tcpdump抓包结果

  • h1 ping h3的tcpdump抓包结果

阅读L2_learning模块代码,画出程序流程图,使用 tcpdump 验证Switch模块

  • L2_learning模块代码流程图

  • h1 ping h2的tcpdump抓包结果

  • h1 ping h3的tcpdump抓包结果

(二)进阶要求

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

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)

(三)个人总结

  • 实验难度:

本次实验基础部分难度不高,进阶部分难度较大

  • 遇到的困难及解决办法:

    • ./pox.py log.level --DEBUG forwarding.SendFlowInSingle3无法运行
      • 解决方法:SendFlowInSingle3.py应该放在/home/ubuntu/032002240/pox/pox/forwarding目录下
    • 运行SendFlowInSingle3.py时发现6633端口被占用
      • 解决方法:通过命令netstat -lntup | grep 6633查看后发现是上一次pox没有正常关闭的原因,解决之后即可正常运行。
    • 运行SendFlowInSingle3模块后,发现主机始终无法ping通
      • 解决方法:是launch函数多写了一个缩进导致的,将改缩进删去后即可ping通
  • 个人感想:

本次实验使我对POX控制器的工作原理和功能有了更深刻的影响印象,并进一步熟悉了流表,通过实践验证了POX的Hub和L2_learning模块的功能,通过实验也让我发现对POX的学习和使用还要进一步加强,挺多地方卡壳,花了很多时间。

此外进阶要求需要阅读POX使用指南,因为是全英文的让我印象深刻,在查询网上相关资料后才完成进阶模块的操作。我觉得最难的是画流程图,代码好长好长,读得人都傻了。

posted @ 2022-10-10 23:07  zxxxs  阅读(45)  评论(0)    收藏  举报