Commit 2fefbaab authored by Maria Ruiz's avatar Maria Ruiz
Browse files

new service SAT

parent 5efe8d47
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -49,8 +49,8 @@ PCE_EXTERNAL = False

# Controller Flags
# If True, config is not sent to controllers
#DUMMY_MODE = False
DUMMY_MODE = True #MR
DUMMY_MODE = False
#DUMMY_MODE = True #MR

#####TERAFLOW#####
# Teraflow IP
+90 −0
Original line number Diff line number Diff line
@@ -1273,5 +1273,95 @@ class NSController:
    def __sat(self, ietf_intent):
        """
        Prepare an SAT NMS service request based on the IETF intent

        This method configures an Satellite NMS service request by:
        (L2 bridge)

        1. Defining endpoint: HUB-STATION
        2. Loading a service template
        3. Generating a unique service UUID
        4. Configuring service 
        5. Adding QoS constraints

        Args:
            ietf_intent (dict): IETF-formatted network slice intent.

        Returns:
            dict: An Satellite NMS service request for configuration.

        """
        self.answer[self.subnet]["QoS Requirements"] = []
                # Add service constraints
        for i, constraint in enumerate(ietf_intent["ietf-network-slice-service:network-slice-services"]["slo-sle-templates"]["slo-sle-template"][0]["slo-policy"]["metric-bound"]):
            bound = ietf_intent["ietf-network-slice-service:network-slice-services"]["slo-sle-templates"]["slo-sle-template"][0]["slo-policy"]["metric-bound"][i]["bound"]
            metric_type = ietf_intent["ietf-network-slice-service:network-slice-services"]["slo-sle-templates"]["slo-sle-template"][0]["slo-policy"]["metric-bound"][i]["metric-type"]
            metric_unit = ietf_intent["ietf-network-slice-service:network-slice-services"]["slo-sle-templates"]["slo-sle-template"][0]["slo-policy"]["metric-bound"][i]["metric-unit"]
            service_constraint ={
                "custom": {
                    "constraint_type": f"{metric_type}[{metric_unit}]",
                    "constraint_value": f"{bound}"
                }
            }
            self.answer[self.subnet]["QoS Requirements"].append(service_constraint["custom"])
        self.answer[self.subnet]["VLAN"] = ietf_intent["ietf-network-slice-service:network-slice-services"]["slice-service"][0]["sdps"]["sdp"][0]["service-match-criteria"]["match-criterion"][0]["value"]
        
        # Extraer la lista de métricas de forma segura
        metric_bounds = ietf_intent.get("ietf-network-slice-service:network-slice-services", {}) \
            .get("slo-sle-templates", {}) \
            .get("slo-sle-template", [{}])[0] \
            .get("slo-policy", {}) \
            .get("metric-bound", [])    
        # Inicializar valores
        bandwidth = None
        latency = None
        tolerance = None        
        # Asignar valores según el tipo de métrica
        for metric in metric_bounds:            
            metric_type = metric.get("metric-type")
            bound = metric.get("bound")

            if metric_type == "one-way-bandwidth":
                bandwidth = bound
            elif metric_type == "one-way-delay-maximum":
                latency = bound
            elif metric_type == "one-way-delay-variation-maximum": 
                tolerance = bound   
       
        # Construcción del diccionario intent
        intent = {
            "src_node_id":  ietf_intent.get("ietf-network-slice-service:network-slice-services", {})
                .get("slice-service", [{}])[0]
                .get("sdps", {}).get("sdp", [{}])[0]
                .get("node-id"),

            "src_node_ip": ietf_intent.get("ietf-network-slice-service:network-slice-services", {})
                .get("slice-service", [{}])[0]
                .get("sdps", {}).get("sdp", [{}, {}])[0]
                .get("attachment-circuits", {}).get("attachment-circuit", [{}])[0]
                .get("ac-ipv4-address"),

            "dst_node_id":  ietf_intent.get("ietf-network-slice-service:network-slice-services", {})
                .get("slice-service", [{}])[0]
                .get("sdps", {}).get("sdp", [{}])[1]
                .get("node-id"),

            "dst_node_ip": ietf_intent.get("ietf-network-slice-service:network-slice-services", {})
                .get("slice-service", [{}])[0]
                .get("sdps", {}).get("sdp", [{}, {}])[1]
                .get("attachment-circuits", {}).get("attachment-circuit", [{}])[0]
                .get("ac-ipv4-address"),

            "vlan_id": ietf_intent.get("ietf-network-slice-service:network-slice-services", {})
                .get("slice-service", [{}])[0]
                .get("sdps", {}).get("sdp", [{}])[0]
                .get("service-match-criteria", {}).get("match-criterion", [{}])[0]
                .get("value"),

            "bandwidth": bandwidth,
            "latency": latency,
            "tolerance": tolerance,

        }
        logging.info(f"SATELLITE Intent realized\n")
        return intent
    
