Commit 705cd825 authored by Pablo Armingol's avatar Pablo Armingol
Browse files

Merge branch...

Merge branch 'feat/397-tid-e2e-orchestrator-with-pathcomp-for-p2mp-optical-slices' of https://labs.etsi.org/rep/tfs/controller into feat/398-tid-nbi-for-ipowdm-with-device-driver-l3ietf
parents 4ad6f0e7 35eb3a95
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -82,6 +82,9 @@ COPY src/context/client/. context/client/
COPY src/context/service/database/uuids/. context/service/database/uuids/
COPY src/service/__init__.py service/__init__.py
COPY src/service/client/. service/client/
COPY src/pathcomp/__init__.py pathcomp/__init__.py
COPY src/pathcomp/frontend/__init__.py pathcomp/frontend/__init__.py
COPY src/pathcomp/frontend/client/. pathcomp/frontend/client/
COPY src/e2e_orchestrator/. e2e_orchestrator/

# Start the service
+15 −0
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ from common.proto.context_pb2 import Empty, Connection, EndPointId
from common.proto.e2eorchestrator_pb2_grpc import E2EOrchestratorServiceServicer
from context.client.ContextClient import ContextClient
from context.service.database.uuids.EndPoint import endpoint_get_uuid
from common.proto.context_pb2 import ServiceTypeEnum
from pathcomp.frontend.client.PathCompClient import PathCompClient
from common.proto.pathcomp_pb2 import PathCompRequest

LOGGER = logging.getLogger(__name__)

@@ -33,6 +36,18 @@ class E2EOrchestratorServiceServicerImpl(E2EOrchestratorServiceServicer):
    def Compute(
        self, request: E2EOrchestratorRequest, context: grpc.ServicerContext
    ) -> E2EOrchestratorReply:
        if request.service.service_type == ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY:
            LOGGER.info("E2E Orchestrator: Detected OPTICAL_CONNECTIVITY service. Calling PathComp.")
            pathcomp_client = PathCompClient()
            pathcomp_req = PathCompRequest()
            pathcomp_req.services.append(request.service)
            pathcomp_reply = pathcomp_client.Compute(pathcomp_req)
            
            e2e_reply = E2EOrchestratorReply()
            e2e_reply.services.extend(pathcomp_reply.services)
            e2e_reply.connections.extend(pathcomp_reply.connections)
            return e2e_reply

        endpoints_ids = [
            endpoint_get_uuid(endpoint_id)[2]
            for endpoint_id in request.service.service_endpoint_ids
+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
@@ -51,6 +51,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(
@@ -111,6 +112,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
Loading