Example #1
0
def _qdisc_conf_out(dev, root_qdisc_handle, vlan_tag, class_id, qos):
    """Adds the traffic class and filtering to the current hfsc qdisc"""
    flow_id = _ROOT_QDISC_HANDLE + class_id

    def filt_flow_id(filt, kind):
        return filt.get(kind, {}).get('flowid')

    filters = [
        filt for filt in tc._filters(dev, parent=root_qdisc_handle)
        if flow_id in (filt_flow_id(filt, 'basic'), filt_flow_id(filt, 'u32'))
    ]

    # Clear up any previous filters to the class
    for filt in filters:
        try:
            tc.filter.delete(dev, filt['pref'], parent=root_qdisc_handle)
        except tc.TrafficControlException as tce:
            if tce.errCode != errno.EINVAL:  # no filters exist -> EINVAL
                raise

    # Clear the class in case it exists
    try:
        tc.cls.delete(dev, classid=root_qdisc_handle + class_id)
    except tc.TrafficControlException as tce:
        if tce.errCode != errno.ENOENT:
            raise

    _add_hfsc_cls(dev, root_qdisc_handle, class_id, **qos)
    if class_id == _DEFAULT_CLASSID:
        _add_non_vlanned_filter(dev, root_qdisc_handle)
    else:
        _add_vlan_filter(dev, vlan_tag, root_qdisc_handle, class_id)
    _add_fair_qdisc(dev, root_qdisc_handle, class_id)
Example #2
0
File: qos.py Project: fancyKai/vdsm
def _qdisc_conf_out(dev, root_qdisc_handle, vlan_tag, class_id, qos):
    """Adds the traffic class and filtering to the current hfsc qdisc"""
    flow_id = _ROOT_QDISC_HANDLE + class_id

    def filt_flow_id(filt, kind):
        return filt.get(kind, {}).get('flowid')

    filters = [filt for filt in tc._filters(dev, parent=root_qdisc_handle) if
               flow_id in
               (filt_flow_id(filt, 'basic'), filt_flow_id(filt, 'u32'))]

    # Clear up any previous filters to the class
    for filt in filters:
        try:
            tc.filter.delete(dev, filt['pref'], parent=root_qdisc_handle)
        except tc.TrafficControlException as tce:
            if tce.errCode != errno.EINVAL:  # no filters exist -> EINVAL
                raise

    # Clear the class in case it exists
    try:
        tc.cls.delete(dev, classid=root_qdisc_handle + class_id)
    except tc.TrafficControlException as tce:
        if tce.errCode != errno.ENOENT:
            raise

    _add_hfsc_cls(dev, root_qdisc_handle, class_id, **qos)
    if class_id == _DEFAULT_CLASSID:
        _add_non_vlanned_filter(dev, root_qdisc_handle)
    else:
        _add_vlan_filter(dev, vlan_tag, root_qdisc_handle, class_id)
    _add_fair_qdisc(dev, root_qdisc_handle, class_id)
Example #3
0
 def _analyse_filters(self):
     filters = list(tc._filters(self.device_name))
     untagged_filters = self._untagged_filters(filters)
     tagged_filters = self._tagged_filters(filters)
     return TcFilters(untagged_filters, tagged_filters)
