Commit cc058320 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Optical component:

- Corrected composition of topology graph
- Ignored addition of special devices such as controllers
- Added special print method to dump log messages
parent 49aa2da8
Loading
Loading
Loading
Loading
+40 −15
Original line number Original line Diff line number Diff line
@@ -15,6 +15,7 @@
import logging, time
import logging, time
from flask import Flask
from flask import Flask
from flask import render_template
from flask import render_template
from common.DeviceTypes import DeviceTypeEnum
from flask_restplus import Resource, Api
from flask_restplus import Resource, Api
from google.protobuf.json_format import MessageToDict
from google.protobuf.json_format import MessageToDict
from common.proto.context_pb2 import TopologyId
from common.proto.context_pb2 import TopologyId
@@ -317,7 +318,44 @@ class GetTopology(Resource):
            node_dict = {}
            node_dict = {}
            topo, nodes = readTopologyDataFromContext(topog_id)
            topo, nodes = readTopologyDataFromContext(topog_id)


            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:
            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)
                link_dict_type = MessageToDict(link, preserving_proto_field_name=True)


                if "c_slots" in link_dict_type["optical_details"]:
                if "c_slots" in link_dict_type["optical_details"]:
@@ -331,19 +369,6 @@ class GetTopology(Resource):


                links_dict["optical_links"].append(link_dict_type)
                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)
            rsa = RSA(node_dict, links_dict)
            if debug:
            if debug:
                print(rsa.init_link_slots2())
                print(rsa.init_link_slots2())
@@ -354,4 +379,4 @@ class GetTopology(Resource):
            return "Error", 400
            return "Error", 400


if __name__ == '__main__':
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=10060)
    app.run(host='0.0.0.0', port=10060, debug=True)
+5 −0
Original line number Original line Diff line number Diff line
@@ -12,10 +12,15 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.


import logging
from opticalcontroller.dijkstra import Graph, shortest_path
from opticalcontroller.dijkstra import Graph, shortest_path
from opticalcontroller.tools import *
from opticalcontroller.tools import *
from opticalcontroller.variables import *
from opticalcontroller.variables import *


LOGGER = logging.getLogger(__name__)

def print(*args) -> None:
    LOGGER.info(' '.join([str(a) for a in args]))


class RSA():
class RSA():
    def __init__(self, nodes, links):
    def __init__(self, nodes, links):