Loading src/opticalcontroller/OpticalController.py +32 −24 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ from variables import * from RSA import RSA import time , logging from common.proto.context_pb2 import TopologyId import json Loading Loading @@ -200,21 +201,24 @@ class GetBand(Resource): class GetFlows(Resource): @staticmethod def get(): global links_dict #global links_dict global rsa links = rsa.links_dict try: if debug: print(links_dict) return links_dict, 200 print(links) return links, 200 except: return "Error", 404 @optical.route('/GetTopology/<path:context_id>/<path:topology_id>',methods=['GET']) @optical.response(200, 'Success') @optical.response(404, 'Error, not found') class GetTopology(Resource): @staticmethod def get(context_id:str,topology_id:str): global rsa topog_id = TopologyId() topog_id.topology_uuid.uuid=topology_id topog_id.context_id.context_uuid.uuid=context_id Loading @@ -222,26 +226,30 @@ class GetTopology(Resource): try: links_dict={"optical_links":[]} node_dict = {} i=0 nodes , topo = readTopologyDataFromContext(topog_id) for node in nodes : links_dict["optical_links"].append(node) for device in topo : dic = {} dic= { topo , nodes = readTopologyDataFromContext(topog_id) for link in topo: links_dict["optical_links"].append(link) #print(link["optical_details"]["c_slots"]) for device in nodes : dev_dic = {} dev_dic = { "id":device.device_id.device_uuid.uuid, "ip":f"10.30.2.{207+i}", "port":"50001", "type":"OC-ROADM" if device.device_type =="optical-roadm" else "OC-ROADM", #"ip":f"10.30.2.{207+i}", #"port":"50001", "type":"OC-ROADM" if device.device_type =="optical-roadm" else "OC-TP", "driver": "OpticalOC" } node_dict[device.name]=dic i+=1 print(f"refresh_opticacontroller optical_links_dict {links_dict}") print(f"refresh_opticacontroller node_dict {node_dict}") node_dict[device.name]=dev_dic #i+=1 print(f"refresh_optical controller optical_links_dict= {json.dump(links_dict)}") print(f"refresh_optical controller node_dict {json.dump(node_dict)}") rsa = RSA(node_dict, links_dict) return "Done" return rsa.links_dict except Exception as e: print(f"err {e}") return "Error", 404 Loading @@ -252,7 +260,7 @@ class GetTopology(Resource): if __name__ == '__main__': nodes_dict, links_dict = readTopologyData(nodes_json, topology_json) #nodes_dict, links_dict = readTopologyData(nodes_json, topology_json) #rsa = RSA(nodes_dict, links_dict) Loading src/opticalcontroller/RSA.py +1 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ class RSA(): self.s_slot_number = 0 self.optical_bands = {} print(f"node_ctxt {nodes} links_ctxt {links}") def init_link_slots(self, testing): if not testing: for l in self.links_dict["optical_links"]: Loading src/opticalcontroller/tools.py +6 −6 Original line number Diff line number Diff line Loading @@ -143,9 +143,9 @@ def readTopologyData(nodes, topology): nodes_file.close() topo_file.close() return nodes, topo def readTopologyDataFromContext(topology_id:TopologyId): def readTopologyDataFromContext(topology_id:TopologyId): ctx_client = ContextClient() ctx_client.connect() topo_details = ctx_client.GetTopologyDetails(topology_id) Loading @@ -167,7 +167,7 @@ def reverse_links(links): def get_links_from_node(topology, node): result = {} for link in topology["links"]: for link in topology["optical_links"]: if "{}-".format(node) in link["name"]: result[link["name"]] = link return result Loading @@ -175,7 +175,7 @@ def get_links_from_node(topology, node): def get_links_to_node(topology, node): result = {} for link in topology["links"]: for link in topology["optical_links"]: if "-{}".format(node) in link["name"]: result[link["name"]] = link return result Loading Loading
src/opticalcontroller/OpticalController.py +32 −24 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ from variables import * from RSA import RSA import time , logging from common.proto.context_pb2 import TopologyId import json Loading Loading @@ -200,21 +201,24 @@ class GetBand(Resource): class GetFlows(Resource): @staticmethod def get(): global links_dict #global links_dict global rsa links = rsa.links_dict try: if debug: print(links_dict) return links_dict, 200 print(links) return links, 200 except: return "Error", 404 @optical.route('/GetTopology/<path:context_id>/<path:topology_id>',methods=['GET']) @optical.response(200, 'Success') @optical.response(404, 'Error, not found') class GetTopology(Resource): @staticmethod def get(context_id:str,topology_id:str): global rsa topog_id = TopologyId() topog_id.topology_uuid.uuid=topology_id topog_id.context_id.context_uuid.uuid=context_id Loading @@ -222,26 +226,30 @@ class GetTopology(Resource): try: links_dict={"optical_links":[]} node_dict = {} i=0 nodes , topo = readTopologyDataFromContext(topog_id) for node in nodes : links_dict["optical_links"].append(node) for device in topo : dic = {} dic= { topo , nodes = readTopologyDataFromContext(topog_id) for link in topo: links_dict["optical_links"].append(link) #print(link["optical_details"]["c_slots"]) for device in nodes : dev_dic = {} dev_dic = { "id":device.device_id.device_uuid.uuid, "ip":f"10.30.2.{207+i}", "port":"50001", "type":"OC-ROADM" if device.device_type =="optical-roadm" else "OC-ROADM", #"ip":f"10.30.2.{207+i}", #"port":"50001", "type":"OC-ROADM" if device.device_type =="optical-roadm" else "OC-TP", "driver": "OpticalOC" } node_dict[device.name]=dic i+=1 print(f"refresh_opticacontroller optical_links_dict {links_dict}") print(f"refresh_opticacontroller node_dict {node_dict}") node_dict[device.name]=dev_dic #i+=1 print(f"refresh_optical controller optical_links_dict= {json.dump(links_dict)}") print(f"refresh_optical controller node_dict {json.dump(node_dict)}") rsa = RSA(node_dict, links_dict) return "Done" return rsa.links_dict except Exception as e: print(f"err {e}") return "Error", 404 Loading @@ -252,7 +260,7 @@ class GetTopology(Resource): if __name__ == '__main__': nodes_dict, links_dict = readTopologyData(nodes_json, topology_json) #nodes_dict, links_dict = readTopologyData(nodes_json, topology_json) #rsa = RSA(nodes_dict, links_dict) Loading
src/opticalcontroller/RSA.py +1 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ class RSA(): self.s_slot_number = 0 self.optical_bands = {} print(f"node_ctxt {nodes} links_ctxt {links}") def init_link_slots(self, testing): if not testing: for l in self.links_dict["optical_links"]: Loading
src/opticalcontroller/tools.py +6 −6 Original line number Diff line number Diff line Loading @@ -143,9 +143,9 @@ def readTopologyData(nodes, topology): nodes_file.close() topo_file.close() return nodes, topo def readTopologyDataFromContext(topology_id:TopologyId): def readTopologyDataFromContext(topology_id:TopologyId): ctx_client = ContextClient() ctx_client.connect() topo_details = ctx_client.GetTopologyDetails(topology_id) Loading @@ -167,7 +167,7 @@ def reverse_links(links): def get_links_from_node(topology, node): result = {} for link in topology["links"]: for link in topology["optical_links"]: if "{}-".format(node) in link["name"]: result[link["name"]] = link return result Loading @@ -175,7 +175,7 @@ def get_links_from_node(topology, node): def get_links_to_node(topology, node): result = {} for link in topology["links"]: for link in topology["optical_links"]: if "-{}".format(node) in link["name"]: result[link["name"]] = link return result Loading