Example #1
0
    def test_delete_tc_policy_class_htb(self):
        priv_tc_lib.add_tc_qdisc(self.device,
                                 parent=rtnl.TC_H_ROOT,
                                 kind='htb',
                                 handle='1:',
                                 namespace=self.namespace)
        for classid, rates in self.CLASSES.items():
            priv_tc_lib.add_tc_policy_class(self.device,
                                            '1:',
                                            classid,
                                            'htb',
                                            namespace=self.namespace,
                                            **rates)

        tc_classes = priv_tc_lib.list_tc_policy_classes(
            self.device, namespace=self.namespace)
        self.assertEqual(len(self.CLASSES), len(tc_classes))

        for classid in self.CLASSES:
            priv_tc_lib.delete_tc_policy_class(self.device,
                                               '1:',
                                               classid,
                                               namespace=self.namespace)
            tc_classes = priv_tc_lib.list_tc_policy_classes(
                self.device, namespace=self.namespace)
            for tc_class in tc_classes:
                handle = tc_lib._handle_from_hex_to_string(tc_class['handle'])
                self.assertIsNot(classid, handle)

        tc_classes = priv_tc_lib.list_tc_policy_classes(
            self.device, namespace=self.namespace)
        self.assertEqual(0, len(tc_classes))
Example #2
0
    def test_delete_tc_policy_class_htb(self):
        priv_tc_lib.add_tc_qdisc(
            self.device, parent=rtnl.TC_H_ROOT, kind='htb', handle='1:',
            namespace=self.namespace)
        for classid, rates in self.CLASSES.items():
            priv_tc_lib.add_tc_policy_class(
                self.device, '1:', classid, 'htb', namespace=self.namespace,
                **rates)

        tc_classes = priv_tc_lib.list_tc_policy_classes(
            self.device, namespace=self.namespace)
        self.assertEqual(len(self.CLASSES), len(tc_classes))

        for classid in self.CLASSES:
            priv_tc_lib.delete_tc_policy_class(
                self.device, '1:', classid, namespace=self.namespace)
            tc_classes = priv_tc_lib.list_tc_policy_classes(
                self.device, namespace=self.namespace)
            for tc_class in tc_classes:
                handle = tc_lib._handle_from_hex_to_string(tc_class['handle'])
                self.assertIsNot(classid, handle)

        tc_classes = priv_tc_lib.list_tc_policy_classes(
            self.device, namespace=self.namespace)
        self.assertEqual(0, len(tc_classes))
Example #3
0
    def test_add_tc_policy_class_htb(self):
        priv_tc_lib.add_tc_qdisc(self.device,
                                 parent=rtnl.TC_H_ROOT,
                                 kind='htb',
                                 handle='1:',
                                 namespace=self.namespace)
        for classid, rates in self.CLASSES.items():
            priv_tc_lib.add_tc_policy_class(self.device,
                                            '1:',
                                            classid,
                                            'htb',
                                            namespace=self.namespace,
                                            **rates)

        tc_classes = priv_tc_lib.list_tc_policy_classes(
            self.device, namespace=self.namespace)
        self.assertEqual(len(self.CLASSES), len(tc_classes))
        for tc_class in tc_classes:
            handle = tc_lib._handle_from_hex_to_string(tc_class['handle'])
            tca_options = tc_lib._get_attr(tc_class, 'TCA_OPTIONS')
            tca_htb_params = tc_lib._get_attr(tca_options, 'TCA_HTB_PARMS')
            self.assertEqual(self.CLASSES[handle]['rate'],
                             tca_htb_params['rate'])
            self.assertEqual(self.CLASSES[handle]['ceil'],
                             tca_htb_params['ceil'])
            burst = tc_lib._calc_burst(self.CLASSES[handle]['rate'],
                                       tca_htb_params['buffer'])
            self.assertEqual(self.CLASSES[handle]['burst'], burst)
