Esempio n. 1
0
def list_tc_filters(device, parent, namespace=None):
    LOG.info('%s(): caller(): %s', log_utils.get_fname(1),
             log_utils.get_fname(2))
    """List TC filter in a device

    :param device: (string) device name
    :param parent: (string) qdisc parent class ('root', 'ingress', '2:10')
    :param namespace: (string) (optional) namespace name

    """
    parent = iproute_linux.transform_handle(parent)
    filters = priv_tc_lib.list_tc_filters(device, parent, namespace=namespace)
    retval = []
    for filter in filters:
        tca_options = _get_attr(filter, 'TCA_OPTIONS')
        if not tca_options:
            continue
        tca_u32_sel = _get_attr(tca_options, 'TCA_U32_SEL')
        if not tca_u32_sel:
            continue
        keys = []
        for key in tca_u32_sel['keys']:
            key_off = key['key_off']
            value = 0
            for i in range(4):
                value = (value << 8) + (key_off & 0xff)
                key_off = key_off >> 8
            keys.append({
                'value': value,
                'mask': key['key_val'],
                'offset': key['key_offmask']
            })

        value = {'keys': keys}

        tca_u32_police = _get_attr(tca_options, 'TCA_U32_POLICE')
        if tca_u32_police:
            tca_police_tbf = _get_attr(tca_u32_police, 'TCA_POLICE_TBF')
            if tca_police_tbf:
                value['rate_kbps'] = int(tca_police_tbf['rate'] * 8 / 1024)
                value['burst_kb'] = int(
                    _calc_burst(tca_police_tbf['rate'],
                                tca_police_tbf['burst']) * 8 / 1024)
                value['mtu'] = tca_police_tbf['mtu']

        retval.append(value)

    return retval
Esempio n. 2
0
def list_tc_filters(device, parent, namespace=None):
    """List TC filter in a device

    :param device: (string) device name
    :param parent: (string) qdisc parent class ('root', 'ingress', '2:10')
    :param namespace: (string) (optional) namespace name

    """
    parent = iproute_linux.transform_handle(parent)
    filters = priv_tc_lib.list_tc_filters(device, parent, namespace=namespace)
    retval = []
    for filter in filters:
        tca_options = _get_attr(filter, 'TCA_OPTIONS')
        if not tca_options:
            continue
        tca_u32_sel = _get_attr(tca_options, 'TCA_U32_SEL')
        if not tca_u32_sel:
            continue
        keys = []
        for key in tca_u32_sel['keys']:
            key_off = key['key_off']
            value = 0
            for i in range(4):
                value = (value << 8) + (key_off & 0xff)
                key_off = key_off >> 8
            keys.append({'value': value,
                         'mask': key['key_val'],
                         'offset': key['key_offmask']})

        value = {'keys': keys}

        tca_u32_police = _get_attr(tca_options, 'TCA_U32_POLICE')
        if tca_u32_police:
            tca_police_tbf = _get_attr(tca_u32_police, 'TCA_POLICE_TBF')
            if tca_police_tbf:
                value['rate_kbps'] = int(tca_police_tbf['rate'] * 8 / 1024)
                value['burst_kb'] = int(
                    _calc_burst(tca_police_tbf['rate'],
                                tca_police_tbf['burst']) * 8 / 1024)
                value['mtu'] = tca_police_tbf['mtu']

        retval.append(value)

    return retval