首页 文章

从数据路径获取OpenFlow规则

提问于
浏览
2

在Ryu Controller中,对于选定的数据路径,如何从交换机获取OpenFlow规则?例如,对于以下规则:

cookie = 0x0,duration = 18575.528s,table = 0,n_packets = 1,n_bytes = 98,priority = 1,ip,in_port = 3,nw_dst = 10.0.0.1 actions = output:1

我想获得nw_dst和actions字段 .

1 回答

  • 1

    使用 OFPTableStatsRequest 对象 . 它将返回包含所有已安装流的列表 .

    请注意,还有一个 OFPGroupStatsRequest 对组执行相同的操作 .

    一个未经测试的示例,它依赖于实例变量 datapath .

    import ryu.app.ofctl.api as api
    
    def ofdpaTableStatsRequest(datapath):
        parser = datapath.ofproto_parser
        return parser.OFPTableStatsRequest(datapath)
    
    def getFlows(self):
        """
        Obtain a list of Flows loaded on the switch
        `
        :return: A list of Flow Entires
        """
        msg = ofdpaTableStatsRequest(self.datapath)
        reply = api.send_msg(self.ryuapp, msg,
                             reply_cls=self.parser.OFPTableStatsReply,
                             reply_multi=True)
        // the flow entries you are looking for will be in the reply
    

    如果这对您有用,请告诉我

相关问题