Ejemplo n.º 1
0
 def test_add_tc_filter_vxlan(self, mock_add_filter):
     tc_lib.add_tc_filter_vxlan('device',
                                'parent',
                                'classid',
                                '12:34:56:78:90:ab',
                                52,
                                namespace='ns')
     keys = [
         '0x3400/0xffffff00+32', '0x12345678/0xffffffff+42',
         '0x90ab0000/0xffff0000+46'
     ]
     mock_add_filter.assert_called_once_with('device',
                                             'parent',
                                             1,
                                             'classid',
                                             keys,
                                             namespace='ns')
Ejemplo n.º 2
0
    def test_add_tc_filter_vxlan(self):
        # The traffic control is applied on the veth pair device of the first
        # namespace (self.ns[0]). The traffic created from the VXLAN interface
        # when replying to the ping (sent from the other namespace), is
        # encapsulated in a VXLAN frame and goes through the veth pair
        # interface.
        self._create_two_namespaces_connected_using_vxlan()

        tc_lib.add_tc_qdisc(self.device[0],
                            'htb',
                            parent='root',
                            handle='1:',
                            namespace=self.ns[0])
        classes = tc_lib.list_tc_policy_class(self.device[0],
                                              namespace=self.ns[0])
        self.assertEqual(0, len(classes))

        class_ids = []
        for i in range(1, 10):
            class_id = '1:%s' % i
            class_ids.append(class_id)
            tc_lib.add_tc_policy_class(self.device[0],
                                       '1:',
                                       class_id,
                                       namespace=self.ns[0],
                                       min_kbps=1000,
                                       max_kbps=2000,
                                       burst_kb=1600)

        # Add a filter for a randomly chosen created class, in the first
        # namespace veth pair device, with the VXLAN MAC address. The traffic
        # from the VXLAN device must go through this chosen class.
        chosen_class_id = random.choice(class_ids)
        tc_lib.add_tc_filter_vxlan(self.device[0],
                                   '1:',
                                   chosen_class_id,
                                   self.mac_vxlan[0],
                                   self.vxlan_id,
                                   namespace=self.ns[0])

        tc_classes = tc_lib.list_tc_policy_class(self.device[0],
                                                 namespace=self.ns[0])
        for tc_class in (c for c in tc_classes
                         if c['classid'] == chosen_class_id):
            bytes = tc_class['stats']['bytes']
            packets = tc_class['stats']['packets']
            break
        else:
            self.fail('TC class %(class_id)s is not present in the device '
                      '%(device)s' % {
                          'class_id': chosen_class_id,
                          'device': self.device[0]
                      })

        net_helpers.assert_ping(self.ns[1],
                                str(netaddr.IPNetwork(self.ip_vxlan[0]).ip),
                                count=1)
        tc_classes = tc_lib.list_tc_policy_class(self.device[0],
                                                 namespace=self.ns[0])
        for tc_class in tc_classes:
            if tc_class['classid'] == chosen_class_id:
                self.assertGreater(tc_class['stats']['bytes'], bytes)
                self.assertGreater(tc_class['stats']['packets'], packets)
            else:
                self.assertEqual(0, tc_class['stats']['bytes'])
                self.assertEqual(0, tc_class['stats']['packets'])