Ejemplo n.º 1
0
 def test_get_root_qdisc(self):
     root = {
         'kind': 'hfsc',
         'root': True,
         'handle': '1:',
         'refcnt': 2,
         'hfsc': {
             'default': 0x5000
         }
     }
     qdiscs = (root, {
         'kind': 'sfq',
         'handle': '10:',
         'parent': '1:10',
         'sfq': {
             'limit': 127,
             'quantum': 1514
         }
     }, {
         'kind': 'sfq',
         'handle': '20:',
         'parent': '1:20',
         'sfq': {
             'limit': 127,
             'quantum': 1514
         }
     })
     assert qos.get_root_qdisc(qdiscs) == root
Ejemplo n.º 2
0
def remove_outbound(device, vlan_tag):
    """Removes the qosOutbound configuration from the device and restores
    pfifo_fast if it was the last QoSed network on the device. vlan_tag
    can be None"""
    class_id = '%x' % (_NON_VLANNED_ID if vlan_tag is None else vlan_tag)
    MISSING_OBJ_ERR_CODES = (errno.EINVAL, errno.ENOENT, errno.EOPNOTSUPP)

    try:
        tc.filter.delete(
            device, pref=_NON_VLANNED_ID if vlan_tag is None else vlan_tag)
    except tc.TrafficControlException as tce:
        if tce.errCode not in MISSING_OBJ_ERR_CODES:  # No filter exists
            raise

    device_qdiscs = list(tc.qdiscs(device))
    if not device_qdiscs:
        return
    root_qdisc_handle = netinfo_qos.get_root_qdisc(device_qdiscs)['handle']
    try:
        tc.cls.delete(device, classid=root_qdisc_handle + class_id)
    except tc.TrafficControlException as tce:
        if tce.errCode not in MISSING_OBJ_ERR_CODES:  # No class exists
            raise

    if not _uses_classes(device, root_qdisc_handle=root_qdisc_handle):
        try:
            tc._qdisc_del(device)
            tc._qdisc_del(device, kind='ingress')
        except tc.TrafficControlException as tce:
            if tce.errCode not in MISSING_OBJ_ERR_CODES:  # No qdisc
                raise
Ejemplo n.º 3
0
def remove_outbound(device, vlan_tag, net_info):
    """Removes the qosOutbound configuration from the device and restores
    pfifo_fast if it was the last QoSed network on the device. vlan_tag
    can be None"""
    class_id = '%x' % (_NON_VLANNED_ID if vlan_tag is None else vlan_tag)
    MISSING_OBJ_ERR_CODES = (errno.EINVAL, errno.ENOENT, errno.EOPNOTSUPP)

    try:
        tc.filter.delete(
            device, pref=_NON_VLANNED_ID if vlan_tag is None else vlan_tag)
    except tc.TrafficControlException as tce:
        if tce.errCode not in MISSING_OBJ_ERR_CODES:  # No filter exists
            raise

    device_qdiscs = list(tc.qdiscs(device))
    if not device_qdiscs:
        return
    root_qdisc_handle = netinfo_qos.get_root_qdisc(device_qdiscs)['handle']
    try:
        tc.cls.delete(device, classid=root_qdisc_handle + class_id)
    except tc.TrafficControlException as tce:
        if tce.errCode not in MISSING_OBJ_ERR_CODES:  # No class exists
            raise

    if not _uses_classes(device, net_info,
                         root_qdisc_handle=root_qdisc_handle):
        try:
            tc._qdisc_del(device)
            tc._qdisc_del(device, kind='ingress')
        except tc.TrafficControlException as tce:
            if tce.errCode not in MISSING_OBJ_ERR_CODES:  # No qdisc
                raise
Ejemplo n.º 4
0
 def test_get_root_qdisc(self):
     root = {
         'kind': 'hfsc',
         'root': True,
         'handle': '1:',
         'refcnt': 2,
         'hfsc': {
             'default': 0x5000
         },
     }
     qdiscs = (
         root,
         {
             'kind': 'hfsc',
             'handle': '1:10',
             'parent': '1:',
             'leaf': '10:',
             'hfsc': {
                 'default': 0x8002
             },
         },
         {
             'kind': 'hfsc',
             'handle': '1:20',
             'parent': '1:',
             'leaf': '20:',
             'hfsc': {
                 'default': 0x8002
             },
         },
     )
     assert qos.get_root_qdisc(qdiscs) == root
