Commit 06505bcc authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Optical Controller component:

- Fix logging framework
- Minor code fixes
- Fixed composition of link_names
parent 3c100ed4
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -434,13 +434,16 @@ class GetTopology(Resource):
            topo , nodes = readTopologyDataFromContext(topog_id)

            OPTICAL_ROADM_TYPES = {
                DeviceTypeEnum.OPTICAL_ROADM.value, DeviceTypeEnum.EMULATED_OPTICAL_ROADM.value,
                DeviceTypeEnum.OPTICAL_ROADM.value,
                DeviceTypeEnum.EMULATED_OPTICAL_ROADM.value,
            }
            OPTICAL_OPENROADM_TYPES = {
                DeviceTypeEnum.OPEN_ROADM.value, DeviceTypeEnum.EMULATED_OPEN_ROADM.value,
                DeviceTypeEnum.OPEN_ROADM.value,
                DeviceTypeEnum.EMULATED_OPEN_ROADM.value,
            }
            OPTICAL_TRANSPONDER_TYPES = {
                DeviceTypeEnum.OPTICAL_TRANSPONDER.value, DeviceTypeEnum.EMULATED_OPTICAL_TRANSPONDER.value,
                DeviceTypeEnum.OPTICAL_TRANSPONDER.value,
                DeviceTypeEnum.EMULATED_OPTICAL_TRANSPONDER.value,
                DeviceTypeEnum.NETWORK.value,
            }
            added_device_uuids = set()
+23 −9
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ class RSA():
        self.s_slot_number = 0
        self.optical_bands = {}

        
    def init_link_slots(self, testing):
        if full_links:
            for l in self.links_dict["optical_links"]:
@@ -130,6 +129,7 @@ class RSA():

            link_name = '{:s}-{:s}'.format(src_node_name, dst_node_name)
            self.link_key__to__src_dst_node_names[link_name] = (src_node_name, dst_node_name)
            link['name'] = link_name

            self.g.add_edge(src_node_name, dst_node_name, src_port, dst_port, 1)

@@ -542,6 +542,10 @@ class RSA():
            
             
    def get_fibers_forward(self, links, slots, band):
        LOGGER.info('[RSA:get_fibers_forward] Starting path forward computation')
        MSG = '[RSA:get_fibers_forward] Input parameters: links={:s}, slots={:s}, band={:s}'
        LOGGER.info(MSG.format(str(links), str(slots), str(band)))

        fiber_list = {}
        add = links[0]
        drop = links[-1]
@@ -578,17 +582,24 @@ class RSA():
                        #self.update_link(fib, slots, band)
                        self.update_link_2(fib,slots,band,link)
                        break
        print("INFO: Path forward computation completed")

        MSG = '[RSA:get_fibers_forward] Path forward computation completed: fiber_list={:s}'
        LOGGER.info(MSG.format(str(fiber_list)))
        return fiber_list

    def get_link_by_name (self, key):
    def get_link_by_name(self, key : str) -> Dict:
        for link in self.links_dict["optical_links"]:
            if link["name"] == key:
                #if debug:
                #    print(link)
                break
                return link

        MSG = '[RSA:get_link_by_name] Link with name {:s} not found. links_dict: {:s}'
        LOGGER.error(MSG.format(str(key), str(self.links_dict["optical_links"])))

        MSG = '[RSA:get_link_by_name] Link with name {:s} not found'
        raise ValueError(MSG.format(str(key)))

    def get_fiber_details(self, link_key, fiber_id):
        for link in self.links_dict["optical_links"]:
            if link["name"] == link_key:
@@ -601,6 +612,8 @@ class RSA():

    def get_fibers_backward(self, links, slots, band):
        LOGGER.info('[RSA:get_fibers_backward] Starting path backward computation')
        MSG = '[RSA:get_fibers_backward] Input parameters: links={:s}, slots={:s}, band={:s}'
        LOGGER.info(MSG.format(str(links), str(slots), str(band)))

        fiber_list = {}
        #r_drop = reverse_link(links[0], self.link_key__to__src_dst_node_names)
@@ -632,7 +645,8 @@ class RSA():
                    #fiber_list[r_l] = r_fib["ID"]
                    self.update_link(r_fib, slots, band)

        LOGGER.info('[RSA:get_fibers_backward] Path backward computation completed')
        MSG = '[RSA:get_fibers_backward] Path backward computation completed: fiber_list={:s}'
        LOGGER.info(MSG.format(str(fiber_list)))
        return fiber_list

    #function invoked for lightpaths and OB
+58 −46
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@ from common.proto.context_pb2 import DeviceId, Service
from common.tools.object_factory.Device import json_device_id
from service.service.service_handler_api.Tools import get_endpoint_matching

