Anamort
Anamort

Reputation: 341

Getting OpenFlow rules from a datapath

In Ryu Controller, for a selected datapath, how can I get the OpenFlow rules from the switch? For example, for the rule below:

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

I want to get nw_dst and actions fields.

Upvotes: 2

Views: 479

Answers (1)

AlanObject
AlanObject

Reputation: 9973

Use the OFPTableStatsRequest object. It will return a list with all the installed flows.

Note there is also an OFPGroupStatsRequest that does the same thing for groups.

An untested example that relies on an instance variable 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

Let me know if this works for you

Upvotes: 1

Related Questions