软件定义网络实验6

这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/FZUZCSDN202201
这个作业要求在哪里 https://edu.cnblogs.com/campus/fzzcxy/FZUZCSDN202201/homework/12709
这个作业的目标 能够独立部署RYU控制器;
能够理解RYU控制器实现软件定义的集线器原理;
能够理解RYU控制器实现软件定义的交换机原理。
学号 212006240

基础要求

(1)搭建下图所示SDN拓扑,协议使用Open Flow 1.0,并连接Ryu控制器,通过Ryu的图形界面查看网络拓扑。

执行

sudo mn --topo=single,3 --mac --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow10
ryu-manager ryu/ryu/app/gui_topology/gui_topology.py --observe-links

(2) 阅读Ryu文档的The First Application一节,运行当中的L2Switch,h1 ping h2或h3,在目标主机使用 tcpdump 验证L2Switch,分析L2Switch和POX的Hub模块有何不同。

生成拓扑后,执行pingall不能ping通,执行ryu-manager L2Switch.py之后再次pingall即可

进行h1 ping h2 以及 h1 ping h3的操作,同时在h2和h3的端口抓包


h1 ping h2



h1 ping h3

查看流表

  • ryu查看流表


  • pox查看流表

  • 相同:Ryu的L2Switch模块和POX的Hub模块都采用洪泛转发,在h1 ping h2时,h3可以抓到数据包,在h1 ping h3时,h2可以抓到数据包

  • 不同:之处在于Ryu的L2Switch模块运行时不能查看流表,而POX的Hub模块运行时可以查看流表

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

from ryu.base import app_manager
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_feathers_handler(self, ev):
        datapath = ev.msg.datapath
        ofproto = datapath.ofproto
        ofp_parser = datapath.ofproto_parser
 
        # install flow table-miss flow entry
        match = ofp_parser.OFPMatch()
        actions = [ofp_parser.OFPActionOutput(ofproto.OFPP_CONTROLLER, ofproto.OFPCML_NO_BUFFER)]
        # 1\OUTPUT PORT, 2\BUFF IN SWITCH?
        self.add_flow(datapath, 0, match, actions)
 
    def add_flow(self, datapath, priority, match, actions):
        # 1\ datapath for the switch, 2\priority for flow entry, 3\match field, 4\action for packet
        ofproto = datapath.ofproto
        ofp_parser = datapath.ofproto_parser
        # install flow
        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']  # get in port of the packet
 
        # add a flow entry for the packet
        match = ofp_parser.OFPMatch()
        actions = [ofp_parser.OFPActionOutput(ofproto.OFPP_FLOOD)]
        self.add_flow(datapath, 1, match, actions)
 
        # to output the current packet. for install rules only output later packets
        out = ofp_parser.OFPPacketOut(datapath=datapath, buffer_id=msg.buffer_id, in_port=in_port, actions=actions)
        # buffer id: locate the buffered packet
        datapath.send_msg(out)

心得体会

1、执行ryu-manager时出错,推测是因为没有安装好python-dev
2、随后安装时报错Package 'python-dev' has no installation candidate,搜索后应该为ubuntu版本过高没有对应版本,故借用同学配置的虚拟机环境完成本次实验
3、在执行ryu-manager L2Switch后pingall仍然不通,可以清一下拓扑或者重启解决

posted @ 2022-10-29 09:39  计科废物2  阅读(33)  评论(0编辑  收藏  举报