2

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.

Anamort
  • 341
  • 4
  • 17

1 Answers1

1

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

AlanObject
  • 9,613
  • 19
  • 86
  • 142
  • Yes it works, thank you. Also I solved it inside the event handler. For example: @set_ev_cls(ofp_event.EventOFPFlowStatsReply, MAIN_DISPATCHER) def flowStatsHandler(self, ev): body = ev.msg.body for flow in body: self.ipv4Dest = flow.match['ipv4_dst'] – Anamort Dec 01 '16 at 19:33