def send_and_receive_message_to_orchestrator(self, message): log.info("Sending Message using send_channel_orchestrator") self.connect_to_another_server(self.orchestrator.orchestrator) self.send_message(message) x = self.send_channel.recv(SocketSize.RECEIVE_BUFFER.value) answer_message = pickle.loads(x) return answer_message.data.topology
def send_message(self, message): # log.info("Sending Message using send_channel") str_log = 'Sending Message using send_channel of type:' + str( type(message)) log.info(str_log) data_string = pickle.dumps(message) self.send_channel.sendall(data_string)
def handle_switch_exchange(self): m1 = self.client_socket.recv(4096) answer_message = pickle.loads(m1) log.info(answer_message) m2 = SwitchDoneMessage(None) # TODO: This could only be a talk with self.client instead of server.send_socket self.current_server.send_message_to_socket(self.client_socket, m2)
def process_package(source, param): log.info(''.join(["SOURCE: ", source])) resized_clip = (VideoFileClip(source).fx(vfx.resize, width=param.width, height=param.height)) log.info(''.join(["Video processed correctly: "])) return resized_clip
def is_affected_vnf_already_migrating(self, vnf, migrating_vnfs): for mig_vnf in migrating_vnfs: if vnf == mig_vnf['ip']: log.info('VNF found, cycle detected!') self.update_affected_vnf(vnf, mig_vnf['mig_ip']) return True return False
def check_if_previous_vnf_must_migrate(self, v, new_vnf, migrating_vnfs=None): answer_message = self.send_migration_message_to_previous_vnf( v, new_vnf, migrating_vnfs) if isinstance(answer_message.data, Topology): m_ack = MigrationAckMessage("Ok for delete") log.info('Sending ACK message to previous') self.server.send_message(m_ack) self.server.disconnect_send_channel() # TODO: This connects to the new vnf server new_previous_vnf = CommunicationEntityPackage( answer_message.data.ip, answer_message.data.port) str_ip = str(answer_message.data.ip) log.info('Connecting to new Previous VNF: IP ' + str_ip) self.server.connect_to_another_server(new_previous_vnf) m_rec_mig = MigrationDeactivateRecursiveMessage("Do it") log.info('Send MigrationDeactivateRecursiveMessage to new VNF') self.server.send_message(m_rec_mig) log.info('Wait for ACK from new NVF') # TODO: THis is the correct way to use the constant types x = self.server.send_channel.recv(SocketSize.RECEIVE_BUFFER.value) answer_message = pickle.loads(x) str_log = 'Message received of type: ' + str(type(answer_message)) log.info(str_log)
def connect_to_another_server(self, server): # self.connect_channel_to_server(server, self.send_channel) self.send_channel = socket.socket(socket.AF_INET, socket.SOCK_STREAM) log.info(''.join( ["Send Channel Host: ", server.host, " Port: ", str(server.port)])) self.send_channel.connect((server.host, int(server.port)))
def terminate_migration_without_recursion(self): log.info('Send TerminateMessageWithoutRecursion to new VNF') m1 = TerminateMessageWithoutRecursion(None) self.server.send_message_virtual(m1) # Wait for message is power log.info('Waiting for Queues answer') x = self.server.send_virtual_channel.recv( SocketSize.RECEIVE_BUFFER.value) answer_message = pickle.loads(x) str_log = 'Received answer from new VNF TYPE: ' + str( type(answer_message)) log.info(str_log) if isinstance(answer_message, SendAllStatesMessage): queue_p = answer_message.queue_p queue_q = answer_message.queue_q queue_r = answer_message.queue_r self.configuration.get_state().exchange_queues( queue_p, queue_q, queue_r) m_ack = MigrationAckMessage('OK') log.info('Sending ACK message to previous') self.server.send_message_virtual(m_ack) self.server.disconnect_send_virtual_channel() self.server.disconnect_send_channel() log.info('Finished disconnecting all the channels') self.update_information_after_migration_to_orchestrator()
def migration_switch_message_exchange(self): m1 = SwitchMessage(None) log.info('Sending Switch message to previous VNF') self.server.send_message(m1) log.info('Waiting for ACK from previous VNF') return pickle.loads( self.server.send_channel.recv(SocketSize.RECEIVE_BUFFER.value))
def generate_operation(op): log.info(op) if op == "ANNOTATE": return MessageType.ANNOTATE if op == "BLACK_WHITE": return MessageType.BLACK_WHITE if op == "COMPOSITE": return MessageType.COMPOSITE if op == "CROP": return MessageType.CROP if op == "FADE_IN": return MessageType.FADE_IN if op == "FADE_OUT": return MessageType.FADE_OUT if op == "INVERT_COLORS": return MessageType.INVERT_COLORS if op == "MIRROR_X": return MessageType.MIRROR_X if op == "MIRROR_Y": return MessageType.MIRROR_Y if op == "PAINTING": return MessageType.PAINTING if op == "RESIZE": return MessageType.RESIZE if op == "ROTATE": return MessageType.ROTATE if op == "SPEED_UP": return MessageType.SPEED_UP return MessageType.INVALID
def process_by_command_line(self): log.info(''.join(["Searching for VNF: ", self.data.vnf_name])) vnf_local = self.current_server.orchestrator.get_local_vnf( self.data.vnf_name) if vnf_local is None: log.info("VNF not Found!") answer = VNFNotFound(self.data) log.info(''.join(["Sending message to", str(self.client_address)])) self.current_server.connect_to_another_server(self.test_server) self.current_server.send_message(answer) self.current_server.get_ack_channel() self.current_server.disconnect_send_channel() self.terminate_connections() else: log.info("Found!") self.data.topology = vnf_local[2] self.data.topology.ip = vnf_local[0] self.data.topology.port = vnf_local[1] answer = VNFFound(self.data) log.info(''.join(["Sending message to", str(self.client_address)])) self.current_server.connect_to_another_server(self.test_server) self.current_server.send_message(answer) self.current_server.get_ack_channel() self.current_server.disconnect_send_channel() self.terminate_connections()
def process_by_command_line(self): str_log = 'Received message from: ' + str( self.client_socket) + ' address: ' + str(self.client_address) log.info(str_log) self.wait_for_r_queue() self.wait_for_all_queues() self.wait_for_terminate()
def send_data_message_video_to_new_vnf(self, new_file): log.info('Sending DataVideoMessage to next VNF in chain') data_queue = self.current_server.orchestrator.configuration.state.get_all_queue_data( ) message_prepare_data_transfer = DataVideoMessage(new_file, data_queue) self.current_server.send_message(message_prepare_data_transfer) log.info('Finish sending DataVideoMessage to next VNF in chain')
def save_video(self, video, name: str, format_file="", operation=""): name = self.parse_name(name) log.info(''.join(["Ready to save file: ", name + operation])) if format_file == ".mp4": self.transcoder_mp4(video, name + operation) elif format_file == ".webm": self.transcoder_web(video, name + operation)
def process_by_command_line(self): log.info( "Extending the current queues based with the previous one to new VNF" ) self.current_server.orchestrator.configuration.get_state( ).extend_queue("P", self.queue_p) self.current_server.orchestrator.configuration.get_state( ).extend_queue("Q", self.queue_q) self.current_server.orchestrator.configuration.get_state( ).extend_queue("R", self.queue_r) log.info("Waiting for video from client") while True: conn, address = self.current_server.receive_two_communication_channel.accept( ) with open(self.video_name, 'wb') as f: log.info('receiving data...') while True: data = conn.recv(1024) if not data: break f.write(data) f.close() log.info('Successfully got the file') conn.close() log.info('Connection closed') break
def process_by_command_line(self): log.info("Extending the current queues based with the previous one to new VNF") self.current_server.orchestrator.configuration.get_state().extend_queue("P", self.queue_p) self.current_server.orchestrator.configuration.get_state().extend_queue("Q", self.queue_q) self.current_server.orchestrator.configuration.get_state().extend_queue("R", self.queue_r) # Send an ack to synchronize servers ack_message = 'Queue received' self.client_socket.send(ack_message.encode("UTF-8"))
def terminate_migration(self): m1 = TerminateMessage(None) log.info('Send TerminateMessage to new VNF') self.server.send_message_virtual(m1) self.server.disconnect_send_virtual_channel() self.server.disconnect_send_channel() log.info('Finished disconnecting all the channels') self.update_information_after_migration_to_orchestrator()
async def send_message(message): url = 'http://' + message.host + ':' + str( message.port) + '/' + message.type log.info(url) async with aiohttp.ClientSession() as session: async with session.post(url, data=message.data) as resp: str_log_encoded = await (resp.text()) log.info(str_log_encoded)
def update_information_after_migration_to_orchestrator(self): log.info('Sending update to orchestrator') self.server.connect_to_orchestrator(self.configuration.get_orchestrator()) message = UpdateVnfInfoAfterMigration(self.configuration.host(), self.configuration.host(), self.migration_vnf_ip, self.configuration.topology_migration_vnf()) self.server.send_message_to_orchestrator(message)
def collect_data_to_queue(self, queue: list): log.info('Waiting for answer from previous nfv') x = self.server.send_channel.recv(SocketSize.RECEIVE_BUFFER.value) answer_message = pickle.loads(x) str_log = 'Message received of type: ' + str(type(answer_message)) log.info(str_log) for d in answer_message.data: queue.append(d)
def connect_to_orchestrator(self, server): # self.connect_channel_to_server(server, self.send_orchestrator_channel) self.send_orchestrator_channel = socket.socket(socket.AF_INET, socket.SOCK_STREAM) log.info(''.join( ["Orchestrator Host: ", server.host, " Port: ", str(server.port)])) self.send_orchestrator_channel.connect((server.host, server.port))
def set_up_channel(self, socket_pkg, channel): log.info(''.join( ["Self Host: ", socket_pkg.host, " Port: ", str(socket_pkg.port)])) try: channel.bind((socket_pkg.host, socket_pkg.port)) channel.listen(socket_pkg.max_clients) except OSError as err: log.critical("OS error: {0}".format(err))
def send_all_queues_to_new_vnf(self): log.info( 'Sending all the queue information to the next VNF in the chain') data_queue = self.current_server.orchestrator.configuration.state.get_all_queue_data( ) message_all_queue = AllQueueInformation(data_queue) self.current_server.send_message(message_all_queue) self.current_server.get_ack_channel() log.info('Finish sending all the queue information!')
def send_message_query_vnf(self, message): # log.info("Sending Message using send_channel") str_log = 'Sending Message using send_channel of type: ' + str( type(message)) log.info(str_log) data_string = pickle.dumps(message) self.send_channel.send(data_string) answer_message = self.wait_for_reply_two_communication_channel() return answer_message
def send_video_to_next_vnf_in_chain(self, new_file): log.info('Sending serialized video as bytes...') filename = new_file f = open(filename, 'rb') l_buffer = f.read(1024) while l_buffer: self.current_server.send_virtual_channel.send(l_buffer) l_buffer = f.read(1024) f.close() log.info('Done sending')
def process_by_message(self, parameter: ParameterPackage): log.info(''.join( ["Processing message...", parameter.file_pack.get_vnf_name])) source = parameter.file_pack.get_vnf_name video = self.process_package(source) source_no_format = source[:-4] operation_name = "_mirrorX" self.save_video(video, source_no_format, parameter.file_pack.format, operation_name) return source_no_format + operation_name + parameter.file_pack.format
def send_information_to_next_vnf_in_chain(self, new_file): log.info(''.join([ "LEN SEND: ", str(len(self.parameters.vnf_servers)), " IDX: ", str(self.current_op_index) ])) self.generate_new_message(new_file) # self.send_all_queues_to_new_vnf() self.send_data_message_video_to_new_vnf(new_file) self.send_video_to_next_vnf_in_chain(new_file)
def process_package(source: str): log.info(''.join(["SOURCE: ", source])) main_clip = VideoFileClip(source).margin(10) clip2 = main_clip.fx(vfx.mirror_x) clip3 = main_clip.fx(vfx.mirror_y) clip4 = main_clip.resize(0.60) # downsize 60% final_clip = clips_array([[main_clip, clip2], [clip3, clip4]]) final_clip.resize(width=480) return final_clip
def get_operation_by_id_and_original_service_id(self, service_id, service_original_id, sender_service_id): for operation in self.pending_operations: # log.info('Pending operation: ' + str(operation)) if self.is_single_scale_operation(operation, service_original_id, service_id, sender_service_id): return operation elif self.is_operation_original_service_and_service_received_is_a_pending_operation( operation, service_original_id, service_id): log.info( 'Operation is original service and service received is a pending operation' ) # log.info('Removing from Pending operation: ' + str(operation)) return operation elif self.is_received_service_a_dependency_of_operation_with_same_original_service_id_comes_from_same_sender( operation, service_original_id, service_id, sender_service_id): log.info( 'Service is a dependency with the same original service and sender' ) # log.info('Removing from Pending operation: ' + str(operation)) return operation elif self.is_received_service_a_original_dependency_from_the_scale_request( operation, service_original_id, service_id, sender_service_id): return operation if len(self.pending_operations) == 0: empty_operation = dict() empty_operation['id'] = '' empty_operation['type'] = '' empty_operation['first_operation'] = True empty_operation['pending_operations'] = list() str_log = 'Operation of ' + service_id[ 0:8] + ' originally from ' + service_original_id[ 0:8] + ' not found!' log.info(str_log) return empty_operation if self.vnfc_is_not_a_dependency_from_operation( operation, service_original_id, service_id, sender_service_id): empty_operation = dict() empty_operation['id'] = '' empty_operation['type'] = '' empty_operation['first_operation'] = True empty_operation['pending_operations'] = list() str_log = 'Operation of ' + service_id[ 0:8] + ' originally from ' + service_original_id[ 0:8] + ' not found!' log.info(str_log) return empty_operation log.info('None, serious error why!?') return None
async def send_grant_messages_to_dependencies(self, data_list): asynchronous_tasks = list() for data in data_list: log.info('Sending grant to ' + data['vnf_component_to_scale_id'][0:8]) scaling_message = GrantLCMMessage(host=data['host_dependency'], port=data['port_dependency'], data=data) self.orchestrator.increment_sent_messages() asynchronous_tasks.append(send_message(scaling_message)) await asyncio.gather(*asynchronous_tasks)