Пример #1
0
def Get_LocatorRecord_Object(rloc,
                             weights="1/1/255/0",
                             flags=0o01,
                             loc_id="ISP1"):
    """Description: Returns locator record object from pyangbind generated classes
    Returns: locator record object
    Params:
     rloc: eid_string for lisp address object
     weights: priority/weight/multicastPriority/multicastWeight
     flags: Three bit parameter in the sequence routed->rlocProbed->routed
     loc_id: id of locator record object
    """
    sys.path.insert(0, workspace)
    from LISPFlowMappingYANGBindings.odl_mappingservice_rpc.add_mapping.input import (
        input, )

    rpc_input = input()
    lrecord_obj = rpc_input.mapping_record.LocatorRecord
    # TODO: What should be the locator-id
    lrecord_obj.add(loc_id)
    lrecord_ele = weights.split("/")
    lrecord_obj[loc_id].priority = lrecord_ele[0]
    lrecord_obj[loc_id].weight = lrecord_ele[1]
    lrecord_obj[loc_id].multicastPriority = lrecord_ele[2]
    lrecord_obj[loc_id].multicastWeight = lrecord_ele[3]
    laddr_obj = lrecord_obj[loc_id].rloc
    laddr_obj = Get_LispAddress_Object(rloc, laddr_obj=laddr_obj)
    lrecord_obj[loc_id].localLocator = flags % 10
    lrecord_obj[loc_id].rlocProbed = (flags / 10) % 10
    lrecord_obj[loc_id].routed = (flags / 100) % 10
    return lrecord_obj
Пример #2
0
def Get_MappingRecord_Object(eid,
                             locators,
                             ttl=1440,
                             authoritative=True,
                             action="NoAction"):
    """Description: Returns mapping record object from pyangbind generated classes.
    Returns: mapping record object
    Params:
     eid: lisp address object
     locators: list of locator record objects
     ttl: recordTtl
     authoritative: authoritative
     action: action
    """
    sys.path.insert(0, workspace)
    from LISPFlowMappingYANGBindings.odl_mappingservice_rpc.add_mapping.input import (
        input, )

    rpc_input = input()
    mrecord_obj = rpc_input.mapping_record
    mrecord_obj.recordTtl = ttl
    mrecord_obj.authoritative = authoritative
    mrecord_obj.action = action
    copy_eid(mrecord_obj.eid, eid)
    idx = 0
    loc_ids = []
    for loc in locators:
        loc_id = loc.keys()[0]
        loc_obj = loc[loc_id]
        if loc_id in loc_ids:
            print("Locator objects should have different keys")
            break
        # TODO: Locator-id, currently in the format of loc_id0, loc_id1
        mrecord_obj.LocatorRecord.add(loc_id)
        mrecord_loc_obj = mrecord_obj.LocatorRecord[loc_id]
        mrecord_loc_obj.priority = loc_obj.priority
        mrecord_loc_obj.weight = loc_obj.weight
        mrecord_loc_obj.multicastPriority = loc_obj.multicastPriority
        mrecord_loc_obj.multicastWeight = loc_obj.multicastWeight
        copy_rloc(mrecord_loc_obj.rloc, loc_obj.rloc)
        mrecord_loc_obj.localLocator = loc_obj.localLocator
        mrecord_loc_obj.rlocProbed = loc_obj.rlocProbed
        mrecord_loc_obj.routed = loc_obj.routed
        idx += 1
    return mrecord_obj
Пример #3
0
def Get_MappingRecord_Object(eid, locators, ttl=1440, authoritative=True, action='NoAction'):
    """ Description: Returns mapping record object from pyangbind generated classes.
        Returns: mapping record object
        Params:
         eid: lisp address object
         locators: list of locator record objects
         ttl: recordTtl
         authoritative: authoritative
         action: action
    """
    sys.path.insert(0, workspace)
    from LISPFlowMappingYANGBindings.odl_mappingservice_rpc.add_mapping.input import input
    rpc_input = input()
    mrecord_obj = rpc_input.mapping_record
    mrecord_obj.recordTtl = ttl
    mrecord_obj.authoritative = authoritative
    mrecord_obj.action = action
    copy_eid(mrecord_obj.eid, eid)
    idx = 0
    loc_ids = []
    for loc in locators:
        loc_id = loc.keys()[0]
        loc_obj = loc[loc_id]
        if loc_id in loc_ids:
            print "Locator objects should have different keys"
            break
        # TODO: Locator-id, currently in the format of loc_id0, loc_id1
        mrecord_obj.LocatorRecord.add(loc_id)
        mrecord_loc_obj = mrecord_obj.LocatorRecord[loc_id]
        mrecord_loc_obj.priority = loc_obj.priority
        mrecord_loc_obj.weight = loc_obj.weight
        mrecord_loc_obj.multicastPriority = loc_obj.multicastPriority
        mrecord_loc_obj.multicastWeight = loc_obj.multicastWeight
        copy_rloc(mrecord_loc_obj.rloc, loc_obj.rloc)
        mrecord_loc_obj.localLocator = loc_obj.localLocator
        mrecord_loc_obj.rlocProbed = loc_obj.rlocProbed
        mrecord_loc_obj.routed = loc_obj.routed
        idx += 1
    return mrecord_obj