log = logging.getLogger(__name__)

LOGGER = logging.getLogger(__name__)


def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]])->Dict:
@@ -28,7 +28,7 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]])
    end = len(endpoints)
    i = 0
    bidir = 0
    log.debug("end={}".format(end))
    LOGGER.debug("end={}".format(end))
    while(i < end):
        endpoint = endpoints[i]
        device_uuid, endpoint_uuid = endpoint[0:2]
@@ -41,12 +41,12 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]])
            next_device_uuid, next_endpoint_uuid = next_endpoint[0:2]
            if next_device_uuid == device_uuid :
                bidir = 1
                log.info("connection is bidirectional")
                LOGGER.info("connection is bidirectional")
                entry_tuple = next_endpoint_uuid, "0"
                entries[device_uuid].append(entry_tuple)
                i = i + 1
            else:
                log.debug("connection is unidirectional")
                LOGGER.debug("connection is unidirectional")
        else:
            if not bidir:
                if i == end-1:
@@ -62,17 +62,17 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]])
                        entries[device_uuid].append(entry_tuple)
                        i = i + 1
                    else:
                        log.debug("ERROR in unidirectional connection 4")
                        LOGGER.debug("ERROR in unidirectional connection 4")
                        return {}
            else:
                log.debug("Ocheck i {}, {}, {}".format(i, i+1, end-1))
                LOGGER.debug("Ocheck i {}, {}, {}".format(i, i+1, end-1))
                if i + 1 == end-1:
                    log.debug("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid))
                    LOGGER.debug("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid))
                    #is the last node
                    entry_tuple = endpoint_uuid, "0"
                    entries[device_uuid].append(entry_tuple)
                    next_endpoint = endpoints[i+1]
                    log.debug("OCTools i+1 step {}, {}, {}".format(i+1, next_device_uuid, device_uuid))
                    LOGGER.debug("OCTools i+1 step {}, {}, {}".format(i+1, next_device_uuid, device_uuid))

                    next_device_uuid, next_endpoint_uuid = next_endpoint[0:2]
                    if next_device_uuid == device_uuid:
@@ -80,10 +80,10 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]])
                        entries[device_uuid].append(entry_tuple)
                        i = i + 1
                    else:
                        log.debug("ERROR in bidirectional connection 2")
                        LOGGER.debug("ERROR in bidirectional connection 2")
                        return entries
                else:
                    log.debug("OCTools i+1+2+3 step {}, {}, {}".format(i+1, next_device_uuid, device_uuid))
                    LOGGER.debug("OCTools i+1+2+3 step {}, {}, {}".format(i+1, next_device_uuid, device_uuid))
                    #i+1
                    next_endpoint = endpoints[i+1]
                    next_device_uuid, next_endpoint_uuid = next_endpoint[0:2]
@@ -91,8 +91,8 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]])
                        entry_tuple = endpoint_uuid, next_endpoint_uuid
                        entries[device_uuid].append(entry_tuple)
                    else:
                        log.debug("ERROR in bidirectional connection 3")
                        log.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid))
                        LOGGER.debug("ERROR in bidirectional connection 3")
                        LOGGER.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid))
                        return entries
                    #i+2
                    next_2_endpoint = endpoints[i+2]
@@ -100,14 +100,14 @@ def convert_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]])
                    #i+3
                    next_3_endpoint = endpoints[i+3]
                    next_3_device_uuid, next_3_endpoint_uuid = next_3_endpoint[0:2]
                    log.debug(f"de {device_uuid} and i {i}")
                    log.debug(f"de2 {next_2_device_uuid} and dev3 {next_3_device_uuid}")
                    LOGGER.debug(f"de {device_uuid} and i {i}")
                    LOGGER.debug(f"de2 {next_2_device_uuid} and dev3 {next_3_device_uuid}")
                    if next_2_device_uuid == next_3_device_uuid and next_3_device_uuid == device_uuid:
                        entry_tuple = next_2_endpoint_uuid, next_3_endpoint_uuid
                        entries[device_uuid].append(entry_tuple)
                        i = i + 3
                    else:
                        log.debug("ERROR in bidirection connection 4")
                        LOGGER.debug("ERROR in bidirection connection 4")
                        return {}
        i = i + 1
    return entries
@@ -121,7 +121,7 @@ def convert_or_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]
    end = len(endpoints)
    i = 0
    if bidir:
        log.info(f"i starts with {i} ")
        LOGGER.info(f"i starts with {i} ")
        i = i + 1
        while(i < end-2):
            #i
