Commit d79451b4 authored by Pablo Armingol's avatar Pablo Armingol
Browse files

refactor: consolidate optical E2E path computation into TFS API and remove legacy module

parent 26d98495
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ export TFS_COMPONENTS="context device pathcomp service nbi webui"
#export TFS_COMPONENTS="${TFS_COMPONENTS} forecaster"

# Uncomment to activate E2E Orchestrator
#export TFS_COMPONENTS="${TFS_COMPONENTS} e2e_orchestrator"
export TFS_COMPONENTS="${TFS_COMPONENTS} e2e_orchestrator"

# Uncomment to activate VNT Manager
#export TFS_COMPONENTS="${TFS_COMPONENTS} vnt_manager"
@@ -143,7 +143,7 @@ export CRDB_PASSWORD="tfs123"
export CRDB_DEPLOY_MODE="single"

# Disable flag for dropping database, if it exists.
export CRDB_DROP_DATABASE_IF_EXISTS=""
export CRDB_DROP_DATABASE_IF_EXISTS="YES"

# Disable flag for re-deploying CockroachDB from scratch.
export CRDB_REDEPLOY=""
@@ -211,7 +211,7 @@ export QDB_TABLE_MONITORING_KPIS="tfs_monitoring_kpis"
export QDB_TABLE_SLICE_GROUPS="tfs_slice_groups"

# Disable flag for dropping tables if they exist.
export QDB_DROP_TABLES_IF_EXIST=""
export QDB_DROP_TABLES_IF_EXIST="YES"

# Disable flag for re-deploying QuestDB from scratch.
export QDB_REDEPLOY=""
+0 −2
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ 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(
@@ -112,7 +111,6 @@ register_vntm_recommend (nbi_app)
register_ipowdm          (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()
+0 −69
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
+0 −26
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'
    )
+49 −1
Original line number Diff line number Diff line
@@ -18,15 +18,18 @@ from typing import Dict, List
from flask.json import jsonify
from flask_restful import Resource, request
from werkzeug.exceptions import BadRequest
from common.proto.context_pb2 import Empty, LinkTypeEnum
from common.proto.context_pb2 import Empty, LinkTypeEnum, Service, ServiceTypeEnum, ConfigActionEnum, ConfigRule
from common.proto.e2eorchestrator_pb2 import E2EOrchestratorRequest
from common.tools.descriptor.Tools import format_device_custom_config_rules, format_service_custom_config_rules
from common.tools.grpc.Tools import grpc_message_to_json
from context.client.ContextClient import ContextClient
from device.client.DeviceClient import DeviceClient
from e2e_orchestrator.client.E2EOrchestratorClient import E2EOrchestratorClient
from service.client.ServiceClient import ServiceClient
from slice.client.SliceClient import SliceClient
from vnt_manager.client.VNTManagerClient import VNTManagerClient


from .Tools import (
    format_grpc_to_json, grpc_connection_id, grpc_context, grpc_context_id, grpc_device,
    grpc_device_id, grpc_link, grpc_link_id, grpc_policy_rule_id,
@@ -360,3 +363,48 @@ class PolicyRules(_Resource):
class PolicyRule(_Resource):
    def get(self, policy_rule_uuid : str):
        return format_grpc_to_json(self.context_client.GetPolicyRule(grpc_policy_rule_id(policy_rule_uuid)))

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