Пример #1
0
 def send_message_to_orchestrators(self, message):
     message.source_server = self.server
     for o in self.list_orchestrator:
         log.info(''.join(
             ["Log Querying Orchestrator: ",
              str(o[0]), " ",
              str(o[1])]))
         orchestrator_server = CommunicationEntityPackage(o[0], o[1])
         self.server.connect_to_another_server(orchestrator_server)
         message.source_server = None
         answer_message = self.server.send_message_query_vnf(message)
         self.server.disconnect_send_channel()
         if isinstance(answer_message, VNFFound):
             log.info(''.join([
                 "Querying Orchestrator: ",
                 str(o[0]), " ",
                 str(o[1]), " has it"
             ]))
             return answer_message
         log.info(''.join([
             "Querying Orchestrator: ",
             str(o[0]), " ",
             str(o[1]), " does not have it"
         ]))
     return None
 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 begin_migration(self, new_vnf):
     virtual_link_new_vnf_socket = CommunicationEntityPackage(new_vnf.ip, new_vnf.port, 1)
     log.info(''.join(["New IP: ", new_vnf.ip, " New Port ", str(new_vnf.port)]))
     self.server.connect_to_another_server_virtual(virtual_link_new_vnf_socket)
     raw_text_message = RawTextMessage("Ready to migrate")
     self.server.send_message_virtual(raw_text_message)
     log.info('Waiting for ACK from new VNF')
     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)
 def __init__(self, configuration):
     self.configuration = configuration
     self.server = GenericServer(self, CommunicationEntityPackage(configuration.host(),
                                                                  configuration.port()))
     self.list_affected_vnf = []
     #TODO: This one needs to be here, due to many classes using it, it is necessary to refactor code
     self.orchestrator = configuration.get_orchestrator()
     self.migration_vnf_ip = configuration.migration_vnf()
     self.set_up_to_orchestrator(configuration.get_orchestrator(),
                                 configuration.host(),
                                 configuration.port())
     self.print_state_vnf()
Пример #5
0
    def generate_process_message(self):
        messages = list()
        with open(self.json_file, 'r') as json_file:
            data = json.load(json_file)
            for service in data['services']:

                operations = service['operations']
                # Substract operation from current server
                # number_servers = len(operations) - 1
                number_servers = len(operations)
                if 'annotation' in service['parameters']:
                    annotation_parameter = service['parameters']['annotation']
                if 'crop' in service['parameters']:
                    crop_parameter = service['parameters']['crop']
                if 'fade_in' in service['parameters']:
                    fade_in_parameter = service['parameters']['fade_in']
                if 'fade_out' in service['parameters']:
                    fade_out_parameter = service['parameters']['fade_out']
                file_parameter = service['parameters']['file']
                if 'resize' in service['parameters']:
                    resize_parameter = service['parameters']['resize']
                # print("Width: ", str(resize_parameter.width), "Height: ", str(resize_parameter.height))
                host_servers = service['host_servers']
                port_servers = service['port_servers']
                speed_factor = service['speed_factor']
                operations = self.parse_operations(operations)
                param_gen = ParameterGenerator(annotation_parameter,
                                               crop_parameter,
                                               fade_in_parameter,
                                               fade_out_parameter,
                                               file_parameter,
                                               resize_parameter)
                param_gen.generate_parameters()

                servers = list()
                for i in range(number_servers):
                    # print("Index: ", i)
                    servers.append(CommunicationEntityPackage(host_servers[i], int(port_servers[i])))

                parameters = ParameterPackage(annotation=param_gen.annotation,
                                              file_pack=param_gen.file,
                                              vnf_servers=servers,
                                              operations=operations,
                                              speed_factor=speed_factor,
                                              crop=param_gen.crop,
                                              fade_in=param_gen.fade_in,
                                              fade_out=param_gen.fade_out,
                                              resize=param_gen.resize)
                m = ProcessDataMessage(parameters)
                messages.append(m)
        return messages
 def send_migration_message_to_previous_vnf(self, previous_vnf, new_vnf, migrating_vnfs=None):
     previous_vnf_in_chain = CommunicationEntityPackage(previous_vnf.host, previous_vnf.port)
     self.server.connect_to_another_server(previous_vnf_in_chain)
     m = MigrationDeactivateMessage(new_vnf)
     migration_vnf = dict()
     migration_vnf['ip'] = self.configuration.host()
     migration_vnf['mig_ip'] = self.migration_vnf_ip
     # TODO: Changes done to
     m.migrating_vnfs.append(migration_vnf)
     if migrating_vnfs is not None:
         for vnf_mig in migrating_vnfs:
             m.migrating_vnfs.append(vnf_mig)
     self.server.send_message(m)
     log.info('Waiting for ACK previous acknowledge message')
     return pickle.loads(self.server.send_channel.recv(SocketSize.RECEIVE_BUFFER.value))
Пример #7
0
def main(argv):
    host = "127.0.0.1"
    port = ""
    name = ""
    path = ""
    experiment_name = ""

    debug = True

    if debug:
        port = "5463"
        name = "orch_2"
        path = '/first/480/exp_1_4/experiments/'
        # path = 'experiments/first/' + str(video_definition) + '/'
        experiment_name = "experiment_0.json"

    try:
        opts, args = getopt.getopt(
            argv, "h:p:n:",
            ["host=", "port=", "name=", "path=", "experiment_name="])
    except getopt.GetoptError:
        print(help_message)
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--host"):
            host = arg
        elif opt in ("-p", "--port"):
            port = arg
        elif opt in ("-n", "--name"):
            name = arg
        elif opt in ("-x", "--path"):
            path = arg
        elif opt in ("-z", "--experiment_name"):
            experiment_name = arg

    if valid_input(host, port, name):
        port = int(port)
        server = CommunicationEntityPackage(host=host, port=port)
        orchestrator = Orchestrator(server=server,
                                    name=name,
                                    path=path,
                                    experiment_name=experiment_name)
        orchestrator.serve_clients()
    else:
        print("Invalid input")
        print(help_message)
