Commit 2ff7f1b5 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

NBI component - IETF L2VPN connector:

- Fixed parsing of L2 Site Network Accesses
parent 131bb963
Loading
Loading
Loading
Loading
+72 −39
Original line number Original line Diff line number Diff line
@@ -65,37 +65,87 @@ def process_site_network_access(
    site_id : str, network_access : Dict, errors : List[Dict]
    site_id : str, network_access : Dict, errors : List[Dict]
) -> None:
) -> None:
    try:
    try:
        site_network_access_type = network_access['site-network-access-type']
        #device_uuid   = None
        site_network_access_type = site_network_access_type.replace('ietf-l2vpn-svc:', '')
        #endpoint_uuid = None
        if site_network_access_type != 'multipoint':
        #if 'device-reference' in network_access:
            MSG = 'Site Network Access Type: {:s}'
        #    device_uuid   = network_access['device-reference']
            msg = MSG.format(str(network_access['site-network-access-type']))
        #    endpoint_uuid = network_access['network-access-id']
            raise NotImplementedError(msg)

        bearer_reference = None
        if 'bearer' in network_access:
            network_access_bearer = network_access['bearer']
            if 'bearer-reference' in network_access_bearer:
                bearer_reference = network_access_bearer['bearer-reference']

        bearer_mapping = BEARER_MAPPINGS.get(bearer_reference)
        if bearer_mapping is None:
            if ':' in bearer_reference:
                bearer_mapping = str(bearer_reference).split(':', maxsplit=1)
                bearer_mapping.extend([None, None, None, None, None, None, None])
                bearer_mapping = tuple(bearer_mapping)
                MSG = 'Bearer({:s}) not found; auto-generated mapping: {:s}'
                LOGGER.warning(MSG.format(str(bearer_reference), str(bearer_mapping)))
            else:
                MSG = 'Bearer({:s}) not found; unable to auto-generated mapping'
                raise Exception(MSG.format(str(bearer_reference)))


        access_role : str = network_access['vpn-attachment']['site-role']
        (
        access_role = access_role.replace('ietf-l2vpn-svc:', '').replace('-role', '') # hub/spoke
            device_uuid, endpoint_uuid, router_id, route_dist, sub_if_index,
        if access_role not in {'hub', 'spoke'}:
            address_ip, address_prefix, remote_router, circuit_id
            MSG = 'Site VPN Attackment Role: {:s}'
        ) = bearer_mapping
            raise NotImplementedError(MSG.format(str(network_access['site-network-access-type'])))


        device_uuid   = network_access['device-reference']
        endpoint_uuid = network_access['site-network-access-id']
        service_uuid  = network_access['vpn-attachment']['vpn-id']
        service_uuid  = network_access['vpn-attachment']['vpn-id']


        encapsulation_type = network_access['connection']['encapsulation-type']
        network_access_connection = network_access['connection']
        cvlan_tag_id = network_access['connection']['tagged-interface'][encapsulation_type]['cvlan-id']
        encapsulation_type = network_access_connection['encapsulation-type']

        encapsulation_type = encapsulation_type.replace('ietf-l2vpn-svc:', '')
        bearer_reference = network_access['bearer']['bearer-reference']
        if encapsulation_type != 'vlan':

            encapsulation_type = network_access_connection['encapsulation-type']
        service_mtu              = network_access['service']['svc-mtu']
            MSG = 'EncapsulationType({:s}) not supported'
        service_input_bandwidth  = network_access['service']['svc-input-bandwidth']
            raise NotImplementedError(MSG.format(str(encapsulation_type)))
        service_output_bandwidth = network_access['service']['svc-output-bandwidth']

        cvlan_tag_id = None
        if 'tagged-interface' in network_access_connection:
            nac_tagged_if = network_access_connection['tagged-interface']
            nac_tagged_if_type = nac_tagged_if.get('type', 'priority-tagged')
            nac_tagged_if_type = nac_tagged_if_type.replace('ietf-l2vpn-svc:', '')
            if nac_tagged_if_type == 'dot1q':
                encapsulation_data = nac_tagged_if['dot1q-vlan-tagged']
                tag_type = encapsulation_data.get('tg-type', 'c-vlan')
                tag_type = tag_type.replace('ietf-l2vpn-svc:', '')
                if tag_type == 'c-vlan':
                    cvlan_tag_id = encapsulation_data['cvlan-id']
                else:
                    tag_type = encapsulation_data.get('tg-type', 'c-vlan')
                    MSG = 'TagType({:s}) not supported'
                    raise NotImplementedError(MSG.format(str(tag_type)))
            else:
                nac_tagged_if_type = nac_tagged_if.get('type', 'priority-tagged')
                MSG = 'TaggedInterfaceType({:s}) not supported'
                raise NotImplementedError(MSG.format(str(nac_tagged_if_type)))

        network_access_service = network_access.get('service', dict())

        service_mtu              = network_access_service.get('svc-mtu', DEFAULT_MTU)

        service_input_bandwidth  = network_access_service.get('svc-input-bandwidth')
        service_bandwidth_bps

        service_output_bandwidth = network_access_service.get('svc-output-bandwidth')
        service_bandwidth_bps    = max(service_input_bandwidth, service_output_bandwidth)
        service_bandwidth_bps    = max(service_input_bandwidth, service_output_bandwidth)
        service_bandwidth_gbps   = service_bandwidth_bps / 1.e9
        service_bandwidth_gbps   = service_bandwidth_bps / 1.e9


        max_e2e_latency_ms = None
        max_e2e_latency_ms = None
        availability       = None
        availability       = None
        for qos_profile_class in network_access['service']['qos']['qos-profile']['classes']['class']:

        qos_profile_classes = (
            network_access.get('service', dict())
            .get('qos', dict())
            .get('qos-profile', dict())
            .get('classes', dict())
            .get('class', list())
        )
        for qos_profile_class in qos_profile_classes:
            if qos_profile_class['class-id'] != 'qos-realtime':
            if qos_profile_class['class-id'] != 'qos-realtime':
                MSG = 'Site Network Access QoS Class Id: {:s}'
                MSG = 'Site Network Access QoS Class Id: {:s}'
                raise NotImplementedError(MSG.format(str(qos_profile_class['class-id'])))
                raise NotImplementedError(MSG.format(str(qos_profile_class['class-id'])))
