实验六

(一)基本要求
搭建下图所示SDN拓扑,协议使用Open Flow 1.0

并连接Ryu控制器

通过Ryu的图形界面查看网络拓扑。

阅读Ryu文档的The First Application一节,运行当中的L2Switch

运行l2switch之后与之前对比

h1 ping h2或h3在目标主机使用 tcpdump 验证L2Switch

分析L2Switch和POX的Hub模块有何不同。
L2Switch:

POX的hub模块:

由此可见:
二者均通过洪泛发送报文,
pox的Hub模块可以查看流表,
但是ryu的L2Swtich的下发流表不可查看。

编程修改L2Switch.py,另存为L2xxxxxxxxx.py,使之和POX的Hub模块的变得一致?(xxxxxxxxx为学号)


修改后能够查看流表

from ryu.ofproto import ofproto_v1_3
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER, CONFIG_DISPATCHER
from ryu.controller.handler import set_ev_cls

class Hub(app_manager.RyuApp):
    OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]

    def __init__(self, *args, **kwargs):
        super(Hub, self).__init__(*args, **kwargs)

    @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
    def switch_features_handler(self, ev):
        datapath = ev.msg.datapath
        ofproto = datapath.ofproto
        ofp_parser = datapath.ofproto_parser

    #install the table-miss flow entry
        match = ofp_parser.OFPMatch()
        actions=[ofp_parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,ofproto.OFPCML_NO_BUFFER)]
        self.add_flow(datapath, 0, match, actions)

    def add_flow(self, datapath, priority, match, actions):
        #add a flow entry, and install it into datapath
        ofproto = datapath.ofproto
        ofp_parser = datapath.ofproto_parser

        #contruct a flow_mod msg and sent it
        inst = [ofp_parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,actions)]
        mod = ofp_parser.OFPFlowMod(datapath=datapath, priority=priority,match=match, instructions=inst)

        datapath.send_msg(mod)

    @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
    def packet_in_handler(self, ev):
        msg = ev.msg
        datapath = msg.datapath
        ofproto = datapath.ofproto
        ofp_parser = datapath.ofproto_parser
        in_port = msg.match['in_port']

        #contruct a flow entry
        match = ofp_parser.OFPMatch()
        actions = [ofp_parser.OFPActionOutput(ofproto.OFPP_FLOOD)]

        #install flow_mod to a avoid packet_ining next time
        self.add_flow(datapath, 1, match, actions)

        out = ofp_parser.OFPPacterOut(datapath=datapath, buffer_id=msg.buffer_id, in_port=in_port,actions=actions)
        datapath.send_msg(out)

实验心得:运行ryu-manager时遇到is_timeout错误,大量查证之后找到问题出在安装ryu时使用的pip install .命令,该命令会将组件安装至推荐版本,从而导致ryu组件版本不兼容发生错误。
解决方法:将0.31.1版本eventlet降低至0.16.1即可。
运行ryu-manager出现'AttributeError: module 'collections' has no attribute 'MutableMapping'是由于使用的python3.10中'MutableMapping,MutableSet'放的位置变了,所以需要在'namedict.py'文件中将'collections.MutableMapping'改为'collections.abc.MutableMapping'。

posted @ 2022-10-30 22:54  大岩洞  阅读(81)  评论(0)    收藏  举报