Hi, thank you for trying Ryu.

2012/12/13 ahmed hawas <[email protected]>:
> Hi,
>
> I'm trying to call the function get_flow_stats(dp, waiters): for an
> application to get the stats of a flow like packet count, byte count, etc. I
> imported the file /ryu/ryu/lib/ofctl_v1_0.py to be able to use the function.
> However, im not really familiar with the waiters and what value i should set
> it to. I tried making it an empty dictionary {}, but im getting errors when
> i run my application.

ryu/app/ofctl_rest.py use get_flow_stats(). Please refer to it. If you
don't need lock mechanism, you can write flow_dump application like
the following:

--
import gevent

from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.controller import dpset
from ryu.ofproto import ofproto_v1_0
from ryu.lib import ofctl_v1_0


class FlowDumper(app_manager.RyuApp):
    OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]
    _CONTEXTS = {
        'dpset': dpset.DPSet
    }

    def __init__(self, *args, **kwargs):
        super(FlowDumper, self).__init__(*args, **kwargs)
        self.dpset = kwargs['dpset']
        gevent.spawn_later(0, self.flow_request)

    def flow_request(self):
        while True:
            for dp in self.dpset.dps.values():
                match = dp.ofproto_parser.OFPMatch(
                    dp.ofproto.OFPFW_ALL, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0)
                stats = dp.ofproto_parser.OFPFlowStatsRequest(
                    dp, 0, match, 0xff, dp.ofproto.OFPP_NONE)
                dp.send_msg(stats)
            gevent.sleep(1)

    @set_ev_cls(ofp_event.EventOFPFlowStatsReply,
                        MAIN_DISPATCHER)
    def _stats_reply_handler(self, ev):
        for stats in ev.msg.body:
            actions = ofctl_v1_0.actions_to_str(stats.actions)
            match = ofctl_v1_0.match_to_str(stats.match)
            print {'dpid' : ev.msg.datapath.id,
                   'priority': stats.priority,
                   'cookie': stats.cookie,
                   'idle_timeout': stats.idle_timeout,
                   'hard_timeout': stats.hard_timeout,
                   'actions': actions,
                   'match': match,
                   'byte_count': stats.byte_count,
                   'duration_sec': stats.duration_sec,
                   'duration_nsec': stats.duration_nsec,
                   'packet_count': stats.packet_count,
                   'table_id': stats.table_id}

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to