diff --git a/src/opticalcontroller/OpticalController.py b/src/opticalcontroller/OpticalController.py index 3b857374445ca8095541ed2f79b40d02d129ef20..e626cc13b411072cbc7f8b8356dba8a0a7c3751b 100644 --- a/src/opticalcontroller/OpticalController.py +++ b/src/opticalcontroller/OpticalController.py @@ -6,6 +6,7 @@ from variables import * from RSA import RSA import time , logging from common.proto.context_pb2 import TopologyId +import json @@ -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 @@ -222,26 +226,30 @@ class GetTopology(Resource): try: links_dict={"optical_links":[]} node_dict = {} - i=0 - nodes , topo = readTopologyDataFromContext(topog_id) + topo , nodes = readTopologyDataFromContext(topog_id) - for node in nodes : - links_dict["optical_links"].append(node) - for device in topo : - dic = {} - 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", - "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}") - rsa = RSA(node_dict, links_dict) - return "Done" + 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-TP", + "driver": "OpticalOC" + } + 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 rsa.links_dict except Exception as e: print(f"err {e}") return "Error", 404 @@ -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) diff --git a/src/opticalcontroller/RSA.py b/src/opticalcontroller/RSA.py index b6f9b0cbd2f90ed88808f7f5c2d81e4ef9baec3c..5fb08efab06b1f2b920d927087e21ad5373b58fe 100644 --- a/src/opticalcontroller/RSA.py +++ b/src/opticalcontroller/RSA.py @@ -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"]: diff --git a/src/opticalcontroller/tools.py b/src/opticalcontroller/tools.py index 19730525571ea09cef58494fbb4258ca11fbfdc0..5cb6d5b7e043ad3421efb39d18218e667f485125 100644 --- a/src/opticalcontroller/tools.py +++ b/src/opticalcontroller/tools.py @@ -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) @@ -153,7 +153,7 @@ def readTopologyDataFromContext(topology_id:TopologyId): nodes = topo_details.devices ctx_client.close() return topo , nodes - + def reverse_links(links): temp_links = links.copy() @@ -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 @@ -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