Commit a63f0a7b authored by Leandro Campos's avatar Leandro Campos
Browse files

PON Driver Updated

parent 17a045c0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -323,7 +323,7 @@ enum ServiceTypeEnum {
  SERVICETYPE_E2E = 5;
  SERVICETYPE_OPTICAL_CONNECTIVITY = 6;
  SERVICETYPE_QKD = 7;
  SEVICETYPE_PON_ACCESS = 9;
  SERVICETYPE_PON_ACCESS = 8;
}

enum ServiceStatusEnum {
+2 −2
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ export TFS_REGISTRY_IMAGES=${TFS_REGISTRY_IMAGES:-"http://localhost:32000/tfs/"}

# If not already set, set the list of components, separated by spaces, you want to build images for, and deploy.
# By default, only basic components are deployed
export TFS_COMPONENTS=${TFS_COMPONENTS:-"context device automation monitoring pathcomp service slice compute webui load_generator"}
export TFS_COMPONENTS=${TFS_COMPONENTS:-"context device pathcomp service slice nbi webui"}

# If not already set, set the tag you want to use for your images.
export TFS_IMAGE_TAG=${TFS_IMAGE_TAG:-"dev"}
@@ -47,7 +47,7 @@ export TFS_SKIP_BUILD=${TFS_SKIP_BUILD:-"YES"}

# If TFS_SKIP_BUILD is "YES", select the containers to be build
# Any other container will use previous docker images
export TFS_QUICK_COMPONENTS="bgpls_speaker"
export TFS_QUICK_COMPONENTS="device"

# ----- CockroachDB ------------------------------------------------------------

+3 −34
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ from device.service.driver_api.AnyTreeTools import TreeNode, dump_subtree, get_s
from .Constants import SPECIAL_RESOURCE_MAPPINGS
from .SyntheticSamplingParameters import SyntheticSamplingParameters, do_sampling
from .Tools import compose_resource_endpoint
from .connectionRequest import connectionRequest
import requests

LOGGER = logging.getLogger(__name__)
@@ -36,11 +37,6 @@ DRIVER_NAME = 'PON_DRIVER'
METRICS_POOL = MetricsPool('Device', 'Driver', labels={'driver': DRIVER_NAME})


CONTROLLER_IP = "CONTROLLER-IP-ADDRESS"  # REPLACE
CONTROLLER_PORT = 3333 
API_ENDPOINT = f"http://{CONTROLLER_IP}:{CONTROLLER_PORT}/api/service/"


class PON_Driver(_Driver):
    def __init__(self, address : str, port : int, **settings) -> None:
        super().__init__(DRIVER_NAME, address, port, **settings)
@@ -119,34 +115,7 @@ class PON_Driver(_Driver):
                results.extend(dump_subtree(resource_node))
            return results

    def send_pon_connection_request(self, ont_id: str, cvlan: int, ethernet_port: str, svlan: int, profile: str, bw: int) -> bool:
        """
        Envía una petición POST para establecer la conexión entre la red de acceso PON y la OLS.
        """
        payload = {
            "ont_id": ont_id,
            "cvlan": cvlan,
            "ethernet_port": ethernet_port,
            "svlan": svlan,
            "profile": profile,
            "bw": bw
        }
        headers = {
            "accept": "application/json",
            "Content-Type": "application/json"
        }

        try:
            response = requests.post(API_ENDPOINT, headers=headers, json=payload)
            if response.status_code == 200:
                LOGGER.info(f"Connection successfully established: {payload}")
                return True
            else:
                LOGGER.error(f"Connection error: {response.status_code} - {response.text}")
                return False
        except requests.RequestException as e:
            LOGGER.error(f"Error when sending the request: {str(e)}")
            return False

    @metered_subclass_method(METRICS_POOL)
    def SetConfig(self, resources : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]:
@@ -165,7 +134,7 @@ class PON_Driver(_Driver):
                    resource_path = resource_key.split('/')


                    result = self.send_pon_connection_request(2, 22, 2, 333, "ef", 2500000)
                    result = connectionRequest("2", "22", "2","333", "ef", "2500000")
                    results.append(result)

                except Exception as e:
+58 −0
Original line number Diff line number Diff line
import requests
import json
import logging
from typing import Optional

LOGGER = logging.getLogger(__name__)

CONTROLLER_IP = "CONTROLLER-IP-ADDRESS"  # REPLACE
CONTROLLER_PORT = 3333 
API_ENDPOINT = f"http://{CONTROLLER_IP}:{CONTROLLER_PORT}/api/service/"

def connectionRequest(self, ont_id: str, cvlan: int, ethernet_port: str, svlan: int, profile: str, bw: int) -> bool:
        """
        Envía una petición POST para establecer la conexión PON.
        En caso de error, muestra el comando curl equivalente.
        """
        
        payload = {
            "ont_id": ont_id,
            "cvlan": str(cvlan),
            "ethernet_port": ethernet_port,
            "svlan": str(svlan),
            "profile": profile,
            "bw": str(bw)
        }
        
        headers = {
            "accept": "application/json",
            "Content-Type": "application/json"
        }

        curl_command = self._generate_curl_command(payload, headers)
        
        try:
            response = requests.post(self.API_ENDPOINT, headers=headers, json=payload)
            
            if response.status_code == 200:
                LOGGER.info(f"PON Connection OK: {payload}")
                return True
                
            LOGGER.error(f"Connection Error. CODE: {response.status_code} - RESPONSE: {response.text}")
            LOGGER.info(f"CURL COMMAND: \n{curl_command}")
            return False
            
        except requests.RequestException as e:
            LOGGER.error(f"Connection Error: {str(e)}")
            LOGGER.info(f"CURL COMMAND: \n{curl_command}")
            return False

def _generate_curl_command(self, payload: dict, headers: dict) -> str:

        header_string = " ".join([f"-H '{k}: {v}'" for k, v in headers.items()])
        json_data = json.dumps(payload, indent=2).replace("'", "'\\''")
        return (
            f"curl -X POST '{self.API_ENDPOINT}' \\\n"
            f"     {header_string} \\\n"
            f"     -d $'{json_data}'"
        )
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ DEVICE_DRIVER_VALUES = {
    DeviceDriverEnum.DEVICEDRIVER_OC,
    DeviceDriverEnum.DEVICEDRIVER_QKD,
    DeviceDriverEnum.DEVICEDRIVER_IETF_L3VPN,
    DeviceDriverEnum.DEVICEDRIVER_PON_ACCESS,
    DeviceDriverEnum.DEVICEDRIVER_PON,
}

# Map allowed filter fields to allowed values per Filter field. If no restriction (free text) None is specified
Loading