Example #1
0
File: qos.py Project: kanalun/vdsm
def report_network_qos(netinfo):
    """Augment netinfo information with QoS data for the engine"""
    qdiscs = defaultdict(list)
    for qdisc in tc.qdiscs(dev=None):  # None -> all dev qdiscs
        qdiscs[qdisc['dev']].append(qdisc)
    for net, attrs in netinfo['networks'].iteritems():
        iface = attrs['iface']
        if iface in netinfo['bridges']:
            host_ports = [port for port in attrs['ports'] if
                          not port.startswith('vnet')]
            if not host_ports:  # Port-less bridge
                continue
            iface, = host_ports
        if iface in netinfo['vlans']:
            vlan_id = netinfo['vlans'][iface]['vlanid']
            iface = netinfo['vlans'][iface]['iface']
            iface_qdiscs = qdiscs.get(iface)
            if iface_qdiscs is None:
                continue
            class_id = (get_root_qdisc(iface_qdiscs)['handle'] + '%x' %
                        vlan_id)
        else:
            iface_qdiscs = qdiscs.get(iface)
            if iface_qdiscs is None:
                continue
            class_id = (get_root_qdisc(iface_qdiscs)['handle'] +
                        DEFAULT_CLASSID)

        # Now that iface is either a bond or a nic, let's get the QoS info
        classes = [cls for cls in tc.classes(iface, classid=class_id) if
                   cls['kind'] == 'hfsc']
        if classes:
            cls, = classes
            attrs['hostQos'] = {'out': cls['hfsc']}
Example #2
0
File: qos.py Project: fancyKai/vdsm
def report_network_qos(netinfo):
    """Augment netinfo information with QoS data for the engine"""
    qdiscs = defaultdict(list)
    for qdisc in tc.qdiscs(dev=None):  # None -> all dev qdiscs
        qdiscs[qdisc['dev']].append(qdisc)
    for net, attrs in netinfo['networks'].iteritems():
        iface = attrs['iface']
        if iface in netinfo['bridges']:
            host_ports = [port for port in attrs['ports'] if
                          not port.startswith('vnet')]
            if not host_ports:  # Port-less bridge
                continue
            iface, = host_ports
        if iface in netinfo['vlans']:
            vlan_id = netinfo['vlans'][iface]['vlanid']
            iface = netinfo['vlans'][iface]['iface']
            iface_qdiscs = qdiscs.get(iface)
            if iface_qdiscs is None:
                continue
            class_id = (get_root_qdisc(iface_qdiscs)['handle'] + '%x' %
                        vlan_id)
        else:
            iface_qdiscs = qdiscs.get(iface)
            if iface_qdiscs is None:
                continue
            class_id = (get_root_qdisc(iface_qdiscs)['handle'] +
                        DEFAULT_CLASSID)

        # Now that iface is either a bond or a nic, let's get the QoS info
        classes = [cls for cls in tc.classes(iface, classid=class_id) if
                   cls['kind'] == 'hfsc']
        if classes:
            cls, = classes
            attrs['hostQos'] = {'out': cls['hfsc']}
Example #3
0
 def _analyse_classes(self):
     all_classes = list(tc.classes(self.device_name))
     root_class = self._root_class(all_classes)
     default_class = self._default_class(all_classes)
     all_classes.remove(root_class)
     all_classes.remove(default_class)
     return TcClasses(all_classes, default_class, root_class)
Example #4
0
 def _analyse_classes(self):
     all_classes = list(tc.classes(self.device_name))
     root_class = self._root_class(all_classes)
     default_class = self._default_class(all_classes)
     all_classes.remove(root_class)
     all_classes.remove(default_class)
     return TcClasses(all_classes, default_class, root_class)
