コード例 #1
0
def get_queue_stats(dp, waiters, port=None, queue_id=None, to_user=True):
    ofp = dp.ofproto

    if port is None:
        port = ofp.OFPP_ANY
    else:
        port = str_to_int(port)

    if queue_id is None:
        queue_id = ofp.OFPQ_ALL
    else:
        queue_id = str_to_int(queue_id)

    stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, port,
                                                   queue_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    s = []
    for msg in msgs:
        stats = msg.body
        for stat in stats:
            s.append({'duration_nsec': stat.duration_nsec,
                      'duration_sec': stat.duration_sec,
                      'port_no': stat.port_no,
                      'queue_id': stat.queue_id,
                      'tx_bytes': stat.tx_bytes,
                      'tx_errors': stat.tx_errors,
                      'tx_packets': stat.tx_packets})

    return wrap_dpid_dict(dp, s, to_user)
コード例 #2
0
ファイル: ofctl_v1_4.py プロジェクト: jhhan/ryu
def get_meter_config(dp, waiters):
    flags = {
        dp.ofproto.OFPMF_KBPS: "KBPS",
        dp.ofproto.OFPMF_PKTPS: "PKTPS",
        dp.ofproto.OFPMF_BURST: "BURST",
        dp.ofproto.OFPMF_STATS: "STATS",
    }

    stats = dp.ofproto_parser.OFPMeterConfigStatsRequest(dp, 0, dp.ofproto.OFPM_ALL)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    configs = []
    for msg in msgs:
        for config in msg.body:
            c = config.to_jsondict()[config.__class__.__name__]
            bands = []
            for band in config.bands:
                b = band.to_jsondict()[band.__class__.__name__]
                t = UTIL.ofp_meter_band_type_to_user(band.type)
                b["type"] = t if t != band.type else "UNKNOWN"
                bands.append(b)
            c_flags = []
            for k, v in sorted(flags.items()):
                if k & config.flags:
                    c_flags.append(v)
            c["flags"] = c_flags
            c["bands"] = bands
            configs.append(c)
    configs = {str(dp.id): configs}
    return configs
コード例 #3
0
ファイル: ofctl_v1_4.py プロジェクト: ruicao93/ryu-cluster
def get_meter_config(dp, waiters):
    flags = {dp.ofproto.OFPMF_KBPS: 'KBPS',
             dp.ofproto.OFPMF_PKTPS: 'PKTPS',
             dp.ofproto.OFPMF_BURST: 'BURST',
             dp.ofproto.OFPMF_STATS: 'STATS'}

    stats = dp.ofproto_parser.OFPMeterConfigStatsRequest(
        dp, 0, dp.ofproto.OFPM_ALL)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    configs = []
    for msg in msgs:
        for config in msg.body:
            c = config.to_jsondict()[config.__class__.__name__]
            bands = []
            for band in config.bands:
                b = band.to_jsondict()[band.__class__.__name__]
                t = UTIL.ofp_meter_band_type_to_user(band.type)
                b['type'] = t if t != band.type else 'UNKNOWN'
                bands.append(b)
            c_flags = []
            for k, v in sorted(flags.items()):
                if k & config.flags:
                    c_flags.append(v)
            c['flags'] = c_flags
            c['bands'] = bands
            configs.append(c)
    configs = {str(dp.id): configs}
    return configs