@@ -146,8 +146,8 @@ def convert_or_endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]
            #i+3
            next_3_endpoint = endpoints[i+3]
            next_3_device_uuid, next_3_endpoint_uuid = next_3_endpoint[0:2]
            log.info(f"dev {device_uuid} ")
            log.info(f"dev2 {next_2_device_uuid} dev3 {next_3_device_uuid} ")
            LOGGER.info(f"dev {device_uuid} ")
            LOGGER.info(f"dev2 {next_2_device_uuid} dev3 {next_3_device_uuid} ")
            if next_2_device_uuid == next_3_device_uuid and next_3_device_uuid == device_uuid:
                entry_tuple = next_2_endpoint_uuid, next_3_endpoint_uuid
                entries[device_uuid].append(entry_tuple)
@@ -198,7 +198,7 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int):
            entry_tuple = next_endpoint_uuid, "0"
            entries[next_device_uuid].append(entry_tuple)
        else:
            log.info("error expected device_id {}, found {}".format(device_uuid, next_device_uuid))
            LOGGER.info("error expected device_id {}, found {}".format(device_uuid, next_device_uuid))
            return {} 
        i = i + 2
        if end > 4:
@@ -207,7 +207,7 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int):
                #i
                endpoint = endpoints[i]
                device_uuid, endpoint_uuid = endpoint[0:2]
                log.debug("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid))
                LOGGER.debug("current OCTools step {}, {}, {}".format(i, device_uuid, endpoint_uuid))
                if device_uuid not in entries.keys():
                    entries[device_uuid] = []
                #i+1
@@ -217,8 +217,8 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int):
                    entry_tuple = endpoint_uuid, next_endpoint_uuid
                    entries[device_uuid].append(entry_tuple)
                else:
                    log.debug("ERROR in bidirectional ob")
                    log.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid))
                    LOGGER.debug("ERROR in bidirectional ob")
                    LOGGER.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid))
                    return {} 
                #i+2
                next_2_endpoint = endpoints[i+2]
@@ -231,7 +231,7 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int):
                    entries[device_uuid].append(entry_tuple)
                    i = i + 4
                else:
                    log.debug("ERROR in bidirection ob")
                    LOGGER.debug("ERROR in bidirection ob")
                    return {}            
        endpoint = endpoints[i]
        device_uuid, endpoint_uuid = endpoint[0:2]
@@ -247,7 +247,7 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int):
            entry_tuple = "0", next_endpoint_uuid
            entries[next_device_uuid].append(entry_tuple)
        else:
            log.debug("error expected device_id {}, found {}".format(device_uuid, next_device_uuid))
            LOGGER.debug("error expected device_id {}, found {}".format(device_uuid, next_device_uuid))
    else:
        endpoint = endpoints[i]
        device_uuid, endpoint_uuid = endpoint[0:2]
@@ -273,8 +273,8 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int):
                    entry_tuple = endpoint_uuid, next_endpoint_uuid
                    entries[device_uuid].append(entry_tuple)
                else:
                    log.debug("ERROR in bidirectional ob")
                    log.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid))
                    LOGGER.debug("ERROR in bidirectional ob")
                    LOGGER.debug("{}, {}, {}".format(i, next_device_uuid, device_uuid))
                    return {}
                i = i + 2 
        next_endpoint = endpoints[i]
@@ -287,6 +287,9 @@ def ob_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int):


def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op_mode: int):
    MSG = '[OCTools:conn_flows] endpoints={:s}, bidir={:s}, op_mode={:s}'
    LOGGER.info(MSG.format(str(endpoints), str(bidir), str(op_mode)))

    if op_mode is not None:
        entries = {}
        end = len(endpoints)
@@ -302,7 +305,7 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op
        i = i + 1
        #if bidir reading 4 endpoints per node
        if bidir:
            log.info(f"i starts with {i} ")
            LOGGER.info(f"i starts with {i} ")
            device0 , endpoint0=endpoints[0][0:2]
            device1 , endpoint1=endpoints[1][0:2]
            finalend=end-2
@@ -324,7 +327,8 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op
                    entry_tuple = endpoint_uuid, next_endpoint_uuid
                    entries[device_uuid].append(entry_tuple)
                else:
                    log.info(f"error : next_dev {next_device_uuid} dev {device_uuid} for i {i} ")
                    MSG = '[OCTools:conn_flows] error : next_dev {:s} dev {:s} for i {:d}'
                    LOGGER.error(MSG.format(str(next_device_uuid), str(device_uuid), i))
                    return {}
                #i+2

