def range_to_match_struct(rangeFS):
    match = {}
    for attr_name, (to_str, from_str, width, om_name, of_name) in om_ch_translate.attr_funcs.items():
        om_start = "%s_s" % om_name
        om_end = "%s_e" % om_name
        match[of_name] = []
        # Some value must be within the boundaries
        if (getattr(rangeFS,om_start) > 0 or getattr(rangeFS,om_end) < 2**width-1):
            # Same value
            if (getattr(rangeFS,om_start) == getattr(rangeFS,om_end)):
                match[of_name].append(to_str(getattr(rangeFS,om_start)))
            else:
                # Ports
                if (attr_name == "nw_src" or attr_name == "nw_dst"):
                    ips = getattr(rangeFS,om_start)
                    ipe = getattr(rangeFS,om_end)
                    while (ips <= ipe):
                        for i in range(1,32):
                            if not ((ips | (2**i - 1 )) < ipe and (ips % 2**i)==0) :
                                obtained_match = "%s/%d"%(to_str(ips),33-i)
                                match[of_name].append(obtained_match)
                                ips = (ips| (2**(i-1) - 1 )) + 1
                                break
                else:
                    # If not full range, check that range is not too big
                    if not check_full_range(om_name, getattr(rangeFS,om_start), getattr(rangeFS,om_end)):
                        # Different factor for 32b or 64b OS's
                        factor_avoid_overflow = 1
                        # A limited number of rules should be set in FlowVisor avoiding
                        # overflow on its Java heap space (Xms: 100M, Xmx: 1000M currently)
                        # and also avoiding a lot of time processing (around 11 minutes now)
                        import sys
                        if (sys.maxsize <= 2**31-1):
                            factor_avoid_overflow = 1/5e6 # Allows circa 429 MACs
                        elif (sys.maxsize <= 2**63-1):
                            factor_avoid_overflow = 1/2e16 # Allows circa 461 MACs, e.g. [00:..:00, 00:..:FF]

                        # Avoid huge ranges of numbers (e.g. MACs) or to prevent Java heap space problems
                        # The whole range of VLANs is permitted
                        if (getattr(rangeFS,om_end)+1-getattr(rangeFS,om_start) > (sys.maxsize*factor_avoid_overflow) and om_name != "vlan_id"):
                            range_too_big = True
                            exception_range = "[%s, %s]" % (str(om_start), str(om_end))
                            raise Exception("Range too big for values '%s'" % exception_range)
                        # Compute range otherwise
                        else:
                            for value in range(getattr(rangeFS,om_start), getattr(rangeFS, om_end)+1):
                                match[of_name].append(to_str(value))

    #Now try to combine different of_name(s) together:
    all_match = [""]
    for key in match.keys():
        new_match = []
        for value in match[key]:
            for elem in all_match:
                if (elem == ""):
                    new_match.append("%s=%s"%(key,value))                    
                else:
                    new_match.append("%s,%s=%s"%(elem,key,value))
        if len(match[key]) > 0:
            all_match = new_match

    return all_match
Convert a FlowSpace element that has range for each of its fields to a list of openflow
dataset/ETHPy150Open fp7-ofelia/ocf/optin_manager/src/python/openflow/optin_manager/flowspace/helper.py/range_to_match_struct