Пример #4
0
def Get_LispAddress_Object(eid_string, vni=None, laddr_obj=None):
    """Description: Returns lisp address object from pyangbind generated classes.
    Returns: lisp address object
    Params:
     eid_string: type of lisp address
     vni: virtual network id
     laddr_obj: lisp address object
    """
    if laddr_obj is None:
        sys.path.insert(0, workspace)
        from LISPFlowMappingYANGBindings.odl_mappingservice_rpc.add_mapping.input import (
            input, )

        rpc_input = input()
        laddr_obj = rpc_input.mapping_record.eid

    if vni:
        laddr_obj.virtual_network_id = vni

    eid_string = eid_string.split(":")
    prefix, text = eid_string[0], ":".join(eid_string[1:])
    if prefix:
        if prefix == "srcdst":
            # Example: srcdst:192.0.2.1/32|192.0.2.2/32
            laddr_obj.address_type = "laddr:source-dest-key-lcaf"
            text = text.split("|")
            laddr_obj.source_dest_key.source = text[0]
            laddr_obj.source_dest_key.dest = text[1]
        elif prefix == "no":
            # Example: no:
            laddr_obj.address_type = "laddr:no-address-afi"
        elif prefix == "ipv4":
            if "/" in text:
                # Case: ipv4-prefix
                laddr_obj.address_type = "laddr:ipv4-prefix-afi"
                laddr_obj.ipv4_prefix = text
            else:
                # Case: ipv4
                laddr_obj.address_type = "laddr:ipv4-afi"
                laddr_obj.ipv4 = text
        elif prefix == "ipv6":
            if "/" in text:
                # Case: ipv6-prefix
                laddr_obj.address_type = "laddr:ipv6-prefix-afi"
                laddr_obj.ipv6_prefix = text
            else:
                laddr_obj.address_type = "laddr:ipv6-afi"
                laddr_obj.ipv6 = text
        elif prefix == "mac":
            # Example: mac:00:00:5E:00:53:00
            laddr_obj.address_type = "laddr:mac-afi"
            laddr_obj.mac = text
        elif prefix == "dn":
            # Example: dn:stringAsIs
            laddr_obj.address_type = "laddr:distinguished-name-afi"
            laddr_obj.distinguished_name = text
        elif prefix == "as":
            # Example: as:AS64500
            laddr_obj.address_type = "laddr:as-number-afi"
            laddr_obj.as_number = text
        elif prefix == "list":
            # Example: list:{192.0.2.1,192.0.2.2,2001:db8::1}
            laddr_obj.address_type = "laddr:afi-list-lcaf"
            list_elements = text[1:len(text) - 1].split(
                ",")  # removed start and end braces
            laddr_obj.afi_list.address_list = list_elements
        elif prefix == "appdata":
            # Example: appdata:192.0.2.1!128!17!80-81!6667-7000
            laddr_obj.address_type = "laddr:application-data-lcaf"
            text = text.split("!")
            laddr_obj.application_data.address = text[0]
            laddr_obj.application_data.ip_tos = text[1]
            laddr_obj.application_data.protocol = text[2]
            local_ports = text[3].split("-")
            laddr_obj.application_data.local_port_low = local_ports[0]
            laddr_obj.application_data.local_port_high = local_ports[1]
            remote_ports = text[4].split("-")
            laddr_obj.application_data.remote_port_low = remote_ports[0]
            laddr_obj.application_data.remote_port_high = remote_ports[1]
        elif prefix == "elp":
            # TODO: BITS_TYPE_for_lps
            # Example: elp:{192.0.2.1->192.0.2.2|lps->192.0.2.3}
            laddr_obj.address_type = "laddr:explicit-locator-path-lcaf"
            text = text[1:len(text) - 1]
            text = text.split("->")  # all the hops
            for i in range(0, len(text)):
                cur_hop = text[i].split("|")
                address = cur_hop[0]
                lrs_bits = ""
                hop_id = "Hop " + str(i + 1) + " " + lrs_bits
                if len(cur_hop) > 1:
                    lps = cur_hop[1]
                    if "l" in lps:
                        lrs_bits += "lookup "
                    if "p" in lps:
                        lrs_bits += "rloc-probe "
                    if "s" in lps:
                        lrs_bits += "strict "
                laddr_obj.explicit_locator_path.hop.add(hop_id)
                laddr_obj.explicit_locator_path.hop[hop_id].address = address
        elif prefix == "kv":
            # Example: kv:192.0.2.1->192.0.2.2
            laddr_obj.address_type = "laddr:key-value-address-lcaf"
            text = text.split("->")
            laddr_obj.key_value_address.key = text[0]
            laddr_obj.key_value_address.value = text[1]
        elif prefix == "sp":
            # Example: sp:42(3)
            laddr_obj.address_type = "laddr:service-path-lcaf"
            text = text.split("(")
            laddr_obj.service_path.service_path_id = text[0]
            laddr_obj.service_path.service_index = text[1][:-1]

    return laddr_obj