コード例 #4
0
def get_meter_config(dp, waiters, meter_id=None, to_user=True):
    flags = {dp.ofproto.OFPMF_KBPS: 'KBPS',
             dp.ofproto.OFPMF_PKTPS: 'PKTPS',
             dp.ofproto.OFPMF_BURST: 'BURST',
             dp.ofproto.OFPMF_STATS: 'STATS'}

    band_type = {dp.ofproto.OFPMBT_DROP: 'DROP',
                 dp.ofproto.OFPMBT_DSCP_REMARK: 'DSCP_REMARK',
                 dp.ofproto.OFPMBT_EXPERIMENTER: 'EXPERIMENTER'}

    if meter_id is None:
        meter_id = dp.ofproto.OFPM_ALL
    else:
        meter_id = str_to_int(meter_id)

    stats = dp.ofproto_parser.OFPMeterConfigStatsRequest(
        dp, 0, meter_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    configs = []
    for msg in msgs:
        for config in msg.body:
            bands = []
            for band in config.bands:
                b = {'rate': band.rate,
                     'burst_size': band.burst_size}

                if to_user:
                    b['type'] = band_type.get(band.type, '')

                else:
                    b['type'] = band.type

                if band.type == dp.ofproto.OFPMBT_DSCP_REMARK:
                    b['prec_level'] = band.prec_level
                elif band.type == dp.ofproto.OFPMBT_EXPERIMENTER:
                    b['experimenter'] = band.experimenter
                bands.append(b)
            c_flags = []
            for k, v in sorted(flags.items()):
                if k & config.flags:
                    if to_user:
                        c_flags.append(v)

                    else:
                        c_flags.append(k)

            c = {'flags': c_flags,
                 'bands': bands}

            if to_user:
                c['meter_id'] = UTIL.ofp_meter_to_user(config.meter_id)

            else:
                c['meter_id'] = config.meter_id

            configs.append(c)

    return wrap_dpid_dict(dp, configs, to_user)
コード例 #5
0
ファイル: ofctl_v1_4.py プロジェクト: ruicao93/ryu-cluster
def get_queue_desc_stats(dp, waiters, port_no=None, queue_id=None):
    ofp = dp.ofproto
    port_no = port_no if port_no else ofp.OFPP_ANY
    queue_id = queue_id if queue_id else ofp.OFPQ_ALL

    stats = dp.ofproto_parser.OFPQueueDescStatsRequest(
        dp, 0, port_no, queue_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    configs = []
    for msg in msgs:
        for queue in msg.body:
            q = queue.to_jsondict()[queue.__class__.__name__]
            prop_list = []
            for prop in queue.properties:
                p = prop.to_jsondict()[prop.__class__.__name__]
                t = UTIL.ofp_queue_desc_prop_type_to_user(prop.type)
                p['type'] = t if t != prop.type else 'UNKNOWN'
                prop_list.append(p)
            q['properties'] = prop_list
            configs.append(q)
    configs = {str(dp.id): configs}

    return configs
コード例 #6
0
def get_flow_stats(dp, waiters, flow=None):
    flow = flow if flow else {}
    match = to_match(dp, flow.get('match', {}))
    table_id = UTIL.ofp_table_from_user(
        flow.get('table_id', 0xff))
    out_port = UTIL.ofp_port_from_user(
        flow.get('out_port', dp.ofproto.OFPP_NONE))

    stats = dp.ofproto_parser.OFPFlowStatsRequest(
        dp, 0, match, table_id, out_port)

    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    flows = []
    for msg in msgs:
        for stats in msg.body:
            actions = actions_to_str(stats.actions)
            match = match_to_str(stats.match)

            s = {'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': UTIL.ofp_table_to_user(stats.table_id)}
            flows.append(s)

    return {str(dp.id): flows}
コード例 #7
0
ファイル: ofctl_v1_2.py プロジェクト: KooDongSoo/ryu
def get_queue_config(dp, port, waiters):
    port = UTIL.ofp_port_from_user(port)
    stats = dp.ofproto_parser.OFPQueueGetConfigRequest(dp, port)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    prop_type = {dp.ofproto.OFPQT_MIN_RATE: 'MIN_RATE',
                 dp.ofproto.OFPQT_MAX_RATE: 'MAX_RATE',
                 dp.ofproto.OFPQT_EXPERIMENTER: 'EXPERIMENTER',
                 }

    configs = []
    for config in msgs:
        queue_list = []
        for queue in config.queues:
            prop_list = []
            for prop in queue.properties:
                p = {'property': prop_type.get(prop.property, 'UNKNOWN')}
                if prop.property == dp.ofproto.OFPQT_MIN_RATE or \
                   prop.property == dp.ofproto.OFPQT_MAX_RATE:
                    p['rate'] = prop.rate
                elif prop.property == dp.ofproto.OFPQT_EXPERIMENTER:
                    p['experimenter'] = prop.experimenter
                    p['data'] = prop.data
                prop_list.append(p)
            q = {'port': UTIL.ofp_port_to_user(queue.port),
                 'properties': prop_list,
                 'queue_id': UTIL.ofp_queue_to_user(queue.queue_id)}
            queue_list.append(q)
        c = {'port': UTIL.ofp_port_to_user(config.port),
             'queues': queue_list}
        configs.append(c)
    configs = {str(dp.id): configs}

    return configs
コード例 #8
0
ファイル: ofctl_v1_4.py プロジェクト: jhhan/ryu
def get_aggregate_flow_stats(dp, waiters, flow=None):
    flow = flow if flow else {}
    table_id = UTIL.ofp_table_from_user(flow.get("table_id", dp.ofproto.OFPTT_ALL))
    flags = int(flow.get("flags", 0))
    out_port = UTIL.ofp_port_from_user(flow.get("out_port", dp.ofproto.OFPP_ANY))
    out_group = UTIL.ofp_group_from_user(flow.get("out_group", dp.ofproto.OFPG_ANY))
    cookie = int(flow.get("cookie", 0))
    cookie_mask = int(flow.get("cookie_mask", 0))
    match = to_match(dp, flow.get("match", {}))

    stats = dp.ofproto_parser.OFPAggregateStatsRequest(
        dp, flags, table_id, out_port, out_group, cookie, cookie_mask, match
    )

    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    flows = []
    for msg in msgs:
        stats = msg.body
        s = stats.to_jsondict()[stats.__class__.__name__]
        flows.append(s)
    flows = {str(dp.id): flows}

    return flows
コード例 #9
0
ファイル: ofctl_v1_4.py プロジェクト: ruicao93/ryu-cluster
def get_flow_stats(dp, waiters, flow=None):
    flow = flow if flow else {}
    table_id = UTIL.ofp_table_from_user(
        flow.get('table_id', dp.ofproto.OFPTT_ALL))
    flags = int(flow.get('flags', 0))
    out_port = UTIL.ofp_port_from_user(
        flow.get('out_port', dp.ofproto.OFPP_ANY))
    out_group = UTIL.ofp_group_from_user(
        flow.get('out_group', dp.ofproto.OFPG_ANY))
    cookie = int(flow.get('cookie', 0))
    cookie_mask = int(flow.get('cookie_mask', 0))
    match = to_match(dp, flow.get('match', {}))

    stats = dp.ofproto_parser.OFPFlowStatsRequest(
        dp, flags, table_id, out_port, out_group, cookie, cookie_mask,
        match)

    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    flows = []
    for msg in msgs:
        for stats in msg.body:
            s = stats.to_jsondict()[stats.__class__.__name__]
            s['instructions'] = instructions_to_str(stats.instructions)
            s['match'] = match_to_str(stats.match)
            flows.append(s)
    flows = {str(dp.id): flows}

    return flows
コード例 #10
0
ファイル: ofctl_v1_3.py プロジェクト: Aries-Sushi/ryu
def get_aggregate_flow_stats(dp, waiters, flow=None, to_user=True):
    flow = flow if flow else {}
    table_id = UTIL.ofp_table_from_user(
        flow.get('table_id', dp.ofproto.OFPTT_ALL))
    flags = int(flow.get('flags', 0))
    out_port = UTIL.ofp_port_from_user(
        flow.get('out_port', dp.ofproto.OFPP_ANY))
    out_group = UTIL.ofp_group_from_user(
        flow.get('out_group', dp.ofproto.OFPG_ANY))
    cookie = int(flow.get('cookie', 0))
    cookie_mask = int(flow.get('cookie_mask', 0))
    match = to_match(dp, flow.get('match', {}))

    stats = dp.ofproto_parser.OFPAggregateStatsRequest(
        dp, flags, table_id, out_port, out_group, cookie, cookie_mask,
        match)

    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    flows = []
    for msg in msgs:
        stats = msg.body
        s = {'packet_count': stats.packet_count,
             'byte_count': stats.byte_count,
             'flow_count': stats.flow_count}
        flows.append(s)

    return wrap_dpid_dict(dp, flows, to_user)
コード例 #11
0
ファイル: ofctl_v1_4.py プロジェクト: Aries-Sushi/ryu
def get_group_desc(dp, waiters, to_user=True):
    stats = dp.ofproto_parser.OFPGroupDescStatsRequest(dp, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    descs = []
    for msg in msgs:
        for stats in msg.body:
            d = stats.to_jsondict()[stats.__class__.__name__]
            buckets = []
            for bucket in stats.buckets:
                b = bucket.to_jsondict()[bucket.__class__.__name__]
                actions = []
                for action in bucket.actions:
                    if to_user:
                        actions.append(action_to_str(action))

                    else:
                        actions.append(action)
                b['actions'] = actions
                buckets.append(b)

            d['buckets'] = buckets
            if to_user:
                d['group_id'] = UTIL.ofp_group_to_user(stats.group_id)
                t = UTIL.ofp_group_type_to_user(stats.type)
                d['type'] = t if t != stats.type else 'UNKNOWN'

            descs.append(d)

    return wrap_dpid_dict(dp, descs, to_user)
コード例 #12
0
def get_group_desc(dp, waiters, to_user=True):
    stats = dp.ofproto_parser.OFPGroupDescStatsRequest(dp, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    descs = []
    for msg in msgs:
        for stats in msg.body:
            d = stats.to_jsondict()[stats.__class__.__name__]
            buckets = []
            for bucket in stats.buckets:
                b = bucket.to_jsondict()[bucket.__class__.__name__]
                actions = []
                for action in bucket.actions:
                    if to_user:
                        actions.append(action_to_str(action))

                    else:
                        actions.append(action)
                b['actions'] = actions
                buckets.append(b)

            d['buckets'] = buckets
            if to_user:
                d['group_id'] = UTIL.ofp_group_to_user(stats.group_id)
                t = UTIL.ofp_group_type_to_user(stats.type)
                d['type'] = t if t != stats.type else 'UNKNOWN'

            descs.append(d)

    return wrap_dpid_dict(dp, descs, to_user)
コード例 #13
0
ファイル: ofctl_v1_0.py プロジェクト: Aries-Sushi/ryu
def get_aggregate_flow_stats(dp, waiters, flow=None):
    flow = flow if flow else {}
    match = to_match(dp, flow.get('match', {}))
    table_id = UTIL.ofp_table_from_user(
        flow.get('table_id', 0xff))
    out_port = UTIL.ofp_port_from_user(
        flow.get('out_port', dp.ofproto.OFPP_NONE))

    stats = dp.ofproto_parser.OFPAggregateStatsRequest(
        dp, 0, match, table_id, out_port)

    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    flows = []
    for msg in msgs:
        stats = msg.body
        for st in stats:
            s = {'packet_count': st.packet_count,
                 'byte_count': st.byte_count,
                 'flow_count': st.flow_count}
            flows.append(s)
    flows = {str(dp.id): flows}

    return flows
コード例 #14
0
def get_aggregate_flow_stats(dp, waiters, flow=None):
    flow = flow if flow else {}
    match = to_match(dp, flow.get('match', {}))
    table_id = UTIL.ofp_table_from_user(flow.get('table_id', 0xff))
    out_port = UTIL.ofp_port_from_user(
        flow.get('out_port', dp.ofproto.OFPP_NONE))

    stats = dp.ofproto_parser.OFPAggregateStatsRequest(dp, 0, match, table_id,
                                                       out_port)

    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    flows = []
    for msg in msgs:
        stats = msg.body
        for st in stats:
            s = {
                'packet_count': st.packet_count,
                'byte_count': st.byte_count,
                'flow_count': st.flow_count
            }
            flows.append(s)

    return {str(dp.id): flows}
コード例 #15
0
def get_port_desc(dp, waiters, port_no=None, to_user=True):
    if port_no is None:
        port_no = dp.ofproto.OFPP_ANY
    else:
        port_no = UTIL.ofp_port_from_user(port_no)

    stats = dp.ofproto_parser.OFPPortDescStatsRequest(dp, 0, port_no)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    descs = []

    for msg in msgs:
        stats = msg.body
        for stat in stats:
            d = stat.to_jsondict()[stat.__class__.__name__]
            properties = []
            for prop in stat.properties:
                p = prop.to_jsondict()[prop.__class__.__name__]

                if to_user:
                    t = UTIL.ofp_port_desc_prop_type_to_user(prop.type)
                    p['type'] = t if t != prop.type else 'UNKNOWN'

                properties.append(p)
            d['name'] = stat.name.decode('utf-8')
            d['properties'] = properties

            if to_user:
                d['port_no'] = UTIL.ofp_port_to_user(stat.port_no)

            descs.append(d)

    return wrap_dpid_dict(dp, descs, to_user)
コード例 #16
0
ファイル: ofctl_v1_5.py プロジェクト: vinaykothiyal/ryu
def get_aggregate_flow_stats(dp, waiters, flow=None, to_user=True):
    flow = flow if flow else {}
    table_id = UTIL.ofp_table_from_user(
        flow.get('table_id', dp.ofproto.OFPTT_ALL))
    flags = str_to_int(flow.get('flags', 0))
    out_port = UTIL.ofp_port_from_user(
        flow.get('out_port', dp.ofproto.OFPP_ANY))
    out_group = UTIL.ofp_group_from_user(
        flow.get('out_group', dp.ofproto.OFPG_ANY))
    cookie = str_to_int(flow.get('cookie', 0))
    cookie_mask = str_to_int(flow.get('cookie_mask', 0))
    match = to_match(dp, flow.get('match', {}))

    stats = dp.ofproto_parser.OFPAggregateStatsRequest(
        dp, flags, table_id, out_port, out_group, cookie, cookie_mask,
        match)

    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    flows = []
    for msg in msgs:
        stats = msg.body
        s = stats.to_jsondict()[stats.__class__.__name__]
        s['stats'] = stats_to_str(stats.stats)
        flows.append(s)

    return wrap_dpid_dict(dp, flows, to_user)
コード例 #17
0
def get_meter_stats(dp, waiters, meter_id=None, to_user=True):
    if meter_id is None:
        meter_id = dp.ofproto.OFPM_ALL
    else:
        meter_id = UTIL.ofp_meter_from_user(meter_id)

    stats = dp.ofproto_parser.OFPMeterStatsRequest(dp, 0, meter_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    meters = []
    for msg in msgs:
        for stats in msg.body:
            s = stats.to_jsondict()[stats.__class__.__name__]
            bands = []
            for band in stats.band_stats:
                b = band.to_jsondict()[band.__class__.__name__]
                bands.append(b)
            s['band_stats'] = bands

            if to_user:
                s['meter_id'] = UTIL.ofp_meter_to_user(stats.meter_id)

            meters.append(s)

    return wrap_dpid_dict(dp, meters, to_user)
コード例 #18
0
def get_group_stats(dp, waiters, group_id=None, to_user=True):
    if group_id is None:
        group_id = dp.ofproto.OFPG_ALL
    else:
        group_id = UTIL.ofp_group_from_user(group_id)

    stats = dp.ofproto_parser.OFPGroupStatsRequest(dp, 0, group_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    groups = []
    for msg in msgs:
        for stats in msg.body:
            g = stats.to_jsondict()[stats.__class__.__name__]
            bucket_stats = []
            for bucket_stat in stats.bucket_stats:
                c = bucket_stat.to_jsondict()[bucket_stat.__class__.__name__]
                bucket_stats.append(c)
            g['bucket_stats'] = bucket_stats

            if to_user:
                g['group_id'] = UTIL.ofp_group_to_user(stats.group_id)

            groups.append(g)

    return wrap_dpid_dict(dp, groups, to_user)
コード例 #19
0
def get_aggregate_flow_stats(dp, waiters, flow=None, to_user=True):
    flow = flow if flow else {}
    table_id = UTIL.ofp_table_from_user(
        flow.get('table_id', dp.ofproto.OFPTT_ALL))
    flags = int(flow.get('flags', 0))
    out_port = UTIL.ofp_port_from_user(
        flow.get('out_port', dp.ofproto.OFPP_ANY))
    out_group = UTIL.ofp_group_from_user(
        flow.get('out_group', dp.ofproto.OFPG_ANY))
    cookie = int(flow.get('cookie', 0))
    cookie_mask = int(flow.get('cookie_mask', 0))
    match = to_match(dp, flow.get('match', {}))

    stats = dp.ofproto_parser.OFPAggregateStatsRequest(dp, flags, table_id,
                                                       out_port, out_group,
                                                       cookie, cookie_mask,
                                                       match)

    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    flows = []
    for msg in msgs:
        stats = msg.body
        s = stats.to_jsondict()[stats.__class__.__name__]
        s['stats'] = stats_to_str(stats.stats)
        flows.append(s)

    return wrap_dpid_dict(dp, flows, to_user)
コード例 #20
0
def get_port_stats(dp, waiters, port_no=None, to_user=True):
    if port_no is None:
        port_no = dp.ofproto.OFPP_ANY
    else:
        port_no = UTIL.ofp_port_from_user(port_no)

    stats = dp.ofproto_parser.OFPPortStatsRequest(dp, 0, port_no)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    ports = []
    for msg in msgs:
        for stats in msg.body:
            s = stats.to_jsondict()[stats.__class__.__name__]
            properties = []
            for prop in stats.properties:
                p = prop.to_jsondict()[prop.__class__.__name__]
                t = UTIL.ofp_port_stats_prop_type_to_user(prop.type)
                p['type'] = t if t != prop.type else 'UNKNOWN'
                properties.append(p)
            s['properties'] = properties

            if to_user:
                s['port_no'] = UTIL.ofp_port_to_user(stats.port_no)

            ports.append(s)

    return wrap_dpid_dict(dp, ports, to_user)
コード例 #21
0
def get_flow_stats(dp, waiters, flow=None, to_user=True):
    flow = flow if flow else {}
    table_id = UTIL.ofp_table_from_user(
        flow.get('table_id', dp.ofproto.OFPTT_ALL))
    flags = int(flow.get('flags', 0))
    out_port = UTIL.ofp_port_from_user(
        flow.get('out_port', dp.ofproto.OFPP_ANY))
    out_group = UTIL.ofp_group_from_user(
        flow.get('out_group', dp.ofproto.OFPG_ANY))
    cookie = int(flow.get('cookie', 0))
    cookie_mask = int(flow.get('cookie_mask', 0))
    match = to_match(dp, flow.get('match', {}))
    # Note: OpenFlow does not allow to filter flow entries by priority,
    # but for efficiency, ofctl provides the way to do it.
    priority = int(flow.get('priority', -1))

    stats = dp.ofproto_parser.OFPFlowStatsRequest(dp, flags, table_id,
                                                  out_port, out_group, cookie,
                                                  cookie_mask, match)

    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    flows = []
    for msg in msgs:
        for stats in msg.body:
            if 0 <= priority != stats.priority:
                continue

            s = stats.to_jsondict()[stats.__class__.__name__]
            s['stats'] = stats_to_str(stats.stats)
            s['match'] = match_to_str(stats.match)
            flows.append(s)

    return wrap_dpid_dict(dp, flows, to_user)
コード例 #22
0
def get_queue_desc(dp, waiters, port_no=None, queue_id=None, to_user=True):
    if port_no is None:
        port_no = dp.ofproto.OFPP_ANY
    else:
        port_no = UTIL.ofp_port_from_user(port_no)
    if queue_id is None:
        queue_id = dp.ofproto.OFPQ_ALL
    else:
        queue_id = UTIL.ofp_queue_from_user(queue_id)

    stats = dp.ofproto_parser.OFPQueueDescStatsRequest(dp, 0, port_no,
                                                       queue_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    configs = []
    for msg in msgs:
        for queue in msg.body:
            q = queue.to_jsondict()[queue.__class__.__name__]
            prop_list = []
            for prop in queue.properties:
                p = prop.to_jsondict()[prop.__class__.__name__]
                if to_user:
                    t = UTIL.ofp_queue_desc_prop_type_to_user(prop.type)
                    p['type'] = t if t != prop.type else 'UNKNOWN'
                prop_list.append(p)
            q['properties'] = prop_list
            configs.append(q)

    return wrap_dpid_dict(dp, configs, to_user)
コード例 #23
0
def get_queue_stats(dp, waiters, port_no=None, queue_id=None, to_user=True):
    if port_no is None:
        port_no = dp.ofproto.OFPP_ANY
    else:
        port_no = UTIL.ofp_port_from_user(port_no)
    if queue_id is None:
        queue_id = dp.ofproto.OFPQ_ALL
    else:
        queue_id = UTIL.ofp_queue_from_user(queue_id)

    stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, port_no, queue_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    desc = []
    for msg in msgs:
        stats = msg.body
        for stat in stats:
            s = stat.to_jsondict()[stat.__class__.__name__]
            properties = []
            for prop in stat.properties:
                p = prop.to_jsondict()[prop.__class__.__name__]
                if to_user:
                    t = UTIL.ofp_queue_stats_prop_type_to_user(prop.type)
                    p['type'] = t if t != p['type'] else 'UNKNOWN'
                properties.append(p)
            s['properties'] = properties
            desc.append(s)

    return wrap_dpid_dict(dp, desc, to_user)
コード例 #24
0
ファイル: ofctl_v1_2.py プロジェクト: 5g-empower/empower-ryu
def get_group_stats(dp, waiters, group_id=None):
    if group_id is None:
        group_id = dp.ofproto.OFPG_ALL
    else:
        group_id = str_to_int(group_id)

    stats = dp.ofproto_parser.OFPGroupStatsRequest(
        dp, group_id, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    groups = []
    for msg in msgs:
        for stats in msg.body:
            bucket_counters = []
            for bucket_counter in stats.bucket_counters:
                c = {'packet_count': bucket_counter.packet_count,
                     'byte_count': bucket_counter.byte_count}
                bucket_counters.append(c)
            g = {'length': stats.length,
                 'group_id': UTIL.ofp_group_to_user(stats.group_id),
                 'ref_count': stats.ref_count,
                 'packet_count': stats.packet_count,
                 'byte_count': stats.byte_count,
                 'bucket_stats': bucket_counters}
            groups.append(g)

    return {str(dp.id): groups}
コード例 #25
0
ファイル: ofctl_v1_4.py プロジェクト: ruicao93/ryu-cluster
def get_meter_features(dp, waiters):
    ofp = dp.ofproto
    type_convert = {ofp.OFPMBT_DROP: 'DROP',
                    ofp.OFPMBT_DSCP_REMARK: 'DSCP_REMARK'}

    capa_convert = {ofp.OFPMF_KBPS: 'KBPS',
                    ofp.OFPMF_PKTPS: 'PKTPS',
                    ofp.OFPMF_BURST: 'BURST',
                    ofp.OFPMF_STATS: 'STATS'}

    stats = dp.ofproto_parser.OFPMeterFeaturesStatsRequest(dp, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    features = []
    for msg in msgs:
        for feature in msg.body:
            band_types = []
            for k, v in type_convert.items():
                if (1 << k) & feature.band_types:
                    band_types.append(v)
            capabilities = []
            for k, v in sorted(capa_convert.items()):
                if k & feature.capabilities:
                    capabilities.append(v)
            f = {'max_meter': feature.max_meter,
                 'band_types': band_types,
                 'capabilities': capabilities,
                 'max_bands': feature.max_bands,
                 'max_color': feature.max_color}
            features.append(f)
    features = {str(dp.id): features}
    return features
コード例 #26
0
ファイル: ofctl_v1_5.py プロジェクト: Huangmachi/ryu
def get_flow_stats(dp, waiters, flow=None, to_user=True):
    flow = flow if flow else {}
    table_id = UTIL.ofp_table_from_user(
        flow.get('table_id', dp.ofproto.OFPTT_ALL))
    flags = int(flow.get('flags', 0))
    out_port = UTIL.ofp_port_from_user(
        flow.get('out_port', dp.ofproto.OFPP_ANY))
    out_group = UTIL.ofp_group_from_user(
        flow.get('out_group', dp.ofproto.OFPG_ANY))
    cookie = int(flow.get('cookie', 0))
    cookie_mask = int(flow.get('cookie_mask', 0))
    match = to_match(dp, flow.get('match', {}))
    # Note: OpenFlow does not allow to filter flow entries by priority,
    # but for efficiency, ofctl provides the way to do it.
    priority = int(flow.get('priority', -1))

    stats = dp.ofproto_parser.OFPFlowStatsRequest(
        dp, flags, table_id, out_port, out_group, cookie, cookie_mask,
        match)

    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    flows = []
    for msg in msgs:
        for stats in msg.body:
            if 0 <= priority != stats.priority:
                continue

            s = stats.to_jsondict()[stats.__class__.__name__]
            s['stats'] = stats_to_str(stats.stats)
            s['match'] = match_to_str(stats.match)
            flows.append(s)

    return wrap_dpid_dict(dp, flows, to_user)
コード例 #27
0
ファイル: ofctl_v1_2.py プロジェクト: liuweiping2020/ReasoNet
def get_port_desc(dp, waiters):

    stats = dp.ofproto_parser.OFPFeaturesRequest(dp)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    descs = []

    for msg in msgs:
        stats = msg.ports
        for stat in stats.values():
            d = {
                'port_no': UTIL.ofp_port_to_user(stat.port_no),
                'hw_addr': stat.hw_addr,
                'name': stat.name.decode('utf-8'),
                'config': stat.config,
                'state': stat.state,
                'curr': stat.curr,
                'advertised': stat.advertised,
                'supported': stat.supported,
                'peer': stat.peer,
                'curr_speed': stat.curr_speed,
                'max_speed': stat.max_speed
            }
            descs.append(d)

    return {str(dp.id): descs}
コード例 #28
0
ファイル: ofctl_v1_2.py プロジェクト: liuweiping2020/ReasoNet
def get_port_stats(dp, waiters, port=None):
    if port is None:
        port = dp.ofproto.OFPP_ANY
    else:
        port = int(str(port), 0)

    stats = dp.ofproto_parser.OFPPortStatsRequest(dp, port, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    ports = []
    for msg in msgs:
        for stats in msg.body:
            s = {
                'port_no': UTIL.ofp_port_to_user(stats.port_no),
                'rx_packets': stats.rx_packets,
                'tx_packets': stats.tx_packets,
                'rx_bytes': stats.rx_bytes,
                'tx_bytes': stats.tx_bytes,
                'rx_dropped': stats.rx_dropped,
                'tx_dropped': stats.tx_dropped,
                'rx_errors': stats.rx_errors,
                'tx_errors': stats.tx_errors,
                'rx_frame_err': stats.rx_frame_err,
                'rx_over_err': stats.rx_over_err,
                'rx_crc_err': stats.rx_crc_err,
                'collisions': stats.collisions
            }
            ports.append(s)

    return {str(dp.id): ports}
コード例 #29
0
ファイル: ofctl_v1_2.py プロジェクト: liuweiping2020/ReasoNet
def get_group_stats(dp, waiters, group_id=None):
    if group_id is None:
        group_id = dp.ofproto.OFPG_ALL
    else:
        group_id = int(str(group_id), 0)

    stats = dp.ofproto_parser.OFPGroupStatsRequest(dp, group_id, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    groups = []
    for msg in msgs:
        for stats in msg.body:
            bucket_counters = []
            for bucket_counter in stats.bucket_counters:
                c = {
                    'packet_count': bucket_counter.packet_count,
                    'byte_count': bucket_counter.byte_count
                }
                bucket_counters.append(c)
            g = {
                'length': stats.length,
                'group_id': UTIL.ofp_group_to_user(stats.group_id),
                'ref_count': stats.ref_count,
                'packet_count': stats.packet_count,
                'byte_count': stats.byte_count,
                'bucket_stats': bucket_counters
            }
            groups.append(g)

    return {str(dp.id): groups}
コード例 #30
0
ファイル: ofctl_v1_2.py プロジェクト: liuweiping2020/ReasoNet
def get_queue_stats(dp, waiters, port=None, queue_id=None):
    ofp = dp.ofproto

    if port is None:
        port = ofp.OFPP_ANY
    else:
        port = int(str(port), 0)

    if queue_id is None:
        queue_id = ofp.OFPQ_ALL
    else:
        queue_id = int(str(queue_id), 0)

    stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, port, queue_id, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    s = []
    for msg in msgs:
        stats = msg.body
        for stat in stats:
            s.append({
                'port_no': stat.port_no,
                'queue_id': stat.queue_id,
                'tx_bytes': stat.tx_bytes,
                'tx_errors': stat.tx_errors,
                'tx_packets': stat.tx_packets
            })

    return {str(dp.id): s}
コード例 #31
0
ファイル: ofctl_v1_2.py プロジェクト: liuweiping2020/ReasoNet
def get_aggregate_flow_stats(dp, waiters, flow=None):
    flow = flow if flow else {}
    table_id = UTIL.ofp_table_from_user(
        flow.get('table_id', dp.ofproto.OFPTT_ALL))
    out_port = UTIL.ofp_port_from_user(
        flow.get('out_port', dp.ofproto.OFPP_ANY))
    out_group = UTIL.ofp_group_from_user(
        flow.get('out_group', dp.ofproto.OFPG_ANY))
    cookie = int(flow.get('cookie', 0))
    cookie_mask = int(flow.get('cookie_mask', 0))
    match = to_match(dp, flow.get('match', {}))

    stats = dp.ofproto_parser.OFPAggregateStatsRequest(dp, table_id, out_port,
                                                       out_group, cookie,
                                                       cookie_mask, match)

    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    flows = []
    for msg in msgs:
        stats = msg.body
        s = {
            'packet_count': stats.packet_count,
            'byte_count': stats.byte_count,
            'flow_count': stats.flow_count
        }
        flows.append(s)

    return {str(dp.id): flows}
コード例 #32
0
ファイル: ofctl_v1_5.py プロジェクト: Huangmachi/ryu
def get_queue_desc(dp, waiters, port_no=None, queue_id=None, to_user=True):
    if port_no is None:
        port_no = dp.ofproto.OFPP_ANY
    else:
        port_no = UTIL.ofp_port_from_user(port_no)
    if queue_id is None:
        queue_id = dp.ofproto.OFPQ_ALL
    else:
        queue_id = UTIL.ofp_queue_from_user(queue_id)

    stats = dp.ofproto_parser.OFPQueueDescStatsRequest(
        dp, 0, port_no, queue_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    configs = []
    for msg in msgs:
        for queue in msg.body:
            q = queue.to_jsondict()[queue.__class__.__name__]
            prop_list = []
            for prop in queue.properties:
                p = prop.to_jsondict()[prop.__class__.__name__]
                if to_user:
                    t = UTIL.ofp_queue_desc_prop_type_to_user(prop.type)
                    p['type'] = t if t != prop.type else 'UNKNOWN'
                prop_list.append(p)
            q['properties'] = prop_list
            configs.append(q)

    return wrap_dpid_dict(dp, configs, to_user)
コード例 #33
0
ファイル: ofctl_v1_2.py プロジェクト: 5g-empower/empower-ryu
def get_group_desc(dp, waiters):

    type_convert = {dp.ofproto.OFPGT_ALL: 'ALL',
                    dp.ofproto.OFPGT_SELECT: 'SELECT',
                    dp.ofproto.OFPGT_INDIRECT: 'INDIRECT',
                    dp.ofproto.OFPGT_FF: 'FF'}

    stats = dp.ofproto_parser.OFPGroupDescStatsRequest(dp, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    descs = []
    for msg in msgs:
        for stats in msg.body:
            buckets = []
            for bucket in stats.buckets:
                actions = []
                for action in bucket.actions:
                    actions.append(action_to_str(action))
                b = {'weight': bucket.weight,
                     'watch_port': bucket.watch_port,
                     'watch_group': bucket.watch_group,
                     'actions': actions}
                buckets.append(b)
            d = {'type': type_convert.get(stats.type),
                 'group_id': UTIL.ofp_group_to_user(stats.group_id),
                 'buckets': buckets}
            descs.append(d)

    return {str(dp.id): descs}
コード例 #34
0
def get_port_desc(dp, waiters, to_user=True):

    stats = dp.ofproto_parser.OFPPortDescStatsRequest(dp, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    descs = []

    for msg in msgs:
        stats = msg.body
        for stat in stats:
            d = {
                'hw_addr': stat.hw_addr,
                'name': stat.name.decode('utf-8'),
                'config': stat.config,
                'state': stat.state,
                'curr': stat.curr,
                'advertised': stat.advertised,
                'supported': stat.supported,
                'peer': stat.peer,
                'curr_speed': stat.curr_speed,
                'max_speed': stat.max_speed
            }

            if to_user:
                d['port_no'] = UTIL.ofp_port_to_user(stat.port_no)

            else:
                d['port_no'] = stat.port_no

            descs.append(d)

    return wrap_dpid_dict(dp, descs, to_user)
コード例 #35
0
ファイル: ofctl_v1_5.py プロジェクト: Huangmachi/ryu
def get_group_stats(dp, waiters, group_id=None, to_user=True):
    if group_id is None:
        group_id = dp.ofproto.OFPG_ALL
    else:
        group_id = UTIL.ofp_group_from_user(group_id)

    stats = dp.ofproto_parser.OFPGroupStatsRequest(
        dp, 0, group_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    groups = []
    for msg in msgs:
        for stats in msg.body:
            g = stats.to_jsondict()[stats.__class__.__name__]
            bucket_stats = []
            for bucket_stat in stats.bucket_stats:
                c = bucket_stat.to_jsondict()[bucket_stat.__class__.__name__]
                bucket_stats.append(c)
            g['bucket_stats'] = bucket_stats

            if to_user:
                g['group_id'] = UTIL.ofp_group_to_user(stats.group_id)

            groups.append(g)

    return wrap_dpid_dict(dp, groups, to_user)
コード例 #36
0
ファイル: ofctl_v1_5.py プロジェクト: Huangmachi/ryu
def get_port_desc(dp, waiters, port_no=None, to_user=True):
    if port_no is None:
        port_no = dp.ofproto.OFPP_ANY
    else:
        port_no = UTIL.ofp_port_from_user(port_no)

    stats = dp.ofproto_parser.OFPPortDescStatsRequest(dp, 0, port_no)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    descs = []

    for msg in msgs:
        stats = msg.body
        for stat in stats:
            d = stat.to_jsondict()[stat.__class__.__name__]
            properties = []
            for prop in stat.properties:
                p = prop.to_jsondict()[prop.__class__.__name__]

                if to_user:
                    t = UTIL.ofp_port_desc_prop_type_to_user(prop.type)
                    p['type'] = t if t != prop.type else 'UNKNOWN'

                properties.append(p)
            d['name'] = stat.name.decode('utf-8')
            d['properties'] = properties

            if to_user:
                d['port_no'] = UTIL.ofp_port_to_user(stat.port_no)

            descs.append(d)

    return wrap_dpid_dict(dp, descs, to_user)
コード例 #37
0
ファイル: ofctl_v1_3.py プロジェクト: Aries-Sushi/ryu
def get_queue_stats(dp, waiters, port=None, queue_id=None, to_user=True):
    ofp = dp.ofproto

    if port is None:
        port = ofp.OFPP_ANY
    else:
        port = int(str(port), 0)

    if queue_id is None:
        queue_id = ofp.OFPQ_ALL
    else:
        queue_id = int(str(queue_id), 0)

    stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, port,
                                                   queue_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    s = []
    for msg in msgs:
        stats = msg.body
        for stat in stats:
            s.append({'duration_nsec': stat.duration_nsec,
                      'duration_sec': stat.duration_sec,
                      'port_no': stat.port_no,
                      'queue_id': stat.queue_id,
                      'tx_bytes': stat.tx_bytes,
                      'tx_errors': stat.tx_errors,
                      'tx_packets': stat.tx_packets})

    return wrap_dpid_dict(dp, s, to_user)
コード例 #38
0
ファイル: ofctl_v1_5.py プロジェクト: Huangmachi/ryu
def get_port_stats(dp, waiters, port_no=None, to_user=True):
    if port_no is None:
        port_no = dp.ofproto.OFPP_ANY
    else:
        port_no = UTIL.ofp_port_from_user(port_no)

    stats = dp.ofproto_parser.OFPPortStatsRequest(dp, 0, port_no)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    ports = []
    for msg in msgs:
        for stats in msg.body:
            s = stats.to_jsondict()[stats.__class__.__name__]
            properties = []
            for prop in stats.properties:
                p = prop.to_jsondict()[prop.__class__.__name__]
                t = UTIL.ofp_port_stats_prop_type_to_user(prop.type)
                p['type'] = t if t != prop.type else 'UNKNOWN'
                properties.append(p)
            s['properties'] = properties

            if to_user:
                s['port_no'] = UTIL.ofp_port_to_user(stats.port_no)

            ports.append(s)

    return wrap_dpid_dict(dp, ports, to_user)
コード例 #39
0
ファイル: ofctl_v1_3.py プロジェクト: Aries-Sushi/ryu
def get_meter_config(dp, waiters, meter_id=None, to_user=True):
    flags = {dp.ofproto.OFPMF_KBPS: 'KBPS',
             dp.ofproto.OFPMF_PKTPS: 'PKTPS',
             dp.ofproto.OFPMF_BURST: 'BURST',
             dp.ofproto.OFPMF_STATS: 'STATS'}

    band_type = {dp.ofproto.OFPMBT_DROP: 'DROP',
                 dp.ofproto.OFPMBT_DSCP_REMARK: 'DSCP_REMARK',
                 dp.ofproto.OFPMBT_EXPERIMENTER: 'EXPERIMENTER'}

    if meter_id is None:
        meter_id = dp.ofproto.OFPM_ALL
    else:
        meter_id = int(str(meter_id), 0)

    stats = dp.ofproto_parser.OFPMeterConfigStatsRequest(
        dp, 0, meter_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    configs = []
    for msg in msgs:
        for config in msg.body:
            bands = []
            for band in config.bands:
                b = {'rate': band.rate,
                     'burst_size': band.burst_size}

                if to_user:
                    b['type'] = band_type.get(band.type, '')

                else:
                    b['type'] = band.type

                if band.type == dp.ofproto.OFPMBT_DSCP_REMARK:
                    b['prec_level'] = band.prec_level
                elif band.type == dp.ofproto.OFPMBT_EXPERIMENTER:
                    b['experimenter'] = band.experimenter
                bands.append(b)
            c_flags = []
            for k, v in sorted(flags.items()):
                if k & config.flags:
                    if to_user:
                        c_flags.append(v)

                    else:
                        c_flags.append(k)

            c = {'flags': c_flags,
                 'bands': bands}

            if to_user:
                c['meter_id'] = UTIL.ofp_meter_to_user(config.meter_id)

            else:
                c['meter_id'] = config.meter_id

            configs.append(c)

    return wrap_dpid_dict(dp, configs, to_user)
コード例 #40
0
ファイル: ofctl_v1_2.py プロジェクト: 5g-empower/empower-ryu
def get_port_desc(dp, waiters):

    stats = dp.ofproto_parser.OFPFeaturesRequest(dp)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    descs = []

    for msg in msgs:
        stats = msg.ports
        for stat in stats.values():
            d = {'port_no': UTIL.ofp_port_to_user(stat.port_no),
                 'hw_addr': stat.hw_addr,
                 'name': stat.name.decode('utf-8'),
                 'config': stat.config,
                 'state': stat.state,
                 'curr': stat.curr,
                 'advertised': stat.advertised,
                 'supported': stat.supported,
                 'peer': stat.peer,
                 'curr_speed': stat.curr_speed,
                 'max_speed': stat.max_speed}
            descs.append(d)

    return {str(dp.id): descs}
コード例 #41
0
ファイル: ofctl_v1_5.py プロジェクト: Huangmachi/ryu
def get_meter_stats(dp, waiters, meter_id=None, to_user=True):
    if meter_id is None:
        meter_id = dp.ofproto.OFPM_ALL
    else:
        meter_id = UTIL.ofp_meter_from_user(meter_id)

    stats = dp.ofproto_parser.OFPMeterStatsRequest(
        dp, 0, meter_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    meters = []
    for msg in msgs:
        for stats in msg.body:
            s = stats.to_jsondict()[stats.__class__.__name__]
            bands = []
            for band in stats.band_stats:
                b = band.to_jsondict()[band.__class__.__name__]
                bands.append(b)
            s['band_stats'] = bands

            if to_user:
                s['meter_id'] = UTIL.ofp_meter_to_user(stats.meter_id)

            meters.append(s)

    return wrap_dpid_dict(dp, meters, to_user)
コード例 #42
0
ファイル: ofctl_v1_0.py プロジェクト: Huangmachi/ryu
def get_queue_stats(dp, waiters, port=None, queue_id=None):
    if port is None:
        port = dp.ofproto.OFPP_ALL
    else:
        port = int(str(port), 0)

    if queue_id is None:
        queue_id = dp.ofproto.OFPQ_ALL
    else:
        queue_id = int(str(queue_id), 0)

    stats = dp.ofproto_parser.OFPQueueStatsRequest(dp, 0, port,
                                                   queue_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    s = []
    for msg in msgs:
        stats = msg.body
        for stat in stats:
            s.append({'port_no': stat.port_no,
                      'queue_id': stat.queue_id,
                      'tx_bytes': stat.tx_bytes,
                      'tx_errors': stat.tx_errors,
                      'tx_packets': stat.tx_packets})

    return {str(dp.id): s}
コード例 #43
0
ファイル: ofctl_v1_5.py プロジェクト: Huangmachi/ryu
def get_queue_stats(dp, waiters, port_no=None, queue_id=None, to_user=True):
    if port_no is None:
        port_no = dp.ofproto.OFPP_ANY
    else:
        port_no = UTIL.ofp_port_from_user(port_no)
    if queue_id is None:
        queue_id = dp.ofproto.OFPQ_ALL
    else:
        queue_id = UTIL.ofp_queue_from_user(queue_id)

    stats = dp.ofproto_parser.OFPQueueStatsRequest(
        dp, 0, port_no, queue_id)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    desc = []
    for msg in msgs:
        stats = msg.body
        for stat in stats:
            s = stat.to_jsondict()[stat.__class__.__name__]
            properties = []
            for prop in stat.properties:
                p = prop.to_jsondict()[prop.__class__.__name__]
                if to_user:
                    t = UTIL.ofp_queue_stats_prop_type_to_user(prop.type)
                    p['type'] = t if t != p['type'] else 'UNKNOWN'
                properties.append(p)
            s['properties'] = properties
            desc.append(s)

    return wrap_dpid_dict(dp, desc, to_user)
コード例 #44
0
ファイル: ofctl_v1_0.py プロジェクト: Huangmachi/ryu
def get_port_stats(dp, waiters, port=None):
    if port is None:
        port = dp.ofproto.OFPP_NONE
    else:
        port = int(str(port), 0)

    stats = dp.ofproto_parser.OFPPortStatsRequest(
        dp, 0, port)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    ports = []
    for msg in msgs:
        for stats in msg.body:
            s = {'port_no': UTIL.ofp_port_to_user(stats.port_no),
                 'rx_packets': stats.rx_packets,
                 'tx_packets': stats.tx_packets,
                 'rx_bytes': stats.rx_bytes,
                 'tx_bytes': stats.tx_bytes,
                 'rx_dropped': stats.rx_dropped,
                 'tx_dropped': stats.tx_dropped,
                 'rx_errors': stats.rx_errors,
                 'tx_errors': stats.tx_errors,
                 'rx_frame_err': stats.rx_frame_err,
                 'rx_over_err': stats.rx_over_err,
                 'rx_crc_err': stats.rx_crc_err,
                 'collisions': stats.collisions}
            ports.append(s)

    return {str(dp.id): ports}
コード例 #45
0
ファイル: ofctl_v1_3.py プロジェクト: Aries-Sushi/ryu
def get_port_desc(dp, waiters, to_user=True):

    stats = dp.ofproto_parser.OFPPortDescStatsRequest(dp, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    descs = []

    for msg in msgs:
        stats = msg.body
        for stat in stats:
            d = {'hw_addr': stat.hw_addr,
                 'name': stat.name.decode('utf-8'),
                 'config': stat.config,
                 'state': stat.state,
                 'curr': stat.curr,
                 'advertised': stat.advertised,
                 'supported': stat.supported,
                 'peer': stat.peer,
                 'curr_speed': stat.curr_speed,
                 'max_speed': stat.max_speed}

            if to_user:
                d['port_no'] = UTIL.ofp_port_to_user(stat.port_no)

            else:
                d['port_no'] = stat.port_no

            descs.append(d)

    return wrap_dpid_dict(dp, descs, to_user)
コード例 #46
0
ファイル: ofctl_v1_2.py プロジェクト: 5g-empower/empower-ryu
def get_group_features(dp, waiters):

    ofp = dp.ofproto
    type_convert = {ofp.OFPGT_ALL: 'ALL',
                    ofp.OFPGT_SELECT: 'SELECT',
                    ofp.OFPGT_INDIRECT: 'INDIRECT',
                    ofp.OFPGT_FF: 'FF'}
    cap_convert = {ofp.OFPGFC_SELECT_WEIGHT: 'SELECT_WEIGHT',
                   ofp.OFPGFC_SELECT_LIVENESS: 'SELECT_LIVENESS',
                   ofp.OFPGFC_CHAINING: 'CHAINING',
                   ofp.OFPGFC_CHAINING_CHECKS: 'CHAINING_CHECKS'}
    act_convert = {ofp.OFPAT_OUTPUT: 'OUTPUT',
                   ofp.OFPAT_COPY_TTL_OUT: 'COPY_TTL_OUT',
                   ofp.OFPAT_COPY_TTL_IN: 'COPY_TTL_IN',
                   ofp.OFPAT_SET_MPLS_TTL: 'SET_MPLS_TTL',
                   ofp.OFPAT_DEC_MPLS_TTL: 'DEC_MPLS_TTL',
                   ofp.OFPAT_PUSH_VLAN: 'PUSH_VLAN',
                   ofp.OFPAT_POP_VLAN: 'POP_VLAN',
                   ofp.OFPAT_PUSH_MPLS: 'PUSH_MPLS',
                   ofp.OFPAT_POP_MPLS: 'POP_MPLS',
                   ofp.OFPAT_SET_QUEUE: 'SET_QUEUE',
                   ofp.OFPAT_GROUP: 'GROUP',
                   ofp.OFPAT_SET_NW_TTL: 'SET_NW_TTL',
                   ofp.OFPAT_DEC_NW_TTL: 'DEC_NW_TTL',
                   ofp.OFPAT_SET_FIELD: 'SET_FIELD'}

    stats = dp.ofproto_parser.OFPGroupFeaturesStatsRequest(dp, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    features = []
    for msg in msgs:
        feature = msg.body
        types = []
        for k, v in type_convert.items():
            if (1 << k) & feature.types:
                types.append(v)
        capabilities = []
        for k, v in cap_convert.items():
            if k & feature.capabilities:
                capabilities.append(v)
        max_groups = []
        for k, v in type_convert.items():
            max_groups.append({v: feature.max_groups[k]})
        actions = []
        for k1, v1 in type_convert.items():
            acts = []
            for k2, v2 in act_convert.items():
                if (1 << k2) & feature.actions[k1]:
                    acts.append(v2)
            actions.append({v1: acts})
        f = {'types': types,
             'capabilities': capabilities,
             'max_groups': max_groups,
             'actions': actions}
        features.append(f)

    return {str(dp.id): features}
コード例 #47
0
def get_flow_stats(dp, waiters, flow=None, to_user=True):
    flow = flow if flow else {}
    table_id = UTIL.ofp_table_from_user(
        flow.get('table_id', dp.ofproto.OFPTT_ALL))
    flags = str_to_int(flow.get('flags', 0))
    out_port = UTIL.ofp_port_from_user(
        flow.get('out_port', dp.ofproto.OFPP_ANY))
    out_group = UTIL.ofp_group_from_user(
        flow.get('out_group', dp.ofproto.OFPG_ANY))
    cookie = str_to_int(flow.get('cookie', 0))
    cookie_mask = str_to_int(flow.get('cookie_mask', 0))
    match = to_match(dp, flow.get('match', {}))
    # Note: OpenFlow does not allow to filter flow entries by priority,
    # but for efficiency, ofctl provides the way to do it.
    priority = str_to_int(flow.get('priority', -1))

    stats = dp.ofproto_parser.OFPFlowStatsRequest(dp, flags, table_id,
                                                  out_port, out_group, cookie,
                                                  cookie_mask, match)

    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    flows = []
    for msg in msgs:
        for stats in msg.body:
            if 0 <= priority != stats.priority:
                continue

            s = {
                'priority': stats.priority,
                'cookie': stats.cookie,
                'idle_timeout': stats.idle_timeout,
                'hard_timeout': stats.hard_timeout,
                'byte_count': stats.byte_count,
                'duration_sec': stats.duration_sec,
                'duration_nsec': stats.duration_nsec,
                'packet_count': stats.packet_count,
                'length': stats.length,
                'flags': stats.flags
            }

            if to_user:
                s['actions'] = actions_to_str(stats.instructions)
                s['match'] = match_to_str(stats.match)
                s['table_id'] = UTIL.ofp_table_to_user(stats.table_id)

            else:
                s['actions'] = stats.instructions
                s['instructions'] = stats.instructions
                s['match'] = stats.match
                s['table_id'] = stats.table_id

            flows.append(s)

    return wrap_dpid_dict(dp, flows, to_user)
コード例 #48
0
ファイル: ofctl_v1_3.py プロジェクト: 5g-empower/empower-ryu
def get_flow_stats(dp, waiters, flow=None, to_user=True):
    flow = flow if flow else {}
    table_id = UTIL.ofp_table_from_user(
        flow.get('table_id', dp.ofproto.OFPTT_ALL))
    flags = str_to_int(flow.get('flags', 0))
    out_port = UTIL.ofp_port_from_user(
        flow.get('out_port', dp.ofproto.OFPP_ANY))
    out_group = UTIL.ofp_group_from_user(
        flow.get('out_group', dp.ofproto.OFPG_ANY))
    cookie = str_to_int(flow.get('cookie', 0))
    cookie_mask = str_to_int(flow.get('cookie_mask', 0))
    match = to_match(dp, flow.get('match', {}))
    # Note: OpenFlow does not allow to filter flow entries by priority,
    # but for efficiency, ofctl provides the way to do it.
    priority = str_to_int(flow.get('priority', -1))

    stats = dp.ofproto_parser.OFPFlowStatsRequest(
        dp, flags, table_id, out_port, out_group, cookie, cookie_mask,
        match)

    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    flows = []
    for msg in msgs:
        for stats in msg.body:
            if 0 <= priority != stats.priority:
                continue

            s = {'priority': stats.priority,
                 'cookie': stats.cookie,
                 'idle_timeout': stats.idle_timeout,
                 'hard_timeout': stats.hard_timeout,
                 'byte_count': stats.byte_count,
                 'duration_sec': stats.duration_sec,
                 'duration_nsec': stats.duration_nsec,
                 'packet_count': stats.packet_count,
                 'length': stats.length,
                 'flags': stats.flags}

            if to_user:
                s['actions'] = actions_to_str(stats.instructions)
                s['match'] = match_to_str(stats.match)
                s['table_id'] = UTIL.ofp_table_to_user(stats.table_id)

            else:
                s['actions'] = stats.instructions
                s['instructions'] = stats.instructions
                s['match'] = stats.match
                s['table_id'] = stats.table_id

            flows.append(s)

    return wrap_dpid_dict(dp, flows, to_user)
コード例 #49
0
def get_desc_stats(dp, waiters, to_user=True):
    stats = dp.ofproto_parser.OFPDescStatsRequest(dp, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
    s = {}

    for msg in msgs:
        stats = msg.body
        s = stats.to_jsondict()[stats.__class__.__name__]

    return wrap_dpid_dict(dp, s, to_user)
コード例 #50
0
ファイル: ofctl_v1_2.py プロジェクト: MrCocoaCat/ryu
def get_desc_stats(dp, waiters):
    stats = dp.ofproto_parser.OFPDescStatsRequest(dp)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    s = {}
    for msg in msgs:
        stats = msg.body
        s = stats.to_jsondict()[stats.__class__.__name__]

    return {str(dp.id): s}
コード例 #51
0
ファイル: ofctl_v1_5.py プロジェクト: Huangmachi/ryu
def get_desc_stats(dp, waiters, to_user=True):
    stats = dp.ofproto_parser.OFPDescStatsRequest(dp, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
    s = {}

    for msg in msgs:
        stats = msg.body
        s = stats.to_jsondict()[stats.__class__.__name__]

    return wrap_dpid_dict(dp, s, to_user)
コード例 #52
0
ファイル: ofctl_v1_4.py プロジェクト: jhhan/ryu
def get_desc_stats(dp, waiters):
    stats = dp.ofproto_parser.OFPDescStatsRequest(dp, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)
    s = {}

    for msg in msgs:
        stats = msg.body
        s = stats.to_jsondict()[stats.__class__.__name__]
    desc = {str(dp.id): s}
    return desc
コード例 #53
0
def get_queue_config(dp, waiters, port=None, to_user=True):
    ofp = dp.ofproto
    if port is None:
        port = ofp.OFPP_ANY
    else:
        port = UTIL.ofp_port_from_user(int(str(port), 0))
    stats = dp.ofproto_parser.OFPQueueGetConfigRequest(dp, port)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    prop_type = {
        dp.ofproto.OFPQT_MIN_RATE: 'MIN_RATE',
        dp.ofproto.OFPQT_MAX_RATE: 'MAX_RATE',
        dp.ofproto.OFPQT_EXPERIMENTER: 'EXPERIMENTER',
    }

    configs = []
    for config in msgs:
        queue_list = []
        for queue in config.queues:
            prop_list = []
            for prop in queue.properties:
                p = {'property': prop_type.get(prop.property, 'UNKNOWN')}
                if prop.property == dp.ofproto.OFPQT_MIN_RATE or \
                   prop.property == dp.ofproto.OFPQT_MAX_RATE:
                    p['rate'] = prop.rate
                elif prop.property == dp.ofproto.OFPQT_EXPERIMENTER:
                    p['experimenter'] = prop.experimenter
                    p['data'] = prop.data
                prop_list.append(p)

            q = {'properties': prop_list}

            if to_user:
                q['port'] = UTIL.ofp_port_to_user(queue.port)
                q['queue_id'] = UTIL.ofp_queue_to_user(queue.queue_id)

            else:
                q['port'] = queue.port
                q['queue_id'] = queue.queue_id

            queue_list.append(q)

        c = {'queues': queue_list}

        if to_user:
            c['port'] = UTIL.ofp_port_to_user(config.port)

        else:
            c['port'] = config.port

        configs.append(c)

    return wrap_dpid_dict(dp, configs, to_user)
コード例 #54
0
ファイル: ofctl_v1_3.py プロジェクト: Aries-Sushi/ryu
def get_queue_config(dp, waiters, port=None, to_user=True):
    ofp = dp.ofproto
    if port is None:
        port = ofp.OFPP_ANY
    else:
        port = UTIL.ofp_port_from_user(int(str(port), 0))
    stats = dp.ofproto_parser.OFPQueueGetConfigRequest(dp, port)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    prop_type = {dp.ofproto.OFPQT_MIN_RATE: 'MIN_RATE',
                 dp.ofproto.OFPQT_MAX_RATE: 'MAX_RATE',
                 dp.ofproto.OFPQT_EXPERIMENTER: 'EXPERIMENTER',
                 }

    configs = []
    for config in msgs:
        queue_list = []
        for queue in config.queues:
            prop_list = []
            for prop in queue.properties:
                p = {'property': prop_type.get(prop.property, 'UNKNOWN')}
                if prop.property == dp.ofproto.OFPQT_MIN_RATE or \
                   prop.property == dp.ofproto.OFPQT_MAX_RATE:
                    p['rate'] = prop.rate
                elif prop.property == dp.ofproto.OFPQT_EXPERIMENTER:
                    p['experimenter'] = prop.experimenter
                    p['data'] = prop.data
                prop_list.append(p)

            q = {'properties': prop_list}

            if to_user:
                q['port'] = UTIL.ofp_port_to_user(queue.port)
                q['queue_id'] = UTIL.ofp_queue_to_user(queue.queue_id)

            else:
                q['port'] = queue.port
                q['queue_id'] = queue.queue_id

            queue_list.append(q)

        c = {'queues': queue_list}

        if to_user:
            c['port'] = UTIL.ofp_port_to_user(config.port)

        else:
            c['port'] = config.port

        configs.append(c)

    return wrap_dpid_dict(dp, configs, to_user)
コード例 #55
0
def get_table_stats(dp, waiters):
    stats = dp.ofproto_parser.OFPTableStatsRequest(dp, 0)
    ofp = dp.ofproto
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    match_convert = {
        ofp.OFPFW_IN_PORT: 'IN_PORT',
        ofp.OFPFW_DL_VLAN: 'DL_VLAN',
        ofp.OFPFW_DL_SRC: 'DL_SRC',
        ofp.OFPFW_DL_DST: 'DL_DST',
        ofp.OFPFW_DL_TYPE: 'DL_TYPE',
        ofp.OFPFW_NW_PROTO: 'NW_PROTO',
        ofp.OFPFW_TP_SRC: 'TP_SRC',
        ofp.OFPFW_TP_DST: 'TP_DST',
        ofp.OFPFW_NW_SRC_SHIFT: 'NW_SRC_SHIFT',
        ofp.OFPFW_NW_SRC_BITS: 'NW_SRC_BITS',
        ofp.OFPFW_NW_SRC_MASK: 'NW_SRC_MASK',
        ofp.OFPFW_NW_SRC: 'NW_SRC',
        ofp.OFPFW_NW_SRC_ALL: 'NW_SRC_ALL',
        ofp.OFPFW_NW_DST_SHIFT: 'NW_DST_SHIFT',
        ofp.OFPFW_NW_DST_BITS: 'NW_DST_BITS',
        ofp.OFPFW_NW_DST_MASK: 'NW_DST_MASK',
        ofp.OFPFW_NW_DST: 'NW_DST',
        ofp.OFPFW_NW_DST_ALL: 'NW_DST_ALL',
        ofp.OFPFW_DL_VLAN_PCP: 'DL_VLAN_PCP',
        ofp.OFPFW_NW_TOS: 'NW_TOS',
        ofp.OFPFW_ALL: 'ALL',
        ofp.OFPFW_ICMP_TYPE: 'ICMP_TYPE',
        ofp.OFPFW_ICMP_CODE: 'ICMP_CODE'
    }

    tables = []
    for msg in msgs:
        stats = msg.body
        for stat in stats:
            wildcards = []
            for k, v in match_convert.items():
                if (1 << k) & stat.wildcards:
                    wildcards.append(v)
            s = {
                'table_id': UTIL.ofp_table_to_user(stat.table_id),
                'name': stat.name.decode('utf-8'),
                'wildcards': wildcards,
                'max_entries': stat.max_entries,
                'active_count': stat.active_count,
                'lookup_count': stat.lookup_count,
                'matched_count': stat.matched_count
            }
            tables.append(s)
    desc = {str(dp.id): tables}

    return desc
コード例 #56
0
ファイル: RyuApp_openflow.py プロジェクト: palanik1/tipsy
  def configure_1(self):
    self.change_status('configure_1')
    parser = self.dp.ofproto_parser

    self.insert_fakedrop_rules()
    self.pl.config_switch(parser)

    # Finally, send and wait for a barrier
    msg = parser.OFPBarrierRequest(self.dp)
    msgs = []
    ofctl.send_stats_request(self.dp, msg, self.waiters, msgs, self.logger)

    self.handle_configured()
コード例 #57
0
ファイル: ofctl_v1_4.py プロジェクト: ruicao93/ryu-cluster
def get_table_stats(dp, waiters):
    stats = dp.ofproto_parser.OFPTableStatsRequest(dp, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    tables = []
    for msg in msgs:
        stats = msg.body
        for stat in stats:
            s = stat.to_jsondict()[stat.__class__.__name__]
            tables.append(s)
    desc = {str(dp.id): tables}

    return desc
コード例 #58
0
ファイル: ofctl_v1_4.py プロジェクト: jhhan/ryu
def get_table_stats(dp, waiters):
    stats = dp.ofproto_parser.OFPTableStatsRequest(dp, 0)
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    tables = []
    for msg in msgs:
        stats = msg.body
        for stat in stats:
            s = stat.to_jsondict()[stat.__class__.__name__]
            tables.append(s)
    desc = {str(dp.id): tables}

    return desc
コード例 #59
0
ファイル: ofctl_v1_0.py プロジェクト: Aries-Sushi/ryu
def get_table_stats(dp, waiters):
    stats = dp.ofproto_parser.OFPTableStatsRequest(dp, 0)
    ofp = dp.ofproto
    msgs = []
    ofctl_utils.send_stats_request(dp, stats, waiters, msgs, LOG)

    match_convert = {ofp.OFPFW_IN_PORT: 'IN_PORT',
                     ofp.OFPFW_DL_VLAN: 'DL_VLAN',
                     ofp.OFPFW_DL_SRC: 'DL_SRC',
                     ofp.OFPFW_DL_DST: 'DL_DST',
                     ofp.OFPFW_DL_TYPE: 'DL_TYPE',
                     ofp.OFPFW_NW_PROTO: 'NW_PROTO',
                     ofp.OFPFW_TP_SRC: 'TP_SRC',
                     ofp.OFPFW_TP_DST: 'TP_DST',
                     ofp.OFPFW_NW_SRC_SHIFT: 'NW_SRC_SHIFT',
                     ofp.OFPFW_NW_SRC_BITS: 'NW_SRC_BITS',
                     ofp.OFPFW_NW_SRC_MASK: 'NW_SRC_MASK',
                     ofp.OFPFW_NW_SRC: 'NW_SRC',
                     ofp.OFPFW_NW_SRC_ALL: 'NW_SRC_ALL',
                     ofp.OFPFW_NW_DST_SHIFT: 'NW_DST_SHIFT',
                     ofp.OFPFW_NW_DST_BITS: 'NW_DST_BITS',
                     ofp.OFPFW_NW_DST_MASK: 'NW_DST_MASK',
                     ofp.OFPFW_NW_DST: 'NW_DST',
                     ofp.OFPFW_NW_DST_ALL: 'NW_DST_ALL',
                     ofp.OFPFW_DL_VLAN_PCP: 'DL_VLAN_PCP',
                     ofp.OFPFW_NW_TOS: 'NW_TOS',
                     ofp.OFPFW_ALL: 'ALL',
                     ofp.OFPFW_ICMP_TYPE: 'ICMP_TYPE',
                     ofp.OFPFW_ICMP_CODE: 'ICMP_CODE'}

    tables = []
    for msg in msgs:
        stats = msg.body
        for stat in stats:
            wildcards = []
            for k, v in match_convert.items():
                if (1 << k) & stat.wildcards:
                    wildcards.append(v)
            s = {'table_id': UTIL.ofp_table_to_user(stat.table_id),
                 'name': stat.name.decode('utf-8'),
                 'wildcards': wildcards,
                 'max_entries': stat.max_entries,
                 'active_count': stat.active_count,
                 'lookup_count': stat.lookup_count,
                 'matched_count': stat.matched_count}
            tables.append(s)
    desc = {str(dp.id): tables}

    return desc