+82 −1
Original line number Diff line number Diff line
@@ -15,11 +15,92 @@
# This file is an original contribution from Telefonica Innovación Digital S.L.

import ipaddress, logging
import requests
from requests.auth import HTTPBasicAuth
from http import HTTPStatus
from src.Constants import SATNMS_IP
import json

class SAT_NMS:
    
    def __init__(self, satnms_ip=SATNMS_IP):
        self.satnms_ip = satnms_ip

    def nscSATNMS(self, json_data):
        
        print(f'\n\n{json_data}\n')

        logging.info("Procesando petición")

        src_node_id = json_data.get("src_node_id", None)
        dst_node_ip = json_data.get("dst_node_id", None)
        src_node_ip = json_data.get("src_node_ip", None)
        dst_node_ip = json_data.get("dst_node_ip", None)
        vlan_id = json_data.get("vlan_id", None)
        bandwidth = json_data.get("bandwidth", None)
        latency = json_data.get("latency", None)
        tolerance = json_data.get("tolerance", None)

        new_service = self.new_service(self.satnms_ip, vlan_id)
        print(f'\n\n{new_service}\n')


    def loggin_NMS(self,ip):

        url= "http://"+ip+":8000/api/tree/login/nms=0"

        response = requests.get(url, auth=HTTPBasicAuth('admin', '12345'))

        if HTTPStatus.OK == response.status_code:
            cookies = response.cookies
            logging.info("sesion iniciada en el NMS")
            print(f'\n\n{cookies}\n')
            return cookies
            
        else:
            print(f"error al obtener la informacion de la IP; {response.status_code}")
            return None
    
   
   
    def new_service(self,ip, vlan_id):

        session = self.loggin_NMS(ip)

        if session is None:
            print("No se pudo iniciar sesion en el NMS")
            return None

        url= "http://"+ip+":8000/api/object/write/network=0/new_item=service"
        
        body_dict = {
            "uprow": "LAB_TEL",
            "name": "test_106",
            "accesses": "",
            "hub_vlan": vlan_id,
            "stn_vlan": vlan_id,
            "svlan_range": "L2_bridge",
            "ctr_normal": "ON",
            "ctr_gateway": "OFF",
            "ctr_mesh": "OFF",
            "stn_normal": "ON",
            "stn_gateway": "OFF",
            "stn_mesh": "OFF",
            "group_id": 0,
            "mesh_routing": "None",
            "nonlocal": "OFF",
            "rip_announced": "OFF",
            "allow_overlap": "OFF"
        }
        
        payload = json.dumps(body_dict)
        response = requests.post(url, cookies=session, auth=('admin', '12345'), data=payload)

        if response.status_code==200:
            logging.info("servicio creado en el NMS")
            return response.json()
        else:
            print(f"error al crear el servicio; {response.status_code}")
            return response.json()
        