@@ -126,22 +176,6 @@ def process_site_network_access(
        single_active   : bool = len(network_access_availability.get('single-active', [])) > 0
        single_active   : bool = len(network_access_availability.get('single-active', [])) > 0
        all_active      : bool = len(network_access_availability.get('all-active', [])) > 0
        all_active      : bool = len(network_access_availability.get('all-active', [])) > 0


        mapping = BEARER_MAPPINGS.get(bearer_reference)
        if mapping is None:
            if ':' not in bearer_reference:
                MSG = 'Bearer({:s}) not found; unable to auto-generated mapping'
                raise Exception(MSG.format(str(bearer_reference)))
            mapping = str(bearer_reference).split(':', maxsplit=1)
            mapping.extend([None, None, None, None, None, None, None])
            mapping = tuple(mapping)
            MSG = 'Bearer({:s}) not found; auto-generated mapping: {:s}'
            LOGGER.warning(MSG.format(str(bearer_reference), str(mapping)))

        (
            device_uuid, endpoint_uuid, router_id, route_dist, sub_if_index,
            address_ip, address_prefix, remote_router, circuit_id
        ) = mapping

        context_client = ContextClient()
        context_client = ContextClient()
        service = get_service_by_uuid(
        service = get_service_by_uuid(
            context_client, service_uuid, context_uuid=DEFAULT_CONTEXT_NAME, rw_copy=True
            context_client, service_uuid, context_uuid=DEFAULT_CONTEXT_NAME, rw_copy=True
@@ -179,7 +213,6 @@ def process_site_network_access(
            update_constraint_sla_availability(constraints, num_disjoint_paths, all_active, 0.0)
            update_constraint_sla_availability(constraints, num_disjoint_paths, all_active, 0.0)


        service_settings_key = '/settings'
        service_settings_key = '/settings'
        if service_mtu is None: service_mtu = DEFAULT_MTU
        field_updates = {
        field_updates = {
            'mtu'             : (service_mtu,              True),
            'mtu'             : (service_mtu,              True),
            #'address_families': (DEFAULT_ADDRESS_FAMILIES, True),
            #'address_families': (DEFAULT_ADDRESS_FAMILIES, True),