Commit e75b8ed6 authored by Javier Velázquez's avatar Javier Velázquez
Browse files

Merge branch 'develop' of https://labs.etsi.org/rep/tfs/nsc into feat/32-update-code-commentaries

parents 5797e626 ffaed27a
Loading
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -43,9 +43,14 @@ if [ ! -f src/config/.env.example ]; then
    exit 1
fi

# Copy .env.example to .env
echo "Generating .env file..."
# Copy .env if not exists
if [ -f src/config/.env ]; then
    echo "Using existing src/config/.env file..."
    cp src/config/.env .env
else
    echo "Generating .env file from example..."
    cp src/config/.env.example .env
fi

# Read NSC_PORT from .env
NSC_PORT=$(grep '^NSC_PORT=' .env | cut -d '=' -f2)
+3 −3
Original line number Diff line number Diff line
@@ -31,12 +31,12 @@ NRP_ENABLED=false
PLANNER_ENABLED=true
# Flag to determine if external PCE is used
PCE_EXTERNAL=false
# Type of planner to be used. Options: ENERGY, HRAT, TFS_OPTICAL
# Type of planner to be used. Options: ENERGY, HRAT, E2E_OPTICAL
PLANNER_TYPE=ENERGY
# HRAT
HRAT_IP=10.0.0.1
# TFS_OPTICAL
OPTICAL_PLANNER_IP=10.0.0.1
# E2E_OPTICAL
E2E_OPTICAL_IP=127.0.0.1

# -------------------------
# Realizer
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ def create_config(app: Flask):
    app.config["PLANNER_TYPE"] = os.getenv("PLANNER_TYPE", "ENERGY")
    app.config["PCE_EXTERNAL"] = os.getenv("PCE_EXTERNAL", "false").lower() == "true"
    app.config["HRAT_IP"] = os.getenv("HRAT_IP", "192.168.1.143")
    app.config["OPTICAL_PLANNER_IP"] = os.getenv("OPTICAL_PLANNER_IP", "10.30.7.66")
    app.config["E2E_OPTICAL_IP"] = os.getenv("E2E_OPTICAL_IP", "127.0.0.1")

    # Realizer
    app.config["DUMMY_MODE"] = os.getenv("DUMMY_MODE", "true").lower() == "true"
+57 −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 requests
import json
from src.utils.safe_get import safe_get

def e2e_optical_planner(intent, ip: str, action: str = "create") -> dict:
    """
    Plan E2E optical layer configuration using TFS NBI.
    
    Args:
        intent (dict or str): Network slice intent
        ip (str): IP address of the TFS NBI service
        action (str, optional): Operation to perform - "create" or "delete". 
                               Defaults to "create"
    """
    if action == 'delete':
        logging.debug("DELETE REQUEST RECEIVED FOR E2EOptical: %s", intent)
        return None

    url = f"http://{ip}/restconf/e2epathcomp/v0/e2e_path_computation"
    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json"
    }

    payload = intent

    logging.debug(f"Sending request to E2EOptical Planner: {url}")
    
    try:
        response = requests.post(url, headers=headers, json=payload, timeout=10)
        
        if response.status_code in [200, 201]:
            response_data = response.json()
            logging.info(f"E2EOptical Planner Response: {json.dumps(response_data, indent=2)}")
            return response_data
        else:
            logging.warning(f"E2EOptical Planner returned status {response.status_code}: {response.text}")
            return None
            
    except requests.exceptions.RequestException as e:
        logging.warning(f"Error connecting to the E2EOptical Planner service: {e}")
        return None
+3 −3
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
import logging
from src.planner.energy_planner.energy           import energy_planner
from src.planner.hrat_planner.hrat               import hrat_planner
from src.planner.tfs_optical_planner.tfs_optical import tfs_optical_planner
from src.planner.e2e_optical_planner.e2e_optical import e2e_optical_planner
from flask import current_app


@@ -47,7 +47,7 @@ class Planner:
        if type   == "ENERGY"     : return energy_planner(intent)
        # Use HRAT planner with configured IP
        elif type == "HRAT"       : return hrat_planner(intent, current_app.config["HRAT_IP"])
        # Use TFS optical planner with configured IP
        elif type == "TFS_OPTICAL": return tfs_optical_planner(intent, current_app.config["OPTICAL_PLANNER_IP"], action = "create")
        # Use E2E optical planner with configured IP
        elif type == "E2E_OPTICAL": return e2e_optical_planner(intent, current_app.config["E2E_OPTICAL_IP"], action = "create")
        # Return None if planner type is unsupported
        else : return None
Loading