Ejemplo n.º 5
0
 def test_get_root_qdisc(self):
     root = {"kind": "hfsc", "root": True, "handle": "1:", "refcnt": 2, "hfsc": {"default": 0x5000}}
     inp = (
         root,
         {"kind": "sfq", "handle": "10:", "parent": "1:10", "sfq": {"limit": 127, "quantum": 1514}},
         {"kind": "sfq", "handle": "20:", "parent": "1:20", "sfq": {"limit": 127, "quantum": 1514}},
     )
     self.assertEqual(qos.get_root_qdisc(inp), root)
Ejemplo n.º 6
0
 def test_get_root_qdisc(self):
     root = {'kind': 'hfsc', 'root': True, 'handle': '1:', 'refcnt': 2,
             'hfsc': {'default': 0x5000}}
     inp = (root,
            {'kind': 'sfq', 'handle': '10:', 'parent': '1:10',
             'sfq': {'limit': 127, 'quantum': 1514}},
            {'kind': 'sfq', 'handle': '20:', 'parent': '1:20',
             'sfq': {'limit': 127, 'quantum': 1514}})
     self.assertEqual(qos.get_root_qdisc(inp), root)
Ejemplo n.º 7
0
def configure_outbound(qosOutbound, device, vlan_tag):
    """Adds the qosOutbound configuration to the backing device (be it bond
    or nic). Adds a class and filter for default traffic if necessary. vlan_tag
    can be None"""
    root_qdisc = netinfo_qos.get_root_qdisc(tc.qdiscs(device))
    class_id = '%x' % (_NON_VLANNED_ID if vlan_tag is None else vlan_tag)
    if not root_qdisc or root_qdisc['kind'] != _SHAPING_QDISC_KIND:
        _fresh_qdisc_conf_out(device, vlan_tag, class_id, qosOutbound)
    else:
        _qdisc_conf_out(device, root_qdisc['handle'], vlan_tag, class_id,
                        qosOutbound)
Ejemplo n.º 8
0
Archivo: qos.py Proyecto: rexhsu/vdsm
def _uses_classes(device, root_qdisc_handle=None):
    """Returns true iff there's traffic classes in the device, ignoring the
    root class and a default unused class"""
    if root_qdisc_handle is None:
        root_qdisc = netinfo_qos.get_root_qdisc(tc.qdiscs(device))
        root_qdisc_handle = root_qdisc['handle']
    classes = [cls for cls in tc.classes(device, parent=root_qdisc_handle) if
               not cls.get('root')]
    return (classes and
            not(len(classes) == 1 and not ifaceUsed(device) and
                classes[0]['handle'] == root_qdisc_handle + _DEFAULT_CLASSID))
Ejemplo n.º 9
0
def _uses_classes(device, root_qdisc_handle=None):
    """Returns true iff there's traffic classes in the device, ignoring the
    root class and a default unused class"""
    if root_qdisc_handle is None:
        root_qdisc = netinfo_qos.get_root_qdisc(tc.qdiscs(device))
        root_qdisc_handle = root_qdisc['handle']
    classes = [cls for cls in tc.classes(device, parent=root_qdisc_handle) if
               not cls.get('root')]
    return (classes and
            not(len(classes) == 1 and not ifaceUsed(device) and
                classes[0]['handle'] == root_qdisc_handle + _DEFAULT_CLASSID))
Ejemplo n.º 10
0
def configure_outbound(qosOutbound, device, vlan_tag):
    """Adds the qosOutbound configuration to the backing device (be it bond
    or nic). Adds a class and filter for default traffic if necessary. vlan_tag
    can be None"""
    root_qdisc = netinfo_qos.get_root_qdisc(tc.qdiscs(device))
    class_id = '%x' % (_NON_VLANNED_ID if vlan_tag is None else vlan_tag)
    if not root_qdisc or root_qdisc['kind'] != _SHAPING_QDISC_KIND:
        _fresh_qdisc_conf_out(device, vlan_tag, class_id, qosOutbound)
    else:
        _qdisc_conf_out(device, root_qdisc['handle'], vlan_tag, class_id,
                        qosOutbound)