Loading src/network_slice_controller.py +90 −23 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ class NSController: self.__teraflow_template = "" self.__nrp_view = "" self.subnet="" self.satnms_ip = satnms_ip # API Methods def add_flow(self, intent): Loading Loading @@ -240,6 +241,61 @@ class NSController: except Exception as e: return self.__send_response(False, code=500, message=str(e)) def delete_flows_sat(self, slice_id=None): """ Delete transport network slices satellite transport segment """ try: # Delete specific slice if slice_id is provided if slice_id: SAT_NMS().del_service(self.satnms_ip,slice_id) with open(os.path.join(SRC_PATH, "planner/sat_resources_ddbb.json"), "r") as file: data = json.load(file) links = data["satellite-segment-nodes"][0]["links"]["link"] links_id = [link for link in links if link.get("slice-id") != str(slice_id)] if len(links_id) == len(links): raise ValueError("Transport network slice not found") data["satellite-segment-nodes"][0]["links"]["link"] = links_id with open(os.path.join(SRC_PATH, "planner/sat_resources_ddbb.json"), 'w') as file: json.dump(data, file, indent=4) logging.info(f"Slice {slice_id} removed successfully") with open(os.path.join(SRC_PATH, "planner/sat_resources_ddbb.json"), "r") as file: data = json.load(file) links = data["satellite-segment-nodes"][0]["links"]["link"] if len(links) !=0: SAT_NMS().reajuste_shaper_cir() else: SAT_NMS().reinicio_shaper(self.satnms_ip) return self.__send_response(False, code=200, status="success", message=f"Transpor network slice {slice_id} deleted successfully") except ValueError as e: return self.__send_response(False, code=404, message=str(e)) except Exception as e: return self.__send_response(False, code=500, message=str(e)) def get_sat_ddbb(self): try: with open(os.path.join(SRC_PATH, "planner/sat_resources_ddbb.json"), "r") as file: data = json.load(file) print(json.dumps(data, indent=4, ensure_ascii=False)) self.__send_response(True, code=200) return data except ValueError as e: return self.__send_response(False, code=404, message=str(e)) except Exception as e: return self.__send_response(False, code=500, message=str(e)) # Main NSC Functionalities def nsc(self, intent_json, slice_id=None): """ Loading Loading @@ -290,18 +346,18 @@ class NSController: self.__store_data(intent, slice_id) # Mapper # Realizer if self.controller_type == "sat": viability = self.__mapper(intent) if viability != "error": if viability == "error": return self.__send_response(False, code=500, message="Slice request cannot be realized due to insufficient satellite resources") elif viability != "error": tfs_request, sat_request = self.__realizer(intent) requests["services"].append(tfs_request) requests2 = {"services":[]} requests2["services"].append(sat_request) logging.info(f"Realizing request to: SAT NMS {tfs_request} and SAT RM {sat_request}") else: logging.info("Slice request cannot be realized due to insufficient satellite resources") else: tfs_request = self.__realizer(intent) requests["services"].append(tfs_request) Loading @@ -314,15 +370,7 @@ class NSController: if DUMP_TEMPLATES: with open(os.path.join(TEMPLATES_PATH, "realizer_template.json"), "w") as archivo: archivo.write(json.dumps(requests,indent=2)) if self.controller_type == "sat" and requests2: if DUMP_TEMPLATES: with open(os.path.join(TEMPLATES_PATH, "realizer_template_sat.json"), "w") as archivo: archivo.write(json.dumps(requests2,indent=2)) elif self.controller_type == "sdn": with open(os.path.join(TEMPLATES_PATH, "realizer_template_sdn.json"), "w") as archivo: archivo.write(json.dumps(requests,indent=2)) archivo.write(json.dumps(requests,indent=2)) if self.controller_type == "sat" and requests2: if self.controller_type == "sat" and requests2 is not None : if DUMP_TEMPLATES: with open(os.path.join(TEMPLATES_PATH, "realizer_template_sat.json"), "w") as archivo: archivo.write(json.dumps(requests2,indent=2)) Loading Loading @@ -485,7 +533,6 @@ class NSController: if self.controller_type == "sat": viability= SATPlanner().satplanner(ietf_intent) if viability == "error": logging.info(f"Resource allocation : Not enough satellite resources") return viability elif viability == "ok": logging.info(f"Resource allocation : Sufficient satellite resources available") Loading Loading @@ -1587,7 +1634,7 @@ class NSController: # 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") Loading @@ -1600,10 +1647,29 @@ class NSController: elif metric_type == "one-way-delay-variation-maximum": tolerance = bound if self.__mapper(ietf_intent) != "ok" and self.__mapper(ietf_intent) != "error": cir = self.__mapper(ietf_intent) else: cir = None QoS_profile = ietf_intent.get("ietf-network-slice-service:network-slice-services", {}) \ .get("slo-sle-templates", {}).get("slo-sle-template", [{}])[0] \ .get("id") resp_mapper = self.__mapper(ietf_intent) logging.info(f'RESPUESTA MAPPER {resp_mapper}') if resp_mapper == "ok": cirB = None cirC = None self.__send_response(True, status="Success") elif resp_mapper == "error": self.__send_response(False, status="error", message="Resource allocation : Not enough satellite resources") elif resp_mapper != "ok" and resp_mapper != "error": cirB, cirC = self.__mapper(ietf_intent) if QoS_profile == "C": logging.info(f"NUEVO CIR1: {cirB}, {cirC}") elif QoS_profile == "B": logging.info(f"NUEVOS CIRB, CIRC: {cirB} , {cirC}") elif QoS_profile == "A": logging.info(f"NUEVOS CIRB, CIRC: {cirB} , {cirC}") self.__send_response(True, status="Success", message="CIR limitation") # Construcción del diccionario intent intent_nms = { Loading Loading @@ -1646,7 +1712,8 @@ class NSController: "coding-rate": "8/9", "roll-off-factor": "0.2", "symbol-rate": 52000000, "cir": cir "CIR_limitationB": cirB, "CIR_limitationC": cirC } # intent que se enviaría al controlador satelital Loading Loading
src/network_slice_controller.py +90 −23 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ class NSController: self.__teraflow_template = "" self.__nrp_view = "" self.subnet="" self.satnms_ip = satnms_ip # API Methods def add_flow(self, intent): Loading Loading @@ -240,6 +241,61 @@ class NSController: except Exception as e: return self.__send_response(False, code=500, message=str(e)) def delete_flows_sat(self, slice_id=None): """ Delete transport network slices satellite transport segment """ try: # Delete specific slice if slice_id is provided if slice_id: SAT_NMS().del_service(self.satnms_ip,slice_id) with open(os.path.join(SRC_PATH, "planner/sat_resources_ddbb.json"), "r") as file: data = json.load(file) links = data["satellite-segment-nodes"][0]["links"]["link"] links_id = [link for link in links if link.get("slice-id") != str(slice_id)] if len(links_id) == len(links): raise ValueError("Transport network slice not found") data["satellite-segment-nodes"][0]["links"]["link"] = links_id with open(os.path.join(SRC_PATH, "planner/sat_resources_ddbb.json"), 'w') as file: json.dump(data, file, indent=4) logging.info(f"Slice {slice_id} removed successfully") with open(os.path.join(SRC_PATH, "planner/sat_resources_ddbb.json"), "r") as file: data = json.load(file) links = data["satellite-segment-nodes"][0]["links"]["link"] if len(links) !=0: SAT_NMS().reajuste_shaper_cir() else: SAT_NMS().reinicio_shaper(self.satnms_ip) return self.__send_response(False, code=200, status="success", message=f"Transpor network slice {slice_id} deleted successfully") except ValueError as e: return self.__send_response(False, code=404, message=str(e)) except Exception as e: return self.__send_response(False, code=500, message=str(e)) def get_sat_ddbb(self): try: with open(os.path.join(SRC_PATH, "planner/sat_resources_ddbb.json"), "r") as file: data = json.load(file) print(json.dumps(data, indent=4, ensure_ascii=False)) self.__send_response(True, code=200) return data except ValueError as e: return self.__send_response(False, code=404, message=str(e)) except Exception as e: return self.__send_response(False, code=500, message=str(e)) # Main NSC Functionalities def nsc(self, intent_json, slice_id=None): """ Loading Loading @@ -290,18 +346,18 @@ class NSController: self.__store_data(intent, slice_id) # Mapper # Realizer if self.controller_type == "sat": viability = self.__mapper(intent) if viability != "error": if viability == "error": return self.__send_response(False, code=500, message="Slice request cannot be realized due to insufficient satellite resources") elif viability != "error": tfs_request, sat_request = self.__realizer(intent) requests["services"].append(tfs_request) requests2 = {"services":[]} requests2["services"].append(sat_request) logging.info(f"Realizing request to: SAT NMS {tfs_request} and SAT RM {sat_request}") else: logging.info("Slice request cannot be realized due to insufficient satellite resources") else: tfs_request = self.__realizer(intent) requests["services"].append(tfs_request) Loading @@ -314,15 +370,7 @@ class NSController: if DUMP_TEMPLATES: with open(os.path.join(TEMPLATES_PATH, "realizer_template.json"), "w") as archivo: archivo.write(json.dumps(requests,indent=2)) if self.controller_type == "sat" and requests2: if DUMP_TEMPLATES: with open(os.path.join(TEMPLATES_PATH, "realizer_template_sat.json"), "w") as archivo: archivo.write(json.dumps(requests2,indent=2)) elif self.controller_type == "sdn": with open(os.path.join(TEMPLATES_PATH, "realizer_template_sdn.json"), "w") as archivo: archivo.write(json.dumps(requests,indent=2)) archivo.write(json.dumps(requests,indent=2)) if self.controller_type == "sat" and requests2: if self.controller_type == "sat" and requests2 is not None : if DUMP_TEMPLATES: with open(os.path.join(TEMPLATES_PATH, "realizer_template_sat.json"), "w") as archivo: archivo.write(json.dumps(requests2,indent=2)) Loading Loading @@ -485,7 +533,6 @@ class NSController: if self.controller_type == "sat": viability= SATPlanner().satplanner(ietf_intent) if viability == "error": logging.info(f"Resource allocation : Not enough satellite resources") return viability elif viability == "ok": logging.info(f"Resource allocation : Sufficient satellite resources available") Loading Loading @@ -1587,7 +1634,7 @@ class NSController: # 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") Loading @@ -1600,10 +1647,29 @@ class NSController: elif metric_type == "one-way-delay-variation-maximum": tolerance = bound if self.__mapper(ietf_intent) != "ok" and self.__mapper(ietf_intent) != "error": cir = self.__mapper(ietf_intent) else: cir = None QoS_profile = ietf_intent.get("ietf-network-slice-service:network-slice-services", {}) \ .get("slo-sle-templates", {}).get("slo-sle-template", [{}])[0] \ .get("id") resp_mapper = self.__mapper(ietf_intent) logging.info(f'RESPUESTA MAPPER {resp_mapper}') if resp_mapper == "ok": cirB = None cirC = None self.__send_response(True, status="Success") elif resp_mapper == "error": self.__send_response(False, status="error", message="Resource allocation : Not enough satellite resources") elif resp_mapper != "ok" and resp_mapper != "error": cirB, cirC = self.__mapper(ietf_intent) if QoS_profile == "C": logging.info(f"NUEVO CIR1: {cirB}, {cirC}") elif QoS_profile == "B": logging.info(f"NUEVOS CIRB, CIRC: {cirB} , {cirC}") elif QoS_profile == "A": logging.info(f"NUEVOS CIRB, CIRC: {cirB} , {cirC}") self.__send_response(True, status="Success", message="CIR limitation") # Construcción del diccionario intent intent_nms = { Loading Loading @@ -1646,7 +1712,8 @@ class NSController: "coding-rate": "8/9", "roll-off-factor": "0.2", "symbol-rate": 52000000, "cir": cir "CIR_limitationB": cirB, "CIR_limitationC": cirC } # intent que se enviaría al controlador satelital Loading