Пример #8
0
 def send_message_to_vnf(self, vnf, message):
     vnf_server = CommunicationEntityPackage(vnf[0], vnf[1])
     self.server.connect_to_another_server(vnf_server)
     self.server.send_message(message)
     self.server.disconnect_send_channel()
 def connect_to_new_server(self, vnf_server):
     self.current_server.connect_to_another_server(
         CommunicationEntityPackage(vnf_server.host, vnf_server.port))
 def connect_to_new_channel(self, vnf_server, new_message):
     log.info('Connecting to new channel')
     self.current_server.connect_to_another_server(
         CommunicationEntityPackage(vnf_server.host, vnf_server.port))
     self.current_server.send_message(new_message)
     self.current_server.disconnect_send_channel()
 def connect_to_virtual_channel_from_vnf(self, vnf_server):
     self.current_server.connect_to_another_server_virtual(
         CommunicationEntityPackage(vnf_server.host, vnf_server.port + 1))
Пример #12
0
def main(argv):
    vnf_host = "127.0.0.1"
    debug = True
    vnf_port = ""
    orchestrator_host = ""
    orchestrator_port = ""
    vnf_name = ""
    initial_seed = ""
    services = []
    topology = []
    migration_vnf = ""
    topology_migration_vnf = []
    list_of_services = []

    if debug:
        vnf_port = "4433"
        orchestrator_host = "127.0.0.1"
        orchestrator_port = "5463"
        vnf_name = "other"
        services = [50, 23, 12, 53]
        topology = [22, 20, 3.5, 13]
        initial_seed = 4
        migration_vnf = "500.0.0.1"
        topology_migration_vnf = [13, 32, 325, 313]

    try:
        opts, args = getopt.getopt(argv, "h:v:o:q:n:s:t:x:k:i",
                                   ["vnf_host=",
                                    "vnf_port=",
                                    "orq_host=",
                                    "orq_port=",
                                    "vnf_name=",
                                    "services=",
                                    "topology=",
                                    "migration_ip=",
                                    "migration_topology=",
                                    "initial="])
    except getopt.GetoptError:
        print(help_message)
        sys.exit(2)
    for opt, arg in opts:
        print(opt, ' ', arg)
        if opt in ("-h", "--vnf_host"):
            vnf_host = arg
        elif opt in ("-v", "--vnf_port"):
            vnf_port = arg
        elif opt in ("-o", "--orq_host"):
            orchestrator_host = arg
        elif opt in ("-q", "--orq_port"):
            orchestrator_port = arg
        elif opt in("-n", "--vnf_name"):
            vnf_name = arg
        elif opt in("-s", "--services"):
            services = arg
        elif opt in("-x", "--migration_topology"):
            topology_migration_vnf = arg
        elif opt in ("-k", "--migration_ip"):
            migration_vnf = arg
        elif opt in("-t", "--topology"):
            topology = arg
        elif opt in("-i", "--initial"):
            initial_seed = arg

    # print("Initial seed: ", initial_seed)

    if isinstance(topology, str):
        topology = topology.split(",")

    if isinstance(services, str):
        services = services.split(",")
    # if isinstance(limits, str):
    #     limits = limits.split(",")
    if valid_input(vnf_host, vnf_port, vnf_name, orchestrator_host, orchestrator_port):
        if len(topology_migration_vnf) == 0 or migration_vnf == '' or len(services) == 0:
            print("Invalid input")
            print(help_message)
            exit()
        orchestrator_port = int(orchestrator_port)
        topology_vnf = Topology(topology[0], topology[1], topology[2], topology[3])
        topology_vnf.ip = vnf_host
        topology_vnf.port = vnf_port
        number_of_services = int(len(services)/4)
        running_index = 0
        for i in range(number_of_services):
            print('Service: ', str(i))
            print('Running_index: ', running_index)
            service = ServicePackage(services[running_index],
                                     services[running_index + 1],
                                     services[running_index + 2],
                                     services[running_index + 3])
            running_index += 4
            list_of_services.append(service)
        # service_vnf = ServicePackage(service[0], service[1], service[2], service[3])

        orchestrator = CommunicationEntityPackage(orchestrator_host, orchestrator_port)
        vnf_host, vnf_port, vnf_name = parse_parameters(vnf_host, vnf_port, vnf_name)
        static_configuration = VnfStaticConfiguration(host=vnf_host,
                                                      port=vnf_port,
                                                      name=vnf_name,
                                                      initial=int(initial_seed))

        migration_configuration = MigrationConfiguration(migration_vnf=migration_vnf,
                                                         topology_migration_vnf=topology_migration_vnf)

        dependency_list = ['nissan', 'altima']
        vnf_configuration = VnfConfiguration(static_configuration=static_configuration,
                                             service_package=list_of_services,
                                             topology=topology_vnf,
                                             orchestrator=orchestrator,
                                             migration_configuration=migration_configuration,
                                             dependency_list=dependency_list)


        annotate_vnf = GenericVNF(vnf_configuration)
        annotate_vnf.serve_clients()
    else:
        print("Invalid input")
        print(help_message)