diff --git a/src/opticalcontroller/OpticalController.py b/src/opticalcontroller/OpticalController.py index 74fd7882689d92a654a749ea5be0c2583841a31b..9cf0f67334037e90b1d58fffb0e8a8e9ba6259db 100644 --- a/src/opticalcontroller/OpticalController.py +++ b/src/opticalcontroller/OpticalController.py @@ -15,6 +15,7 @@ import logging, time from flask import Flask from flask import render_template +from common.DeviceTypes import DeviceTypeEnum from flask_restplus import Resource, Api from google.protobuf.json_format import MessageToDict from common.proto.context_pb2 import TopologyId @@ -317,7 +318,44 @@ class GetTopology(Resource): node_dict = {} topo, nodes = readTopologyDataFromContext(topog_id) - for link in topo: + OPTICAL_ROADM_TYPES = { + DeviceTypeEnum.OPTICAL_ROADM.value, DeviceTypeEnum.EMULATED_OPTICAL_ROADM.value + } + OPTICAL_TRANSPONDER_TYPES = { + DeviceTypeEnum.OPTICAL_TRANSPONDER.value, DeviceTypeEnum.EMULATED_OPTICAL_TRANSPONDER.value + } + added_device_uuids = set() + for device in nodes: + if device.device_type in OPTICAL_ROADM_TYPES: + dev_type = "OC-ROADM" + elif device.device_type in OPTICAL_TRANSPONDER_TYPES: + dev_type = "OC-TP" + else: + continue + + dev_dic = { + "id":device.device_id.device_uuid.uuid, + #"ip":f"10.30.2.{207+i}", + #"port":"50001", + "type": dev_type, + "driver": "OpticalOC" + } + node_dict[device.name] = dev_dic + added_device_uuids.add(device.device_id.device_uuid.uuid) + #i+=1 + #print(f"refresh_optical controller optical_links_dict= {links_dict}") + #print(f"refresh_optical controller node_dict {node_dict}") + + for link in topo: + endpoint_id_a = link.link_endpoint_ids[ 0] + endpoint_id_z = link.link_endpoint_ids[-1] + + device_uuid_a = endpoint_id_a.device_id.device_uuid.uuid + if device_uuid_a not in added_device_uuids: continue + + device_uuid_z = endpoint_id_z.device_id.device_uuid.uuid + if device_uuid_z not in added_device_uuids: continue + link_dict_type = MessageToDict(link, preserving_proto_field_name=True) if "c_slots" in link_dict_type["optical_details"]: @@ -331,19 +369,6 @@ class GetTopology(Resource): links_dict["optical_links"].append(link_dict_type) - for device in nodes : - 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= {links_dict}") - #print(f"refresh_optical controller node_dict {node_dict}") - rsa = RSA(node_dict, links_dict) if debug: print(rsa.init_link_slots2()) @@ -354,4 +379,4 @@ class GetTopology(Resource): return "Error", 400 if __name__ == '__main__': - app.run(host='0.0.0.0', port=10060) + app.run(host='0.0.0.0', port=10060, debug=True) diff --git a/src/opticalcontroller/RSA.py b/src/opticalcontroller/RSA.py index da31187eb1d5c3f6f51cbbdc1c9641653b683e4b..e5cf6e4065f0daf116fa623b93f0dea36215b457 100644 --- a/src/opticalcontroller/RSA.py +++ b/src/opticalcontroller/RSA.py @@ -12,10 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging from opticalcontroller.dijkstra import Graph, shortest_path from opticalcontroller.tools import * from opticalcontroller.variables import * +LOGGER = logging.getLogger(__name__) + +def print(*args) -> None: + LOGGER.info(' '.join([str(a) for a in args])) class RSA(): def __init__(self, nodes, links):