@@ -333,14 +337,15 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op
                #i+3
                next_3_endpoint = endpoints[i+3]
                next_3_device_uuid, next_3_endpoint_uuid = next_3_endpoint[0:2]
                log.info(f"dev {device_uuid} ")
                log.info(f"dev2 {next_2_device_uuid} dev3 {next_3_device_uuid} ")
                LOGGER.info(f"dev {device_uuid} ")
                LOGGER.info(f"dev2 {next_2_device_uuid} dev3 {next_3_device_uuid} ")
                if next_2_device_uuid == next_3_device_uuid and next_3_device_uuid == device_uuid:
                    entry_tuple = next_2_endpoint_uuid, next_3_endpoint_uuid
                    entries[device_uuid].append(entry_tuple)
                    i = i + 4
                else:
                    log.info(f"error : next_2_dev {next_2_device_uuid} next_3_device{next_3_device_uuid} dev {device_uuid} for i {i} ")
                    MSG = '[OCTools:conn_flows] error : next_2_dev {:s} next_3_device{:s} dev {:s} for i {:d}'
                    LOGGER.error(MSG.format(str(next_2_device_uuid), str(next_3_device_uuid), str(device_uuid), i))
                    return {}
        else:
            while(i < end-1):
@@ -358,6 +363,8 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op
                    entries[device_uuid].append(entry_tuple)
                    i = i + 2
                else:
                    MSG = '[OCTools:conn_flows] error : next_dev {:s} dev {:s} for i {:d}'
                    LOGGER.error(MSG.format(str(next_device_uuid), str(device_uuid), i))
                    return {}
        #rx tp
        endpoint = endpoints[i]
@@ -369,7 +376,8 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op
    else:
        entries = {}
        if len(endpoints) != 4:
            log.info(f"PDP : expected alien configuration with 4 endpoints ")
            MSG = '[OCTools:conn_flows] error : expected 4 endpoints for PDP, found {:d}'
            LOGGER.error(MSG.format(len(endpoints)))
            return {}
        i = 0
        device0 , endpoint0 = endpoints[0][0:2]
@@ -395,7 +403,7 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op
        #if bidir reading 4 endpoints per node
        '''
        if bidir:
            log.info(f"i starts with {i} ")
            LOGGER.info(f"i starts with {i} ")
            device0 , endpoint0=endpoints[0][0:2]
            device1 , endpoint1=endpoints[1][0:2]
            finalend=end-2
@@ -417,7 +425,7 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op
                    entry_tuple = endpoint_uuid, next_endpoint_uuid
                    entries[device_uuid].append(entry_tuple)
                else:
                    log.info(f"error : next_dev {next_device_uuid} dev {device_uuid} for i {i} ")
                    LOGGER.info(f"error : next_dev {next_device_uuid} dev {device_uuid} for i {i} ")
                    return {} 
                #i+2
                
@@ -426,14 +434,14 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op
                #i+3
                next_3_endpoint = endpoints[i+3]
                next_3_device_uuid, next_3_endpoint_uuid = next_3_endpoint[0:2]
                log.info(f"dev {device_uuid} ")
                log.info(f"dev2 {next_2_device_uuid} dev3 {next_3_device_uuid} ")
                LOGGER.info(f"dev {device_uuid} ")
                LOGGER.info(f"dev2 {next_2_device_uuid} dev3 {next_3_device_uuid} ")
                if next_2_device_uuid == next_3_device_uuid and next_3_device_uuid == device_uuid:
                    entry_tuple = next_2_endpoint_uuid, next_3_endpoint_uuid
                    entries[device_uuid].append(entry_tuple)
                    i = i + 4
                else:
                    log.info(f"error : next_2_dev {next_2_device_uuid} next_3_device{next_3_device_uuid} dev {device_uuid} for i {i} ")
                    LOGGER.info(f"error : next_2_dev {next_2_device_uuid} next_3_device{next_3_device_uuid} dev {device_uuid} for i {i} ")
                    return {}
        else:
        while(i < end-1):
@@ -460,18 +468,22 @@ def conn_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, op
        entry_tuple = endpoint_uuid, "0", 
        entries[device_uuid].append(entry_tuple)        
        '''
    return entries
    
    MSG = '[OCTools:conn_flows] entries={:s}'
    LOGGER.info(MSG.format(str(entries)))
    return entries


def endpoints_to_flows(endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, is_ob: bool, op_mode: int)->Dict:
def endpoints_to_flows(
    endpoints : List[Tuple[str, str, Optional[str]]], bidir : int, is_ob : bool, op_mode : int
) -> Dict:
    if is_ob:
        entries = ob_flows(endpoints, bidir)
    else:
        entries = conn_flows(endpoints, bidir, op_mode)
        
    return entries


def get_device_endpint_name(endpoint_uuid : str, device_uuid : str, task_executor) -> Tuple:
    device_obj = task_executor.get_device(DeviceId(**json_device_id(device_uuid)))
    endpoint_obj = get_endpoint_matching(device_obj, endpoint_uuid)