Exemplo n.º 1
0
def add_tc_filter_match_mac(device,
                            parent,
                            classid,
                            mac,
                            offset=0,
                            priority=0,
                            protocol=None,
                            namespace=None):
    """Add a TC filter in a device to match a MAC address.

    :param device: (string) device name
    :param parent: (string) qdisc parent class ('root', 'ingress', '2:10')
    :param classid: (string) major:minor handler identifier ('10:20')
    :param mac: (string) MAC address to match
    :param offset: (int) (optional) match offset, starting from the outer
                   packet IP header
    :param priority: (int) (optional) filter priority (lower priority, higher
                     preference)
    :param protocol: (int) (optional) traffic filter protocol; if None, all
                     will be matched.
    :param namespace: (string) (optional) namespace name

    """
    keys = [key['key'] for key in _mac_to_pyroute2_keys(mac, offset)]
    priv_tc_lib.add_tc_filter_match32(device,
                                      parent,
                                      priority,
                                      classid,
                                      keys,
                                      protocol=protocol,
                                      namespace=namespace)
Exemplo n.º 2
0
def add_tc_filter_vxlan(device,
                        parent,
                        classid,
                        src_mac,
                        vxlan_id,
                        namespace=None):
    LOG.info('%s(): caller(): %s', log_utils.get_fname(1),
             log_utils.get_fname(2))
    """Add a TC filter to match VXLAN traffic based on the VM mac and the VNI.

    :param device: (string) device name
    :param parent: (string) qdisc parent class ('root', 'ingress', '2:10')
    :param classid: (string) major:minor handler identifier ('10:20')
    :param src_mac: (string) source MAC address to match (VM mac)
    :param vxlan_id: (int) VXLAN ID (VNI)
    :param namespace: (string) (optional) namespace name
    """
    keys = [hex(int(vxlan_id << 8)) + '/0xffffff00+' + str(VXLAN_VNI_OFFSET)]
    keys += [
        key['key']
        for key in _mac_to_pyroute2_keys(src_mac, VXLAN_INNER_SRC_MAC_OFFSET)
    ]
    priv_tc_lib.add_tc_filter_match32(device,
                                      parent,
                                      1,
                                      classid,
                                      keys,
                                      namespace=namespace)
Exemplo n.º 3
0
    def test_add_tc_filter_match32(self):
        priv_tc_lib.add_tc_qdisc(self.device,
                                 parent=rtnl.TC_H_ROOT,
                                 kind='htb',
                                 handle='1:',
                                 namespace=self.namespace)
        priv_tc_lib.add_tc_policy_class(self.device,
                                        '1:',
                                        '1:10',
                                        'htb',
                                        namespace=self.namespace,
                                        rate=10000)
        keys = tc_lib._mac_to_pyroute2_keys('7a:8c:f9:1f:e5:cb', 41)
        priv_tc_lib.add_tc_filter_match32(self.device,
                                          '1:0',
                                          10,
                                          '1:10',
                                          [keys[0]['key'], keys[1]['key']],
                                          namespace=self.namespace)

        filters = tc_lib.list_tc_filters(self.device,
                                         '1:0',
                                         namespace=self.namespace)
        self.assertEqual(1, len(filters))
        filter_keys = filters[0]['keys']
        self.assertEqual(len(keys), len(filter_keys))
        for index, value in enumerate(keys):
            value.pop('key')
            self.assertEqual(value, filter_keys[index])
Exemplo n.º 4
0
def add_tc_filter_match_mac(device, parent, classid, mac, offset=0, priority=0,
                            protocol=None, namespace=None):
    """Add a TC filter in a device to match a MAC address.

    :param device: (string) device name
    :param parent: (string) qdisc parent class ('root', 'ingress', '2:10')
    :param classid: (string) major:minor handler identifier ('10:20')
    :param mac: (string) MAC address to match
    :param offset: (int) (optional) match offset, starting from the outer
                   packet IP header
    :param priority: (int) (optional) filter priority (lower priority, higher
                     preference)
    :param protocol: (int) (optional) traffic filter protocol; if None, all
                     will be matched.
    :param namespace: (string) (optional) namespace name

    """
    keys = [key['key'] for key in _mac_to_pyroute2_keys(mac, offset)]
    priv_tc_lib.add_tc_filter_match32(device, parent, priority, classid, keys,
                                      protocol=protocol, namespace=namespace)