Пример #5
0
def Get_LispAddress_Object(eid_string, vni=None, laddr_obj=None):
    """ Description: Returns lisp address object from pyangbind generated classes.
        Returns: lisp address object
        Params:
         eid_string: type of lisp address
         vni: virtual network id
         laddr_obj: lisp address object
    """
    if laddr_obj is None:
        sys.path.insert(0, workspace)
        from LISPFlowMappingYANGBindings.odl_mappingservice_rpc.add_mapping.input import input
        rpc_input = input()
        laddr_obj = rpc_input.mapping_record.eid

    if vni:
        laddr_obj.virtual_network_id = vni

    eid_string = eid_string.split(':')
    prefix, text = eid_string[0], ':'.join(eid_string[1:])
    if prefix:
        if prefix == 'srcdst':
            # Example: srcdst:192.0.2.1/32|192.0.2.2/32
            laddr_obj.address_type = 'laddr:source-dest-key-lcaf'
            text = text.split('|')
            laddr_obj.source_dest_key.source = text[0]
            laddr_obj.source_dest_key.dest = text[1]
        elif prefix == 'no':
            # Example: no:
            laddr_obj.address_type = 'laddr:no-address-afi'
        elif prefix == 'ipv4':
            if '/' in text:
                # Case: ipv4-prefix
                laddr_obj.address_type = 'laddr:ipv4-prefix-afi'
                laddr_obj.ipv4_prefix = text
            else:
                # Case: ipv4
                laddr_obj.address_type = 'laddr:ipv4-afi'
                laddr_obj.ipv4 = text
        elif prefix == 'ipv6':
            if '/' in text:
                # Case: ipv6-prefix
                laddr_obj.address_type = 'laddr:ipv6-prefix-afi'
                laddr_obj.ipv6_prefix = text
            else:
                laddr_obj.address_type = 'laddr:ipv6-afi'
                laddr_obj.ipv6 = text
        elif prefix == 'mac':
            # Example: mac:00:00:5E:00:53:00
            laddr_obj.address_type = 'laddr:mac-afi'
            laddr_obj.mac = text
        elif prefix == 'dn':
            # Example: dn:stringAsIs
            laddr_obj.address_type = 'laddr:distinguished-name-afi'
            laddr_obj.distinguished_name = text
        elif prefix == 'as':
            # Example: as:AS64500
            laddr_obj.address_type = 'laddr:as-number-afi'
            laddr_obj.as_number = text
        elif prefix == 'list':
            # Example: list:{192.0.2.1,192.0.2.2,2001:db8::1}
            laddr_obj.address_type = 'laddr:afi-list-lcaf'
            list_elements = text[1:len(text) - 1].split(',')  # removed start and end braces
            laddr_obj.afi_list.address_list = list_elements
        elif prefix == 'appdata':
            # Example: appdata:192.0.2.1!128!17!80-81!6667-7000
            laddr_obj.address_type = 'laddr:application-data-lcaf'
            text = text.split('!')
            laddr_obj.application_data.address = text[0]
            laddr_obj.application_data.ip_tos = text[1]
            laddr_obj.application_data.protocol = text[2]
            local_ports = text[3].split('-')
            laddr_obj.application_data.local_port_low = local_ports[0]
            laddr_obj.application_data.local_port_high = local_ports[1]
            remote_ports = text[4].split('-')
            laddr_obj.application_data.remote_port_low = remote_ports[0]
            laddr_obj.application_data.remote_port_high = remote_ports[1]
        elif prefix == 'elp':
            # TODO: BITS_TYPE_for_lps
            # Example: elp:{192.0.2.1->192.0.2.2|lps->192.0.2.3}
            laddr_obj.address_type = 'laddr:explicit-locator-path-lcaf'
            text = text[1:len(text) - 1]
            text = text.split('->')  # all the hops
            for i in range(0, len(text)):
                cur_hop = text[i].split('|')
                address = cur_hop[0]
                lrs_bits = ""
                hop_id = "Hop " + str(i + 1) + " " + lrs_bits
                if len(cur_hop) > 1:
                    lps = cur_hop[1]
                    if "l" in lps:
                        lrs_bits += "lookup "
                    if "p" in lps:
                        lrs_bits += "rloc-probe "
                    if "s" in lps:
                        lrs_bits += "strict "
                laddr_obj.explicit_locator_path.hop.add(hop_id)
                laddr_obj.explicit_locator_path.hop[hop_id].address = address
        elif prefix == 'kv':
            # Example: kv:192.0.2.1->192.0.2.2
            laddr_obj.address_type = 'laddr:key-value-address-lcaf'
            text = text.split('->')
            laddr_obj.key_value_address.key = text[0]
            laddr_obj.key_value_address.value = text[1]
        elif prefix == 'sp':
            # Example: sp:42(3)
            laddr_obj.address_type = 'laddr:service-path-lcaf'
            text = text.split('(')
            laddr_obj.service_path.service_path_id = text[0]
            laddr_obj.service_path.service_index = text[1][:-1]

    return laddr_obj
