Commit 6423c890 authored by Pablo Armingol's avatar Pablo Armingol
Browse files

Add initial JSON templates for IPoWDM orchestrator, Optical slice, TAPI...

Add initial JSON templates for IPoWDM orchestrator, Optical slice, TAPI service, and network slice service

- Created IPoWDM_orchestrator.json to define service configurations for optical and packet devices.
- Added Optical_slice.json to outline the structure for optical slice contexts and topology.
- Introduced TAPI_service.json for TAPI LSP service definitions, including service configurations and rules.
- Implemented slice1.json to specify network slice services with SLO policies and connection groups.
parent a86f79df
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -13,13 +13,15 @@
# limitations under the License.

# This file is an original contribution from Telefonica Innovación Digital S.L.
""" This file contains constants used throughout the NSC application. """

import logging, os
import logging
import os
# Default logging level
DEFAULT_LOGGING_LEVEL = logging.INFO

# Default port for NSC deployment
NSC_PORT = 8081
NSC_PORT = 8086

# Paths
# Obtain the absolute path of the current file
@@ -32,6 +34,7 @@ TEMPLATES_PATH = os.path.join(SRC_PATH, "templates")
# Flag to determine if configurations should be uploaded to Teraflow
TFS_UPLOAD = False
# Teraflow IP
TFS_IP = "192.168.165.10"
# Flag to determine if additional L2VPN configuration support is required for deploying L2VPNs with path selection
TFS_IP = "10.95.86.58"
# Flag to determine if additional L2VPN configuration support is
# required for deploying L2VPNs with path selection
TFS_L2VPN_SUPPORT = False
+76 −17
Original line number Diff line number Diff line
@@ -11,10 +11,14 @@
# 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.
""" This file is an original contribution from Telefonica Innovación Digital S.L. """

import logging, requests, json
import json
import logging
import os
import requests
from netmiko import ConnectHandler
from src.Constants import DEFAULT_LOGGING_LEVEL
from src.constants import DEFAULT_LOGGING_LEVEL, SRC_PATH

# Configure logging to provide clear and informative log messages
logging.basicConfig(
@@ -22,9 +26,16 @@ logging.basicConfig(
    format='%(levelname)s - %(message)s')

#Teraflow
class tfs_connector():
class TFSConnector():
    """Connector class for interacting with Teraflow SDN.
       This class provides methods to send requests to
       Teraflow SDN for network service configuration."""

    def simple_post(self, tfs_ip, service):
        """Send a simple POST request to Teraflow SDN.
           This method sends a JSON payload to the Teraflow SDN
           service endpoint to configure network services."""

        user="admin"
        password="admin"
        token=""
@@ -33,28 +44,37 @@ class tfs_connector():
        url=f'http://{tfs_ip}/webui'
        response=session.get(url=url)
        for item in response.iter_lines():
            if("csrf_token" in str(item)):
            if "csrf_token" in str(item):
                string=str(item).split('<input id="csrf_token" name="csrf_token" type="hidden" value=')[1]
                token=string.split(">")[0].strip('"')
        logging.debug("csrf token %s",token)

        files = {'descriptors': ("data.json", json.dumps(service).encode("utf-8"), "application/json")}
        files = {'descriptors': ("data.json", json.dumps(service).encode(
                                                                     "utf-8"), "application/json")}
        token={'csrf_token':token}
        response = session.post(url,files=files,data=token,timeout=60)
        logging.debug("Http response: %s",response.text)
        return response

#CISCO
class cisco_connector():
class CiscoConnector():
    """Connector class for interacting with Cisco devices.
       This class provides methods to execute configuration commands
       on Cisco devices via SSH."""

    def __init__(self, address, configs=None):
        self.address=address
        self.configs=configs

    def execute_commands(self, commands):
        """Execute a list of commands on the Cisco device via SSH.
           Connects to the device and sends configuration commands.
           This method is used to send configuration commands to the Cisco device."""

        try:
            # Configuración del dispositivo
            device = {
                'device_type': 'cisco_xr',  # Esto depende del tipo de dispositivo (ej: 'cisco_ios', 'cisco_xr', 'linux', etc.)
                'device_type': 'cisco_xr',
                'host': self.address,
                'username': 'cisco',
                'password': 'cisco12345',
@@ -70,10 +90,13 @@ class cisco_connector():
            # Cerrar la conexión
            connection.disconnect()

        except Exception as e:
            logging.error(f"Failed to execute commands on {self.address}: {str(e)}")
        except EOFError as e:
            logging.error("Failed to execute commands on %s: %s",self.address, str(e))

    def create_command_template(self, config):
        """Create a command template for configuring L2VPN on a Cisco device.
           This method generates the necessary commands to configure L2VPN
           based on the provided configuration parameters."""

        commands = [
            "l2vpn",
@@ -101,10 +124,13 @@ class cisco_connector():
            f"pw-class l2vpn_vpws_profile_example_{config['number']}"
        ])


        return commands

    def full_create_command_template(self):
        """Create a full command template for configuring L2VPN on a Cisco device.
           This method generates all necessary commands to configure L2VPN based on
           the provided configurations."""

        commands =[]
        for config in self.configs:
            commands_temp = self.create_command_template(config)
@@ -114,11 +140,44 @@ class cisco_connector():
        return commands

    def create_command_template_delete(self):
        """Create a command template for deleting L2VPN configuration on a Cisco device.
           This method generates the necessary commands to remove L2VPN configurations."""

        commands = [
            "no l2vpn",
        ]
    
        commands.append("commit")
        commands.append("end")

        return commands

def send_network_slice_request(data: str, action: str = "create") -> dict:

    url = 'http://192.168.1.143:9090/api/resource-allocation/transport-network-slice-l3'
    headers = {'Content-Type': 'application/json'}
    try:
        if action == "delete":
            data = {
                "ietf-network-slice-service:network-slice-services": {
                    "slice-service": [
                        {
                            "id": data
                        }
                    ]
                }
                }
            response = requests.delete(url, headers=headers, json=data, timeout=15)
        elif action == "create":
            response = requests.post(url, headers=headers, json=data, timeout=15)
        else:
            raise ValueError("Invalid action. Use 'create' or 'delete'.")
    except requests.exceptions.RequestException as e:
        logging.error(f"HTTP request failed: {e}")
        return {}


    # Comprobar y devolver la respuesta
    if response.ok:
        return response.json()
    else:
        print(f"Request failed with status code {response.status_code}: {response.text}")
        response.raise_for_status()
Loading