Commit 8523a11d authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

PathComp component - Frontend:

- Fixed KDisjoint Algorithm Reply
parent bd3fe6ed
Loading
Loading
Loading
Loading
+65 −55
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ class KDisjointPathAlgorithm(_Algorithm):

        Path = List[Dict]
        Path_NoPath = Optional[Path] # None = no path, list = path
        self.json_reply : Dict[Tuple[str, str], List[Path_NoPath]] = dict()
        service_to_paths : Dict[Tuple[str, str], List[Path_NoPath]] = dict()

        for num_path in range(self.num_disjoint):
            algorithm.service_list = list()
@@ -189,66 +189,76 @@ class KDisjointPathAlgorithm(_Algorithm):
            for response in response_list:
                service_id = response['serviceId']
                service_key = (service_id['contextId'], service_id['service_uuid'])
                json_reply_service = self.json_reply.setdefault(service_key, list())
                json_reply_service = service_to_paths.setdefault(service_key, list())

                no_path_issue = response.get('noPath', {}).get('issue')
                if no_path_issue is not None:
                    json_reply_service.append(None)
                    continue
                if no_path_issue is not None: continue

                path_endpoints = response['path'][0]['devices']
                json_reply_service.append(path_endpoints)
                algorithm.link_list = self.remove_traversed_links(algorithm.link_list, path_endpoints)

        self.json_reply = dict()
        response_list = self.json_reply.get('response-list', [])
        for service_key,paths in service_to_paths.items():
            response = {'serviceId': {
                'contextId': service_key[0],
                'service_uuid': service_key[1],
            }}
            response['path'] = paths
            if len(paths) < self.num_disjoint:
                response['noPath'] = {'issue': 1}
            response_list.append(response)

        self.logger.debug('self.json_reply = {:s}'.format(str(self.json_reply)))

    def get_reply(self) -> PathCompReply:
        reply = PathCompReply()
        grpc_services : Dict[Tuple[str, str], Service] = {}
        grpc_connections : Dict[Tuple[int, str], Connection] = {}
        for service_key,paths in self.json_reply.items():
            context_uuid, service_uuid = service_key

            grpc_services[service_key] = self.add_service_to_reply(reply, context_uuid, service_uuid)

            for num_path,service_path_ero in enumerate(paths):
                self.logger.warning('num_path={:d}'.format(num_path))
                self.logger.warning('service_path_ero={:s}'.format(str(service_path_ero)))
                if service_path_ero is None: continue
                path_hops = eropath_to_hops(service_path_ero, self.endpoint_to_link_dict)
                self.logger.warning('path_hops={:s}'.format(str(path_hops)))
                connections = convert_explicit_path_hops_to_connections(path_hops, self.device_dict, service_uuid)
                self.logger.warning('connections={:s}'.format(str(connections)))

                for connection in connections:
                    connection_uuid,device_layer,path_hops,_ = connection

                    service_key = (context_uuid, connection_uuid)
                    grpc_service = grpc_services.get(service_key)
                    if grpc_service is not None: continue
                    grpc_service = self.add_service_to_reply(
                        reply, context_uuid, connection_uuid, device_layer=device_layer, path_hops=path_hops)
                    grpc_services[service_key] = grpc_service

                for connection in connections:
                    connection_uuid,device_layer,path_hops,dependencies = connection

                    service_key = (context_uuid, connection_uuid)
                    grpc_service = grpc_services.get(service_key)
                    if grpc_service is None: raise Exception('Service({:s}) not found'.format(str(service_key)))

                    connection_uuid = '{:s}:{:d}'.format(connection_uuid, num_path)
                    grpc_connection = grpc_connections.get(connection_uuid)
                    if grpc_connection is not None: continue
                    grpc_connection = self.add_connection_to_reply(reply, connection_uuid, grpc_service, path_hops)
                    grpc_connections[connection_uuid] = grpc_connection

                    for sub_service_uuid in dependencies:
                        sub_service_key = (context_uuid, sub_service_uuid)
                        grpc_sub_service = grpc_services.get(sub_service_key)
                        if grpc_sub_service is None:
                            raise Exception('Service({:s}) not found'.format(str(sub_service_key)))
                        grpc_sub_service_id = grpc_connection.sub_service_ids.add()
                        grpc_sub_service_id.CopyFrom(grpc_sub_service.service_id)

        return reply
#    def get_reply(self) -> PathCompReply:
#        reply = PathCompReply()
#        grpc_services : Dict[Tuple[str, str], Service] = {}
#        grpc_connections : Dict[Tuple[int, str], Connection] = {}
#        for service_key,paths in self.json_reply.items():
#            context_uuid, service_uuid = service_key
#
#            grpc_services[service_key] = self.add_service_to_reply(reply, context_uuid, service_uuid)
#
#            for num_path,service_path_ero in enumerate(paths):
#                self.logger.warning('num_path={:d}'.format(num_path))
#                self.logger.warning('service_path_ero={:s}'.format(str(service_path_ero)))
#                if service_path_ero is None: continue
#                path_hops = eropath_to_hops(service_path_ero, self.endpoint_to_link_dict)
#                self.logger.warning('path_hops={:s}'.format(str(path_hops)))
#                connections = convert_explicit_path_hops_to_connections(path_hops, self.device_dict, service_uuid)
#                self.logger.warning('connections={:s}'.format(str(connections)))
#
#                for connection in connections:
#                    connection_uuid,device_layer,path_hops,_ = connection
#
#                    service_key = (context_uuid, connection_uuid)
#                    grpc_service = grpc_services.get(service_key)
#                    if grpc_service is not None: continue
#                    grpc_service = self.add_service_to_reply(
#                        reply, context_uuid, connection_uuid, device_layer=device_layer, path_hops=path_hops)
#                    grpc_services[service_key] = grpc_service
#
#                for connection in connections:
#                    connection_uuid,device_layer,path_hops,dependencies = connection
#
#                    service_key = (context_uuid, connection_uuid)
#                    grpc_service = grpc_services.get(service_key)
#                    if grpc_service is None: raise Exception('Service({:s}) not found'.format(str(service_key)))
#
#                    connection_uuid = '{:s}:{:d}'.format(connection_uuid, num_path)
#                    grpc_connection = grpc_connections.get(connection_uuid)
#                    if grpc_connection is not None: continue
#                    grpc_connection = self.add_connection_to_reply(reply, connection_uuid, grpc_service, path_hops)
#                    grpc_connections[connection_uuid] = grpc_connection
#
#                    for sub_service_uuid in dependencies:
#                        sub_service_key = (context_uuid, sub_service_uuid)
#                        grpc_sub_service = grpc_services.get(sub_service_key)
#                        if grpc_sub_service is None:
#                            raise Exception('Service({:s}) not found'.format(str(sub_service_key)))
#                        grpc_sub_service_id = grpc_connection.sub_service_ids.add()
#                        grpc_sub_service_id.CopyFrom(grpc_sub_service.service_id)
#
#        return reply