Beispiel #1
0
def _report_network_qos(caps):
    """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 caps['networks'].iteritems():
        iface = attrs['iface']
        if iface in caps['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 caps['vlans']:
            vlan_id = caps['vlans'][iface]['vlanid']
            iface = caps['vlans'][iface]['iface']
            iface_qdiscs = qdiscs.get(iface)
            if iface_qdiscs is None:
                continue
            class_id = (qos._root_qdisc(iface_qdiscs)['handle'] + '%x' %
                        vlan_id)
        else:
            iface_qdiscs = qdiscs.get(iface)
            if iface_qdiscs is None:
                continue
            class_id = (qos._root_qdisc(iface_qdiscs)['handle'] +
                        qos._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']}
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
0
def _report_network_qos(caps):
    """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 caps['networks'].iteritems():
        iface = attrs['iface']
        if iface in caps['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 caps['vlans']:
            vlan_id = caps['vlans'][iface]['vlanid']
            iface = caps['vlans'][iface]['iface']
            iface_qdiscs = qdiscs.get(iface)
            if iface_qdiscs is None:
                continue
            class_id = (qos._root_qdisc(iface_qdiscs)['handle'] +
                        '%x' % vlan_id)
        else:
            iface_qdiscs = qdiscs.get(iface)
            if iface_qdiscs is None:
                continue
            class_id = (qos._root_qdisc(iface_qdiscs)['handle'] +
                        qos._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']}