def delete_slice(slice_id): """ Deletes the WAN Slice between the endpoints """ logger.info(f"Terminating WAN Slice {slice_id}") slice_data = mongoUtils.get("slice", slice_id) connections = slice_data.get("connections", None) if connections: for conn in connections: try: rules = conn["rules"] except KeyError: logger.info(f"Skipping {conn}") continue subprocess.run([f"wim/rules/{rules}", "delete", slice_data["_id"]]) # Send the slice_id to the monitoring module wim_monitoring = os.getenv("WIM_MONITORING", None) if wim_monitoring: # Create the Kafka Producer producer = create_producer() wim_message = {"action": "terminate", "slice_data": slice_data} # Send the message producer.send("wan-monitoring", value=wim_message) logger.info("Updated monitoring module") mongoUtils.delete("slice", slice_id)
def get(self, _id): """ Find the slice from the database based on the id and return it If not found, return 404 error """ _slice = mongoUtils.get("slice", _id) return (_slice, 200) if _slice else (f"Slice {_id} was not found", 404)
def post(self, _id): """ Create a new slice and store it in the database """ args = request.json args["_id"] = _id if mongoUtils.get("slice", _id): return f"Slice {_id} already exists" producer = kafkaUtils.create_producer() wim_message = {"action": "create", "data": args} producer.send("wan-slice", value=wim_message) return (f"Creating Slice {_id}", 201)
def delete(self, _id): """ Delete an existing slice If not found, return 404 error """ _slice = mongoUtils.get("slice", _id) if _slice: producer = kafkaUtils.create_producer() wim_message = {"action": "terminate", "data": _id} producer.send("wan-slice", value=wim_message) return (f"Terrminating Slice {_id}", 200) else: return (f"Slice {_id} was not found", 404)
for node in NODE_LIST: # Find the switch from neo4j db target = db.get_node(node["switch-id"]) if not target: logger.error(f"Could not find node {node['swich-id']}") exit(9999) try: ctl = target["sdn_controller"] dpid = target["dpid"] except KeyError: logger.error( f"SDN Controller and DPID were not defined for node {node['swich-id']}" ) exit(9999) node["switch-dpid"] = dpid node["sdn-ctl"] = ctl subprocess.run([ "bash", node["script"], "-c", ctl, "-d", dpid, "-f", slice_id, action ]) # Update the slice information with the created SDN flows slice_data = mongoUtils.get("slice", slice_id) slice_flows = slice_data.get("slice_flows", []) if action == "create": new_slice_flows = slice_flows + NODE_LIST else: new_slice_flows = [node for node in slice_flows if node not in NODE_LIST] slice_data["slice_flows"] = new_slice_flows mongoUtils.update("slice", slice_id, slice_data)
def create_slice(slice_data): """ Creates the WAN Slice between the endpoints """ logger.info("Creating WAN Slice") # Add the slice to the database mongoUtils.add("slice", slice_data) logger.info(slice_data) # Get the slices SLAs sla = slice_data["slice_sla"] # Get the probes probes = slice_data.get("probes", []) # Get the slice Components components = [ins["vim"] for ins in slice_data.get("extra_ns", [])] + probes for connection in slice_data["core_connections"]: core = connection["core"] core_vims = [ins["vim"] for ins in core.get("ns", [])] core_pnf = [ipnf["pnf-id"] for ipnf in core.get("pnf", [])] radio = connection["radio"] radio_vims = [ins["vim"] for ins in radio.get("ns", [])] radio_pnf = [ipnf["pnf-id"] for ipnf in radio.get("pnf", [])] components = set(core_vims + core_pnf + radio_vims + radio_pnf + components) # Create the slice connections connections = [] while True: try: base_comp = components.pop() except KeyError: break for i in components: connections.append({"endpoints": (base_comp, i)}) # TODO: Calculate the qos level based on SLA # Find the rules to be created rules_list = [] for conn in connections: endpoints = conn["endpoints"] rule = mongoUtils.find("rules", {"source": endpoints[0], "dest": endpoints[1]}) if not rule: logger.warning(f"Didn't find connection rule from {endpoints[0]} to {endpoints[1]}") continue rule_file = rule["rule"] logger.info(f"Creating connection from {endpoints[0]} to {endpoints[1]}") subprocess.run([f"wim/rules/{rule_file}", "create", slice_data["_id"]]) rules_list.append(rule_file) conn["rules"] = rule_file slice_data = mongoUtils.get("slice", slice_data["_id"]) slice_data["connections"] = connections mongoUtils.update("slice", slice_data["_id"], slice_data) # Send the slice_id to the monitoring module if monitoring is enabled wim_monitoring = os.getenv("WIM_MONITORING", None) if wim_monitoring: # Create the Kafka Producer producer = create_producer() wim_message = {"action": "create", "slice_data": slice_data} # Send the message producer.send("wan-monitoring", value=wim_message) logger.info("Updated monitoring module")