Commit 5e8a5f3a authored by Pablo Armingol's avatar Pablo Armingol
Browse files

Merge branch 'feat/325-tid-nbi-e2e-to-manage-e2e-path-computation' of...

Merge branch 'feat/325-tid-nbi-e2e-to-manage-e2e-path-computation' of https://labs.etsi.org/rep/tfs/controller into feat/397-tid-e2e-orchestrator-with-pathcomp-for-p2mp-optical-slices
parents 7ec87bb3 d1956045
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -92,6 +92,10 @@ COPY src/slice/__init__.py slice/__init__.py
COPY src/slice/client/. slice/client/
COPY src/vnt_manager/__init__.py vnt_manager/__init__.py
COPY src/vnt_manager/client/. vnt_manager/client/

COPY src/e2e_orchestrator/. e2e_orchestrator/__init__.py
COPY src/e2e_orchestrator/client/. e2e_orchestrator/client/

RUN mkdir -p /var/teraflow/tests/tools
COPY src/tests/tools/mock_osm/. tests/tools/mock_osm/
COPY src/nbi/. nbi/
+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ from .tfs_api import register_tfs_api
from .vntm_recommend import register_vntm_recommend
from .well_known_meta import register_well_known
from .media_channel import register_media_channel
from .optical_e2e_path_computation import register_e2e_path_computation

LOG_LEVEL = get_log_level()
logging.basicConfig(
@@ -109,6 +110,7 @@ register_tfs_api (nbi_app)
register_vntm_recommend  (nbi_app)
register_media_channel   (nbi_app)
register_well_known      (nbi_app)
register_e2e_path_computation(nbi_app)
LOGGER.info('All connectors registered')

nbi_app.dump_configuration()
+69 −0
Original line number Diff line number Diff line
# Copyright 2022-2026 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import json
from flask import request
from flask_restful import Resource
from common.proto.context_pb2 import Service, ServiceTypeEnum, ConfigActionEnum, ConfigRule
from common.proto.e2eorchestrator_pb2 import E2EOrchestratorRequest
from e2e_orchestrator.client.E2EOrchestratorClient import E2EOrchestratorClient
from common.tools.grpc.Tools import grpc_message_to_json

LOGGER = logging.getLogger(__name__)

class E2epathcomp(Resource):
    def __init__(self):
        super().__init__()
        self.e2e_client = E2EOrchestratorClient()

    def post(self):
        data = request.get_json()
        LOGGER.info(f"Received E2E Optical Path Computation request: {json.dumps(data, indent=2)}")

        try:
            # Construct a Service protobuf to encapsulate the intent for the E2E Orchestrator
            service = Service()
            service.service_id.service_uuid.uuid = "e2e-optical-service"
            service.service_id.context_id.context_uuid.uuid = "admin"
            service.service_type = ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY
            
            # Pack the original JSON payload into a config rule so E2E Orchestrator and PathComp can access it
            config_rule = ConfigRule()
            config_rule.action = ConfigActionEnum.CONFIGACTION_SET
            config_rule.custom.resource_key = "intent"
            config_rule.custom.resource_value = json.dumps(data)
            service.service_config.config_rules.append(config_rule)

            req = E2EOrchestratorRequest(service=service)
            
            LOGGER.info("Sending request to E2E Orchestrator Compute...")
            reply = self.e2e_client.Compute(req)
            
            reply_json = grpc_message_to_json(reply)
            
            # Check if there is an optical_path_result injected by PathComp
            if reply.services:
                for cr in reply.services[0].service_config.config_rules:
                    if cr.WhichOneof('config_rule') == 'custom' and cr.custom.resource_key == "optical_path_result":
                        LOGGER.info("Found optical_path_result, returning it directly.")
                        return json.loads(cr.custom.resource_value), 200

            LOGGER.info(f"Received reply from E2E Orchestrator: {json.dumps(reply_json)}")
            # The NBI returns the standard protobuf JSON response if no custom result is found
            return reply_json, 200

        except Exception as e:
            LOGGER.error(f"Error calling E2E Orchestrator: {str(e)}", exc_info=True)
            return {"status": "error", "message": str(e)}, 500
+26 −0
Original line number Diff line number Diff line
# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from nbi.service.NbiApplication import NbiApplication
from .Resources import E2epathcomp  # solo necesitamos este

URL_PREFIX = '/restconf/e2epathcomp/v0'

def register_e2e_path_computation(nbi_app: NbiApplication):
    nbi_app.add_rest_api_resource(
        E2epathcomp,
        URL_PREFIX + '/e2e_path_computation',
        endpoint='e2e_path_computation'
    )