Exemple #1
0
def create_matches(dp, config):
    LOG.debug('MATCHES:')
    fields = {}
    '''
    Matches config
    is a list
    '''
    LOG.debug('matches config: %s', config)

    for key in config.keys():
        if key[0] == '#':
            continue
        val = config[key]
        LOG.debug('key: %s', key)
        LOG.debug('val: %s', val)

        '''
        Process outdated '*_mask' keys.
        '''
        if (key[-5:] == '_mask'):
            LOG.debug('ignore: %s', key)
            continue

        if key not in matches_all:
            raise Exception('Wrong match name:', key)

        if key in matches_int:
            fields[key] = fields[key] = Utils.string_to_int_tuple(val)

        if key in matches_mac:
            key_mask = key + '_mask'
            if  key_mask in config.keys():
                LOG.debug('key_mask: %s', key_mask)
                val_mask = (val, config[key_mask])
                LOG.debug('val_mask: %s', val_mask)
                fields[key] = val_mask
            else:
                fields[key] = val

        if key in matches_ipv4:
            fields[key] = Utils.ip_to_long(val)

        if key in matches_ipv6:
            fields[key] = Utils.int_from_ipv6(val)

        LOG.debug('fields: %s', fields)

    matches = dp.ofproto_parser.OFPMatch(**fields)

    LOG.debug('matches: %s', matches)
    return matches
Exemple #2
0
def action_set_field(dp, config):
    LOG.debug('set_field config: %s', config)
    fields = {}
    for key in config.keys():
        if key[0] == '#':
            continue
        val = config[key]
        LOG.debug('key: %s', key)
        LOG.debug('val: %s', val)
        '''
        Process outdated '*_mask' keys.
        '''
        if (key[-5:] == '_mask'):
            LOG.debug('ignore: %s', key)
            continue

        if (key == 'eth_dst') or (key == 'eth_src'):
            LOG.debug('1 key:val %s:%s', key, val)
            key_mask = key + '_mask'
            if key_mask in config.keys():
                LOG.debug('key_mask: %s', key_mask)
                val_mask = config[key_mask]
                val_bin = Utils.mac_str_to_bin(val)
                val_mask_bin = Utils.mac_str_to_bin(val_mask)
                LOG.debug('val_bin: %x val_bin_mask: %x', val_bin,
                          val_mask_bin)
                val_bin = val_bin | val_mask_bin
                val = Utils.mac_bin_to_str(val_bin)
                LOG.debug('val: %s', val)
                #fields[key] = ('de:ad:be:ef:00:01', '00:00:00:ff:ff:ff')#val_mask
            fields[key] = val
        elif (key[:5] == 'ipv4_'):
            LOG.debug('2 key:val %s:%s', key, val)
            fields[key] = Utils.ip_to_long(val)
        elif (key == 'ipv6_src') or (key == 'ipv6_dst'):
            LOG.debug('3 key:val %s:%s', key, val)
            fields[key] = Utils.int_from_ipv6(val)
        else:
            LOG.debug('4 key:val %s:%s', key, val)
            fields[key] = int(val, 0)

    LOG.debug('fields: %s', fields)
    return dp.ofproto_parser.OFPActionSetField(**fields)
Exemple #3
0
def action_set_field(dp, config):
    LOG.debug("set_field config: %s", config)
    fields = {}
    for key in config.keys():
        if key[0] == "#":
            continue
        val = config[key]
        LOG.debug("key: %s", key)
        LOG.debug("val: %s", val)
        """
        Process outdated '*_mask' keys.
        """
        if key[-5:] == "_mask":
            LOG.debug("ignore: %s", key)
            continue

        if (key == "eth_dst") or (key == "eth_src"):
            LOG.debug("1 key:val %s:%s", key, val)
            key_mask = key + "_mask"
            if key_mask in config.keys():
                LOG.debug("key_mask: %s", key_mask)
                val_mask = config[key_mask]
                val_bin = Utils.mac_str_to_bin(val)
                val_mask_bin = Utils.mac_str_to_bin(val_mask)
                LOG.debug("val_bin: %x val_bin_mask: %x", val_bin, val_mask_bin)
                val_bin = val_bin | val_mask_bin
                val = Utils.mac_bin_to_str(val_bin)
                LOG.debug("val: %s", val)
                # fields[key] = ('de:ad:be:ef:00:01', '00:00:00:ff:ff:ff')#val_mask
            fields[key] = val
        elif key[:5] == "ipv4_":
            LOG.debug("2 key:val %s:%s", key, val)
            fields[key] = Utils.ip_to_long(val)
        elif (key == "ipv6_src") or (key == "ipv6_dst"):
            LOG.debug("3 key:val %s:%s", key, val)
            fields[key] = Utils.int_from_ipv6(val)
        else:
            LOG.debug("4 key:val %s:%s", key, val)
            fields[key] = int(val, 0)

    LOG.debug("fields: %s", fields)
    return dp.ofproto_parser.OFPActionSetField(**fields)