diff --git a/src/opticalcontroller/OpticalController.py b/src/opticalcontroller/OpticalController.py index e626cc13b411072cbc7f8b8356dba8a0a7c3751b..0e1e5c3f55522d06b3c6e057913d3f9e4df2d215 100644 --- a/src/opticalcontroller/OpticalController.py +++ b/src/opticalcontroller/OpticalController.py @@ -5,11 +5,12 @@ from tools import * from variables import * from RSA import RSA import time , logging -from common.proto.context_pb2 import TopologyId +from common.proto.context_pb2 import TopologyId , OpticalLink import json - - - +from google.protobuf.message import Message +from google.protobuf.json_format import MessageToDict +global rsa +global links_dict rsa = None @@ -201,9 +202,11 @@ class GetBand(Resource): class GetFlows(Resource): @staticmethod def get(): - #global links_dict global rsa - links = rsa.links_dict + #global links_dict + links = None + if rsa is not None : + links = rsa.links_dict try: if debug: print(links) @@ -218,21 +221,24 @@ class GetFlows(Resource): class GetTopology(Resource): @staticmethod def get(context_id:str,topology_id:str): + logging.info("get the request") global rsa topog_id = TopologyId() topog_id.topology_uuid.uuid=topology_id topog_id.context_id.context_uuid.uuid=context_id - - try: - links_dict={"optical_links":[]} - node_dict = {} - topo , nodes = readTopologyDataFromContext(topog_id) - - for link in topo: - links_dict["optical_links"].append(link) - #print(link["optical_details"]["c_slots"]) + print(f"topog_id {topog_id}") + try: + links_dict={"optical_links":[]} + node_dict = {} + topo , nodes = readTopologyDataFromContext(topog_id) + + for link in topo: + link_dict_type = MessageToDict(link, preserving_proto_field_name=True) + links_dict["optical_links"].append(link_dict_type) + + - for device in nodes : + for device in nodes : dev_dic = {} dev_dic = { "id":device.device_id.device_uuid.uuid, @@ -243,27 +249,22 @@ class GetTopology(Resource): } 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)}") + #print(f"refresh_optical controller optical_links_dict= {links_dict}") + #print(f"refresh_optical controller node_dict {node_dict}") + + rsa = RSA(node_dict, links_dict) - rsa = RSA(node_dict, links_dict) - - return rsa.links_dict + return "ok" ,200 except Exception as e: print(f"err {e}") - return "Error", 404 + return "Error", 400 if __name__ == '__main__': - - - #nodes_dict, links_dict = readTopologyData(nodes_json, topology_json) - - - #rsa = RSA(nodes_dict, links_dict) - #print(rsa.init_link_slots2(testing)) + + app.run(host='0.0.0.0', port=10060) diff --git a/src/opticalcontroller/RSA.py b/src/opticalcontroller/RSA.py index 5fb08efab06b1f2b920d927087e21ad5373b58fe..78b027a3d53dc98d95bc8c8515ae5357d5d0aeef 100644 --- a/src/opticalcontroller/RSA.py +++ b/src/opticalcontroller/RSA.py @@ -17,7 +17,7 @@ class RSA(): self.l_slot_number = 0 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: @@ -86,7 +86,9 @@ class RSA(): self.g.printGraph() def initGraph2(self): + self.g = dijsktra.Graph() + for n in self.nodes_dict: self.g.add_vertex(n) for l in self.links_dict["optical_links"]: diff --git a/test.py b/test.py index f8e77b70bf32d2fcc89df82ac0c59969313f5b51..47133fe9fd323d86af1ff9e6f5f3601b6f3f437a 100644 --- a/test.py +++ b/test.py @@ -83,15 +83,19 @@ def extract_value (xml_data): else: print(" element not found.") -def main () : - with manager.connect(**device) as m: - # Perform operations on the remote machine using the 'm' object - # For example, you can retrieve the running configuration: - #result =m.edit_config(target='running',config=edit_config) - running_config = m.get_config('running').data_xml +if __name__ == '__main__': + # with manager.connect(**device) as m: + # # Perform operations on the remote machine using the 'm' object + # # For example, you can retrieve the running configuration: + # #result =m.edit_config(target='running',config=edit_config) + # running_config = m.get_config('running').data_xml - #extract_roadm_ports(running_config) - x,y= [1,3] - print (x) - - + # #extract_roadm_ports(running_config) + # x,y= [1,3] + # print (x) + nodes = { + "t13":{"name":"t1","value":1}, + "t2":{"name":"t2","value":2} + } + for n in nodes : + print (n)