Esempio n. 1
0
    def test_add_tc_qdisc_tbf(self):
        burst = 192000
        rate = 320000
        latency = 50000
        priv_tc_lib.add_tc_qdisc(self.device,
                                 parent=rtnl.TC_H_ROOT,
                                 kind='tbf',
                                 burst=burst,
                                 rate=rate,
                                 latency=latency,
                                 namespace=self.namespace)
        qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                            namespace=self.namespace)
        self.assertEqual(1, len(qdiscs))
        self.assertEqual(rtnl.TC_H_ROOT, qdiscs[0]['parent'])
        self.assertEqual('tbf', tc_lib._get_attr(qdiscs[0], 'TCA_KIND'))
        tca_options = tc_lib._get_attr(qdiscs[0], 'TCA_OPTIONS')
        tca_tbf_parms = tc_lib._get_attr(tca_options, 'TCA_TBF_PARMS')
        self.assertEqual(rate, tca_tbf_parms['rate'])
        self.assertEqual(
            burst,
            tc_lib._calc_burst(tca_tbf_parms['rate'], tca_tbf_parms['buffer']))
        self.assertEqual(
            latency,
            tc_lib._calc_latency_ms(tca_tbf_parms['limit'], burst,
                                    tca_tbf_parms['rate']) * 1000)

        priv_tc_lib.delete_tc_qdisc(self.device,
                                    parent=rtnl.TC_H_ROOT,
                                    namespace=self.namespace)
        qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                            namespace=self.namespace)
        self.assertEqual(0, len(qdiscs))
Esempio n. 2
0
    def test_add_tc_qdisc_tbf(self):
        burst = 192000
        rate = 320000
        latency = 50000
        priv_tc_lib.add_tc_qdisc(
            self.device, parent=rtnl.TC_H_ROOT, kind='tbf', burst=burst,
            rate=rate, latency=latency, namespace=self.namespace)
        qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                            namespace=self.namespace)
        self.assertEqual(1, len(qdiscs))
        self.assertEqual(rtnl.TC_H_ROOT, qdiscs[0]['parent'])
        self.assertEqual('tbf', tc_lib._get_attr(qdiscs[0], 'TCA_KIND'))
        tca_options = tc_lib._get_attr(qdiscs[0], 'TCA_OPTIONS')
        tca_tbf_parms = tc_lib._get_attr(tca_options, 'TCA_TBF_PARMS')
        self.assertEqual(rate, tca_tbf_parms['rate'])
        self.assertEqual(burst, tc_lib._calc_burst(tca_tbf_parms['rate'],
                                                   tca_tbf_parms['buffer']))
        self.assertEqual(latency, tc_lib._calc_latency_ms(
            tca_tbf_parms['limit'], burst, tca_tbf_parms['rate']) * 1000)

        priv_tc_lib.delete_tc_qdisc(self.device, parent=rtnl.TC_H_ROOT,
                                    namespace=self.namespace)
        qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                            namespace=self.namespace)
        self.assertEqual(0, len(qdiscs))
Esempio n. 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)
Esempio n. 4
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)
Esempio n. 5
0
    def test_add_tc_qdisc_ingress(self):
        priv_tc_lib.add_tc_qdisc(self.device, kind='ingress',
                                 namespace=self.namespace)
        qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                            namespace=self.namespace)
        self.assertEqual(1, len(qdiscs))
        self.assertEqual('ingress', tc_lib._get_attr(qdiscs[0], 'TCA_KIND'))
        self.assertEqual(rtnl.TC_H_INGRESS, qdiscs[0]['parent'])
        self.assertEqual(0xffff0000, qdiscs[0]['handle'])

        priv_tc_lib.delete_tc_qdisc(self.device, kind='ingress',
                                    namespace=self.namespace)
        qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                            namespace=self.namespace)
        self.assertEqual(0, len(qdiscs))