Example #4
0
    def test_filters(self):
        filters = (
            {'protocol': 'all', 'pref': 168, 'kind': 'basic',
             'parent': '1389:', 'basic': {}},
            {'protocol': 'all', 'pref': 168, 'kind': 'basic',
             'parent': '1389:',
             'basic': {'flowid': '1389:a8', 'handle': '0x1',
                       'mask': 0, 'module': 'meta', 'object': 'vlan',
                       'relation': 'eq', 'value': 168}},
            {'protocol': 'all', 'pref': 168, 'kind': 'basic',
             'parent': '1389:',
             'basic': {'flowid': '1389:a8', 'handle': '0x1',
                       'mask': 0, 'module': 'meta', 'object': 'vlan'}},
            {'protocol': 'all', 'pref': 168, 'kind': 'basic',
             'parent': '1389:',
             'basic': {'module': 'meta', 'flowid': '1389:a8',
                       'handle': '0x1'}},
            {'protocol': 'all', 'pref': 49149, 'kind': 'u32', 'u32': {}},
            {'protocol': 'all', 'pref': 49149, 'kind': 'u32', 'u32': {
                'fh': '803:', 'ht_divisor': 1}},
            {'protocol': 'all', 'pref': 49149, 'kind': 'u32', 'u32': {
                'fh': '803::800', 'order': 2048, 'key_ht': 0x803,
                'key_bkt': 0x0, 'terminal': True, 'match': {
                    'value': 0x0, 'mask': 0x0, 'offset': 0x0},
                'actions': [
                    {'order': 1, 'kind': 'mirred', 'action': 'egress_mirror',
                     'target': 'tap1', 'op': 'pipe', 'index': 18, 'ref': 1,
                     'bind': 1}]}},

            {'protocol': 'all', 'pref': 49150, 'kind': 'u32', 'u32': {}},
            {'protocol': 'all', 'pref': 49150, 'kind': 'u32', 'u32': {
                'fh': '802:', 'ht_divisor': 1}},
            {'protocol': 'all', 'pref': 49150, 'kind': 'u32', 'u32': {
                'fh': '802::800', 'order': 2048, 'key_ht': 0x802,
                'key_bkt': 0x0, 'terminal': True, 'match': {
                    'value': 0x0, 'mask': 0x0, 'offset': 0x0},
                'actions': [
                    {'order': 33, 'kind': 'mirred', 'action': 'egress_mirror',
                     'target': 'tap2', 'op': 'pipe', 'index': 17, 'ref': 1,
                     'bind': 1}]}},

            {'protocol': 'all', 'pref': 49152, 'kind': 'u32', 'u32': {}},
            {'protocol': 'all', 'pref': 49152, 'kind': 'u32', 'u32': {
                'fh': '800:', 'ht_divisor': 1}},
            {'protocol': 'all', 'pref': 49152, 'kind': 'u32', 'u32': {
                'fh': '800::800', 'order': 2048, 'key_ht': 0x800,
                'key_bkt': 0x0, 'terminal': True, 'match': {
                    'value': 0x0, 'mask': 0x0, 'offset': 0x0},
                'actions': [
                    {'order': 1, 'kind': 'mirred', 'action': 'egress_mirror',
                     'target': 'target', 'op': 'pipe', 'index': 60, 'ref': 1,
                     'bind': 1},
                    {'order': 2, 'kind': 'mirred', 'action': 'egress_mirror',
                     'target': 'target2', 'op': 'pipe', 'index': 61, 'ref': 1,
                     'bind': 1},
                ]}},
        )
        dirName = os.path.dirname(os.path.realpath(__file__))
        path = os.path.join(dirName, "tc_filter_show.out")
        with open(path) as tc_filter_show:
            data = tc_filter_show.read()

        for parsed, correct in izip_longest(tc._filters(None, out=data),
                                            filters):
            self.assertEqual(parsed, correct)
Example #5
0
 def _analyse_filters(self):
     filters = list(tc._filters(self.device_name))
     untagged_filters = self._untagged_filters(filters)
     tagged_filters = self._tagged_filters(filters)
     return TcFilters(untagged_filters, tagged_filters)