Example #5
0
File: qos.py Project: fancyKai/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))
Example #6
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))
Example #7
0
 def test_classes(self):
     cmd_line_ls_10 = 3200
     cmd_line_ls_m1_20 = 6400
     cmd_line_ls_d_20 = 152
     cmd_line_ls_m2_20 = 3200
     cmd_line_ls_30 = 3500
     cmd_line_ls_m2_5000 = 40000
     data = '\n'.join((
         'class hfsc 1: root',
         'class hfsc 1:10 parent 1: leaf 10: sc m1 0bit d 0us '
         'm2 {0}Kbit'.format(cmd_line_ls_10),  # end of previous line
         'class hfsc 1:20 parent 1: leaf 20: ls m1 {0}Kibit d {1}us '
         'm2 {2}Kbit ul m1 0bit d 0us m2 30000Kbit'.format(
             cmd_line_ls_m1_20, cmd_line_ls_d_20, cmd_line_ls_m2_20),
         'class hfsc 1:30 parent 1: leaf 40: sc m1 0bit d 0us '
         'm2 {0}bit'.format(cmd_line_ls_30),  # end of previous line
         'class hfsc 1:5000 parent 1: leaf 5000: ls m1 0bit d 0us '
         'm2 {0}Kbit'.format(cmd_line_ls_m2_5000),  # end of previous line
     ))
     reported_ls_10 = cmd_line_ls_10 * 1000 / 8
     reported_ls_m1_20 = cmd_line_ls_m1_20 * 1024 / 8
     reported_ls_d_20 = cmd_line_ls_d_20 / 8
     reported_ls_m2_20 = cmd_line_ls_m2_20 * 1000 / 8
     reported_ls_30 = cmd_line_ls_30 / 8
     reported_ls_5000 = cmd_line_ls_m2_5000 * 1000 / 8
     classes = (
         {'kind': 'hfsc', 'root': True, 'handle': '1:'},
         {'kind': 'hfsc', 'handle': '1:10', 'parent': '1:', 'leaf': '10:',
          'hfsc': {'ls': {'m1': 0, 'd': 0, 'm2': reported_ls_10},
                   'rt': {'m1': 0, 'd': 0, 'm2': reported_ls_10}}},
         {'kind': 'hfsc', 'handle': '1:20', 'parent': '1:', 'leaf': '20:',
          'hfsc': {'ls': {'m1': reported_ls_m1_20, 'd': reported_ls_d_20,
                          'm2': reported_ls_m2_20},
                   'ul': {'m1': 0, 'd': 0, 'm2': 30000 * 1000}}},
         {'kind': 'hfsc', 'handle': '1:30', 'parent': '1:', 'leaf': '40:',
          'hfsc': {'ls': {'m1': 0, 'd': 0, 'm2': reported_ls_30},
                   'rt': {'m1': 0, 'd': 0, 'm2': reported_ls_30}}},
         {'kind': 'hfsc', 'handle': '1:5000', 'parent': '1:',
          'leaf': '5000:', 'hfsc': {'ls': {'m1': 0, 'd': 0,
                                           'm2': reported_ls_5000}}},
     )
     for parsed, correct in izip_longest(tc.classes(None, out=data),
                                         classes):
         self.assertEqual(parsed, correct)
Example #8
0
 def test_classes(self):
     cmd_line_ls_10 = 3200
     cmd_line_ls_m1_20 = 6400
     cmd_line_ls_d_20 = 152
     cmd_line_ls_m2_20 = 3200
     cmd_line_ls_30 = 3500
     cmd_line_ls_m2_5000 = 40000
     data = '\n'.join((
         'class hfsc 1: root',
         'class hfsc 1:10 parent 1: leaf 10: sc m1 0bit d 0us '
         'm2 {0}Kbit'.format(cmd_line_ls_10),  # end of previous line
         'class hfsc 1:20 parent 1: leaf 20: ls m1 {0}Kibit d {1}us '
         'm2 {2}Kbit ul m1 0bit d 0us m2 30000Kbit'.format(
             cmd_line_ls_m1_20, cmd_line_ls_d_20, cmd_line_ls_m2_20),
         'class hfsc 1:30 parent 1: leaf 40: sc m1 0bit d 0us '
         'm2 {0}bit'.format(cmd_line_ls_30),  # end of previous line
         'class hfsc 1:5000 parent 1: leaf 5000: ls m1 0bit d 0us '
         'm2 {0}Kbit'.format(cmd_line_ls_m2_5000),  # end of previous line
     ))
     reported_ls_10 = cmd_line_ls_10 * 1000 / 8
     reported_ls_m1_20 = cmd_line_ls_m1_20 * 1024 / 8
     reported_ls_d_20 = cmd_line_ls_d_20 / 8
     reported_ls_m2_20 = cmd_line_ls_m2_20 * 1000 / 8
     reported_ls_30 = cmd_line_ls_30 / 8
     reported_ls_5000 = cmd_line_ls_m2_5000 * 1000 / 8
     classes = (
         {
             'kind': 'hfsc',
             'root': True,
             'handle': '1:'
         },
         {
             'kind': 'hfsc',
             'handle': '1:10',
             'parent': '1:',
             'leaf': '10:',
             'hfsc': {
                 'ls': {
                     'm1': 0,
                     'd': 0,
                     'm2': reported_ls_10
                 },
                 'rt': {
                     'm1': 0,
                     'd': 0,
                     'm2': reported_ls_10
                 }
             }
         },
         {
             'kind': 'hfsc',
             'handle': '1:20',
             'parent': '1:',
             'leaf': '20:',
             'hfsc': {
                 'ls': {
                     'm1': reported_ls_m1_20,
                     'd': reported_ls_d_20,
                     'm2': reported_ls_m2_20
                 },
                 'ul': {
                     'm1': 0,
                     'd': 0,
                     'm2': 30000 * 1000
                 }
             }
         },
         {
             'kind': 'hfsc',
             'handle': '1:30',
             'parent': '1:',
             'leaf': '40:',
             'hfsc': {
                 'ls': {
                     'm1': 0,
                     'd': 0,
                     'm2': reported_ls_30
                 },
                 'rt': {
                     'm1': 0,
                     'd': 0,
                     'm2': reported_ls_30
                 }
             }
         },
         {
             'kind': 'hfsc',
             'handle': '1:5000',
             'parent': '1:',
             'leaf': '5000:',
             'hfsc': {
                 'ls': {
                     'm1': 0,
                     'd': 0,
                     'm2': reported_ls_5000
                 }
             }
         },
     )
     for parsed, correct in izip_longest(tc.classes(None, out=data),
                                         classes):
         self.assertEqual(parsed, correct)