Creates an instance of the BGP Route Target Community (if "subtype=2")
    or Route Origin Community ("subtype=3").

    :param value: String of Route Target or Route Origin value.
    :param subtype: Subtype of Extended Community.
    :return: An instance of Route Target or Route Origin Community.

def create_rt_extended_community(value, subtype=2):
    """
    Creates an instance of the BGP Route Target Community (if "subtype=2")
    or Route Origin Community ("subtype=3").

    :param value: String of Route Target or Route Origin value.
    :param subtype: Subtype of Extended Community.
    :return: An instance of Route Target or Route Origin Community.
    """
    global_admin, local_admin = value.split(':')
    local_admin = int(local_admin)
    if global_admin.isdigit() and 0 <= int(global_admin) <= 0xffff:
        ext_com = BGPTwoOctetAsSpecificExtendedCommunity(
            subtype=subtype,
            as_number=int(global_admin),
            local_administrator=local_admin)
    elif global_admin.isdigit() and 0xffff < int(global_admin) <= 0xffffffff:
        ext_com = BGPFourOctetAsSpecificExtendedCommunity(
            subtype=subtype,
            as_number=int(global_admin),
            local_administrator=local_admin)
    elif ip.valid_ipv4(global_admin):
        ext_com = BGPIPv4AddressSpecificExtendedCommunity(
            subtype=subtype,
            ipv4_address=global_admin,
            local_administrator=local_admin)
    else:
        raise ValueError(
            'Invalid Route Target or Route Origin value: %s' % value)

    return ext_com