Example #6
0
    def test_filters(self):
        filters = (
            {
                'protocol': 'all',
                'pref': 168,
                'kind': 'basic',
                'parent': '1389:',
                'basic': {}
            },
            {
                'protocol': 'all',
                'pref': 168,
                'kind': 'basic',
                'parent': '1389:',
                'basic': {
                    'flowid': '1389:a8',
                    'handle': '0x1',
                    'mask': 0,
                    'module': 'meta',
                    'object': 'vlan',
                    'relation': 'eq',
                    'value': 168
                }
            },
            {
                'protocol': 'all',
                'pref': 168,
                'kind': 'basic',
                'parent': '1389:',
                'basic': {
                    'flowid': '1389:a8',
                    'handle': '0x1',
                    'mask': 0,
                    'module': 'meta',
                    'object': 'vlan'
                }
            },
            {
                'protocol': 'all',
                'pref': 168,
                'kind': 'basic',
                'parent': '1389:',
                'basic': {
                    'module': 'meta',
                    'flowid': '1389:a8',
                    'handle': '0x1'
                }
            },
            {
                'protocol': 'all',
                'pref': 49149,
                'kind': 'u32',
                'u32': {}
            },
            {
                'protocol': 'all',
                'pref': 49149,
                'kind': 'u32',
                'u32': {
                    'fh': '803:',
                    'ht_divisor': 1
                }
            },
            {
                'protocol': 'all',
                'pref': 49149,
                'kind': 'u32',
                'u32': {
                    'fh':
                    '803::800',
                    'order':
                    2048,
                    'key_ht':
                    0x803,
                    'key_bkt':
                    0x0,
                    'terminal':
                    True,
                    'match': {
                        'value': 0x0,
                        'mask': 0x0,
                        'offset': 0x0
                    },
                    'actions': [{
                        'order': 1,
                        'kind': 'mirred',
                        'action': 'egress_mirror',
                        'target': 'tap1',
                        'op': 'pipe',
                        'index': 18,
                        'ref': 1,
                        'bind': 1
                    }]
                }
            },
            {
                'protocol': 'all',
                'pref': 49150,
                'kind': 'u32',
                'u32': {}
            },
            {
                'protocol': 'all',
                'pref': 49150,
                'kind': 'u32',
                'u32': {
                    'fh': '802:',
                    'ht_divisor': 1
                }
            },
            {
                'protocol': 'all',
                'pref': 49150,
                'kind': 'u32',
                'u32': {
                    'fh':
                    '802::800',
                    'order':
                    2048,
                    'key_ht':
                    0x802,
                    'key_bkt':
                    0x0,
                    'terminal':
                    True,
                    'match': {
                        'value': 0x0,
                        'mask': 0x0,
                        'offset': 0x0
                    },
                    'actions': [{
                        'order': 33,
                        'kind': 'mirred',
                        'action': 'egress_mirror',
                        'target': 'tap2',
                        'op': 'pipe',
                        'index': 17,
                        'ref': 1,
                        'bind': 1
                    }]
                }
            },
            {
                'protocol': 'all',
                'pref': 49152,
                'kind': 'u32',
                'u32': {}
            },
            {
                'protocol': 'all',
                'pref': 49152,
                'kind': 'u32',
                'u32': {
                    'fh': '800:',
                    'ht_divisor': 1
                }
            },
            {
                'protocol': 'all',
                'pref': 49152,
                'kind': 'u32',
                'u32': {
                    'fh':
                    '800::800',
                    'order':
                    2048,
                    'key_ht':
                    0x800,
                    'key_bkt':
                    0x0,
                    'terminal':
                    True,
                    'match': {
                        'value': 0x0,
                        'mask': 0x0,
                        'offset': 0x0
                    },
                    'actions': [
                        {
                            'order': 1,
                            'kind': 'mirred',
                            'action': 'egress_mirror',
                            'target': 'target',
                            'op': 'pipe',
                            'index': 60,
                            'ref': 1,
                            'bind': 1
                        },
                        {
                            'order': 2,
                            'kind': 'mirred',
                            'action': 'egress_mirror',
                            'target': 'target2',
                            'op': 'pipe',
                            'index': 61,
                            'ref': 1,
                            'bind': 1
                        },
                    ]
                }
            },
        )
        dirName = os.path.dirname(os.path.realpath(__file__))
        path = os.path.join(dirName, "tc_filter_show.out")
        with open(path) as tc_filter_show:
            data = tc_filter_show.read()

        for parsed, correct in izip_longest(tc._filters(None, out=data),
                                            filters):
            self.assertEqual(parsed, correct)