+3182 −0

File changed.

Preview size limit exceeded, changes collapsed.

+0 −160
Original line number Diff line number Diff line
[
  {
    "ietf-network-slice-service:network-slice-services": {
      "slo-sle-templates": {
        "slo-sle-template": [
          {
            "id": "A",
            "description": "",
            "slo-policy": {
              "metric-bound": [
                {
                  "metric-type": "one-way-bandwidth",
                  "metric-unit": "kbps",
                  "bound": 2
                },
                {
                  "metric-type": "one-way-delay-maximum",
                  "metric-unit": "milliseconds",
                  "bound": 20
                }
              ]
            },
            "sle-policy": {
              "security": "",
              "isolation": "",
              "path-constraints": {
                "service-functions": "",
                "diversity": {
                  "diversity": {
                    "diversity-type": ""
                  }
                }
              }
            }
          }
        ]
      },
      "slice-service": [
        {
          "id": "slice-service-27dafab1-18d5-4a6e-ba6d-15835097a462",
          "description": "Transport network slice mapped with 3GPP slice NetworkSlice1",
          "service-tags": {
            "tag-type": {
              "tag-type": "",
              "value": ""
            }
          },
          "slo-sle-policy": {
            "slo-sle-template": "SAT"
          },
          "status": {},
          "sdps": {
            "sdp": [
              {
                "id": "",
                "geo-location": "",
                "node-id": "HUB",
                "sdp-ip-address": "10.0.200.1", 
                "tp-ref": "",
                "service-match-criteria": {
                  "match-criterion": [
                    {
                      "index": 1,
                      "match-type": "VLAN",
                      "value": "102",
                      "target-connection-group-id": "HUB_STATION_102"
                    }
                  ]
                },
                "incoming-qos-policy": "",
                "outgoing-qos-policy": "",
                "sdp-peering": {
                  "peer-sap-id": "",
                  "protocols": ""
                },
                "ac-svc-ref": [],
                "attachment-circuits": {
                  "attachment-circuit": [
                    {
                      "id": "1",
                      "ac-ipv4-address": "10.0.200.1",
                      "ac-ipv4-prefix-length": 0,
                      "sdp-peering": {
                        "peer-sap-id": "H"
                      },
                      "status": {}
                    }
                  ]
                },
                "status": {},
                "sdp-monitoring": ""
              },
              {
                "id": "",
                "geo-location": "",
                "node-id": "STATION",
                "sdp-ip-address": "10.0.102.2",
                "tp-ref": "",
                "service-match-criteria": {
                  "match-criterion": [
                    {
                      "index": 1,
                      "match-type": "VLAN",
                      "value": "102",
                      "target-connection-group-id": "HUB_STATION_102"
                    }
                  ]
                },
                "incoming-qos-policy": "",
                "outgoing-qos-policy": "",
                "sdp-peering": {
                  "peer-sap-id": "",
                  "protocols": ""
                },
                "ac-svc-ref": [],
                "attachment-circuits": {
                  "attachment-circuit": [
                    {
                      "id": "2",
                      "ac-ipv4-address": "10.0.102.2",
                      "ac-ipv4-prefix-length": 0,
                      "sdp-peering": {
                        "peer-sap-id": "S"
                      },
                      "status": {}
                    }
                  ]
                },
                "status": {},
                "sdp-monitoring": ""
              }
            ]
          },
          "connection-groups": {
            "connection-group": [
              {
                "id": "HUB_STATION_102",
                "connectivity-type": "ietf-vpn-common:any-to-any",
                "connectivity-construct": [
                  {
                    "id": 1,
                    "a2a-sdp": [
                      {
                        "sdp-id": "01"
                      },
                      {
                        "sdp-id": "02"
                      }
                    ]
                  }
                ],
                "status": {}
              }
            ]
          }
        }
      ]
    }
  }
]
 No newline at end of file
Loading