Пример #6
0
    """
    return Wrap_input(Get_LispAddress_JSON(eid_string, vni))


def Get_LocatorRecord_Object(rloc, weights='1/1/255/0', flags=001, loc_id="ISP1"):
    """ Description: Returns locator record object from pyangbind generated classes
        Returns: locator record object
        Params:
         rloc: eid_string for lisp address object
         weights: priority/weight/multicastPriority/multicastWeight
         flags: Three bit parameter in the sequence routed->rlocProbed->routed
         loc_id: id of locator record object
    """
    sys.path.insert(0, workspace)
    from LISPFlowMappingYANGBindings.odl_mappingservice_rpc.add_mapping.input import input
    rpc_input = input()
    lrecord_obj = rpc_input.mapping_record.LocatorRecord
    # TODO: What should be the locator-id
    lrecord_obj.add(loc_id)
    lrecord_ele = weights.split('/')
    lrecord_obj[loc_id].priority = lrecord_ele[0]
    lrecord_obj[loc_id].weight = lrecord_ele[1]
    lrecord_obj[loc_id].multicastPriority = lrecord_ele[2]
    lrecord_obj[loc_id].multicastWeight = lrecord_ele[3]
    laddr_obj = lrecord_obj[loc_id].rloc
    laddr_obj = Get_LispAddress_Object(rloc, laddr_obj=laddr_obj)
    lrecord_obj[loc_id].localLocator = flags % 10
    lrecord_obj[loc_id].rlocProbed = (flags / 10) % 10
    lrecord_obj[loc_id].routed = (flags / 100) % 10
    return lrecord_obj
Пример #7
0
def Get_LocatorRecord_Object(rloc,
                             weights='1/1/255/0',
                             flags=001,
                             loc_id="ISP1"):
    """ Description: Returns locator record object from pyangbind generated classes
        Returns: locator record object
        Params:
         rloc: eid_string for lisp address object
         weights: priority/weight/multicastPriority/multicastWeight
         flags: Three bit parameter in the sequence routed->rlocProbed->routed
         loc_id: id of locator record object
    """
    sys.path.insert(0, workspace)
    from LISPFlowMappingYANGBindings.odl_mappingservice_rpc.add_mapping.input import input
    rpc_input = input()
    lrecord_obj = rpc_input.mapping_record.LocatorRecord
    # TODO: What should be the locator-id
    lrecord_obj.add(loc_id)
    lrecord_ele = weights.split('/')
    lrecord_obj[loc_id].priority = lrecord_ele[0]
    lrecord_obj[loc_id].weight = lrecord_ele[1]
    lrecord_obj[loc_id].multicastPriority = lrecord_ele[2]
    lrecord_obj[loc_id].multicastWeight = lrecord_ele[3]
    laddr_obj = lrecord_obj[loc_id].rloc
    laddr_obj = Get_LispAddress_Object(rloc, laddr_obj=laddr_obj)
    lrecord_obj[loc_id].localLocator = flags % 10
    lrecord_obj[loc_id].rlocProbed = (flags / 10) % 10
    lrecord_obj[loc_id].routed = (flags / 100) % 10
    return lrecord_obj