Example #4
0
def list_tc_policy_class(device, namespace=None):
    LOG.info('%s(): caller(): %s', log_utils.get_fname(1),
             log_utils.get_fname(2))
    """List all TC policy classes of a device

    :param device: (string) device name
    :param namespace: (string) (optional) namespace name
    :return: (list) TC policy classes
    """
    def get_params(tca_options, qdisc_type):
        LOG.info('%s(): caller(): %s', log_utils.get_fname(1),
                 log_utils.get_fname(2))
        if qdisc_type not in TC_QDISC_TYPES:
            return None, None, None

        tca_params = _get_attr(tca_options,
                               'TCA_' + qdisc_type.upper() + '_PARMS')
        burst_kb = int(
            _calc_burst(tca_params['rate'], tca_params['buffer']) * 8 / 1024)
        max_kbps = int(tca_params['ceil'] * 8 / 1024)
        min_kbps = int(tca_params['rate'] * 8 / 1024)
        return max_kbps, min_kbps, burst_kb

    tc_classes = priv_tc_lib.list_tc_policy_classes(device,
                                                    namespace=namespace)
    classes = []
    for tc_class in tc_classes:
        index = tc_class['index']
        parent = TC_QDISC_PARENT_NAME.get(
            tc_class['parent'], _handle_from_hex_to_string(tc_class['parent']))
        classid = _handle_from_hex_to_string(tc_class['handle'])
        qdisc_type = _get_attr(tc_class, 'TCA_KIND')
        tca_options = _get_attr(tc_class, 'TCA_OPTIONS')
        max_kbps, min_kbps, burst_kb = get_params(tca_options, qdisc_type)
        tc_class_data = {
            'device': device,
            'index': index,
            'namespace': namespace,
            'parent': parent,
            'classid': classid,
            'qdisc_type': qdisc_type,
            'min_kbps': min_kbps,
            'max_kbps': max_kbps,
            'burst_kb': burst_kb
        }
        tca_stats = _get_attr(tc_class, 'TCA_STATS')
        if tca_stats:
            tc_class_data['stats'] = tca_stats
        classes.append(tc_class_data)

    return classes
Example #5
0
def list_tc_policy_class(device, namespace=None):
    """List all TC policy classes of a device

    :param device: (string) device name
    :param namespace: (string) (optional) namespace name
    :return: (list) TC policy classes
    """
    def get_params(tca_options, qdisc_type):
        if qdisc_type not in TC_QDISC_TYPES:
            return None, None, None

        tca_params = _get_attr(tca_options,
                               'TCA_' + qdisc_type.upper() + '_PARMS')
        burst_kb = int(
            _calc_burst(tca_params['rate'], tca_params['buffer']) * 8 / 1024)
        max_kbps = int(tca_params['ceil'] * 8 / 1024)
        min_kbps = int(tca_params['rate'] * 8 / 1024)
        return max_kbps, min_kbps, burst_kb

    tc_classes = priv_tc_lib.list_tc_policy_classes(device,
                                                    namespace=namespace)
    classes = []
    for tc_class in tc_classes:
        index = tc_class['index']
        parent = TC_QDISC_PARENT_NAME.get(
            tc_class['parent'], _handle_from_hex_to_string(tc_class['parent']))
        classid = _handle_from_hex_to_string(tc_class['handle'])
        qdisc_type = _get_attr(tc_class, 'TCA_KIND')
        tca_options = _get_attr(tc_class, 'TCA_OPTIONS')
        max_kbps, min_kbps, burst_kb = get_params(tca_options, qdisc_type)
        classes.append({'device': device,
                        'index': index,
                        'namespace': namespace,
                        'parent': parent,
                        'classid': classid,
                        'qdisc_type': qdisc_type,
                        'min_kbps': min_kbps,
                        'max_kbps': max_kbps,
                        'burst_kb': burst_kb})

    return classes
Example #6
0
    def test_add_tc_policy_class_htb(self):
        priv_tc_lib.add_tc_qdisc(
            self.device, parent=rtnl.TC_H_ROOT, kind='htb', handle='1:',
            namespace=self.namespace)
        for classid, rates in self.CLASSES.items():
            priv_tc_lib.add_tc_policy_class(
                self.device, '1:', classid, 'htb', namespace=self.namespace,
                **rates)

        tc_classes = priv_tc_lib.list_tc_policy_classes(
            self.device, namespace=self.namespace)
        self.assertEqual(len(self.CLASSES), len(tc_classes))
        for tc_class in tc_classes:
            handle = tc_lib._handle_from_hex_to_string(tc_class['handle'])
            tca_options = tc_lib._get_attr(tc_class, 'TCA_OPTIONS')
            tca_htb_params = tc_lib._get_attr(tca_options, 'TCA_HTB_PARMS')
            self.assertEqual(self.CLASSES[handle]['rate'],
                             tca_htb_params['rate'])
            self.assertEqual(self.CLASSES[handle]['ceil'],
                             tca_htb_params['ceil'])
            burst = tc_lib._calc_burst(self.CLASSES[handle]['rate'],
                                       tca_htb_params['buffer'])
            self.assertEqual(self.CLASSES[handle]['burst'], burst)