Esempio n. 6
0
    def test_add_tc_qdisc_ingress(self):
        priv_tc_lib.add_tc_qdisc(self.device, kind='ingress',
                                 namespace=self.namespace)
        qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                            namespace=self.namespace)
        self.assertEqual(1, len(qdiscs))
        self.assertEqual('ingress', tc_lib._get_attr(qdiscs[0], 'TCA_KIND'))
        self.assertEqual(rtnl.TC_H_INGRESS, qdiscs[0]['parent'])
        self.assertEqual(0xffff0000, qdiscs[0]['handle'])

        priv_tc_lib.delete_tc_qdisc(self.device, kind='ingress',
                                    namespace=self.namespace)
        qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                            namespace=self.namespace)
        self.assertEqual(0, len(qdiscs))
Esempio n. 7
0
    def test_add_tc_qdisc_htb_no_handle(self):
        priv_tc_lib.add_tc_qdisc(
            self.device, parent=rtnl.TC_H_ROOT, kind='htb',
            namespace=self.namespace)
        qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                            namespace=self.namespace)
        self.assertEqual(1, len(qdiscs))
        self.assertEqual(rtnl.TC_H_ROOT, qdiscs[0]['parent'])
        self.assertEqual(0, qdiscs[0]['handle'] & 0xFFFF)
        self.assertEqual('htb', tc_lib._get_attr(qdiscs[0], 'TCA_KIND'))

        priv_tc_lib.delete_tc_qdisc(self.device, parent=rtnl.TC_H_ROOT,
                                    namespace=self.namespace)
        qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                            namespace=self.namespace)
        self.assertEqual(0, len(qdiscs))
Esempio n. 8
0
    def test_add_tc_qdisc_htb_no_handle(self):
        priv_tc_lib.add_tc_qdisc(
            self.device, parent=rtnl.TC_H_ROOT, kind='htb',
            namespace=self.namespace)
        qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                            namespace=self.namespace)
        self.assertEqual(1, len(qdiscs))
        self.assertEqual(rtnl.TC_H_ROOT, qdiscs[0]['parent'])
        self.assertEqual(0, qdiscs[0]['handle'] & 0xFFFF)
        self.assertEqual('htb', tc_lib._get_attr(qdiscs[0], 'TCA_KIND'))

        priv_tc_lib.delete_tc_qdisc(self.device, parent=rtnl.TC_H_ROOT,
                                    namespace=self.namespace)
        qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                            namespace=self.namespace)
        self.assertEqual(0, len(qdiscs))
Esempio n. 9
0
 def test_delete_tc_qdisc_ingress_twice(self):
     priv_tc_lib.add_tc_qdisc(self.device, kind='ingress',
                              namespace=self.namespace)
     qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                         namespace=self.namespace)
     self.assertEqual(1, len(qdiscs))
     self.assertEqual('ingress', tc_lib._get_attr(qdiscs[0], 'TCA_KIND'))
     self.assertIsNone(
         priv_tc_lib.delete_tc_qdisc(self.device, kind='ingress',
                                     namespace=self.namespace))
     qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                         namespace=self.namespace)
     self.assertEqual(0, len(qdiscs))
     self.assertEqual(
         errno.EINVAL,
         priv_tc_lib.delete_tc_qdisc(self.device, kind='ingress',
                                     namespace=self.namespace,
                                     raise_qdisc_not_found=False))
Esempio n. 10
0
 def test_delete_tc_qdisc_ingress_twice(self):
     priv_tc_lib.add_tc_qdisc(self.device, kind='ingress',
                              namespace=self.namespace)
     qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                         namespace=self.namespace)
     self.assertEqual(1, len(qdiscs))
     self.assertEqual('ingress', tc_lib._get_attr(qdiscs[0], 'TCA_KIND'))
     self.assertIsNone(
         priv_tc_lib.delete_tc_qdisc(self.device, kind='ingress',
                                     namespace=self.namespace))
     qdiscs = priv_tc_lib.list_tc_qdiscs(self.device,
                                         namespace=self.namespace)
     self.assertEqual(0, len(qdiscs))
     self.assertEqual(
         errno.EINVAL,
         priv_tc_lib.delete_tc_qdisc(self.device, kind='ingress',
                                     namespace=self.namespace,
                                     raise_qdisc_not_found=False))